From 307eea8b5aee50a6e61c46d394d3c42e539ea6ff Mon Sep 17 00:00:00 2001 From: Eric Swann Date: Wed, 4 Mar 2015 11:53:45 -0600 Subject: [PATCH] UPdated the version number --- .../WhenRegisteringAndMappingRace.cs | 133 ++++++++++++++++++ src/Mapster/Properties/AssemblyInfo.cs | 4 +- 2 files changed, 135 insertions(+), 2 deletions(-) create mode 100644 src/Mapster.Tests/WhenRegisteringAndMappingRace.cs diff --git a/src/Mapster.Tests/WhenRegisteringAndMappingRace.cs b/src/Mapster.Tests/WhenRegisteringAndMappingRace.cs new file mode 100644 index 00000000..67d69ccc --- /dev/null +++ b/src/Mapster.Tests/WhenRegisteringAndMappingRace.cs @@ -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.NewConfig() + .Map(dest => dest.IHaveADifferentId, src => src.Id) + .Map(dest => dest.MyNamePropertyIsDifferent, src => src.Name) + .Ignore(dest => dest.Children); + + TypeAdapter.Adapt(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(() => + { + for (int i = 0; i < 100; i++) + { + Parallel.Invoke( + () => + { + TypeAdapterConfig.NewConfig() + .Map(dest => dest.IHaveADifferentId, src => src.Id) + .Map(dest => dest.MyNamePropertyIsDifferent, src => src.Name) + .Ignore(dest => dest.Children); + }, + () => { TypeAdapter.Adapt(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(() => + { + for (int i = 0; i < 100; i++) + { + Parallel.Invoke( + () => + { + TypeAdapterConfig.NewConfig() + .Map(dest => dest.IHaveADifferentId, src => src.Id) + .Map(dest => dest.MyNamePropertyIsDifferent, src => src.Name) + .Ignore(dest => dest.Children); + }, + () => { TypeAdapter.Adapt(simplePoco); } + ); + } + }); + + //Type should map at the end because mapping has completed. + TypeAdapter.Adapt(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 Children { get; set; } + } + + #endregion + + + + +} \ No newline at end of file diff --git a/src/Mapster/Properties/AssemblyInfo.cs b/src/Mapster/Properties/AssemblyInfo.cs index fdbe256a..098e95f2 100644 --- a/src/Mapster/Properties/AssemblyInfo.cs +++ b/src/Mapster/Properties/AssemblyInfo.cs @@ -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")]