mirror of
https://github.com/farcasclaudiu/PracticeCalendar.git
synced 2026-06-22 07:01:16 +03:00
added API tests
This commit is contained in:
@@ -26,11 +26,16 @@ namespace PracticeCalendar.UnitTests.Integration
|
||||
{
|
||||
cfg.AddSingleton(svc => domainEventServiceMock.Object);
|
||||
});
|
||||
|
||||
|
||||
_scopeFactory = _factory.Services.GetRequiredService<IServiceScopeFactory>();
|
||||
_configuration = _factory.Services.GetRequiredService<IConfiguration>();
|
||||
}
|
||||
|
||||
public static HttpClient GetHttpClient()
|
||||
{
|
||||
return _factory.CreateClient();
|
||||
}
|
||||
|
||||
public static async Task<TResponse> SendAsync<TResponse>(IRequest<TResponse> request)
|
||||
{
|
||||
using var scope = _scopeFactory.CreateScope();
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
using System.Net;
|
||||
using FluentAssertions;
|
||||
using PracticeCalendar.Domain.Entities;
|
||||
using PracticeCalendar.UnitTests.Integration;
|
||||
using static PracticeCalendar.UnitTests.Integration.Testing;
|
||||
|
||||
public class ControllerApiTest : BaseTest
|
||||
{
|
||||
[Fact]
|
||||
public async Task GetAllEventsEmptyTestAsync()
|
||||
{
|
||||
await RunBeforeAnyTests();
|
||||
var http = GetHttpClient();
|
||||
|
||||
var httpResponse = await http.GetAsync("/api/events");
|
||||
|
||||
httpResponse.IsSuccessStatusCode.Should().BeTrue();
|
||||
httpResponse.StatusCode.Should().Be(HttpStatusCode.OK);
|
||||
|
||||
var responseStr = await httpResponse.Content.ReadAsStringAsync();
|
||||
responseStr.Should().Be("[]");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetAllEventsManyTestAsync()
|
||||
{
|
||||
await RunBeforeAnyTests();
|
||||
await AddAsync(new PracticeEvent("Test Event", "Event description",
|
||||
DateTime.Now.AddHours(-1), DateTime.Now.AddHours(1))
|
||||
{
|
||||
Id = 1,
|
||||
Attendees = {
|
||||
new Attendee("Claudiu F", "claudiuf@busybee.com")
|
||||
{
|
||||
Id = 1
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var http = GetHttpClient();
|
||||
|
||||
var httpResponse = await http.GetAsync("/api/events");
|
||||
|
||||
httpResponse.IsSuccessStatusCode.Should().BeTrue();
|
||||
httpResponse.StatusCode.Should().Be(HttpStatusCode.OK);
|
||||
|
||||
var responseStr = await httpResponse.Content.ReadAsStringAsync();
|
||||
responseStr.Length.Should().Be(257);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user