-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathContextValidator.cs
More file actions
24 lines (20 loc) · 688 Bytes
/
ContextValidator.cs
File metadata and controls
24 lines (20 loc) · 688 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// ReSharper disable UnusedVariable
#region FluentValidation_ContextValidator
public class ContextValidator :
AbstractValidator<TheMessage>
{
public ContextValidator() =>
RuleFor(_ => _.Content)
.Custom((propertyValue, validationContext) =>
{
var messageHeaders = validationContext.Headers();
var bag = validationContext.ContextBag();
if (propertyValue != "User" ||
messageHeaders.ContainsKey("Auth"))
{
return;
}
validationContext.AddFailure("Expected Auth header to exist");
});
}
#endregion