© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•17mo ago•
32 replies
mellowzippy

Unit Testing ASP.NET async api service

Okay. I am trying to make a unit test for my Customer Service. I tried starting with the Read operation which looks like this in my service:

public async Task<Customer> Read(int customerId)
{
    return await _context.Customers
        .FirstOrDefaultAsync(c => c.CustomerId == customerId);
}
public async Task<Customer> Read(int customerId)
{
    return await _context.Customers
        .FirstOrDefaultAsync(c => c.CustomerId == customerId);
}

I tried using this as a guide: https://learn.microsoft.com/en-us/ef/ef6/fundamentals/testing/mocking#testing-query-scenarios
Testing with a mocking framework - EF6
Testing with a mocking framework in Entity Framework 6
Testing with a mocking framework - EF6
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Unit Testing Classes with Dependency Injection (ASP.NET Core)
C#CC# / help
3y ago
✅ Testing in ASP.NET Core Web Api
C#CC# / help
9mo ago
❔ CRUD API ASP.Net
C#CC# / help
3y ago
.NET 6 ASP.NET API [Answered]
C#CC# / help
4y ago