diff --git a/tests/WebApi.Tests/Apis/RecipesApiUnitTests.cs b/tests/WebApi.Tests/Apis/RecipesApiUnitTests.cs index bb345ba..8c73566 100644 --- a/tests/WebApi.Tests/Apis/RecipesApiUnitTests.cs +++ b/tests/WebApi.Tests/Apis/RecipesApiUnitTests.cs @@ -91,6 +91,30 @@ public async void GetListAsyncReturnsRecipes() Assert.NotNull(okResult.Value); Assert.NotEmpty(okResult.Value.Items); + + var firstItem = okResult.Value.Items.First(); + + Assert.Multiple( + () => Assert.Equal(6462416804118528, firstItem.Id), + () => Assert.Equal("73edf737-df51-4c06-ac6f-3ec6d79f1f12", firstItem.OwnerId), + () => Assert.Equal("Test Recipe 5", firstItem.Name), + () => + { + Assert.NotNull(firstItem.CoverImage); + Assert.Equal("/api/v1/recipes/6462416804118528/coverImage", firstItem.CoverImage.Url); + Assert.Equal("A photo of test recipe 5", firstItem.CoverImage.AltText); + }, + () => + { + Assert.NotNull(firstItem.Cuisine); + Assert.Equal(1, firstItem.Cuisine.Id); + Assert.Equal("Test", firstItem.Cuisine.Name); + }, + () => Assert.Null(firstItem.Description), + () => Assert.Equal(new DateTime(638412047602332665, DateTimeKind.Utc), firstItem.Created), + () => Assert.Null(firstItem.Modified), + () => Assert.Null(firstItem.Ingredients), + () => Assert.Null(firstItem.Instructions)); } [Fact] @@ -151,6 +175,51 @@ public async void GetListAsyncReturnsRecipesForCuisineIds() () => Assert.All(okResult.Value.Items, x => Assert.Equal(4, x.Cuisine?.Id))); } + [Fact] + public async void GetListAsyncReturnsRecipesForWithDetails() + { + // Act + var result = await RecipesApi.GetListAsync(_services, null, null, null, true); + + // Assert + Assert.IsType>>(result.Result); + var okResult = (Ok>)result.Result; + Assert.NotNull(okResult.Value); + + Assert.NotEmpty(okResult.Value.Items); + + var firstItem = okResult.Value.Items.First(); + + Assert.Multiple( + () => Assert.Equal(6462416804118528, firstItem.Id), + () => Assert.Equal("73edf737-df51-4c06-ac6f-3ec6d79f1f12", firstItem.OwnerId), + () => Assert.Equal("Test Recipe 5", firstItem.Name), + () => + { + Assert.NotNull(firstItem.CoverImage); + Assert.Equal("/api/v1/recipes/6462416804118528/coverImage", firstItem.CoverImage.Url); + Assert.Equal("A photo of test recipe 5", firstItem.CoverImage.AltText); + }, + () => + { + Assert.NotNull(firstItem.Cuisine); + Assert.Equal(1, firstItem.Cuisine.Id); + Assert.Equal("Test", firstItem.Cuisine.Name); + }, + () => Assert.Equal("This is a test.", firstItem.Description), + () => Assert.Equal(new DateTime(638412047602332665, DateTimeKind.Utc), firstItem.Created), + () => Assert.Null(firstItem.Modified), + () => + { + Assert.NotNull(firstItem.Ingredients); + Assert.Collection(firstItem.Ingredients, + x => Assert.Equal("1 tsp of test ingredient 1", x), + x => Assert.Equal("1 cup of test ingredient 2", x)); + }, + () => Assert.Equal("This is a test.", firstItem.Instructions?.Markdown), + () => Assert.Equal("

This is a test.

\n", firstItem.Instructions?.Html)); + } + [Fact] public async void GetAsyncReturnsRecipeForValidId() { @@ -167,6 +236,12 @@ public async void GetAsyncReturnsRecipeForValidId() () => Assert.Equal("73edf737-df51-4c06-ac6f-3ec6d79f1f12", okResult.Value.OwnerId), () => Assert.Equal("Test Recipe 3", okResult.Value.Name), () => + { + Assert.NotNull(okResult.Value.CoverImage); + Assert.Equal("/api/v1/recipes/6462258523668480/coverImage", okResult.Value.CoverImage.Url); + Assert.Equal("A photo of test recipe 3", okResult.Value.CoverImage.AltText); + }, + () => { Assert.NotNull(okResult.Value.Cuisine); Assert.Equal(1, okResult.Value.Cuisine.Id); diff --git a/tests/WebApi.Tests/Apis/TestData.cs b/tests/WebApi.Tests/Apis/TestData.cs index 914c9b4..5e60bb3 100644 --- a/tests/WebApi.Tests/Apis/TestData.cs +++ b/tests/WebApi.Tests/Apis/TestData.cs @@ -81,6 +81,11 @@ public static class TestData Id = 6461870173061120, OwnerId = "73edf737-df51-4c06-ac6f-3ec6d79f1f12", Name = "Test Recipe 1", + CoverImage = new ImageData + { + Url = "6461870173061120.webp", + AltText = "A photo of test recipe 1" + }, CuisineId = 1, Description = "This is a test.", Created = new DateTime(638412046299055561, DateTimeKind.Utc), @@ -100,6 +105,11 @@ public static class TestData Id = 6462160192405504, OwnerId = "d7df5331-1c53-491f-8b71-91989846874f", Name = "Test Recipe 2", + CoverImage = new ImageData + { + Url = "6462160192405504.webp", + AltText = "A photo of test recipe 2" + }, CuisineId = 1, Description = "This is a test.", Created = new DateTime(638412046990521543, DateTimeKind.Utc), @@ -119,6 +129,11 @@ public static class TestData Id = 6462258523668480, OwnerId = "73edf737-df51-4c06-ac6f-3ec6d79f1f12", Name = "Test Recipe 3", + CoverImage = new ImageData + { + Url = "6462258523668480.webp", + AltText = "A photo of test recipe 3" + }, CuisineId = 1, Description = "This is a test.", Created = new DateTime(638412047224957774, DateTimeKind.Utc), @@ -138,6 +153,11 @@ public static class TestData Id = 6462318867120128, OwnerId = "d7df5331-1c53-491f-8b71-91989846874f", Name = "Test Recipe 4", + CoverImage = new ImageData + { + Url = "6462318867120128.webp", + AltText = "A photo of test recipe 4" + }, CuisineId = 4, Description = "This is a test.", Created = new DateTime(638412047368832961, DateTimeKind.Utc), @@ -157,6 +177,11 @@ public static class TestData Id = 6462416804118528, OwnerId = "73edf737-df51-4c06-ac6f-3ec6d79f1f12", Name = "Test Recipe 5", + CoverImage = new ImageData + { + Url = "6462416804118528.webp", + AltText = "A photo of test recipe 5" + }, CuisineId = 1, Description = "This is a test.", Created = new DateTime(638412047602332665, DateTimeKind.Utc),