Skip to content

Commit

Permalink
Add some basic tests that null values can be found in dictionaries by…
Browse files Browse the repository at this point in the history
… DictionaryContains(Key)ValueConstraint.
  • Loading branch information
Andrew McClement committed Apr 13, 2024
1 parent 19f5d39 commit 625147c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ namespace NUnit.Framework.Tests.Constraints
[TestFixture]
public class DictionaryContainsKeyValuePairConstraintTests
{
[Test]
public void SucceedsWhenKeyValuePairIsPresent()
[Theory]
public void SucceedsWhenKeyValuePairIsPresent(bool valueIsNull)
{
var dictionary = new Dictionary<string, string> { { "Hello", "World" }, { "Hi", "Universe" }, { "Hola", "Mundo" } };
var expectedValue = valueIsNull ? null : "Universe";
var dictionary = new Dictionary<string, string?> { { "Hello", "World" }, { "Hi", expectedValue }, { "Hola", "Mundo" } };

Assert.That(dictionary, new DictionaryContainsKeyValuePairConstraint("Hi", "Universe"));
Assert.That(dictionary, new DictionaryContainsKeyValuePairConstraint("Hi", expectedValue));
}

[Test]
Expand All @@ -38,11 +39,12 @@ public void FailsWhenValueIsMissing()
Assert.That(act, Throws.Exception.TypeOf<AssertionException>());
}

[Test]
public void SucceedsWhenPairIsPresentUsingContainKeyWithValue()
[Theory]
public void SucceedsWhenPairIsPresentUsingContainKeyWithValue(bool valueIsNull)
{
var dictionary = new Dictionary<string, string> { { "Hello", "World" }, { "Hola", "Mundo" } };
Assert.That(dictionary, Does.ContainKey("Hola").WithValue("Mundo"));
var expectedValue = valueIsNull ? null : "Mundo";
var dictionary = new Dictionary<string, string?> { { "Hello", "World" }, { "Hola", expectedValue } };
Assert.That(dictionary, Does.ContainKey("Hola").WithValue(expectedValue));
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ public void FailsWhenValueIsMissing()
Assert.That(act, Throws.Exception.TypeOf<AssertionException>());
}

[Test]
public void SucceedsWhenValueIsPresentUsingContainValue()
[Theory]
public void SucceedsWhenValueIsPresentUsingContainValue(bool valueIsNull)
{
var dictionary = new Dictionary<string, string> { { "Hello", "World" }, { "Hola", "Mundo" } };
Assert.That(dictionary, Does.ContainValue("Mundo"));
var expectedValue = valueIsNull ? null : "Mundo";
var dictionary = new Dictionary<string, string?> { { "Hello", "World" }, { "Hola", expectedValue } };
Assert.That(dictionary, Does.ContainValue(expectedValue));
}

[Test]
Expand Down

0 comments on commit 625147c

Please sign in to comment.