Skip to content

Commit bb22aca

Browse files
committed
Address comments
1 parent 2a9e773 commit bb22aca

File tree

4 files changed

+2
-82
lines changed

4 files changed

+2
-82
lines changed

test/OpenApiKiotaEndToEndTests/ModelStateValidation/ModelStateValidationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ public async Task Cannot_use_double_outside_of_valid_range(double age)
358358

359359
ErrorObject errorObject = document.Errors.First();
360360
errorObject.Title.Should().Be("Input validation failed.");
361-
errorObject.Detail.Should().Be("The field Age must be between 0.1 exclusive and 122.9 exclusive.");
361+
errorObject.Detail.Should().Be("The field Age must be between 0.1 and 122.9.");
362362
errorObject.Source.ShouldNotBeNull();
363363
errorObject.Source.Pointer.Should().Be("/data/attributes/age");
364364
}

test/OpenApiNSwagEndToEndTests/ModelStateValidation/ModelStateValidationTests.cs

Lines changed: 1 addition & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.Globalization;
21
using FluentAssertions;
32
using JsonApiDotNetCore.Configuration;
43
using JsonApiDotNetCore.OpenApi.Client.NSwag;
@@ -352,7 +351,7 @@ public async Task Cannot_use_double_outside_of_valid_range(double age)
352351

353352
ErrorObject errorObject = document.Errors.First();
354353
errorObject.Title.Should().Be("Input validation failed.");
355-
errorObject.Detail.Should().Be("The field Age must be between 0.1 exclusive and 122.9 exclusive.");
354+
errorObject.Detail.Should().Be("The field Age must be between 0.1 and 122.9.");
356355
errorObject.Source.ShouldNotBeNull();
357356
errorObject.Source.Pointer.Should().Be("/data/attributes/age");
358357
}
@@ -534,79 +533,6 @@ public async Task Cannot_use_TimeSpan_outside_of_valid_range()
534533
errorObject.Source.Pointer.Should().Be("/data/attributes/nextRevalidation");
535534
}
536535

537-
[Fact]
538-
public async Task Cannot_use_culture_sensitive_TimeSpan()
539-
{
540-
// Arrange
541-
SocialMediaAccount newAccount = _fakers.SocialMediaAccount.Generate();
542-
543-
using HttpClient httpClient = _testContext.Factory.CreateDefaultClient(_logHttpMessageHandler);
544-
ModelStateValidationClient apiClient = new(httpClient);
545-
546-
SocialMediaAccountPostRequestDocument requestBody = new()
547-
{
548-
Data = new SocialMediaAccountDataInPostRequest
549-
{
550-
Attributes = new SocialMediaAccountAttributesInPostRequest
551-
{
552-
LastName = newAccount.LastName,
553-
NextRevalidation = new TimeSpan(0, 2, 0, 0, 1).ToString("g", new CultureInfo("fr-FR"))
554-
}
555-
}
556-
};
557-
558-
// Act
559-
Func<Task> action = () => apiClient.PostSocialMediaAccountAsync(requestBody);
560-
561-
// Assert
562-
ErrorResponseDocument document = (await action.Should().ThrowExactlyAsync<ApiException<ErrorResponseDocument>>()).Which.Result;
563-
document.Errors.ShouldHaveCount(1);
564-
565-
ErrorObject errorObject = document.Errors.First();
566-
errorObject.Title.Should().Be("Failed to deserialize request body: Incompatible attribute value found.");
567-
568-
errorObject.Detail.Should()
569-
.Be("Failed to convert attribute 'nextRevalidation' with value '2:00:00,001' of type 'String' to type 'Nullable<TimeSpan>'.");
570-
571-
errorObject.Source.ShouldNotBeNull();
572-
errorObject.Source.Pointer.Should().Be("/data/attributes/nextRevalidation");
573-
}
574-
575-
[Fact]
576-
public async Task Cannot_use_invalid_TimeOnly()
577-
{
578-
// Arrange
579-
SocialMediaAccount newAccount = _fakers.SocialMediaAccount.Generate();
580-
581-
using HttpClient httpClient = _testContext.Factory.CreateDefaultClient(_logHttpMessageHandler);
582-
ModelStateValidationClient apiClient = new(httpClient);
583-
584-
SocialMediaAccountPostRequestDocument requestBody = new()
585-
{
586-
Data = new SocialMediaAccountDataInPostRequest
587-
{
588-
Attributes = new SocialMediaAccountAttributesInPostRequest
589-
{
590-
LastName = newAccount.LastName,
591-
ValidatedAtTime = TimeSpan.FromSeconds(-1)
592-
}
593-
}
594-
};
595-
596-
// Act
597-
Func<Task> action = () => apiClient.PostSocialMediaAccountAsync(requestBody);
598-
599-
// Assert
600-
ErrorResponseDocument document = (await action.Should().ThrowExactlyAsync<ApiException<ErrorResponseDocument>>()).Which.Result;
601-
document.Errors.ShouldHaveCount(1);
602-
603-
ErrorObject errorObject = document.Errors.First();
604-
errorObject.Title.Should().Be("Failed to deserialize request body: Incompatible attribute value found.");
605-
errorObject.Detail.Should().Be("Failed to convert attribute 'validatedAtTime' with value '-00:00:01' of type 'String' to type 'Nullable<TimeOnly>'.");
606-
errorObject.Source.ShouldNotBeNull();
607-
errorObject.Source.Pointer.Should().Be("/data/attributes/validatedAtTime");
608-
}
609-
610536
[Fact]
611537
public async Task Can_create_resource_with_valid_properties()
612538
{

test/OpenApiTests/ModelStateValidation/ModelStateValidationTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.Globalization;
21
using System.Text.Json;
32
using TestBuildingBlocks;
43
using Xunit;
@@ -19,7 +18,6 @@ public sealed class ModelStateValidationTests : IClassFixture<OpenApiTestContext
1918

2019
public ModelStateValidationTests(OpenApiTestContext<OpenApiStartup<ModelStateValidationDbContext>, ModelStateValidationDbContext> testContext)
2120
{
22-
CultureInfo.CurrentCulture = new CultureInfo("fr-FR");
2321
_testContext = testContext;
2422

2523
testContext.UseController<SocialMediaAccountsController>();

test/OpenApiTests/ModelStateValidation/SocialMediaAccount.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,7 @@ public sealed class SocialMediaAccount : Identifiable<Guid>
4949
public string? Phone { get; set; }
5050

5151
[Attr]
52-
#if NET6_0
5352
[Range(0.1, 122.9)]
54-
#else
55-
[Range(0.1, 122.9, MinimumIsExclusive = true, MaximumIsExclusive = true)]
56-
#endif
5753
public double? Age { get; set; }
5854

5955
[Attr]

0 commit comments

Comments
 (0)