mirror of https://github.com/abpframework/abp.git
committed by
GitHub
6 changed files with 116 additions and 3 deletions
@ -0,0 +1,9 @@ |
|||||
|
using Newtonsoft.Json; |
||||
|
|
||||
|
namespace Volo.Abp.Json |
||||
|
{ |
||||
|
public class AbpJsonOptions |
||||
|
{ |
||||
|
public JsonSerializerSettings SerializerSettings { get; } = new JsonSerializerSettings(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,27 @@ |
|||||
|
using System; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.AspNetCore.Mvc; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Mvc.Json |
||||
|
{ |
||||
|
[Route("api/json-result-test")] |
||||
|
public class JsonResultController : AbpController |
||||
|
{ |
||||
|
[HttpGet] |
||||
|
[Route("json-result-action")] |
||||
|
public Task<JsonResultModel> ObjectResultAction() |
||||
|
{ |
||||
|
return Task.FromResult(new JsonResultModel |
||||
|
{ |
||||
|
Time = DateTime.Parse("2019-01-01 11:59:59") |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
public class JsonResultModel |
||||
|
{ |
||||
|
public DateTime Time { get; set; } |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
@ -0,0 +1,32 @@ |
|||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.AspNetCore.Hosting; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Shouldly; |
||||
|
using Volo.Abp.Json; |
||||
|
using Xunit; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Mvc.Json |
||||
|
{ |
||||
|
public class JsonResultController_Tests : AspNetCoreMvcTestBase |
||||
|
{ |
||||
|
protected override void ConfigureServices(WebHostBuilderContext context, IServiceCollection services) |
||||
|
{ |
||||
|
services.Configure<AbpJsonOptions>(options => |
||||
|
{ |
||||
|
options.SerializerSettings.DateFormatString = "yyyy*MM*dd"; |
||||
|
}); |
||||
|
|
||||
|
base.ConfigureServices(context, services); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async Task DateFormatString_Test() |
||||
|
{ |
||||
|
var time = await GetResponseAsStringAsync( |
||||
|
"/api/json-result-test/json-result-action" |
||||
|
); |
||||
|
|
||||
|
time.ShouldContain("2019*01*01"); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,40 @@ |
|||||
|
using System; |
||||
|
using Microsoft.AspNetCore.Hosting; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Shouldly; |
||||
|
using Volo.Abp.Json; |
||||
|
using Xunit; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Mvc.Json |
||||
|
{ |
||||
|
public class JsonSerializer_Tests : AspNetCoreMvcTestBase |
||||
|
{ |
||||
|
private readonly IJsonSerializer _jsonSerializer; |
||||
|
|
||||
|
public JsonSerializer_Tests() |
||||
|
{ |
||||
|
_jsonSerializer = ServiceProvider.GetRequiredService<IJsonSerializer>(); |
||||
|
} |
||||
|
|
||||
|
protected override void ConfigureServices(WebHostBuilderContext context, IServiceCollection services) |
||||
|
{ |
||||
|
services.Configure<AbpJsonOptions>(options => |
||||
|
{ |
||||
|
options.SerializerSettings.DateFormatString = "yyyy*MM*dd"; |
||||
|
}); |
||||
|
|
||||
|
base.ConfigureServices(context, services); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void DateFormatString_Test() |
||||
|
{ |
||||
|
var output = _jsonSerializer.Serialize(new |
||||
|
{ |
||||
|
Time = DateTime.Parse("2019-01-01 11:59:59") |
||||
|
}); |
||||
|
|
||||
|
output.ShouldContain("2019*01*01"); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue