Migrated some tests to use System.Text.Json (#385)
* Migrated some tests to use System.Text.Json * Added case insensitive json options to fix broken tests.
This commit is contained in:
@@ -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<WebTestFixture>
|
||||
{
|
||||
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<CatalogIndexViewModel>(stringResponse);
|
||||
var model = JsonSerializer.Deserialize<CatalogIndexViewModel>(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<CatalogIndexViewModel>(stringResponse);
|
||||
var model = JsonSerializer.Deserialize<CatalogIndexViewModel>(stringResponse, _jsonOptions);
|
||||
|
||||
Assert.Equal(2, model.CatalogItems.Count());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user