Browse Source

Fix unit test.

pull/22656/head
maliming 1 year ago
parent
commit
bb1a7df7ca
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 17
      framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpJsonSystemTextJsonTestBase.cs
  2. 6
      framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpNewtonsoftSerializerProviderTests.cs
  3. 10
      framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpSystemTextJsonSerializerProvider_Tests.cs
  4. 5
      framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/InputAndOutputDateTimeFormat_Tests.cs

17
framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpJsonSystemTextJsonTestBase.cs

@ -1,4 +1,9 @@
using Volo.Abp.Testing; using System;
using System.Collections.Concurrent;
using System.Reflection;
using Newtonsoft.Json;
using Volo.Abp.Json.Newtonsoft;
using Volo.Abp.Testing;
namespace Volo.Abp.Json; namespace Volo.Abp.Json;
@ -12,6 +17,16 @@ public abstract class AbpJsonSystemTextJsonTestBase : AbpIntegratedTest<AbpJsonS
public abstract class AbpJsonNewtonsoftJsonTestBase : AbpIntegratedTest<AbpJsonNewtonsoftTestModule> public abstract class AbpJsonNewtonsoftJsonTestBase : AbpIntegratedTest<AbpJsonNewtonsoftTestModule>
{ {
protected AbpJsonNewtonsoftJsonTestBase()
{
var cache = typeof(AbpNewtonsoftJsonSerializer).GetField("JsonSerializerOptionsCache", BindingFlags.NonPublic | BindingFlags.Static);
if (cache != null)
{
var cacheValue = cache.GetValue(null)?.As<ConcurrentDictionary<object, JsonSerializerSettings>>();
cacheValue?.Clear();
}
}
protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options) protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options)
{ {
options.UseAutofac(); options.UseAutofac();

6
framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpNewtonsoftSerializerProviderTests.cs

@ -1,18 +1,18 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Shouldly; using Shouldly;
using Volo.Abp.Json.Newtonsoft;
using Xunit; using Xunit;
namespace Volo.Abp.Json; namespace Volo.Abp.Json;
[Collection("AbpJsonNewtonsoftJsonTest")]
public class AbpNewtonsoftSerializerProviderTests : AbpJsonNewtonsoftJsonTestBase public class AbpNewtonsoftSerializerProviderTests : AbpJsonNewtonsoftJsonTestBase
{ {
protected AbpNewtonsoftJsonSerializer JsonSerializer; protected IJsonSerializer JsonSerializer;
public AbpNewtonsoftSerializerProviderTests() public AbpNewtonsoftSerializerProviderTests()
{ {
JsonSerializer = GetRequiredService<AbpNewtonsoftJsonSerializer>(); JsonSerializer = GetRequiredService<IJsonSerializer>();
} }
public class File public class File

10
framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpSystemTextJsonSerializerProvider_Tests.cs

@ -13,11 +13,11 @@ namespace Volo.Abp.Json;
public abstract class AbpSystemTextJsonSerializerProviderTestBase : AbpJsonSystemTextJsonTestBase public abstract class AbpSystemTextJsonSerializerProviderTestBase : AbpJsonSystemTextJsonTestBase
{ {
protected AbpSystemTextJsonSerializer JsonSerializer; protected IJsonSerializer JsonSerializer;
public AbpSystemTextJsonSerializerProviderTestBase() public AbpSystemTextJsonSerializerProviderTestBase()
{ {
JsonSerializer = GetRequiredService<AbpSystemTextJsonSerializer>(); JsonSerializer = GetRequiredService<IJsonSerializer>();
} }
public class TestExtensibleObjectClass : ExtensibleObject public class TestExtensibleObjectClass : ExtensibleObject
@ -260,6 +260,8 @@ public class AbpSystemTextJsonSerializerProviderDateTimeFormatTests : AbpSystemT
options.InputDateTimeFormats.Add("yyyy*MM*dd"); options.InputDateTimeFormats.Add("yyyy*MM*dd");
options.OutputDateTimeFormat = "yyyy*MM*dd HH*mm*ss"; options.OutputDateTimeFormat = "yyyy*MM*dd HH*mm*ss";
}); });
base.AfterAddApplication(services);
} }
[Fact] [Fact]
@ -326,6 +328,8 @@ public class AbpSystemTextJsonSerializerProviderDatetimeKindUtcTests : AbpSystem
{ {
Kind = DateTimeKind.Utc; Kind = DateTimeKind.Utc;
services.Configure<AbpClockOptions>(x => x.Kind = Kind); services.Configure<AbpClockOptions>(x => x.Kind = Kind);
base.AfterAddApplication(services);
} }
} }
@ -335,6 +339,8 @@ public class AbpSystemTextJsonSerializerProviderDatetimeKindLocalTests : AbpSyst
{ {
Kind = DateTimeKind.Local; Kind = DateTimeKind.Local;
services.Configure<AbpClockOptions>(x => x.Kind = Kind); services.Configure<AbpClockOptions>(x => x.Kind = Kind);
base.AfterAddApplication(services);
} }
} }

5
framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/InputAndOutputDateTimeFormat_Tests.cs

@ -31,6 +31,8 @@ public class InputAndOutputDateTimeFormatSystemTextJsonTests : AbpJsonSystemText
{ {
options.Kind = DateTimeKind.Utc; options.Kind = DateTimeKind.Utc;
}); });
base.AfterAddApplication(services);
} }
[Fact] [Fact]
@ -59,6 +61,7 @@ public class InputAndOutputDateTimeFormatSystemTextJsonTests : AbpJsonSystemText
} }
} }
[Collection("AbpJsonNewtonsoftJsonTest")]
public class InputAndOutputDateTimeFormatNewtonsoftTests : AbpJsonNewtonsoftJsonTestBase public class InputAndOutputDateTimeFormatNewtonsoftTests : AbpJsonNewtonsoftJsonTestBase
{ {
private readonly IJsonSerializer _jsonSerializer; private readonly IJsonSerializer _jsonSerializer;
@ -83,6 +86,8 @@ public class InputAndOutputDateTimeFormatNewtonsoftTests : AbpJsonNewtonsoftJson
{ {
options.Kind = DateTimeKind.Utc; options.Kind = DateTimeKind.Utc;
}); });
base.AfterAddApplication(services);
} }
[Fact] [Fact]

Loading…
Cancel
Save