public void ToComplexEntity_WhenSimpleEntity_ExpectCorrectMap()
        {
            // Arrange
            var mockPropertyMapper = new Mock<IPropertyGetSettersTyped<RefreshToken>>();
            var mockClaimsPrincipalMapper = new Mock<IMapper<SimpleClaimsPrincipal, ClaimsPrincipal>>();
            var mockTokenMapper = new Mock<IMapper<SimpleToken, Token>>();

            mockClaimsPrincipalMapper.Setup(r => r.ToComplexEntity(It.IsAny<SimpleClaimsPrincipal>()))
                .Returns(new ClaimsPrincipal());

            mockTokenMapper.Setup(r => r.ToComplexEntity(It.IsAny<SimpleToken>())).Returns(new Token());

            mockPropertyMapper.Setup(r => r.GetSetters(It.IsAny<Type>()))
                .Returns(new Dictionary<string, TypedSetter<RefreshToken>>());

            var refreshTokenMappers = new RefreshTokenMappers<RefreshToken>(
                mockPropertyMapper.Object,
                mockClaimsPrincipalMapper.Object,
                mockTokenMapper.Object);

            var simpleEntity = new SimpleRefreshToken
            {
                Subject = new SimpleClaimsPrincipal(),
                CreationTime = new DateTimeOffset(new DateTime(2016, 1, 1)),
                AccessToken = new SimpleToken(),
                LifeTime = 1,
                Version = 1
            };

            // Act
            var stopwatch = Stopwatch.StartNew();
            var complexEntity = refreshTokenMappers.ToComplexEntity(simpleEntity);
            stopwatch.Stop();

            // Assert
            this.WriteTimeElapsed(stopwatch);

            Assert.That(complexEntity, Is.Not.Null);

            Assert.That(complexEntity.Subject, Is.Not.Null);
            Assert.That(complexEntity.AccessToken, Is.Not.Null);
            Assert.That(complexEntity.CreationTime, Is.EqualTo(new DateTimeOffset(new DateTime(2016, 1, 1))));
            Assert.That(complexEntity.LifeTime, Is.EqualTo(1));
            Assert.That(complexEntity.Version, Is.EqualTo(1));
        }
        public void ToComplexEntity_WhenSimpleEntityAndExtendedComplex_ExpectCorrectMap()
        {
            // Arrange
            var mockPropertyMapper = new Mock<IPropertyGetSettersTyped<ExtendedRefreshToken>>();
            var mockClaimsPrincipalMapper = new Mock<IMapper<SimpleClaimsPrincipal, ClaimsPrincipal>>();
            var mockTokenMapper = new Mock<IMapper<SimpleToken, Token>>();

            mockClaimsPrincipalMapper.Setup(r => r.ToComplexEntity(It.IsAny<SimpleClaimsPrincipal>()))
                .Returns(new ClaimsPrincipal());

            mockTokenMapper.Setup(r => r.ToComplexEntity(It.IsAny<SimpleToken>())).Returns(new Token());

            var typedSetter = new TypedSetter<ExtendedRefreshToken>
            {
                OriginalType = typeof(int),
                Setter = typeof(ExtendedRefreshToken).GetSetter<ExtendedRefreshToken>("CustomProperty")
            };

            mockPropertyMapper.Setup(r => r.GetSetters(It.IsAny<Type>()))
                .Returns(new Dictionary<string, TypedSetter<ExtendedRefreshToken>> { { "CustomProperty", typedSetter } });

            var refreshTokenMappers = new RefreshTokenMappers<ExtendedRefreshToken>(
                mockPropertyMapper.Object,
                mockClaimsPrincipalMapper.Object,
                mockTokenMapper.Object);

            var simpleEntity = new SimpleRefreshToken
            {
                Subject = new SimpleClaimsPrincipal(),
                CreationTime = new DateTimeOffset(new DateTime(2016, 1, 1)),
                AccessToken = new SimpleToken(),
                LifeTime = 1,
                Version = 1,
                DataBag = new Dictionary<string, object> { { "CustomProperty", new CustomProperty { Name = "Joe", Age = 23 } } }
            };

            // Act
            var stopwatch = Stopwatch.StartNew();
            var complexEntity = refreshTokenMappers.ToComplexEntity(simpleEntity);
            stopwatch.Stop();

            // Assert
            this.WriteTimeElapsed(stopwatch);

            Assert.That(complexEntity, Is.Not.Null);

            Assert.That(complexEntity.Subject, Is.Not.Null);
            Assert.That(complexEntity.AccessToken, Is.Not.Null);
            Assert.That(complexEntity.CreationTime, Is.EqualTo(new DateTimeOffset(new DateTime(2016, 1, 1))));
            Assert.That(complexEntity.LifeTime, Is.EqualTo(1));
            Assert.That(complexEntity.Version, Is.EqualTo(1));

            Assert.That(complexEntity.CustomProperty, Is.Not.Null);
            Assert.That(complexEntity.CustomProperty.Name, Is.EqualTo("Joe"));
            Assert.That(complexEntity.CustomProperty.Age, Is.EqualTo(23));
        }