public async Task GlobalEventsGetEndpoint_ShouldNotReturnEventsFromDatabaseDueToDateQueryParam(string url) { // Arrange var client = GetFactory().CreateClient(); using var scope = GetFactory().Server.Host.Services.CreateScope(); var context = scope.ServiceProvider.GetRequiredService <ApplicationDbContext>(); await context.Events.AddAsync(EventFixtures.SomeEvent().Build()); await context.Events.AddAsync(EventFixtures.SomeEvent().Build()); await context.SaveChangesAsync(); // Act var response = await client.GetAsync(url); var responseContent = await response.Content.ReadAsStringAsync(); var events = JsonConvert.DeserializeObject <List <EventResponse> >(responseContent); // Assert response.EnsureSuccessStatusCode(); Assert.Equal("application/json; charset=utf-8", response.Content.Headers.ContentType.ToString()); Assert.Empty(events); }
public async Task GlobalEventsGetEndpoint_ShouldReturnBothEventsFromDatabase(string url) { // Arrange var client = GetFactory().CreateClient(); using var scope = GetFactory().Server.Host.Services.CreateScope(); var context = scope.ServiceProvider.GetRequiredService <ApplicationDbContext>(); var firstDate = new DateTime(2020, 11, 15); var secondDate = new DateTime(2020, 11, 16); await context.Events.AddAsync(EventFixtures.SomeEvent().Title("First event").Date(firstDate).Build()); await context.Events.AddAsync(EventFixtures.SomeEvent().Title("Second event").Date(secondDate).Build()); await context.SaveChangesAsync(); // Act var response = await client.GetAsync(url); var responseContent = await response.Content.ReadAsStringAsync(); var events = JsonConvert.DeserializeObject <List <EventResponse> >(responseContent); // Assert response.EnsureSuccessStatusCode(); Assert.Equal("application/json; charset=utf-8", response.Content.Headers.ContentType.ToString()); Assert.Equal(2, events.Count); var firstEvent = events.SingleOrDefault(eventResponse => eventResponse.Title.Equals("First event")); var secondEvent = events.SingleOrDefault(eventResponse => eventResponse.Title.Equals("Second event")); Assert.NotNull(firstEvent); Assert.NotNull(secondEvent); Assert.Equal(firstDate, firstEvent.Date); Assert.Equal(secondDate, secondEvent.Date); }