UnitTest1.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using Microsoft.AspNetCore.Mvc.Testing;
  2. using AnalyzerApi;
  3. using Xunit;
  4. using System.Net;
  5. using System.Text;
  6. using System.Text.Json;
  7. using AnalyzerApi.Models;
  8. namespace AnalyzerApi.Tests;
  9. public class IntegrationTests : IClassFixture<WebApplicationFactory<Program>>
  10. {
  11. private readonly WebApplicationFactory<Program> _factory;
  12. public IntegrationTests()
  13. {
  14. _factory = new WebApplicationFactory<Program>()
  15. .WithWebHostBuilder(builder =>
  16. {
  17. // Äîïîëíèòåëüíàÿ êîíôèãóðàöèÿ ïðè íåîáõîäèìîñòè
  18. });
  19. }
  20. [Theory]
  21. [InlineData("Biorad")]
  22. [InlineData("Ledetect")]
  23. public async Task PostOrder_ValidRequest_ReturnsOk(string analyzerName)
  24. {
  25. // Arrange
  26. var client = _factory.CreateClient();
  27. var order = new OrderRequest
  28. {
  29. Patient = 1,
  30. Services = new List<Service>
  31. {
  32. new() { ServiceCode = analyzerName == "Biorad" ? 548 : 311 }
  33. }
  34. };
  35. var content = new StringContent(JsonSerializer.Serialize(order), Encoding.UTF8, "application/json");
  36. // Act
  37. var response = await client.PostAsync($"/api/analyzer/{analyzerName}", content);
  38. var responseContent = await response.Content.ReadAsStringAsync();
  39. Console.WriteLine($"Response: {response.StatusCode}, Content: {responseContent}");
  40. // Assert
  41. Assert.Equal(HttpStatusCode.OK, response.StatusCode);
  42. }
  43. }