-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
201 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
test/aspnet-core-demo/AbpAspNetCoreDemo.Tests/Tests/DateTimeFormatterControllerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
using System.Net.Http; | ||
using System.Net.Http.Json; | ||
using System.Text; | ||
using System.Text.Json; | ||
using System.Threading.Tasks; | ||
using Abp.Web.Models; | ||
using Microsoft.AspNetCore.Mvc.Testing; | ||
using Microsoft.Net.Http.Headers; | ||
using Shouldly; | ||
using Xunit; | ||
using JsonSerializer = System.Text.Json.JsonSerializer; | ||
|
||
namespace AbpAspNetCoreDemo.IntegrationTests.Tests; | ||
|
||
public class DateTimeFormatterControllerTests : IClassFixture<WebApplicationFactory<Startup>> | ||
{ | ||
private readonly WebApplicationFactory<Startup> _factory; | ||
private const string BaseUrl = "/api/date-time-format/"; | ||
|
||
public DateTimeFormatterControllerTests(WebApplicationFactory<Startup> factory) | ||
{ | ||
_factory = factory; | ||
} | ||
|
||
[Theory] | ||
[InlineData("tr", "14.02.2024")] | ||
[InlineData("en-US", "2/14/2024")] | ||
[InlineData("en-GB", "14/02/2024")] | ||
public async Task DateTimeFormat_Controller_Test(string culture, string datetime) | ||
{ | ||
var client = _factory.CreateClient(); | ||
|
||
// Arrange | ||
client.DefaultRequestHeaders.Add(HeaderNames.AcceptLanguage, culture); | ||
var content = new StringContent("{\"TestDate\": \"" + datetime + "\" }", Encoding.UTF8, "application/json"); | ||
|
||
// Act | ||
var response = await client.PostAsync("/api/services/app/ModelBinding/TestDate", content); | ||
|
||
// Assert | ||
response.EnsureSuccessStatusCode(); | ||
var responseContent = await response.Content.ReadAsStringAsync(); | ||
var output = JsonSerializer.Deserialize<AjaxResponse<string>>(responseContent, new JsonSerializerOptions | ||
{ | ||
PropertyNameCaseInsensitive = true | ||
}); | ||
|
||
output.Result.Substring(0, datetime.Length).ShouldBe(datetime); | ||
} | ||
|
||
[Theory] | ||
[InlineData("tr", "14.02.2024")] | ||
[InlineData("en-US", "2/14/2024")] | ||
[InlineData("en-GB", "14/02/2024")] | ||
public async Task DateTimeFormat_Controller_Nullable_Test(string culture, string datetime) | ||
{ | ||
var client = _factory.CreateClient(); | ||
|
||
// Arrange | ||
client.DefaultRequestHeaders.Add(HeaderNames.AcceptLanguage, culture); | ||
var content = new StringContent("{\"TestDate\": \"" + datetime + "\" }", Encoding.UTF8, "application/json"); | ||
|
||
// Act | ||
var response = await client.PostAsync("/api/services/app/ModelBinding/NullableTestDate", content); | ||
|
||
// Assert | ||
response.EnsureSuccessStatusCode(); | ||
var responseContent = await response.Content.ReadAsStringAsync(); | ||
var output = JsonSerializer.Deserialize<AjaxResponse<string>>(responseContent, new JsonSerializerOptions | ||
{ | ||
PropertyNameCaseInsensitive = true | ||
}); | ||
|
||
output.Result.Substring(0, datetime.Length).ShouldBe(datetime); | ||
} | ||
|
||
[Theory] | ||
[InlineData("tr", "14.02.2024")] | ||
[InlineData("en-US", "2/14/2024")] | ||
[InlineData("en-GB", "14/02/2024")] | ||
public async Task DateTimeFormat_Controller_DateOnly_Test(string culture, string datetime) | ||
{ | ||
var client = _factory.CreateClient(); | ||
|
||
// Arrange | ||
client.DefaultRequestHeaders.Add(HeaderNames.AcceptLanguage, culture); | ||
var content = new StringContent("{\"TestDate\": \"" + datetime + "\" }", Encoding.UTF8, "application/json"); | ||
|
||
// Act | ||
var response = await client.PostAsync("/api/services/app/ModelBinding/DateOnlyTestDate", content); | ||
|
||
// Assert | ||
response.EnsureSuccessStatusCode(); | ||
var responseContent = await response.Content.ReadAsStringAsync(); | ||
var output = JsonSerializer.Deserialize<AjaxResponse<string>>(responseContent, new JsonSerializerOptions | ||
{ | ||
PropertyNameCaseInsensitive = true | ||
}); | ||
|
||
output.Result.Substring(0, datetime.Length).ShouldBe(datetime); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
test/aspnet-core-demo/AbpAspNetCoreDemo/Controllers/DateTimeFormatController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System; | ||
using Abp.Application.Services.Dto; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace AbpAspNetCoreDemo.Controllers | ||
{ | ||
public class DateTimeFormatController : DemoControllerBase | ||
{ | ||
[Route("api/date-time-format/test")] | ||
[HttpPost] | ||
public string TestGetArray(TestInputDto model) | ||
{ | ||
return model.TestDate.ToString("yyyy-MM-dd"); | ||
} | ||
|
||
public class TestInputDto : EntityDto | ||
{ | ||
public DateTime TestDate { get; set; } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters