Mercurial > repos > IBBoard.NUnit.Tests
changeset 2:664e47280811
Re #46: Add NUnit helper methods
* Test partial and subset matches with arrays
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 21 Aug 2010 14:54:21 +0000 |
parents | 6ba8ac49a923 |
children | 1a4f10193bf5 |
files | Constraints/ArrayContainsConstraintTest.cs |
diffstat | 1 files changed, 77 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/Constraints/ArrayContainsConstraintTest.cs Sat Aug 21 14:24:41 2010 +0000 +++ b/Constraints/ArrayContainsConstraintTest.cs Sat Aug 21 14:54:21 2010 +0000 @@ -38,6 +38,36 @@ Assert.That(constraint.Matches(new string[] { "something" }), Is.False); Assert.That(constraint.Matches(new string[] { "" }), Is.False); } + + [Test()] + public void TestArrayContainsReturnsFalseForPartialMatch() + { + ArrayContainsConstraint<string> constraint = new ArrayContainsConstraint<string>("str"); + Assert.That(constraint.Matches(new string[] { + "str", + "something" + }), Is.False); + + constraint = new ArrayContainsConstraint<string>("str", "something"); + Assert.That(constraint.Matches(new string[] { + "str", + "something", + "other thing" + }), Is.False); + } + + [Test()] + public void TestArrayContainsReturnsFalseForSubsetMatch() + { + ArrayContainsConstraint<string> constraint = new ArrayContainsConstraint<string>("str", "something"); + Assert.That(constraint.Matches(new string[] { "str" }), Is.False); + + constraint = new ArrayContainsConstraint<string>("str", "something", "other thing"); + Assert.That(constraint.Matches(new string[] { + "str", + "something" + }), Is.False); + } [Test()] public void TestArrayContainsReturnsTrueForSimpleMatch() @@ -52,33 +82,71 @@ } [Test()] - public void TestArrayContainsReturnsCorrectErrorForSimpleNonMatch() + public void TestArrayContainsReturnsCorrectMessageForSimpleNonMatch() { ArrayContainsConstraint<string> constraint = new ArrayContainsConstraint<string>("str"); Assert.That(constraint.Matches(new string[] { "something" }), Is.False); MessageWriter mw = new TextMessageWriter(); constraint.WriteMessageTo(mw); - Console.WriteLine(mw.ToString()); - Assert.That(mw.ToString(), Is.EqualTo(" Expected: \"str\"\n But was: \"something\"\n Incorrect value at 0\n")); + Assert.That(mw.ToString(), Is.EqualTo(" Expected: \"str\"\n But was: \"something\"\n Incorrect value at index 0\n")); Assert.That(constraint.Matches(new string[] { "" }), Is.False); mw = new TextMessageWriter(); constraint.WriteMessageTo(mw); - Console.WriteLine(mw.ToString()); - Assert.That(mw.ToString(), Is.EqualTo(" Expected: \"str\"\n But was: <string.Empty>\n Incorrect value at 0\n")); + Assert.That(mw.ToString(), Is.EqualTo(" Expected: \"str\"\n But was: <string.Empty>\n Incorrect value at index 0\n")); Assert.That(constraint.Matches(new string[0]), Is.False); mw = new TextMessageWriter(); constraint.WriteMessageTo(mw); - Console.WriteLine(mw.ToString()); - Assert.That(mw.ToString(), Is.EqualTo(" Expected: \"str\"\n But was: Empty array\n")); + Assert.That(mw.ToString(), Is.EqualTo(" Expected: \"str\"\n But was: Empty array\n Expected value at index 0\n")); constraint = new ArrayContainsConstraint<string>(); Assert.That(constraint.Matches(new string[] { "" }), Is.False); mw = new TextMessageWriter(); constraint.WriteMessageTo(mw); - Console.WriteLine(mw.ToString()); - Assert.That(mw.ToString(), Is.EqualTo(" Expected: Empty array\n But was: <string.Empty>\n")); + Assert.That(mw.ToString(), Is.EqualTo(" Expected: Empty array\n But was: <string.Empty>\n Unexpected value at index 0\n")); + } + + [Test()] + public void TestArrayContainsReturnsCorrectMessageForPartialMatch() + { + ArrayContainsConstraint<string> constraint = new ArrayContainsConstraint<string>("str"); + Assert.That(constraint.Matches(new string[] { + "str", + "something" + }), Is.False); + MessageWriter mw = new TextMessageWriter(); + constraint.WriteMessageTo(mw); + Assert.That(mw.ToString(), Is.EqualTo(" Expected: End of array\n But was: \"something\"\n Unexpected value at index 1\n")); + + constraint = new ArrayContainsConstraint<string>("str", "something"); + Assert.That(constraint.Matches(new string[] { + "str", + "something", + "other thing" + }), Is.False); + mw = new TextMessageWriter(); + constraint.WriteMessageTo(mw); + Assert.That(mw.ToString(), Is.EqualTo(" Expected: End of array\n But was: \"other thing\"\n Unexpected value at index 2\n")); + } + + [Test()] + public void TestArrayContainsReturnsCorrectMessageForSubsetMatch() + { + ArrayContainsConstraint<string> constraint = new ArrayContainsConstraint<string>("str", "something"); + Assert.That(constraint.Matches(new string[] { "str" }), Is.False); + MessageWriter mw = new TextMessageWriter(); + constraint.WriteMessageTo(mw); + Assert.That(mw.ToString(), Is.EqualTo(" Expected: \"something\"\n But was: End of array\n Expected value at index 1\n")); + + constraint = new ArrayContainsConstraint<string>("str", "something", "other thing"); + Assert.That(constraint.Matches(new string[] { + "str", + "something" + }), Is.False); + mw = new TextMessageWriter(); + constraint.WriteMessageTo(mw); + Assert.That(mw.ToString(), Is.EqualTo(" Expected: \"other thing\"\n But was: End of array\n Expected value at index 2\n")); } } }