Unit Testing complex validations (study)
Some validations are complex. Let’s explore how .NET data annotation validation and FluentValidation can be combined and (unit) tested.
Read the article Unit Testing complex validations (study)Some validations are complex. Let’s explore how .NET data annotation validation and FluentValidation can be combined and (unit) tested.
Read the article Unit Testing complex validations (study)Ever since I wrote the blog “Is One Of” and “Is Not One Of” validation attributes, I’ve wondered if there is anything better for class validation. I mean: validating individual properties is fine, but usually the more interesting stuff is the validation of a combination of members.
Read the article Let’s combine Data Annotation Validation with FluentValidationWhat I love a about data annotations and validation attributes, is that the validation rules are defined very close to the class: when you open it up, you can view all the rules. The ApiController will even automatically do model validation. This is great, but I like some defense it depth; I want to be able to use those validations in my business service as well. I should not have to trust input. Let’s explore how we can make that happen.
Read the article Data Annotation validation with dependency injection in a business serviceAfter implementing Kiota clients with resilience, I felt the need to spend some time on unit testing them. The Kiota docs on unit testing uses NSubstitute to override the response of the adapter. After some testing (pun intended), I did not feel satisfied with the results; we should be able to use the “normal” way of testing an HttpClient, right? In this blog, I’ll show how to use the RichardSzalay.MockHttp package together with Kiota.
Read the article Kiota Client Unit Testing: mocking dataMy new years resolution is to generate HTTP clients for services with an Open API spec. Microsoft released Kiota, a tool that generates C# classes from specs. In this blog, I’ll be looking at dependency injection and resilience.
Read the article Kiota, dependency injection and resilienceI was working on a project that needed to call multiple webservices, so I wanted to add resilience. Luckily, Microsoft has created a HTTP Resilience package as a wrapper for Polly, adding sensible defaults. In this blog I’ll explore how easy it is to add the new package to our services, including deferring to configuration.
Read the article Implementing HTTP Resilience by MicrosoftLet’s add JWT tokens to protect our API endpoints. Connecting services will supply their public keys, so we can validate their JWT tokens. We’ll use a configuration file to map tokens to local policies to restrict access to certain endpoints.
Read the article Simple JWT Access Policies for API security in .NETConsole applications are alive and kicking. Setting them up might be a bit hard. In this article I’ll explore how to create a .NET console application that provides commands using the new System.CommandLine package. This will provide arguments to command mapping out of the box. I’ll be showing how to combine it with dependency injection for even more power ⚡.
Read the article .NET Console Application with injectable commandsAt Wehkamp we’ve been using ASP.NET for a long time. Containers brought .NET with us to our microservices architecture. We used a shell script in a special build container to build our service. Today we’ll discuss how we turned that shell script into a multi stage build Dockerfile.
Read the article Rethinking our ASP.NET Docker CIWhen working on a project, the need arose for better handling of enums decorated with a [Flag] attribute. In a previous article we explored how to use Handlebars.NET to generate JSON strings. In this article we’ll build further on that generator to add support for enums. We will also move away from the static JsonHandlebarsDotNet to an injectable version.
Read the article Handlebars.Net: Fun with [Flags]