-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAreEqual.cs
26 lines (21 loc) · 862 Bytes
/
AreEqual.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
using FluentValidation.Results;
using System.Collections.Generic;
namespace BaseXml.Validation
{
public class AreEqual : IValidateNode
{
private readonly XPath Expected;
public AreEqual(XPath expected)
{
Expected = expected;
}
public ValidationResult IsValid(XPath xpath, string value, IEvaluate evaluate)
{
var failures = new List<ValidationFailure>();
var expected = evaluate.Evaluate<string>(Expected);
if (!string.IsNullOrEmpty(value) && !string.IsNullOrEmpty(expected) && value != expected)
failures.Add(new ValidationFailure(nameof(Required), $"Node [{xpath.Expression}] is different from [{Expected.Expression}]. Actual: [{value}], Expected: [{expected}]"));
return new ValidationResult(failures);
}
}
}