Beispiel #1
0
        public void Map_Use_Defaults()
        {
            // Arrange
            var mapperConfiguration = new MapperConfiguration(expression => { expression.AddProfile <ApiResourceMapperProfile>(); });
            var mapper = new AutoMapperWrapper(new Mapper(mapperConfiguration));

            var entity = new Entities.ApiResource
            {
                Secrets = new System.Collections.Generic.List <Entities.ApiSecret>
                {
                    new Entities.ApiSecret
                    {
                    }
                }
            };

            var def = new Models.ApiResource
            {
                ApiSecrets = { new Models.Secret("foo") }
            };

            // Act
            var mappedModel = mapper.Map <Models.ApiResource>(entity);

            // Assert
            Assert.Equal(def.ApiSecrets.First().Type, mappedModel.ApiSecrets.First().Type);
        }
Beispiel #2
0
        public void Map_Use_Defaults()
        {
            // Arrange
            var mapperConfiguration = new MapperConfiguration(expression => { expression.AddProfile <ClientMapperProfile>(); });
            var mapper = new AutoMapperWrapper(new Mapper(mapperConfiguration));
            var entity = new Entities.Client
            {
                ClientSecrets = new List <Entities.ClientSecret>
                {
                    new Entities.ClientSecret
                    {
                    }
                }
            };

            var def = new Models.Client
            {
                ClientSecrets = { new Models.Secret("foo") }
            };

            // Act
            var mappedModel = mapper.Map <Models.Client>(entity);

            // Assert
            Assert.Equal(def.ProtocolType, mappedModel.ProtocolType);
            Assert.Equal(def.ClientSecrets.First().Type, mappedModel.ClientSecrets.First().Type);
        }
Beispiel #3
0
        public void Map_Properties()
        {
            // Arrange
            var mapperConfiguration = new MapperConfiguration(expression => { expression.AddProfile <ApiResourceMapperProfile>(); });
            var mapper = new AutoMapperWrapper(new Mapper(mapperConfiguration));

            var model = new Models.ApiResource
            {
                Description = "description",
                DisplayName = "displayname",
                Name        = "foo",
                Scopes      = { new Models.Scope("foo1"), new Models.Scope("foo2") },
                Enabled     = false
            };

            // Act
            var mappedEntity = mapper.Map <Entities.ApiResource>(model);
            var mappedModel  = mapper.Map <Models.ApiResource>(mappedEntity);

            // Assert
            Assert.NotNull(mappedEntity);
            Assert.Equal(2, mappedEntity.Scopes.Count);
            Assert.NotNull(mappedEntity.Scopes.FirstOrDefault(x => x.Name == "foo1"));
            Assert.NotNull(mappedEntity.Scopes.FirstOrDefault(x => x.Name == "foo2"));

            Assert.NotNull(model);
            Assert.Equal("description", mappedModel.Description);
            Assert.Equal("displayname", mappedModel.DisplayName);
            Assert.False(mappedModel.Enabled);
            Assert.Equal("foo", mappedModel.Name);
        }
Beispiel #4
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);


            AutoMapperWrapper.Init();

            var container = new Container();

            container.Options.DefaultScopedLifestyle = new WebApiRequestLifestyle();

            var registration = Lifestyle.Scoped.CreateRegistration <CommandQueryFactory>(container);


            container.AddRegistration(typeof(IQueryFactory), registration);
            container.AddRegistration(typeof(ICommandFactory), registration);

            // This is an extension method from the integration package.
            container.RegisterWebApiControllers(GlobalConfiguration.Configuration);

            container.Verify();

            GlobalConfiguration.Configuration.DependencyResolver =
                new SimpleInjectorWebApiDependencyResolver(container);
        }
Beispiel #5
0
        // This method gets called by the runtime. Use this method to add services to the container
        public void ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            services.AddApplicationInsightsTelemetry(Configuration);

            services.AddMvc();

            AutoMapperWrapper.Init();
            //services.AddScoped<CommandQueryFactory>();
            services.AddScoped <IQueryFactory, CommandQueryFactory>();
            services.AddScoped <ICommandFactory, CommandQueryFactory>();
        }
Beispiel #6
0
        public void UpdateFrom(IEntity <TKey> entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("Input argument is null.");
            }

            if (this.GetType() != entity.GetType())
            {
                throw new ArgumentException($"Input argument should be type of {this.GetType().Name}");
            }

            AutoMapperWrapper.Map(entity, this);
        }
        public void Map()
        {
            // Arrange
            var mapperConfiguration = new MapperConfiguration(expression => { expression.AddProfile <IdentityResourceMapperProfile>(); });
            var mapper = new AutoMapperWrapper(new Mapper(mapperConfiguration));
            var model  = new Models.IdentityResource();

            // Act
            var entity = mapper.Map <Entities.IdentityResource>(model);

            model = mapper.Map <Models.IdentityResource>(entity);

            // Assert
            Assert.NotNull(entity);
            Assert.NotNull(model);
            mapperConfiguration.AssertConfigurationIsValid();
        }
Beispiel #8
0
        public void Map_Duplicated_Properties_ThorwsException()
        {
            // Arrange
            var mapperConfiguration = new MapperConfiguration(expression => { expression.AddProfile <ClientMapperProfile>(); });
            var mapper = new AutoMapperWrapper(new Mapper(mapperConfiguration));
            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.Throws <AutoMapperMappingException>(() => mapper.Map <Models.Client>(entity));
        }
Beispiel #9
0
        public void Map_Properties()
        {
            // Arrange
            var mapperConfiguration = new MapperConfiguration(expression => { expression.AddProfile <ClientMapperProfile>(); });
            var mapper = new AutoMapperWrapper(new Mapper(mapperConfiguration));
            var model  = new Models.Client
            {
                Properties =
                {
                    { "foo1", "bar1" },
                    { "foo2", "bar2" }
                }
            };

            // Act
            var mappedEntity = mapper.Map <Entities.Client>(model);
            var mappedModel  = mapper.Map <Models.Client>(mappedEntity);

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

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

            Assert.NotNull(foo2);
            Assert.Equal("bar2", foo2.Value);

            Assert.NotNull(mappedModel);
            Assert.Equal(2, mappedModel.Properties.Count);
            Assert.True(mappedModel.Properties.ContainsKey("foo1"));
            Assert.True(mappedModel.Properties.ContainsKey("foo2"));
            Assert.Equal("bar1", mappedModel.Properties["foo1"]);
            Assert.Equal("bar2", mappedModel.Properties["foo2"]);
        }