Browse Source

Fix unit test.

pull/22656/head
maliming 10 months 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;
@ -12,6 +17,16 @@ public abstract class AbpJsonSystemTextJsonTestBase : AbpIntegratedTest<AbpJsonS
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)
{
options.UseAutofac();

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

@ -1,18 +1,18 @@
using System;
using System.Collections.Generic;
using Shouldly;
using Volo.Abp.Json.Newtonsoft;
using Xunit;
namespace Volo.Abp.Json;
[Collection("AbpJsonNewtonsoftJsonTest")]
public class AbpNewtonsoftSerializerProviderTests : AbpJsonNewtonsoftJsonTestBase
{
protected AbpNewtonsoftJsonSerializer JsonSerializer;
protected IJsonSerializer JsonSerializer;
public AbpNewtonsoftSerializerProviderTests()
{
JsonSerializer = GetRequiredService<AbpNewtonsoftJsonSerializer>();
JsonSerializer = GetRequiredService<IJsonSerializer>();
}
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
{
protected AbpSystemTextJsonSerializer JsonSerializer;
protected IJsonSerializer JsonSerializer;
public AbpSystemTextJsonSerializerProviderTestBase()
{
JsonSerializer = GetRequiredService<AbpSystemTextJsonSerializer>();
JsonSerializer = GetRequiredService<IJsonSerializer>();
}
public class TestExtensibleObjectClass : ExtensibleObject
@ -260,6 +260,8 @@ public class AbpSystemTextJsonSerializerProviderDateTimeFormatTests : AbpSystemT
options.InputDateTimeFormats.Add("yyyy*MM*dd");
options.OutputDateTimeFormat = "yyyy*MM*dd HH*mm*ss";
});
base.AfterAddApplication(services);
}
[Fact]
@ -326,6 +328,8 @@ public class AbpSystemTextJsonSerializerProviderDatetimeKindUtcTests : AbpSystem
{
Kind = DateTimeKind.Utc;
services.Configure<AbpClockOptions>(x => x.Kind = Kind);
base.AfterAddApplication(services);
}
}
@ -335,6 +339,8 @@ public class AbpSystemTextJsonSerializerProviderDatetimeKindLocalTests : AbpSyst
{
Kind = DateTimeKind.Local;
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;
});
base.AfterAddApplication(services);
}
[Fact]
@ -59,6 +61,7 @@ public class InputAndOutputDateTimeFormatSystemTextJsonTests : AbpJsonSystemText
}
}
[Collection("AbpJsonNewtonsoftJsonTest")]
public class InputAndOutputDateTimeFormatNewtonsoftTests : AbpJsonNewtonsoftJsonTestBase
{
private readonly IJsonSerializer _jsonSerializer;
@ -83,6 +86,8 @@ public class InputAndOutputDateTimeFormatNewtonsoftTests : AbpJsonNewtonsoftJson
{
options.Kind = DateTimeKind.Utc;
});
base.AfterAddApplication(services);
}
[Fact]

Loading…
Cancel
Save