using System.Net; using System.Net.Http.Json; using FluentAssertions; using MinAttest.Contracts.Attests; using MinAttest.Contracts.Persons; using MinAttest.Tests.Integration.Server; using Xunit; namespace MinAttest.Tests.Integration.Api; [Collection("IntegrationCollection")] public class PersonsApiTests : IClassFixture { private readonly HttpClient _client; public PersonsApiTests(ApiWebAppFactory factory) => _client = factory.CreateClient(); [Fact] public async Task Upsert_person_and_upload_and_list() { var upsertResp = await _client.PostAsJsonAsync("/api/v1/persons", new PersonUpsertRequest("hash-api-1", "api@example.com", null)); upsertResp.StatusCode.Should().Be(HttpStatusCode.OK); var person = await upsertResp.Content.ReadFromJsonAsync(); person.Should().NotBeNull(); var uploadReq = new PersonAttestUploadRequest( Title: "ApiAttest", From: new DateOnly(2024,1,1), To: new DateOnly(2024,6,1), Summary: "", BlobPath: "", BlobHash: null, ContentBase64: Convert.ToBase64String(new byte[]{1,2,3}), ContentType: "application/octet-stream"); var uploadResp = await _client.PostAsJsonAsync($"/api/v1/persons/{person!.Id}/attests", uploadReq); uploadResp.StatusCode.Should().Be(HttpStatusCode.Created); var listResp = await _client.GetAsync($"/api/v1/persons/{person.Id}/attests"); listResp.StatusCode.Should().Be(HttpStatusCode.OK); } }