Skip to content

Commit

Permalink
Adding test for XmlHelpers.AddAttributeIfNotNullOrEmpty
Browse files Browse the repository at this point in the history
- We were on the way to introduce an optimization, which would have broken the
  implementation without noticing. Introducing a test to ensure that we'll
  not break things.
  • Loading branch information
AndersAbel committed Mar 5, 2015
1 parent 0698415 commit b4a45cc
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Kentor.AuthServices.Tests/Internal/XmlHelpersTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,21 @@ public void XmlHelpers_AddAttributeIfNotNullOrEmpty_IgnoresObjectWithEmptyToStri
e.Attribute("attribute").Should().BeNull();
}

[TestMethod]
public void XmlHelpers_AddAttributeIfNotNullOrEmtpy_TimeSpanSerializedCorrectly()
{
// It might be tempting in the implementation to call value.ToString()
// instead of passing in the value. That would make types that have
// special XML Serialization formats fail. This test ensures that
// nobody takes that shortcut without handling the special cases.

var e = new XElement("xml");

e.AddAttributeIfNotNullOrEmpty("attribute", new TimeSpan(2, 17, 32));

e.Attribute("attribute").Should().NotBeNull().And.Subject.Value.Should().Be("PT2H17M32S");
}

[TestMethod]
public void XmlHelpers_GetValueIfNotNull_NullOnNull()
{
Expand Down Expand Up @@ -110,5 +125,6 @@ public void XmlHelpers_GetTrimmedTextIfNotNull_NullOnNull()

e.GetTrimmedTextIfNotNull().Should().BeNull();
}

}
}

0 comments on commit b4a45cc

Please sign in to comment.