This commit is contained in:
commit
0e79a8eb5e
43 changed files with 1282 additions and 0 deletions
79
tests/Core/Users/UserModuleTests.cs
Normal file
79
tests/Core/Users/UserModuleTests.cs
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
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<TestFixture>
|
||||
{
|
||||
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<CreateUserEndpoint.Response>(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);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue