-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added null handling for DictionaryExtension method (#1036)
- Loading branch information
1 parent
8d23e56
commit f84ee0f
Showing
2 changed files
with
35 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
test/SimplCommerce.Infrastructure.Tests/Extensions/DictionaryExtensionsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System.Collections.Generic; | ||
using SimplCommerce.Infrastructure.Extensions; | ||
using Xunit; | ||
|
||
namespace SimplCommerce.Infrastructure.Tests | ||
{ | ||
public class DictionaryExtensionsTests | ||
{ | ||
internal class MockClass | ||
{ | ||
} | ||
|
||
[Fact] | ||
public void GetOrDefaultShouldReturnDefaultWithNullDictionary() | ||
{ | ||
Dictionary<string, MockClass> dict = null; | ||
MockClass result = dict.GetOrDefault("key"); | ||
Assert.Null(result); | ||
} | ||
|
||
[Fact] | ||
public void GetOrDefaultShouldReturnCorrectValue() | ||
{ | ||
MockClass mockClass = new MockClass(); | ||
Dictionary<string, MockClass> dict = new Dictionary<string, MockClass> { { "key", mockClass } }; | ||
MockClass result = dict.GetOrDefault("key"); | ||
Assert.NotNull(result); | ||
Assert.Equal(mockClass, result); | ||
} | ||
} | ||
} |