- Location:
apps/fakelogger-demo(app) andapps/fakelogger-demo.Test(tests). - Purpose: demonstrates capturing and asserting on ILogger output from
MyServicein unit tests.MyServicelogs a start message and a "Work done" message with a structuredResultvalue (expected value: 42). - Test approach: the tests use the official testing helpers from the
Microsoft.Extensions.Diagnostics.Testingpackage (exposed underMicrosoft.Extensions.Logging.Testing) — specificallyFakeLogger<T>andFakeLogRecord— to collect emitted log records and assert on level, message and structured state.
How to run the demo tests locally (PowerShell):
# run tests for the fakelogger demo
dotnet test .\apps\fakelogger-demo.Test\fakelogger-demo.Test.csproj --no-restore --verbosity minimalNotes:
- Ensure you have a .NET SDK compatible with the projects' TargetFramework (check the projects' csproj files).
- If you modify logging or test packages, run
dotnet restorebefore runningdotnet test. - The repository previously included a local FakeLogger shim during iteration; tests now use the official
Microsoft.Extensions.Diagnostics.Testinghelpers. If tests fail, verify the test project's package references and the project reference to the app are intact.
Considering #240, there is a 2 part project, namely dotnet-fe-auth and angular-auth-example that represent the option that would normally be a dotnet new creation, namely dotnet new angular -o Project. However, this is a project that would be intertwined with controllers and an old angular version, which makes it hard to maintain both. Second, there is no real interaction between the two itself... you have to still create the services to call the controller api.
This combination has nswag in between, creating said interaction.
dotnet-fe-auth is a .NET backend project that provides authentication services using JWT tokens. It includes endpoints for validating tokens and integrates with FastEndpoints for rapid API development. The project is configured to use symmetric key encryption for JWT tokens.
- JWT Authentication
- Token Validation Endpoint
- FastEndpoints Integration
- Swagger Documentation
- Navigate to the
dotnet-fe-authdirectory. - Run
dotnet buildto build the project. - Run
dotnet runto start the server. - The server will be available at
https://localhost:5001.
angular-auth-example is an Angular frontend project that demonstrates authentication using JWT tokens. It includes a login form, protected routes, and integration with the dotnet-fe-auth backend for token validation.
- Login Form
- JWT Token Storage in LocalStorage
- Protected Routes with Angular Guards
- HTTP Interceptor for Adding JWT Token to Requests
- Before ever running, make sure you ran the
npm run dev-certcommand in the root of the repository to generate a development certificate. - Run
npx nx serve angular-auth-exampleto start the development server. - The application will be available at
https://localhost:4200.
This app is dependant on the dotnet-fe-auth backend project to be running in order to authenticate users and validate tokens.