Skip to content

Commit 7126ed7

Browse files
committed
Fix validation behavior for CollectionRuleActionOptions
The generator expects IValidatableObject results to have a MemberName.
1 parent 2a3d8c3 commit 7126ed7

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

src/Tests/CollectionRuleActions.UnitTests/ActionListExecutorTests.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ await TestHostHelper.CreateCollectionRulesHost(_outputHelper, rootOptions =>
7676
});
7777
}
7878

79-
[Fact]
79+
[Fact(Skip = "https://github.com/dotnet/aspnetcore/pull/61402")]
8080
public Task ActionListExecutor_SecondActionFail_DeferredCompletion()
8181
{
8282
return ActionListExecutor_SecondActionFail(waitForCompletion: false);
@@ -165,9 +165,9 @@ await TestHostHelper.CreateCollectionRulesHost(_outputHelper, rootOptions =>
165165
Assert.Equal(string.Format(Strings.ErrorMessage_NonzeroExitCode, "1"), actionExecutionException.Message);
166166

167167
VerifyStartCallbackCount(waitForCompletion, callbackCount);
168-
}, services =>
168+
}, serviceCollection =>
169169
{
170-
services.AddValidation();
170+
AddValidation(serviceCollection);
171171
});
172172
}
173173

@@ -190,9 +190,15 @@ await TestHostHelper.CreateCollectionRulesHost(_outputHelper, rootOptions =>
190190
}, serviceCollection =>
191191
{
192192
serviceCollection.RegisterCollectionRuleAction<PassThroughActionFactory, PassThroughOptions>(nameof(PassThroughAction));
193+
AddValidation(serviceCollection);
193194
});
194195
}
195196

197+
static void AddValidation(IServiceCollection serviceCollection)
198+
{
199+
serviceCollection.AddValidation();
200+
}
201+
196202
private static void VerifyStartCallbackCount(bool waitForCompletion, int callbackCount)
197203
{
198204
//Currently, any attempt to wait on completion will automatically trigger the start callback.

src/Tests/CollectionRuleActions.UnitTests/CollectionRuleActions.UnitTests.csproj

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project>
2+
3+
<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk.Web" />
24

35
<PropertyGroup>
46
<TargetFrameworks>$(ToolTargetFrameworks)</TargetFrameworks>
@@ -16,4 +18,20 @@
1618
<ProjectReference Include="..\Microsoft.Diagnostics.Monitoring.Tool.UnitTestCommon\Microsoft.Diagnostics.Monitoring.Tool.UnitTestCommon.csproj" />
1719
</ItemGroup>
1820

21+
<ItemGroup>
22+
<KnownFrameworkReference
23+
Update="Microsoft.NETCore.App"
24+
TargetingPackVersion="$(NetCoreAppVersion)"
25+
DefaultRuntimeFrameworkVersion="$(NetCoreAppVersion)"
26+
LatestRuntimeFrameworkVersion="$(NetCoreAppVersion)" />
27+
28+
<KnownFrameworkReference
29+
Update="Microsoft.AspNetCore.App"
30+
TargetingPackVersion="$(AspNetCoreAppVersion)"
31+
DefaultRuntimeFrameworkVersion="$(AspNetCoreAppVersion)"
32+
LatestRuntimeFrameworkVersion="$(AspNetCoreAppVersion)" />
33+
</ItemGroup>
34+
35+
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk.Web" />
36+
1937
</Project>

src/Tools/dotnet-monitor/CollectionRules/Options/CollectionRuleActionOptions.Validate.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ IEnumerable<ValidationResult> IValidatableObject.Validate(ValidationContext vali
1818

1919
if (!string.IsNullOrEmpty(Type))
2020
{
21+
validationContext = new ValidationContext(this, displayName: Type, validationContext, items: null)
22+
{
23+
MemberName = nameof(Settings)
24+
};
2125
actionOperations.TryValidateOptions(Type, Settings, validationContext, results);
2226
}
2327

0 commit comments

Comments
 (0)