Skip to content

Commit aafb0b3

Browse files
committed
ensure xsi:type can be used together with placeholders
see xmlunit/xmlunit#276
1 parent 94ae24c commit aafb0b3

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

RELEASE_NOTES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## XMLUnit.NET 2.11.1 - /Not Released, yet/
44

5+
* PlaceholderDifferenceEvaluator would cause InvalidCastException for documents with
6+
differences in `xsi:type` attributes.
7+
Equivalent of XMLUnit Java Issue [#276](https://github.com/xmlunit/xmlunit/issues/276)
8+
59
* added readme files for the nuget packages.
610
Issue [#46](https://github.com/xmlunit/xmlunit.net/issues/46).
711

src/main/net-placeholders/PlaceholderDifferenceEvaluator.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,10 @@ public ComparisonResult Evaluate(Comparison comparison, ComparisonResult outcome
238238
return EvaluateConsideringPlaceholders(controlTarget.Value, testTarget.Value, outcome);
239239

240240
// comparing textual content of attributes
241-
} else if (comparison.Type == ComparisonType.ATTR_VALUE) {
241+
}
242+
else if (comparison.Type == ComparisonType.ATTR_VALUE && controlDetails.Value is string &&
243+
testDetails.Value is string)
244+
{
242245
return EvaluateConsideringPlaceholders((string) controlDetails.Value,
243246
(string) testDetails.Value, outcome);
244247

src/tests/net-placeholders/PlaceholderDifferenceEvaluatorTest.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,5 +446,29 @@ public void IsDateTimePlaceholder_Element_IsDateTime_CustomFormat() {
446446

447447
Assert.IsFalse(diff.HasDifferences());
448448
}
449+
450+
[Test]
451+
public void CanCompareDocmentsWithXsiTypes() {
452+
string control = "<element"
453+
+ " xmlns:myns=\"https://example.org/some-ns\""
454+
+ " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
455+
+ " xsi:type=\"myns:some-type\" />";
456+
string test = "<element"
457+
+ " xmlns:myns=\"https://example.org/some-ns\""
458+
+ " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
459+
+ " xsi:type=\"myns:some-other-type\" />";
460+
461+
var diff = DiffBuilder.Compare(control).WithTest(test)
462+
.WithDifferenceEvaluator(new PlaceholderDifferenceEvaluator().Evaluate).Build();
463+
464+
Assert.IsTrue(diff.HasDifferences());
465+
int count = 0;
466+
foreach (Difference difference in diff.Differences) {
467+
count++;
468+
Assert.AreEqual(ComparisonResult.DIFFERENT, difference.Result);
469+
Assert.AreEqual(ComparisonType.ATTR_VALUE, difference.Comparison.Type);
470+
}
471+
Assert.AreEqual(1, count);
472+
}
449473
}
450474
}

0 commit comments

Comments
 (0)