Watch
1
0
Fork
You've already forked test-web
0
test-web/tests/Core/Jobs/JobModuleTests.cs
Chris Dill 0e79a8eb5e
All checks were successful
Build / build (push) Successful in 52s
Initial commit
2026-05-30 12:26:50 +01:00

83 lines
2.7 KiB
C#

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.Jobs;
namespace TestWeb.Tests.Core.Jobs;
public class JobModuleTests : IClassFixture<TestFixture>
{
private readonly HttpClient client;
public JobModuleTests(TestFixture fixture)
{
client = fixture.Client;
}
[Fact]
public async Task Base()
{
// Create
var createRequest = new CreateJobEndpoint.Request(
"Client name", "Pickup", "Dropoff"
);
var createCall = await client.PostAsJsonAsync(
JobModule.Prefix,
createRequest,
cancellationToken: TestContext.Current.CancellationToken
);
Assert.Equal(HttpStatusCode.OK, createCall.StatusCode);
var createResponse = await createCall.Content
.ReadFromJsonAsync<CreateJobEndpoint.Response>(
cancellationToken: TestContext.Current.CancellationToken
);
Assert.NotNull(createResponse);
// Get
var getListCall = await client.GetAsync(
JobModule.Prefix,
TestContext.Current.CancellationToken
);
Assert.Equal(HttpStatusCode.OK, getListCall.StatusCode);
var getCall = await client.GetAsync(
$"{JobModule.Prefix}/{createResponse.Id}",
TestContext.Current.CancellationToken
);
Assert.Equal(HttpStatusCode.OK, getCall.StatusCode);
// Update
var updateRequest = new UpdateJobEndpoint.Request(
"Client name", "Pickup update", "Dropoff update");
var updateCall = await client.PutAsJsonAsync(
$"{JobModule.Prefix}/{createResponse.Id}", updateRequest,
cancellationToken: TestContext.Current.CancellationToken
);
Assert.Equal(HttpStatusCode.OK, updateCall.StatusCode);
// Delete
var deleteCall = await client.DeleteAsync(
$"{JobModule.Prefix}/{createResponse.Id}",
TestContext.Current.CancellationToken
);
Assert.Equal(HttpStatusCode.OK, deleteCall.StatusCode);
// Not found
var deleteCallNotFound = await client.DeleteAsync(
$"{JobModule.Prefix}/{createResponse.Id}",
TestContext.Current.CancellationToken
);
Assert.Equal(HttpStatusCode.NotFound, deleteCallNotFound.StatusCode);
var getCallNotFound = await client.GetAsync(
$"{JobModule.Prefix}/{createResponse.Id}",
TestContext.Current.CancellationToken
);
Assert.Equal(HttpStatusCode.NotFound, getCallNotFound.StatusCode);
}
}