Sagar viradiya
How to write Testcases with ServiceProvider.GetKeyedService method in .Net 8?
DI Registeration
services.AddKeyedTransient<IReceivableDocument,BuyerReceivableDocumentStrategy>(ReceivableCompanyType.Buyer);
services.AddKeyedTransient<IReceivableDocument,AuctionReceivableDocumentStrategy>(ReceivableCompanyType.Auction);
Class using Service
public class TestReceivableCommandHandler(IServiceProvider receivableDocumentResolver)
: IRequestHandler<CreateReceivableCommand, Result<Unit, ValidationException>>
{
public async Task<Result<Unit, ValidationException>> Handle(CreateReceivableCommand request,
CancellationToken cancellationToken)
{
var receivableStrategy =
receivableDocumentResolver.GetRequiredKeyedService<IReceivableDocument>(
(ReceivableCompanyType)request.CustomerTypeID);
return Result<Unit, ValidationException>.SucceedWith(Unit.Value);
}
}
While running unit test cases, I am getting below error It seems we can not moq Extension methods. if it is case, how we can unit test any KeyedService registration?
Unsupported expression: a => a.GetKeyedService<IReceivableDocument>((object)It.IsAny<ReceivableCompanyType>())
Extension methods (here: ServiceProviderKeyedServiceExtensions.GetKeyedService) may not be used in setup / verification expressions.7 replies
Trunk based development?
we are currently using Git flow strategy for pusing code in production. we have development, staging, production branch. we have multiple teams and working on different microservices.
Now we want to adopt trunk based development. but we have read few documents. but main concerns are:
1. How code review will work?
2. On which stage QA should test?
3. How feture flag works?
4. How code can be reverted, if feature does not work in production?
5. How versioning works?
6 replies
❔ Low code solution for processing Liquid template
is there any opensource solution which stores templates (Liquid template) and provides replaced template with placeholders, we have lots of templates per Events but we don't want to write logic in our code.
I
28 replies
Best CSV reader/writer library?
Best CSV reader/writer library for reading 400 MB file and map into list of Objects, No need of manually mapping.
I have used https://joshclose.github.io/CsvHelper/, but it gets too much memory and very slow.
1 replies