Skip to content

Commit

Permalink
Merge pull request #27 from goggenb/ObjectExtensionTests
Browse files Browse the repository at this point in the history
Added ObjectExtensions tests
  • Loading branch information
Teodor92 authored Oct 19, 2016
2 parents 3120e5d + 6302c30 commit 029cf79
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 0 deletions.
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);
}
}
}
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
{
}
}
}
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
{
}
}
}
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; }
}
}
}
4 changes: 4 additions & 0 deletions Source/MoreDotNet.Test/MoreDotNet.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@
<Compile Include="Extensions\Common\ColorExtensions\ToRgbStringTests.cs" />
<Compile Include="Extensions\Common\DataExtensions\GetNullableTests.cs" />
<Compile Include="Extensions\Common\IntegerExtensions\RangeToTests.cs" />
<Compile Include="Extensions\Common\ObjectExtensions\AsTests.cs" />
<Compile Include="Extensions\Common\ObjectExtensions\IsNotTests.cs" />
<Compile Include="Extensions\Common\ObjectExtensions\ToDictionaryTests.cs" />
<Compile Include="Extensions\Common\ObjectExtensions\IsTests.cs" />
<Compile Include="Extensions\Common\StringExtensions\CapitalizeTests.cs" />
<Compile Include="Extensions\Common\StringExtensions\IsLikeTests.cs" />
<Compile Include="Extensions\Common\StringExtensions\NthIndexOfTests.cs" />
Expand Down

0 comments on commit 029cf79

Please # to comment.