Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made FluentAssertXml classes use "Assert.That" so they can work in clients that use NUnit 4. #1373

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Changed
- [SIL.TestUtilities] Made FluentAssertXml classes use "Assert.That" so they can work in clients that use NUnit 4.

## [15.0.0] - 2025-01-06

### Added
Expand Down
2 changes: 2 additions & 0 deletions Palaso.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=Ibus/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=IETF/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=IMDI/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=inequivalence/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=ingl_00E9s/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=insertable/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=interlinearized/@EntryIndexedValue">True</s:Boolean>
Expand All @@ -94,6 +95,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=Mets/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=migrator/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=modally/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Nodewise/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=nunit/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=OLAC/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=optimizable/@EntryIndexedValue">True</s:Boolean>
Expand Down
2 changes: 1 addition & 1 deletion SIL.DblBundle/DblMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ protected virtual void InitializeMetadata()
}

/// <summary>
/// The language element of the metadata. Can be any class of type DblMetadataLangauge.
/// The language element of the metadata. Can be any class of type DblMetadataLanguage.
/// </summary>
[XmlElement("language")]
public virtual TL Language { get; set; }
Expand Down
34 changes: 14 additions & 20 deletions SIL.TestUtilities/FluentAssertXml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ protected override XmlNode NodeOrDom
/// <summary>
/// Assert functional equivalence of two XML strings while ignoring whitespace
///
/// May fail if XML header is different. Also, see warning in CanonicalXml.
/// May fail if XML header is different. Also, see warning in CanonicalXml.
/// </summary>
/// <param name="xml"></param>
public void EqualsIgnoreWhitespace(string xml)
{
Assert.AreEqual(CanonicalXml.ToCanonicalString(_xmlString), CanonicalXml.ToCanonicalString(xml));
Assert.That(CanonicalXml.ToCanonicalString(xml), Is.EqualTo(CanonicalXml.ToCanonicalString(_xmlString)));
}

/// <summary>
Expand All @@ -63,7 +63,7 @@ public void EqualsIgnoreWhitespace(string xml)
/// <param name="xml"></param>
public void NotEqualsIgnoreWhitespace(string xml)
{
Assert.AreNotEqual(CanonicalXml.ToCanonicalString(_xmlString), CanonicalXml.ToCanonicalString(xml));
Assert.That(CanonicalXml.ToCanonicalString(xml), Is.Not.EqualTo(CanonicalXml.ToCanonicalString(_xmlString)));
}

/// <summary>
Expand All @@ -80,8 +80,8 @@ public void NotEqualsIgnoreWhitespace(string xml)
/// <param name="xml"></param>
public void IsNodewiseEqualTo(string xml)
{
Assert.IsTrue(NodeWiseEquals(xml),
String.Format("{0}\n\nis not nodewise equivalent to\n\n{1}", _xmlString, xml));
Assert.That(NodeWiseEquals(xml), Is.True,
$"{_xmlString}\n\nis not nodewise equivalent to\n\n{xml}");
}

/// <summary>
Expand All @@ -90,8 +90,8 @@ public void IsNodewiseEqualTo(string xml)
/// <param name="xml"></param>
public void IsNotNodewiseEqualTo(string xml)
{
Assert.IsFalse(NodeWiseEquals(xml),
String.Format("{0}\n\nis nodewise equivalent to\n\n{1}", _xmlString, xml));
Assert.That(NodeWiseEquals(xml), Is.False,
$"{_xmlString}\n\nis nodewise equivalent to\n\n{xml}");
}

private bool NodeWiseEquals(string xml)
Expand Down Expand Up @@ -129,13 +129,7 @@ public AssertDom(XmlDocument dom)
_dom = dom;
}

protected override XmlNode NodeOrDom
{
get
{
return _dom;
}
}
protected override XmlNode NodeOrDom => _dom;
}

public abstract class AssertXmlCommands
Expand All @@ -150,7 +144,7 @@ public void HasAtLeastOneMatchForXpath(string xpath, XmlNamespaceManager nameSpa
Console.WriteLine("Could not match " + xpath);
PrintNodeToConsole(NodeOrDom);
}
Assert.IsNotNull(node, "Not matched: " + xpath);
Assert.That(node, Is.Not.Null, "Not matched: " + xpath);
}

/// <summary>
Expand All @@ -164,7 +158,7 @@ public void HasAtLeastOneMatchForXpath(string xpath)
Console.WriteLine("Could not match " + xpath);
PrintNodeToConsole(NodeOrDom);
}
Assert.IsNotNull(node, "Not matched: " + xpath);
Assert.That(node, Is.Not.Null, "Not matched: " + xpath);
}

/// <summary>
Expand All @@ -181,22 +175,22 @@ public void HasSpecifiedNumberOfMatchesForXpath(string xpath, int count, XmlName
public void HasSpecifiedNumberOfMatchesForXpath(string xpath, int count, bool verbose, XmlNamespaceManager nameSpaceManager = null)
{
var nodes = nameSpaceManager == null ? NodeOrDom.SafeSelectNodes(xpath) : NodeOrDom.SafeSelectNodes(xpath, nameSpaceManager);
if (nodes==null)
if (nodes == null)
{
if (count > 0)
{
Console.WriteLine("Expected {0} but got 0 matches for {1}", count, xpath);
if (verbose)
PrintNodeToConsole(NodeOrDom);
}
Assert.AreEqual(count, 0);
Assert.That(count, Is.EqualTo(0));
}
else if (nodes.Count != count)
{
Console.WriteLine("Expected {0} but got {1} matches for {2}", count, nodes.Count, xpath);
if (verbose)
PrintNodeToConsole(NodeOrDom);
Assert.AreEqual(count, nodes.Count, "matches for " + xpath);
Assert.That(nodes.Count, Is.EqualTo(count), "matches for " + xpath);
}
}

Expand Down Expand Up @@ -228,7 +222,7 @@ public void HasNoMatchForXpath(string xpath, XmlNamespaceManager nameSpaceManage
if (print)
PrintNodeToConsole(NodeOrDom);
}
Assert.IsNull(node, "Should not have matched: {0}{1}{2}", xpath, Environment.NewLine, message);
Assert.That(node, Is.Null, "Should not have matched: {0}{1}{2}", xpath, Environment.NewLine, message);
}

private XmlNode GetNode(string xpath)
Expand Down
Loading