using System.Net; using System.Net.Http.Json; using System.Text; using System.Text.Json; using FluentAssertions; using Xunit; namespace Examples.Integration.Tests; /// /// Integration tests for the Billing microservice endpoints. /// public sealed class BillingEndpointTests : IClassFixture { private readonly GatewayFixture _fixture; public BillingEndpointTests(GatewayFixture fixture) { _fixture = fixture; } [Fact] public async Task CreateInvoice_WithValidRequest_ReturnsCreatedInvoice() { // Arrange var request = new { customerId = "CUST-001", amount = 99.99m, description = "Test invoice" }; // Act var response = await _fixture.GatewayClient.PostAsJsonAsync("/invoices", request); // Assert response.StatusCode.Should().Be(HttpStatusCode.OK); var content = await response.Content.ReadAsStringAsync(); content.Should().Contain("invoiceId"); } [Fact] public async Task GetInvoice_WithValidId_ReturnsInvoice() { // Arrange var invoiceId = "INV-12345"; // Act var response = await _fixture.GatewayClient.GetAsync($"/invoices/{invoiceId}"); // Assert response.StatusCode.Should().Be(HttpStatusCode.OK); var content = await response.Content.ReadAsStringAsync(); content.Should().Contain(invoiceId); } [Fact] public async Task UploadAttachment_WithStreamingData_ReturnsSuccess() { // Arrange var invoiceId = "INV-12345"; var attachmentData = Encoding.UTF8.GetBytes("This is test attachment content"); using var content = new ByteArrayContent(attachmentData); content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/octet-stream"); // Act var response = await _fixture.GatewayClient.PostAsync( $"/invoices/{invoiceId}/attachments", content); // Assert response.StatusCode.Should().Be(HttpStatusCode.OK); var responseContent = await response.Content.ReadAsStringAsync(); responseContent.Should().Contain("attachmentId"); } }