diff --git a/backend/tests/Designer.Tests/Controllers/PreviewController/ApplicationMetadataTests.cs b/backend/tests/Designer.Tests/Controllers/PreviewController/ApplicationMetadataTests.cs index c44e62db89f..3671a2b4747 100644 --- a/backend/tests/Designer.Tests/Controllers/PreviewController/ApplicationMetadataTests.cs +++ b/backend/tests/Designer.Tests/Controllers/PreviewController/ApplicationMetadataTests.cs @@ -51,9 +51,9 @@ public async Task Get_ApplicationMetadata_Ok() Assert.Equal(HttpStatusCode.OK, response.StatusCode); string responseBody = await response.Content.ReadAsStringAsync(); - ApplicationMetadata expectedApplicationMetadata = JsonSerializer.Deserialize(expectedApplicationMetadataString, SerializerOptions); + ApplicationMetadata expectedApplicationMetadata = JsonSerializer.Deserialize(expectedApplicationMetadataString, JsonSerializerOptions); expectedApplicationMetadata.AltinnNugetVersion = string.Empty; - string expectedJson = JsonSerializer.Serialize(expectedApplicationMetadata, SerializerOptions); + string expectedJson = JsonSerializer.Serialize(expectedApplicationMetadata, JsonSerializerOptions); JsonUtils.DeepEquals(expectedJson, responseBody).Should().BeTrue(); } @@ -72,9 +72,9 @@ public async Task Get_ApplicationMetadata_With_V8_Altinn_Nuget_Version_Ok() Assert.Equal(HttpStatusCode.OK, response.StatusCode); string responseBody = await response.Content.ReadAsStringAsync(); - ApplicationMetadata expectedApplicationMetadata = JsonSerializer.Deserialize(expectedApplicationMetadataString, SerializerOptions); + ApplicationMetadata expectedApplicationMetadata = JsonSerializer.Deserialize(expectedApplicationMetadataString, JsonSerializerOptions); expectedApplicationMetadata.AltinnNugetVersion = "8.0.0.0"; - string expectedJson = JsonSerializer.Serialize(expectedApplicationMetadata, SerializerOptions); + string expectedJson = JsonSerializer.Serialize(expectedApplicationMetadata, JsonSerializerOptions); JsonUtils.DeepEquals(expectedJson, responseBody).Should().BeTrue(); } @@ -93,7 +93,7 @@ public async Task Get_ApplicationMetadata_WithLessDataTypesThanLayoutSetsFile_Ok Assert.Equal(HttpStatusCode.OK, response.StatusCode); string responseBody = await response.Content.ReadAsStringAsync(); - ApplicationMetadata expectedApplicationMetadata = JsonSerializer.Deserialize(expectedApplicationMetadataString, SerializerOptions); + ApplicationMetadata expectedApplicationMetadata = JsonSerializer.Deserialize(expectedApplicationMetadataString, JsonSerializerOptions); expectedApplicationMetadata.AltinnNugetVersion = "8.0.0.0"; // Add the mocked data type to expected app metadata expectedApplicationMetadata.DataTypes.Add(new DataType() @@ -110,7 +110,7 @@ public async Task Get_ApplicationMetadata_WithLessDataTypesThanLayoutSetsFile_Ok expectedApplicationMetadata.PartyTypesAllowed.SubUnit = false; expectedApplicationMetadata.PartyTypesAllowed.BankruptcyEstate = false; - string expectedJson = JsonSerializer.Serialize(expectedApplicationMetadata, SerializerOptions); + string expectedJson = JsonSerializer.Serialize(expectedApplicationMetadata, JsonSerializerOptions); JsonUtils.DeepEquals(expectedJson, responseBody).Should().BeTrue(); } @@ -118,7 +118,7 @@ public async Task Get_ApplicationMetadata_WithLessDataTypesThanLayoutSetsFile_Ok public async Task Get_ApplicationMetadata_WithAllPartyTypesAllowedSetToFalse() { string originalApplicationMetadataString = TestDataHelper.GetFileFromRepo(Org, AppV4, Developer, "App/config/applicationmetadata.json"); - ApplicationMetadata originalApplicationMetadata = JsonSerializer.Deserialize(originalApplicationMetadataString, SerializerOptions); + ApplicationMetadata originalApplicationMetadata = JsonSerializer.Deserialize(originalApplicationMetadataString, JsonSerializerOptions); originalApplicationMetadata.PartyTypesAllowed.Person.Should().BeTrue(); originalApplicationMetadata.PartyTypesAllowed.Organisation.Should().BeTrue(); originalApplicationMetadata.PartyTypesAllowed.SubUnit.Should().BeTrue(); @@ -137,7 +137,7 @@ public async Task Get_ApplicationMetadata_WithAllPartyTypesAllowedSetToFalse() string responseBody = await response.Content.ReadAsStringAsync(); - ApplicationMetadata responseApplicationMetadata = JsonSerializer.Deserialize(responseBody, SerializerOptions); + ApplicationMetadata responseApplicationMetadata = JsonSerializer.Deserialize(responseBody, JsonSerializerOptions); responseApplicationMetadata.PartyTypesAllowed.Person.Should().BeFalse(); responseApplicationMetadata.PartyTypesAllowed.Organisation.Should().BeFalse(); responseApplicationMetadata.PartyTypesAllowed.SubUnit.Should().BeFalse(); diff --git a/backend/tests/Designer.Tests/Controllers/PreviewController/PreviewControllerTestsBase.cs b/backend/tests/Designer.Tests/Controllers/PreviewController/PreviewControllerTestsBase.cs index de8910dd32c..62f2d3f2341 100644 --- a/backend/tests/Designer.Tests/Controllers/PreviewController/PreviewControllerTestsBase.cs +++ b/backend/tests/Designer.Tests/Controllers/PreviewController/PreviewControllerTestsBase.cs @@ -1,8 +1,11 @@ -using System.Text.Encodings.Web; +using System.Linq; +using System.Text.Encodings.Web; using System.Text.Json; using System.Text.Json.Serialization; using Designer.Tests.Controllers.ApiTests; using Microsoft.AspNetCore.Mvc.Testing; +using Microsoft.Extensions.Caching.Distributed; +using Microsoft.Extensions.DependencyInjection; namespace Designer.Tests.Controllers.PreviewController { @@ -22,12 +25,19 @@ public class PreviewControllerTestsBase : DesignerEndpointsTestsBase protected const string InstanceGuId = "f1e23d45-6789-1bcd-8c34-56789abcdef0"; protected const string AttachmentGuId = "f47ac10b-58cc-4372-a567-0e02b2c3d479"; protected const string MockedReferrerUrl = "https://studio-mock-url.no"; - protected readonly JsonSerializerOptions SerializerOptions = new JsonSerializerOptions() + + protected override void ConfigureTestServices(IServiceCollection services) { - PropertyNamingPolicy = JsonNamingPolicy.CamelCase, - Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping, - DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, - }; + base.ConfigureTestServices(services); + var cacheServices = services.Where( + d => d.ServiceType == typeof(IDistributedCache)).ToList(); + foreach (ServiceDescriptor serviceDescriptor in cacheServices) + { + services.Remove(serviceDescriptor); + } + + services.AddDistributedMemoryCache(); + } public PreviewControllerTestsBase(WebApplicationFactory factory) : base(factory) {