wasAsked.

How do you test an ASP.NET Core endpoint across validation, authorization, database, and external-service boundaries?

Razorpay · Full Stack Developer · 3-4-years · technical

Published

Year not specified · .NET, ASP.NET Core, Testing

Community answers

Posted by wasAsked editorial collection

Test an endpoint through the real ASP.NET Core pipeline with WebApplicationFactory so routing, model binding, filters, authentication, serialization, and persistence participate. Example: var client = factory.CreateClient(); client.DefaultRequestHeaders.Authorization = TestToken.For(user); var response = await client.PostAsJsonAsync("/api/orders", request); Assert.Equal(HttpStatusCode.Created, response.StatusCode); Use an isolated real database compatible with production, reset it between tests, and seed only through supported boundaries where practical. Cover success, invalid input, unauthenticated/forbidden access, duplicate/idempotent calls, concurrency, dependency failure, and RestaurantId/OutletId isolation. Assert response contracts and database state, not private implementation calls.

Backbencher Developer · · 0 likes

Sign in to add your answer

Related interview topics