الملفات
wonders-app/integrationTestes/WondersApiTests.cs
2025-10-25 20:55:51 +03:00

43 أسطر
1.2 KiB
C#

using System.Net;
using System.Net.Http.Json;
using Xunit;
namespace IntegrationTests
{
public class WondersApiTests : IClassFixture<CustomWebApplicationFactory>
{
private readonly CustomWebApplicationFactory _factory;
public WondersApiTests(CustomWebApplicationFactory factory)
{
_factory = factory;
}
[Fact]
public async Task GetAllWonders_ShouldReturnSuccess()
{
var client = _factory.CreateClient();
var response = await client.GetAsync("/api/wonders");
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}
[Fact]
public async Task CreateWonder_ShouldReturnCreated()
{
var client = _factory.CreateClient();
var wonder = new
{
Name = "Pyramids",
Country = "Egypt",
Era = "Ancient",
Type = "Monument",
Description = "One of the ancient wonders",
DiscoveryYear = 2560
};
var response = await client.PostAsJsonAsync("/api/wonders", wonder);
Assert.Equal(HttpStatusCode.Created, response.StatusCode);
}
}
}