using System.Collections.Generic; using System.Net; using System.Net.Http.Headers; using System.Net.Http.Json; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc.Testing; using TestWeb.Infra; using TestWeb.Core.Users; namespace TestWeb.Tests.Core.Users; public class UserModuleTests : IClassFixture { private readonly HttpClient client; public UserModuleTests(TestFixture fixture) { client = fixture.Client; } [Fact] public async Task Base() { // Create var createRequest = new CreateUserEndpoint.Request("Test"); var createCall = await client.PostAsJsonAsync( UserModule.Prefix, createRequest, cancellationToken: TestContext.Current.CancellationToken ); Assert.Equal(HttpStatusCode.OK, createCall.StatusCode); var createResponse = await createCall.Content .ReadFromJsonAsync(cancellationToken: TestContext.Current.CancellationToken); Assert.NotNull(createResponse); // Get var getListCall = await client.GetAsync( UserModule.Prefix, TestContext.Current.CancellationToken ); Assert.Equal(HttpStatusCode.OK, getListCall.StatusCode); var getCall = await client.GetAsync( $"{UserModule.Prefix}/{createResponse.Id}", TestContext.Current.CancellationToken ); Assert.Equal(HttpStatusCode.OK, getCall.StatusCode); // Update var updateRequest = new UpdateUserEndpoint.Request("Test"); var updateCall = await client.PutAsJsonAsync( $"{UserModule.Prefix}/{createResponse.Id}", updateRequest, cancellationToken: TestContext.Current.CancellationToken ); Assert.Equal(HttpStatusCode.OK, updateCall.StatusCode); // Delete var deleteCall = await client.DeleteAsync( $"{UserModule.Prefix}/{createResponse.Id}", TestContext.Current.CancellationToken ); Assert.Equal(HttpStatusCode.OK, deleteCall.StatusCode); // Not found var deleteCallNotFound = await client.DeleteAsync( $"{UserModule.Prefix}/{createResponse.Id}", TestContext.Current.CancellationToken ); Assert.Equal(HttpStatusCode.NotFound, deleteCallNotFound.StatusCode); var getCallNotFound = await client.GetAsync( $"{UserModule.Prefix}/{createResponse.Id}", TestContext.Current.CancellationToken ); Assert.Equal(HttpStatusCode.NotFound, getCallNotFound.StatusCode); } }