public void ToSimpleEntity_WhenComplexEntityAndExtendedComplex_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.ToSimpleEntity(It.IsAny<ClaimsPrincipal>())) .Returns(new SimpleClaimsPrincipal()); mockTokenMapper.Setup(r => r.ToSimpleEntity(It.IsAny<Token>())).Returns(new SimpleToken()); var mockGetters = new Dictionary<string, Func<ExtendedRefreshToken, object>> { { "CustomProperty", typeof(ExtendedRefreshToken).GetProperty("CustomProperty").GetGetter<ExtendedRefreshToken>() } }; mockPropertyMapper.Setup(r => r.GetGetters(It.IsAny<Type>())).Returns(mockGetters); var refreshTokenMappers = new RefreshTokenMappers<ExtendedRefreshToken>( mockPropertyMapper.Object, mockClaimsPrincipalMapper.Object, mockTokenMapper.Object); var complexEntity = new ExtendedRefreshToken { Subject = new ClaimsPrincipal(), CreationTime = new DateTimeOffset(new DateTime(2016, 1, 1)), AccessToken = new Token(), LifeTime = 1, Version = 1, CustomProperty = new CustomProperty { Name = "Joe", Age = 23 } }; // Act var stopwatch = Stopwatch.StartNew(); var simpleRefreshToken = refreshTokenMappers.ToSimpleEntity(complexEntity); stopwatch.Stop(); // Assert this.WriteTimeElapsed(stopwatch); Assert.That(simpleRefreshToken.Subject, Is.Not.Null); Assert.That(simpleRefreshToken.AccessToken, Is.Not.Null); Assert.That(simpleRefreshToken.CreationTime, Is.EqualTo(new DateTimeOffset(new DateTime(2016, 1, 1)))); Assert.That(simpleRefreshToken.LifeTime, Is.EqualTo(1)); Assert.That(simpleRefreshToken.Version, Is.EqualTo(1)); Assert.That(simpleRefreshToken.DataBag["CustomProperty"], Is.Not.Null); var property = (CustomProperty)simpleRefreshToken.DataBag["CustomProperty"]; Assert.That(property.Name, Is.EqualTo("Joe")); Assert.That(property.Age, Is.EqualTo(23)); }
public void ToSimpleEntity_WhenComplexEntity_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.ToSimpleEntity(It.IsAny<ClaimsPrincipal>())) .Returns(new SimpleClaimsPrincipal()); mockTokenMapper.Setup(r => r.ToSimpleEntity(It.IsAny<Token>())).Returns(new SimpleToken()); mockPropertyMapper.Setup(r => r.GetGetters(It.IsAny<Type>())) .Returns(new Dictionary<string, Func<RefreshToken, object>>()); var refreshTokenMappers = new RefreshTokenMappers<RefreshToken>( mockPropertyMapper.Object, mockClaimsPrincipalMapper.Object, mockTokenMapper.Object); var complexEntity = new RefreshToken { Subject = new ClaimsPrincipal(), CreationTime = new DateTimeOffset(new DateTime(2016, 1, 1)), AccessToken = new Token(), LifeTime = 1, Version = 1 }; // Act var stopwatch = Stopwatch.StartNew(); var simpleRefreshToken = refreshTokenMappers.ToSimpleEntity(complexEntity); stopwatch.Stop(); // Assert this.WriteTimeElapsed(stopwatch); Assert.That(simpleRefreshToken.Subject, Is.Not.Null); Assert.That(simpleRefreshToken.AccessToken, Is.Not.Null); Assert.That(simpleRefreshToken.CreationTime, Is.EqualTo(new DateTimeOffset(new DateTime(2016, 1, 1)))); Assert.That(simpleRefreshToken.LifeTime, Is.EqualTo(1)); Assert.That(simpleRefreshToken.Version, Is.EqualTo(1)); }