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

Improve code coverage and fix some test mutations #1839

Merged
merged 9 commits into from Mar 14, 2022
8 changes: 4 additions & 4 deletions Src/FluentAssertions/Xml/XDocumentAssertions.cs
Expand Up @@ -132,7 +132,7 @@ public AndConstraint<XDocumentAssertions> NotBeEquivalentTo(XDocument unexpected
params object[] becauseArgs)
{
Guard.ThrowIfArgumentIsNull(expected, nameof(expected),
"Cannot assert the document has a root element if the element name is <null>*");
"Cannot assert the document has a root element if the expected name is <null>*");

return HaveRoot(XNamespace.None + expected, because, becauseArgs);
}
Expand All @@ -157,7 +157,7 @@ public AndConstraint<XDocumentAssertions> NotBeEquivalentTo(XDocument unexpected
}

Guard.ThrowIfArgumentIsNull(expected, nameof(expected),
"Cannot assert the document has a root element if the element name is <null>*");
"Cannot assert the document has a root element if the expected name is <null>*");

XElement root = Subject.Root;

Expand Down Expand Up @@ -189,7 +189,7 @@ public AndConstraint<XDocumentAssertions> NotBeEquivalentTo(XDocument unexpected
params object[] becauseArgs)
{
Guard.ThrowIfArgumentIsNull(expected, nameof(expected),
"Cannot assert the document has an element if the element name is <null>*");
"Cannot assert the document has an element if the expected name is <null>*");

return HaveElement(XNamespace.None + expected, because, becauseArgs);
}
Expand Down Expand Up @@ -217,7 +217,7 @@ public AndConstraint<XDocumentAssertions> NotBeEquivalentTo(XDocument unexpected
}

Guard.ThrowIfArgumentIsNull(expected, nameof(expected),
"Cannot assert the document has an element if the element name is <null>*");
"Cannot assert the document has an element if the expected name is <null>*");

Execute.Assertion
.ForCondition(Subject.Root is not null)
Expand Down
3 changes: 1 addition & 2 deletions Src/FluentAssertions/Xml/XmlNodeFormatter.cs
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Xml;
using System.Xml;
using FluentAssertions.Common;
using FluentAssertions.Formatting;

Expand Down
Expand Up @@ -13,8 +13,6 @@ namespace FluentAssertions.Specs.Collections
/// </content>
public partial class CollectionAssertionSpecs
{
#region Contain Single

[Fact]
public void When_injecting_a_null_predicate_into_ContainSingle_it_should_throw()
{
Expand Down Expand Up @@ -272,6 +270,22 @@ public void When_collection_is_IEnumerable_it_should_be_evaluated_only_once()
act.Should().NotThrow();
}

#endregion
[Fact]
public void When_an_assertion_fails_on_ContainSingle_succeeding_message_should_be_included()
{
// Act
Action act = () =>
{
using var _ = new AssertionScope();
var values = new List<int>();
values.Should().ContainSingle();
values.Should().ContainSingle();
};

// Assert
act.Should().Throw<XunitException>()
.WithMessage("Expected*to contain a single item, but the collection is empty*" +
"Expected*to contain a single item, but the collection is empty*");
}
}
}
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using FluentAssertions.Execution;
using Xunit;
using Xunit.Sdk;

Expand Down Expand Up @@ -1570,6 +1571,24 @@ public void When_a_dictionary_checks_a_list_of_keys_not_to_be_present_it_will_ho
// Assert
act.Should().Throw<XunitException>();
}

[Fact]
public void When_an_assertion_fails_on_ContainKey_succeeding_message_should_be_included()
{
// Act
Action act = () =>
{
using var _ = new AssertionScope();
var values = new Dictionary<int, int>();
values.Should().ContainKey(0);
values.Should().ContainKey(1);
};

// Assert
act.Should().Throw<XunitException>()
.WithMessage("Expected*to contain key 0*Expected*to contain key 1*");
}

#endregion

#region ContainValue
Expand Down