public void Map_Properties()
        {
            var model = new Models.Client
            {
                Properties =
                {
                    { "foo1", "bar1" },
                    { "foo2", "bar2" }
                }
            };

            // Act
            var mappedEntity = ClientMappers.ToEntity(model);
            var mappedModel  = ClientMappers.ToModel(mappedEntity);


            // Assert
            Assert.IsNotNull(mappedEntity);
            Assert.AreEqual(2, mappedEntity.Properties.Count);
            var foo1 = mappedEntity.Properties.FirstOrDefault(x => x.Key == "foo1");

            Assert.IsNotNull(foo1);
            Assert.AreEqual("bar1", foo1.Value);
            var foo2 = mappedEntity.Properties.FirstOrDefault(x => x.Key == "foo2");

            Assert.IsNotNull(foo2);
            Assert.AreEqual("bar2", foo2.Value);

            Assert.IsNotNull(mappedModel);
            Assert.AreEqual(2, mappedModel.Properties.Count);
            Assert.IsTrue(mappedModel.Properties.ContainsKey("foo1"));
            Assert.IsTrue(mappedModel.Properties.ContainsKey("foo2"));
            Assert.AreEqual("bar1", mappedModel.Properties["foo1"]);
            Assert.AreEqual("bar2", mappedModel.Properties["foo2"]);
        }
        public void Map()
        {
            var model  = new Models.Client();
            var entity = ClientMappers.ToEntity(model);

            model = ClientMappers.ToModel(entity);

            // Assert
            Assert.IsNotNull(entity);
            Assert.IsNotNull(model);
        }
        public void Map_Duplicated_Properties_ThrowsException()
        {
            var entity = new Entities.Client
            {
                Properties = new System.Collections.Generic.List <Entities.ClientProperty>
                {
                    new Entities.ClientProperty {
                        Key = "foo1", Value = "bar1"
                    },
                    new Entities.ClientProperty {
                        Key = "foo1", Value = "bar2"
                    },
                }
            };

            // Act & Assert
            Assert.ThrowsException <AutoMapperMappingException>(() => ClientMappers.ToModel(entity));
        }
コード例 #4
0
        public void ToComplexEntity_WhenSimpleEntity_ExpectMapSuccess()
        {
            // Arrange
            var mockClaimsMapper = new Mock<IMapper<SimpleClaim, Claim>>();
            var mockPropertyMapper = new Mock<IPropertyGetSettersTyped<Client>>();

            mockClaimsMapper.Setup(r => r.ToComplexEntity(It.IsAny<IEnumerable<SimpleClaim>>())).Returns(new List<Claim> { new Claim("DEFAULT", "DEFAULT") });

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

            var clientMappers = new ClientMappers<Client>(mockClaimsMapper.Object, mockPropertyMapper.Object);

            var secret = new Secret("Value", "Description", new DateTimeOffset(new DateTime(2016, 1, 1))) { Type = "Type" };

            var simpleClient = new SimpleClient
            {
                Claims = new List<SimpleClaim>(),
                Enabled = true,
                AccessTokenType = AccessTokenType.Jwt,
                AbsoluteRefreshTokenLifetime = 1,
                AccessTokenLifetime = 1,
                AllowAccessToAllCustomGrantTypes = true,
                AllowAccessToAllScopes = true,
                AllowRememberConsent = true,
                EnableLocalLogin = true,
                AllowAccessTokensViaBrowser = true,
                LogoutSessionRequired = true,
                Flow = Flows.AuthorizationCode,
                AlwaysSendClientClaims = true,
                PrefixClientClaims = true,
                ClientSecrets = new List<Secret> { secret },
                RefreshTokenExpiration = TokenExpiration.Absolute,
                RequireSignOutPrompt = true,
                RefreshTokenUsage = TokenUsage.OneTimeOnly,
                IdentityTokenLifetime = 1,
                SlidingRefreshTokenLifetime = 1,
                RequireConsent = true,
                AllowClientCredentialsOnly = true,
                IncludeJwtId = true,
                AuthorizationCodeLifetime = 1,
                UpdateAccessTokenClaimsOnRefresh = true,
                ClientName = "ClientName",
                LogoutUri = "LogoutUri",
                RedirectUris = new List<string>(),
                ClientUri = "ClientUri",
                AllowedCustomGrantTypes = new List<string>(),
                AllowedScopes = new List<string>(),
                ClientId = "ClientId",
                PostLogoutRedirectUris = new List<string>(),
                AllowedCorsOrigins = new List<string>(),
                IdentityProviderRestrictions = new List<string>(),
                LogoUri = "LogoUri"
            };

            // Act
            var stopwatch = Stopwatch.StartNew();
            var complexEntity = clientMappers.ToComplexEntity(simpleClient);
            stopwatch.Stop();

            // Assert
            this.WriteTimeElapsed(stopwatch);

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