Victor H
WireMock.NET match on domain
Hello. I want to use WireMock.NET to test my program.
What is a good way I can make sure that each request I send out with a specific HTTP client gets sent to the WireMock server? So for instance if I send a request to
domain1.com
and domain2.com
I want to be able to catch these in WireMock.
Note, I have logic in my application that is dependent on the domain name and thus I can't configure the domain name as a configurable value.
Options I have considered:
1. Add a DelegatingHandler
that rewrites the request URL to WireMock's localhost
URL and port. Then use the Host header to match requests in WireMock.
2. Customize the connection behaviour by writing our own SocketsHttpHandler
that connect to the WireMock server.
3. Configure proxy setting on the HTTP client by creating a HttpClientHandler
.
Can you give me any recommendation on a good approach?1 replies
Generic static factories
Hello. I have the following interface:
This works well but I want to have a specific type of strongly typed id's of type
AggregateId
which must have an underlying backing type of Guid
, especially a version 7 guid. So basically how can I have default implementations for abstract records?
I tried this but infinite recursion.
13 replies
Tighter type constraint
Hello.
Let's say I have the following
and then maybe I have concrete like:
I can do the following now for type-safety, i.e., that to get
Order
you must provide an OrderId
and you can't mistakenly provide the wrong strongly typed ID:
However, this makes for quite a verbose API, is it possible somehow to constrain this so it is possible that LoadAggregate<Order>(orderId)
is only valid if orderId
is an OrderId
and not say ProductId
?10 replies
Parsing data from several sources into a common format.
I have several data sources that I get data from that I must parse into a common format.
Say this is the common format (simplified example):
One approach would be to set up something like a
public record Source1ProductDto
and use annotations like JsonPropertyName
for each data source and let System.Text.JsonSerializer
handle it. However, for more complex types like Price
I might need to combine data from several fields of the original data to parse it into my custom format. My current approach is to use some type of strategy pattern for each field by using this interface:
then I do this (simplified parsing for illustration purpose):
You get the point for PriceParser2.
Can you give me advice on how to improve? Possibly how to leverage .NET strengths better.32 replies
Configuration of Testcontainer, WebApplicationFactory and ConfigurationSource in ASP.NET Core.
Hi, I'm trying to figure out a nice approach to setup my tests. I am writing an application where I am using the the Options pattern in my
Program.cs
to setup some connections option:
where for instance:
In my tests where I am using WebApplicationFactory
together with Testcontainers I want to improve my setup. Can you offer me any advice on how to improve my setup code (next message).7 replies