Skip to content

Commit

Permalink
* All added more tests #6
Browse files Browse the repository at this point in the history
  • Loading branch information
GSerjo committed Sep 15, 2015
1 parent 923edd5 commit 0d8c06c
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 24 deletions.
5 changes: 1 addition & 4 deletions Source/UnitTests/ForTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,20 @@ public void Test()

var source = new Source
{
List = new List<int>{1, 2,3}
List = new List<int> { 1, 2, 3 }
};

var result = TinyMapper.Map<Target>(source);
}


public class Source
{
public IReadOnlyList<int> List { get; set; }
}


public class Target
{
public List<int> List { get; set; }
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Nelibur.ObjectMapper.Bindings;
using Xunit;

namespace UnitTests
namespace UnitTests.Mappings.Attributes
{
public sealed class MappingWithAttributesTests
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Nelibur.ObjectMapper;
using Xunit;

namespace UnitTests
namespace UnitTests.Mappings.Classes
{
public sealed class ClassHierarchyMappingTests
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
using Nelibur.ObjectMapper;
using Xunit;

namespace UnitTests
namespace UnitTests.Mappings.Collections
{
public sealed class CollectionMappingTests
{
[Fact]
public void Map_ClassCollections_Success()
public void Map_Collections_Success()
{
TinyMapper.Bind<Source1, Target1>();

Expand Down Expand Up @@ -51,7 +51,7 @@ public void Map_ClassCollections_Success()
}

[Fact]
public void Map_ClassDifferentCollections_Success()
public void Map_DifferentCollections_Success()
{
TinyMapper.Bind<Person, PersonDto>();

Expand Down Expand Up @@ -80,6 +80,20 @@ public void Map_ClassDifferentCollections_Success()
}
}

[Fact]
public void Map_InterfaceToCollection_Success()
{
TinyMapper.Bind<Source3, Target3>();

var source = new Source3
{
List = new List<int> { 1, 2, 3 }
};

var actual = TinyMapper.Map<Target3>(source);
Assert.Equal(source.List, actual.List);
}

[Fact]
public void Map_NullCollection_Success()
{
Expand Down Expand Up @@ -144,6 +158,11 @@ public class Source2
public List<int> Ints { get; set; }
}

public class Source3
{
public IReadOnlyList<int> List { get; set; }
}

public class Target1
{
public List<Item2> Items { get; set; }
Expand All @@ -155,5 +174,10 @@ public class Target2
public int Int { get; set; }
public List<int> Ints { get; set; }
}

public class Target3
{
public List<int> List { get; set; }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Nelibur.ObjectMapper;
using Xunit;

namespace UnitTests
namespace UnitTests.Mappings.Collections
{
public sealed class DictionaryMappingTests
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Nelibur.ObjectMapper;
using Xunit;

namespace UnitTests
namespace UnitTests.Mappings.Collections
{
public sealed class PrimitiveCollectionMappingTests
{
Expand Down Expand Up @@ -69,7 +69,7 @@ public void Map_Collections_Success()

public class Source2
{
public List<bool> Bool { get; set; }
public IList<bool> Bool { get; set; }
public List<byte> Byte { get; set; }
public List<char> Char { get; set; }
public List<decimal> Decimal { get; set; }
Expand All @@ -78,7 +78,7 @@ public class Source2
public List<int> Int { get; set; }
public List<long> Long { get; set; }
public List<sbyte> Sbyte { get; set; }
public List<short> Short { get; set; }
public IList<short> Short { get; set; }
public List<string> String { get; set; }
public List<uint> Uint { get; set; }
public List<ulong> Ulong { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using System;
using System.Collections.Generic;
using Nelibur.ObjectMapper;
using Xunit;

namespace UnitTests
namespace UnitTests.Mappings
{
public sealed class MappingWithConfigTests
{
Expand Down Expand Up @@ -36,6 +37,26 @@ public void Map_Bind_Success()
Assert.Equal(source.SourceItem.Id, actual.TargetItem.Id);
}

[Fact]
public void Map_ConcreteType_Success()
{
TinyMapper.Bind<Source2, Target2>(config =>
{
config.Bind(target => target.Ints, typeof(List<int>));
config.Bind(target => target.Strings, typeof(List<string>));
});

var source = new Source2
{
Ints = new List<int> { 1, 2, 3 },
Strings = new List<string> { "A", "B", "C" }
};

var actual = TinyMapper.Map<Target2>(source);
Assert.Equal(source.Ints, actual.Ints);
Assert.Equal(source.Strings, actual.Strings);
}

[Fact]
public void Map_Ignore_Success()
{
Expand Down Expand Up @@ -72,6 +93,12 @@ public class Source1
public string String { get; set; }
}

public class Source2
{
public IList<int> Ints { get; set; }
public List<string> Strings { get; set; }
}

public class SourceItem
{
public Guid Id { get; set; }
Expand All @@ -87,6 +114,12 @@ public class Target1
public TargetItem TargetItem { get; set; }
}

public class Target2
{
public IList<int> Ints { get; set; }
public IEnumerable<string> Strings { get; set; }
}

public class TargetItem
{
public Guid Id { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Xunit;
using Xunit.Extensions;

namespace UnitTests
namespace UnitTests.Mappings
{
public sealed class PrimitiveTypeMappingTests
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Nelibur.ObjectMapper;
using Xunit;

namespace UnitTests
namespace UnitTests.Mappings.TypeConverters
{
public sealed class ConvertibleTypeMappingTests
{
Expand Down
16 changes: 8 additions & 8 deletions Source/UnitTests/UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,20 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="CollectionMappingTests.cs" />
<Compile Include="ConvertibleTypeMappingTests.cs" />
<Compile Include="DictionaryMappingTests.cs" />
<Compile Include="ClassHierarchyMappingTests.cs" />
<Compile Include="MappingWithAttributesTests.cs" />
<Compile Include="MappingWithConfigTests.cs" />
<Compile Include="PrimitiveTypeMappingTests.cs" />
<Compile Include="Mappings\Collections\CollectionMappingTests.cs" />
<Compile Include="Mappings\TypeConverters\ConvertibleTypeMappingTests.cs" />
<Compile Include="Mappings\Collections\DictionaryMappingTests.cs" />
<Compile Include="Mappings\Classes\ClassHierarchyMappingTests.cs" />
<Compile Include="Mappings\Attributes\MappingWithAttributesTests.cs" />
<Compile Include="Mappings\MappingWithConfigTests.cs" />
<Compile Include="Mappings\PrimitiveTypeMappingTests.cs" />
<Compile Include="Core\Extensions\TypeExtensionsTests.cs" />
<Compile Include="ForTests.cs" />
<Compile Include="Mappers\Classes\ClassMapperTests.cs" />
<Compile Include="MappingBuilderConfigStub.cs" />
<Compile Include="Mappers\MappingMembers\MappingMemberBuilderTests.cs" />
<Compile Include="Mappers\Types\PrimitiveTypeMapperTests.cs" />
<Compile Include="PrimitiveCollectionMappingTests.cs" />
<Compile Include="Mappings\Collections\PrimitiveCollectionMappingTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Snippets\DynamicMethodSnippet.cs" />
<Compile Include="Snippets\ForeachSnippet.cs" />
Expand Down

0 comments on commit 0d8c06c

Please sign in to comment.