Skip to content

Commit 98cad73

Browse files
committed
Fix async for tests and IValidatableObject
1 parent c6f88cf commit 98cad73

7 files changed

+19
-14
lines changed

src/Http/Http.Extensions/test/ValidationsGenerator/ValidationsGenerator.ComplexType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public class SubTypeWithInheritance : SubType
7575
}
7676
""";
7777
await Verify(source, out var compilation);
78-
VerifyEndpoint(compilation, "/complex-type", async (endpoint, serviceProvider) =>
78+
await VerifyEndpoint(compilation, "/complex-type", async (endpoint, serviceProvider) =>
7979
{
8080
await InvalidIntegerWithRangeProducesError(endpoint);
8181
await InvalidIntegerWithRangeAndDisplayNameProducesError(endpoint);

src/Http/Http.Extensions/test/ValidationsGenerator/ValidationsGenerator.IValidatableObject.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public IEnumerable<ValidationResult> Validate(ValidationContext validationContex
4646
var maximum = rangeService?.GetMaximum();
4747
if (Value1 < minimum || Value1 > maximum)
4848
{
49-
yield return new ValidationResult($"The field {validationContext.DisplayName} must be between {minimum} and {maximum}.", [nameof(Value1)]);
49+
yield return new ValidationResult($"The field {nameof(Value1)} must be between {minimum} and {maximum}.", [nameof(Value1)]);
5050
}
5151
}
5252
}
@@ -88,7 +88,7 @@ public class RangeService : IRangeService
8888

8989
await Verify(source, out var compilation);
9090

91-
VerifyEndpoint(compilation, "/validatable-object", async (endpoint, serviceProvider) =>
91+
await VerifyEndpoint(compilation, "/validatable-object", async (endpoint, serviceProvider) =>
9292
{
9393
await ValidateMethodCalledIfPropertyValidationsFail();
9494
await ValidateForSubtypeInvokedFirst();
@@ -126,12 +126,12 @@ async Task ValidateMethodCalledIfPropertyValidationsFail()
126126
error =>
127127
{
128128
Assert.Equal("SubType.Value3", error.Key);
129-
Assert.Equal("The field StringWithLength must be 'some-value'.", error.Value.Single());
129+
Assert.Equal("The field ValidatableSubType must be 'some-value'.", error.Value.Single());
130130
},
131131
error =>
132132
{
133133
Assert.Equal("Value1", error.Key);
134-
Assert.Equal("The field Value 1 must be between 10 and 100.", error.Value.Single());
134+
Assert.Equal("The field Value1 must be between 10 and 100.", error.Value.Single());
135135
});
136136
}
137137

@@ -157,6 +157,11 @@ async Task ValidateForSubtypeInvokedFirst()
157157
{
158158
Assert.Equal("SubType.Value3", error.Key);
159159
Assert.Equal("The field ValidatableSubType must be 'some-value'.", error.Value.Single());
160+
},
161+
error =>
162+
{
163+
Assert.Equal("Value1", error.Key);
164+
Assert.Equal("The field Value1 must be between 10 and 100.", error.Value.Single());
160165
});
161166
}
162167

@@ -181,7 +186,7 @@ async Task ValidateForTopLevelInvoked()
181186
error =>
182187
{
183188
Assert.Equal("Value1", error.Key);
184-
Assert.Equal("The field ComplexValidatableType must be between 10 and 100.", error.Value.Single());
189+
Assert.Equal("The field Value1 must be between 10 and 100.", error.Value.Single());
185190
});
186191
}
187192
});

src/Http/Http.Extensions/test/ValidationsGenerator/ValidationsGenerator.Parameters.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class CustomValidationAttribute : ValidationAttribute
4040
}
4141
""";
4242
await Verify(source, out var compilation);
43-
VerifyEndpoint(compilation, "/params", async (endpoint, serviceProvider) =>
43+
await VerifyEndpoint(compilation, "/params", async (endpoint, serviceProvider) =>
4444
{
4545
var context = CreateHttpContext(serviceProvider);
4646
context.Request.QueryString = new QueryString("?value1=5&value2=5&value3=&value4=3&value5=5");

src/Http/Http.Extensions/test/ValidationsGenerator/ValidationsGenerator.Polymorphism.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public class DerivedValidatableType : BaseValidatableType
7979
""";
8080
await Verify(source, out var compilation);
8181

82-
VerifyEndpoint(compilation, "/basic-polymorphism", async (endpoint, serviceProvider) =>
82+
await VerifyEndpoint(compilation, "/basic-polymorphism", async (endpoint, serviceProvider) =>
8383
{
8484
var httpContext = CreateHttpContextWithPayload("""
8585
{
@@ -111,7 +111,7 @@ public class DerivedValidatableType : BaseValidatableType
111111
});
112112
});
113113

114-
VerifyEndpoint(compilation, "/validatable-polymorphism", async (endpoint, serviceProvider) =>
114+
await VerifyEndpoint(compilation, "/validatable-polymorphism", async (endpoint, serviceProvider) =>
115115
{
116116
var httpContext = CreateHttpContextWithPayload("""
117117
{
@@ -155,7 +155,7 @@ public class DerivedValidatableType : BaseValidatableType
155155
});
156156
});
157157

158-
VerifyEndpoint(compilation, "/polymorphism-container", async (endpoint, serviceProvider) =>
158+
await VerifyEndpoint(compilation, "/polymorphism-container", async (endpoint, serviceProvider) =>
159159
{
160160
var httpContext = CreateHttpContextWithPayload("""
161161
{

src/Http/Http.Extensions/test/ValidationsGenerator/ValidationsGenerator.Recursion.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class RecursiveType
3333
""";
3434
await Verify(source, out var compilation);
3535

36-
VerifyEndpoint(compilation, "/recursive-type", async (endpoint, serviceProvider) =>
36+
await VerifyEndpoint(compilation, "/recursive-type", async (endpoint, serviceProvider) =>
3737
{
3838
var httpContext = CreateHttpContextWithPayload("""
3939
{

src/Http/Http.Extensions/test/ValidationsGenerator/ValidationsGeneratorTestBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ internal static void VerifyValidatableType(Compilation compilation, string typeN
9494
verifyFunc(validatableTypeInfo);
9595
}
9696

97-
internal static void VerifyEndpoint(Compilation compilation, string routePattern, Action<Endpoint, IServiceProvider> verifyFunc)
97+
internal static async Task VerifyEndpoint(Compilation compilation, string routePattern, Func<Endpoint, IServiceProvider, Task> verifyFunc)
9898
{
9999
if (TryResolveServicesFromCompilation(compilation, targetAssemblyName: "Microsoft.AspNetCore.Routing", typeName: "Microsoft.AspNetCore.Routing.EndpointDataSource", out var services, out var serviceType, out var outputAssemblyName) is false)
100100
{
@@ -103,7 +103,7 @@ internal static void VerifyEndpoint(Compilation compilation, string routePattern
103103
var service = services.GetService(serviceType) ?? throw new InvalidOperationException("Could not resolve EndpointDataSource.");
104104
var endpoints = (IReadOnlyList<Endpoint>)service.GetType().GetProperty("Endpoints", BindingFlags.Instance | BindingFlags.Public).GetValue(service);
105105
var endpoint = endpoints.FirstOrDefault(endpoint => endpoint is RouteEndpoint routeEndpoint && routeEndpoint.RoutePattern.RawText == routePattern);
106-
verifyFunc(endpoint, services);
106+
await verifyFunc(endpoint, services);
107107
}
108108

109109
private static bool TryResolveServicesFromCompilation(Compilation compilation, string targetAssemblyName, string typeName, out IServiceProvider serviceProvider, out Type serviceType, out string outputAssemblyName)

src/Http/Http.Extensions/test/ValidationsGenerator/snapshots/ValidationsGeneratorTests.CanValidateIValidatableObject#ValidatableInfoResolver.g.verified.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ private ValidatableParameterInfo CreateParameterInfomodel()
220220
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.ValidationsGenerator, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")]
221221
file static class GeneratedServiceCollectionExtensions
222222
{
223-
[global::System.Runtime.CompilerServices.InterceptsLocationAttribute(1, "ZbyAIis29Y/4fT/GGaRWq7ABAABQcm9ncmFtLmNz")]
223+
[global::System.Runtime.CompilerServices.InterceptsLocationAttribute(1, "uQnZr9MSHY6ZEeLkq015qrABAABQcm9ncmFtLmNz")]
224224
public static IServiceCollection AddValidation(this IServiceCollection services, Action<ValidationOptions>? configureOptions = null)
225225
{
226226
// Use non-extension method to avoid infinite recursion.

0 commit comments

Comments
 (0)