-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from goggenb/ObjectExtensionTests
Added ObjectExtensions tests
- Loading branch information
Showing
5 changed files
with
137 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
Source/MoreDotNet.Test/Extensions/Common/ObjectExtensions/AsTests.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,25 @@ | ||
namespace MoreDotNet.Tests.Extensions.Common.ObjectExtensions | ||
{ | ||
using System; | ||
using MoreDotNet.Extensions.Common; | ||
using Xunit; | ||
|
||
public class AsTests | ||
{ | ||
[Fact] | ||
public void As_StringObjectAsString_ShouldReturnString() | ||
{ | ||
object input = "Value"; | ||
var result = input.As<string>(); | ||
Assert.IsType<string>(result); | ||
} | ||
|
||
[Fact] | ||
public void As_IntAsString_ShouldReturnNull() | ||
{ | ||
object input = 3; | ||
var result = input.As<string>(); | ||
Assert.Null(result); | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
Source/MoreDotNet.Test/Extensions/Common/ObjectExtensions/IsNotTests.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,38 @@ | ||
namespace MoreDotNet.Tests.Extensions.Common.ObjectExtensions | ||
{ | ||
using System; | ||
using MoreDotNet.Extensions.Common; | ||
using Xunit; | ||
|
||
public class IsNotTests | ||
{ | ||
[Fact] | ||
public void IsNot_NullItem_ShouldThrowShouldThrowArgumentNullException() | ||
{ | ||
ExampleA input = null; | ||
Assert.Throws<ArgumentNullException>(() => input.IsNot<ExampleB>()); | ||
} | ||
|
||
[Fact] | ||
public void IsNot_BIsNotA_ShouldReturnTrue() | ||
{ | ||
var input = new ExampleB(); | ||
Assert.True(input.IsNot<ExampleA>()); | ||
} | ||
|
||
[Fact] | ||
public void IsNot_BIsNotB_ShouldReturnFalse() | ||
{ | ||
var input = new ExampleB(); | ||
Assert.False(input.IsNot<ExampleB>()); | ||
} | ||
|
||
private class ExampleA | ||
{ | ||
} | ||
|
||
private class ExampleB | ||
{ | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
Source/MoreDotNet.Test/Extensions/Common/ObjectExtensions/IsTests.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,30 @@ | ||
namespace MoreDotNet.Tests.Extensions.Common.ObjectExtensions | ||
{ | ||
using MoreDotNet.Extensions.Common; | ||
using Xunit; | ||
|
||
public class IsTests | ||
{ | ||
[Fact] | ||
public void Is_AIsA_ShouldReturnTrue() | ||
{ | ||
var input = new ExampleA(); | ||
Assert.True(input.Is<ExampleA>()); | ||
} | ||
|
||
[Fact] | ||
public void Is_AIsB_ShouldReturnFalse() | ||
{ | ||
var input = new ExampleA(); | ||
Assert.False(input.Is<ExampleB>()); | ||
} | ||
|
||
private class ExampleA | ||
{ | ||
} | ||
|
||
private class ExampleB | ||
{ | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
Source/MoreDotNet.Test/Extensions/Common/ObjectExtensions/ToDictionaryTests.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,40 @@ | ||
namespace MoreDotNet.Tests.Extensions.Common.ObjectExtensions | ||
{ | ||
using System; | ||
using MoreDotNet.Extensions.Common; | ||
using Xunit; | ||
|
||
public class ToDictionaryTests | ||
{ | ||
[Fact] | ||
public void ToDictionary_Null_ShouldThrowArgumentNullException() | ||
{ | ||
Example input = null; | ||
Assert.Throws<ArgumentNullException>(() => input.ToDictionary()); | ||
} | ||
|
||
[Fact] | ||
public void ToDictionary_ExampleA_ShouldReturnDictionaryWithKeysAndValues() | ||
{ | ||
var input = new Example | ||
{ | ||
One = "First", | ||
Two = "Second" | ||
}; | ||
var result = input.ToDictionary(); | ||
|
||
Assert.True(result.ContainsKey("One")); | ||
Assert.Equal("First", result["One"]); | ||
|
||
Assert.True(result.ContainsKey("Two")); | ||
Assert.Equal("Second", result["Two"]); | ||
} | ||
|
||
private class Example | ||
{ | ||
public string One { get; set; } | ||
|
||
public string Two { get; set; } | ||
} | ||
} | ||
} |
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