diff --git a/server.tests/v1/integrationTests/CharactersControllerIntegrationTests.cs b/server.tests/v1/integrationTests/CharactersControllerIntegrationTests.cs index 708b2b0..7d81348 100644 --- a/server.tests/v1/integrationTests/CharactersControllerIntegrationTests.cs +++ b/server.tests/v1/integrationTests/CharactersControllerIntegrationTests.cs @@ -1,13 +1,12 @@ using FluentAssertions; using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.Testing; using MongoDB.Bson; using server.Models; -using System.Net; -using System.Text.Json; using server.tests.Helpers; using server.tests.Http; using server.tests.Options; +using System.Net; +using System.Text.Json; namespace server.tests.v1.IntegrationTests { diff --git a/server.tests/v1/integrationTests/QuotesControllerIntegrationTests.cs b/server.tests/v1/integrationTests/QuotesControllerIntegrationTests.cs index d078d07..dfd13d1 100644 --- a/server.tests/v1/integrationTests/QuotesControllerIntegrationTests.cs +++ b/server.tests/v1/integrationTests/QuotesControllerIntegrationTests.cs @@ -1,8 +1,13 @@ -using server.tests.Http; +using FluentAssertions; +using Microsoft.AspNetCore.Mvc; +using server.Models; +using server.tests.Helpers; +using server.tests.Http; using server.tests.Options; +using System.Net; using System.Text.Json; -namespace server.tests.v1.integrationTests +namespace server.tests.v1.IntegrationTests { public class QuotesControllerIntegrationTests { @@ -16,7 +21,196 @@ namespace server.tests.v1.integrationTests _serializerOptions = OptionsFactory.GetJsonSerializerOptions(); - _endpoint = "/api/seasons"; + _endpoint = "/api/quotes"; + } + + [Fact] + public async Task GetQuotesAsync_AllQuotes_Returns200StatusCodeWithQuotes() + { + var response = await _client.GetAsync(_endpoint); + + var data = await response.Content.ReadAsStreamAsync(); + + var characters = JsonSerializer.Deserialize>(data, _serializerOptions); + + response.StatusCode.Should().Be(HttpStatusCode.OK); + AssertHelper.CheckForRateLimitingHeaders(response.Headers); + + characters.Should().NotBeNull(); + characters.Should().BeOfType>(); + characters.Should().HaveCountGreaterThan(0); + } + + [Fact] + public async Task GetQuotesAsync_SeasonOneQuotes_Returns200StatusCodeWithQoutes() + { + var season = 1; + + var url = $"{_endpoint}?{nameof(season)}={season}"; + + var response = await _client.GetAsync(url); + + var data = await response.Content.ReadAsStreamAsync(); + + var quotes = JsonSerializer.Deserialize>(data, _serializerOptions); + + response.StatusCode.Should().Be(HttpStatusCode.OK); + AssertHelper.CheckForRateLimitingHeaders(response.Headers); + + quotes.Should().NotBeNull(); + quotes.Should().BeOfType>(); + quotes.Should().HaveCountGreaterThan(0); + + foreach (var quote in quotes) + { + quote.Season.Should().Be(season); + } + } + + [Fact] + public async Task GetQuotesAsync_InvalidSeasonQueryParameter_Returns400StatusCodeWithValidationProblemDetails() + { + var season = "test"; + + var url = $"{_endpoint}?{nameof(season)}={season}"; + + var response = await _client.GetAsync(url); + + var data = await response.Content.ReadAsStreamAsync(); + + var details = JsonSerializer.Deserialize(data, _serializerOptions); + + response.StatusCode.Should().Be(HttpStatusCode.BadRequest); + AssertHelper.CheckForRateLimitingHeaders(response.Headers); + + details.Should().NotBeNull(); + details.Should().BeOfType(); + details.Errors.Should().NotBeNull(); + } + + [Fact] + public async Task GetQuotesAsync_EpisodeOneQuotes_Returns200StatusCodeWithQuotes() + { + var episode = 1; + + var url = $"{_endpoint}?{nameof(episode)}={episode}"; + + var response = await _client.GetAsync(url); + + var data = await response.Content.ReadAsStreamAsync(); + + var quotes = JsonSerializer.Deserialize>(data, _serializerOptions); + + response.StatusCode.Should().Be(HttpStatusCode.OK); + AssertHelper.CheckForRateLimitingHeaders(response.Headers); + + quotes.Should().NotBeNull(); + quotes.Should().BeOfType>(); + quotes.Should().HaveCountGreaterThan(0); + + foreach (var quote in quotes) + { + quote.Episode.Should().Be(episode); + } + } + + [Fact] + public async Task GetQuotesAsync_InvalidEpisodeQueryParameter_Returns400StatusCodeWithValidationProblemDetails() + { + var episode = "test"; + + var url = $"{_endpoint}?{nameof(episode)}={episode}"; + + var response = await _client.GetAsync(url); + + var data = await response.Content.ReadAsStreamAsync(); + + var details = JsonSerializer.Deserialize(data, _serializerOptions); + + response.StatusCode.Should().Be(HttpStatusCode.BadRequest); + AssertHelper.CheckForRateLimitingHeaders(response.Headers); + + details.Should().NotBeNull(); + details.Should().BeOfType(); + details.Errors.Should().NotBeNull(); + } + + [Fact] + public async Task GetQuotesAsync_QuotesThatContainEvil_Returns200StatusCodeWithQuotes() + { + var textKeyword = "evil"; + + var url = $"{_endpoint}?{nameof(textKeyword)}={textKeyword}"; + + var response = await _client.GetAsync(url); + + var data = await response.Content.ReadAsStreamAsync(); + + var quotes = JsonSerializer.Deserialize>(data, _serializerOptions); + + response.StatusCode.Should().Be(HttpStatusCode.OK); + AssertHelper.CheckForRateLimitingHeaders(response.Headers); + + quotes.Should().NotBeNull(); + quotes.Should().BeOfType>(); + quotes.Should().HaveCountGreaterThan(0); + + foreach (var quote in quotes) + { + quote.Text.ToLower().Should().Contain(textKeyword); + } + } + + [Fact] + public async Task GetQuotesAsync_QuotesByYoda_Returns200StatusCodeWithQuotes() + { + var source = "yoda"; + + var url = $"{_endpoint}?{nameof(source)}={source}"; + + var response = await _client.GetAsync(url); + + var data = await response.Content.ReadAsStreamAsync(); + + var quotes = JsonSerializer.Deserialize>(data, _serializerOptions); + + response.StatusCode.Should().Be(HttpStatusCode.OK); + AssertHelper.CheckForRateLimitingHeaders(response.Headers); + + quotes.Should().NotBeNull(); + quotes.Should().BeOfType>(); + quotes.Should().HaveCountGreaterThan(0); + + foreach (var quote in quotes) + { + quote.Source.ToLower().Should().Contain(source); + } + } + + [Fact] + public async Task GetQuotesAsync_QuotesNarratedByJason_Returns200StatusCodeWithQuotes() + { + var narrator = "jason"; + + var url = $"{_endpoint}?{nameof(narrator)}={narrator}"; + + var response = await _client.GetAsync(url); + + var data = await response.Content.ReadAsStreamAsync(); + + var quotes = JsonSerializer.Deserialize>(data, _serializerOptions); + + response.StatusCode.Should().Be(HttpStatusCode.OK); + AssertHelper.CheckForRateLimitingHeaders(response.Headers); + + quotes.Should().NotBeNull(); + quotes.Should().BeOfType>(); + quotes.Should().HaveCountGreaterThan(0); + + foreach (var quote in quotes) + { + quote.Narrator.ToLower().Should().Contain(narrator); + } } } }