Skip to content

Commit

Permalink
UPdated the version number
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Swann committed Mar 4, 2015
1 parent 9f795cd commit 307eea8
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 2 deletions.
133 changes: 133 additions & 0 deletions src/Mapster.Tests/WhenRegisteringAndMappingRace.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using NUnit.Framework;
using Should;

namespace Mapster.Tests
{
[TestFixture]
public class WhenRegisteringAndMappingRace
{
[TestFixtureTearDown]
public void TearDown()
{
TypeAdapterConfig.GlobalSettings.RequireExplicitMapping = false;
TypeAdapterConfig.GlobalSettings.RequireDestinationMemberSource = false;
}


[Test]
public void Types_Map_Successfully_If_Mapping_Applied_First()
{
TypeAdapterConfig.GlobalSettings.RequireDestinationMemberSource = true;

var simplePoco = new WhenAddingCustomMappings.SimplePoco {Id = Guid.NewGuid(), Name = "TestName"};

TypeAdapterConfig<WhenAddingCustomMappings.SimplePoco, WeirdPoco>.NewConfig()
.Map(dest => dest.IHaveADifferentId, src => src.Id)
.Map(dest => dest.MyNamePropertyIsDifferent, src => src.Name)
.Ignore(dest => dest.Children);

TypeAdapter.Adapt<WhenAddingCustomMappings.SimplePoco, WeirdPoco>(simplePoco);
}

[Test]
public void Race_Condition_Produces_Error()
{
TypeAdapterConfig.GlobalSettings.RequireDestinationMemberSource = true;

var simplePoco = new WhenAddingCustomMappings.SimplePoco {Id = Guid.NewGuid(), Name = "TestName"};

var exception = Assert.Throws<AggregateException>(() =>
{
for (int i = 0; i < 100; i++)
{
Parallel.Invoke(
() =>
{
TypeAdapterConfig<WhenAddingCustomMappings.SimplePoco, WeirdPoco>.NewConfig()
.Map(dest => dest.IHaveADifferentId, src => src.Id)
.Map(dest => dest.MyNamePropertyIsDifferent, src => src.Name)
.Ignore(dest => dest.Children);
},
() => { TypeAdapter.Adapt<WhenAddingCustomMappings.SimplePoco, WeirdPoco>(simplePoco); }
);
}
});

exception.InnerException.ShouldBeType(typeof(ArgumentOutOfRangeException));

}

[Test, ExpectedException]
public void Explicit_Mapping_Requirement_Throws_Before_Mapping_Attempted()
{
TypeAdapterConfig.GlobalSettings.RequireExplicitMapping = true;
TypeAdapterConfig.GlobalSettings.RequireDestinationMemberSource = true;

var simplePoco = new WhenAddingCustomMappings.SimplePoco { Id = Guid.NewGuid(), Name = "TestName" };

Assert.Throws<InvalidOperationException>(() =>
{
for (int i = 0; i < 100; i++)
{
Parallel.Invoke(
() =>
{
TypeAdapterConfig<WhenAddingCustomMappings.SimplePoco, WeirdPoco>.NewConfig()
.Map(dest => dest.IHaveADifferentId, src => src.Id)
.Map(dest => dest.MyNamePropertyIsDifferent, src => src.Name)
.Ignore(dest => dest.Children);
},
() => { TypeAdapter.Adapt<WhenAddingCustomMappings.SimplePoco, WeirdPoco>(simplePoco); }
);
}
});

//Type should map at the end because mapping has completed.
TypeAdapter.Adapt<WhenAddingCustomMappings.SimplePoco, WeirdPoco>(simplePoco);
}


}


#region TestClasses

public class SimplePoco
{
public Guid Id { get; set; }
public string Name { get; set; }
}

public class ChildPoco
{
public Guid Id { get; set; }
public string Name { get; set; }
}

public class ChildDto
{
public Guid Id { get; set; }
public string Name { get; set; }

public string UnmappedChildMember { get; set; }
}


public class WeirdPoco
{
public Guid IHaveADifferentId { get; set; }

public string MyNamePropertyIsDifferent { get; set; }

public List<ChildDto> Children { get; set; }
}

#endregion




}
4 changes: 2 additions & 2 deletions src/Mapster/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.12.0")]
[assembly: AssemblyFileVersion("1.12.0")]
[assembly: AssemblyVersion("1.14.0")]
[assembly: AssemblyFileVersion("1.14.0")]
[assembly: InternalsVisibleTo("Mapster.Tests")]

0 comments on commit 307eea8

Please sign in to comment.