diff --git a/src/Web/Services/CatalogViewModelService.cs b/src/Web/Services/CatalogViewModelService.cs index 7fb14aa..0e44854 100644 --- a/src/Web/Services/CatalogViewModelService.cs +++ b/src/Web/Services/CatalogViewModelService.cs @@ -57,9 +57,9 @@ namespace Microsoft.eShopWeb.Web.Services Name = i.Name, PictureUri = _uriComposer.ComposePicUri(i.PictureUri), Price = i.Price - }), - Brands = await GetBrands(), - Types = await GetTypes(), + }).ToList(), + Brands = (await GetBrands()).ToList(), + Types = (await GetTypes()).ToList(), BrandFilterApplied = brandId ?? 0, TypesFilterApplied = typeId ?? 0, PaginationInfo = new PaginationInfoViewModel() diff --git a/src/Web/ViewModels/CatalogIndexViewModel.cs b/src/Web/ViewModels/CatalogIndexViewModel.cs index 8715e1d..8a23965 100644 --- a/src/Web/ViewModels/CatalogIndexViewModel.cs +++ b/src/Web/ViewModels/CatalogIndexViewModel.cs @@ -5,9 +5,9 @@ namespace Microsoft.eShopWeb.Web.ViewModels { public class CatalogIndexViewModel { - public IEnumerable CatalogItems { get; set; } - public IEnumerable Brands { get; set; } - public IEnumerable Types { get; set; } + public List CatalogItems { get; set; } + public List Brands { get; set; } + public List Types { get; set; } public int? BrandFilterApplied { get; set; } public int? TypesFilterApplied { get; set; } public PaginationInfoViewModel PaginationInfo { get; set; } diff --git a/src/Web/Web.csproj b/src/Web/Web.csproj index 8217309..002ccd9 100644 --- a/src/Web/Web.csproj +++ b/src/Web/Web.csproj @@ -34,6 +34,7 @@ + diff --git a/tests/FunctionalTests/Web/Controllers/ApiCatalogControllerList.cs b/tests/FunctionalTests/Web/Controllers/ApiCatalogControllerList.cs index 5349559..a0e8134 100644 --- a/tests/FunctionalTests/Web/Controllers/ApiCatalogControllerList.cs +++ b/tests/FunctionalTests/Web/Controllers/ApiCatalogControllerList.cs @@ -1,7 +1,7 @@ using Microsoft.eShopWeb.Web.ViewModels; -using Newtonsoft.Json; using System.Linq; using System.Net.Http; +using System.Text.Json; using System.Threading.Tasks; using Xunit; @@ -10,6 +10,8 @@ namespace Microsoft.eShopWeb.FunctionalTests.Web.Controllers [Collection("Sequential")] public class ApiCatalogControllerList : IClassFixture { + JsonSerializerOptions _jsonOptions = new JsonSerializerOptions { PropertyNameCaseInsensitive = true }; + public ApiCatalogControllerList(WebTestFixture factory) { Client = factory.CreateClient(); @@ -23,7 +25,7 @@ namespace Microsoft.eShopWeb.FunctionalTests.Web.Controllers var response = await Client.GetAsync("/api/catalog/list"); response.EnsureSuccessStatusCode(); var stringResponse = await response.Content.ReadAsStringAsync(); - var model = JsonConvert.DeserializeObject(stringResponse); + var model = JsonSerializer.Deserialize(stringResponse, _jsonOptions); Assert.Equal(10, model.CatalogItems.Count()); } @@ -34,7 +36,7 @@ namespace Microsoft.eShopWeb.FunctionalTests.Web.Controllers var response = await Client.GetAsync("/api/catalog/list?page=1"); response.EnsureSuccessStatusCode(); var stringResponse = await response.Content.ReadAsStringAsync(); - var model = JsonConvert.DeserializeObject(stringResponse); + var model = JsonSerializer.Deserialize(stringResponse, _jsonOptions); Assert.Equal(2, model.CatalogItems.Count()); }