public a_multi_depth_supplied_mapping_matcher()
        {
            _updatedEntities = new List<IEntity>();
            _deletedEntities = new List<IEntity>();

            _mapperContext = new MapperContext(
                new MapperContainer()
                    .Register<Person, PersonEntity>(
                        (f, t, c) =>
                            {
                                c.Map(f.Name, () => t.Name);
                                c.MapAll(f.Addresses, () => t.Addresses, (fa, ta) => fa.Name == ta.Name);
                            }
                    )
                    .Register<Name, NameEntity>(
                        (f, t, c) =>
                            {
                                t.First = f.First;
                                t.Last = f.Last;
                            }
                    )
                    .Register<Address, AddressEntity>(
                        (f, t, c) => { t.Name = f.Name; }
                    ),
                new MapperContext.Parameters
                    {
                        Deleter = o => _deletedEntities.Add((IEntity) o),
                        Updater = o =>
                                      {
                                          var e = o as IEntity;
                                          if (e != null) _updatedEntities.Add(e);
                                      }
                    }
                );

            _from = new Person
                        {
                            Name = new Name {First = "Person"},
                            Addresses = new[]
                                            {
                                                new Address {Name = "Keep"},
                                                new Address {Name = "New"}
                                            }
                        };

            _to = new PersonEntity
                      {
                          Name = new NameEntity {First = "Overwite"},
                          Addresses = new[]
                                          {
                                              new AddressEntity {Name = "Keep"},
                                              new AddressEntity {Name = "Delete"}
                                          }
                      };

            _mapperContext.Map(_from, () => _to);
        }
Example #2
0
        public when_using_ef()
        {
            var mapperContainer =
                new MapperContainer()
                    .Register<Person, PersonEntity>(
                        (f, t, c) =>
                            {
                                c.Map(f.Name, () => t.Name);
                                c.MapAll(f.Addresses, () => t.Addresses);
                            })
                    .Register<Name, NameEntity>(
                        (f, t, c) =>
                            {
                                t.First = f.First;
                                t.Last = f.Last;
                            }
                    )
                    .Register<Address, AddressEntity>(
                        (f, t, c) => { t.Name = f.Name; }
                    );

            Database.SetInitializer(new DropCreateDatabaseIfModelChanges<DataContext>());
            _dataContext = new DataContext(mapperContainer);

            _from = new Person
                        {
                            Name = new Name {First = "Person"},
                            Addresses = new[]
                                            {
                                                new Address {Name = "Keep"},
                                                new Address {Name = "New"}
                                            }
                        };

            _to = _dataContext.Create<PersonEntity>();
            _to.Name = new NameEntity {First = "Overwite"};
            _to.Addresses = new[]
                                {
                                    new AddressEntity {Name = "Keep"},
                                    new AddressEntity {Name = "Delete"}
                                };
            _dataContext.SaveChanges();

            var personId = _to.Id;

            _dataContext.Map(_from, () => _to);
            _dataContext.SaveChanges();

            _dataContext = new DataContext(mapperContainer);
            _to = _dataContext
                .People.Include(p => p.Addresses)
                .Single(p => p.Id == personId);
        }
        void maps_correctly()
        {
            var from = new Person
                           {
                               Email = "*****@*****.**"
                           };

            var to = new PersonEntity();

            _mapperContext.Map(from, () => to);

            Assert.Equal(from.Email, to.Email);
        }
        public a_multi_depth_supplied_mapping_no_matcher()
        {
            new List<IEntity>();
            new List<IEntity>();

            _mapperContext = new MapperContext(
                new MapperContainer()
                    .Register<Person, PersonEntity>(
                        (f, t, c) =>
                            {
                                c.Map(f.Name, () => t.Name);
                                c.MapAll(f.Addresses, () => t.Addresses);
                            })
                    .Register<Name, NameEntity>(
                        (f, t, c) =>
                            {
                                t.First = f.First;
                                t.Last = f.Last;
                            }
                    )
                    .Register<Address, AddressEntity>(
                        (f, t, c) => { t.Name = f.Name; }
                    )
                );

            _from = new Person
                        {
                            Name = new Name {First = "Person"},
                            Addresses = new[]
                                            {
                                                new Address {Name = "Address"}
                                            }
                        };

            _to = new PersonEntity
                      {
                          Name = new NameEntity {First = "Overwite"},
                          Addresses = new[]
                                          {
                                              new AddressEntity {Name = "Overwite"},
                                              new AddressEntity {Name = "Overwite"}
                                          }
                      };

            _mapperContext.Map(_from, () => _to);
        }
Example #5
0
        public void fails_with_lambda_invoke()
        {
            var obj = new Person
                          {
                              Addresses = new[]
                                              {
                                                  new Address()
                                              }
                          };
            var lambda = (Func<IEnumerable<Address>>)
                         (() => obj.Addresses);

            var exp = (Expression<Func<IEnumerable<Address>>>)
                      (() => lambda());

            var sut = new CollapseMembersExpressionVisitor();

            var ex = Assert.Throws<NotSupportedException>(() => sut.Modify(exp));
        }
Example #6
0
        public void gets_simple_expression()
        {
            var obj = new Person
                          {
                              Addresses = new[]
                                              {
                                                  new Address()
                                              }
                          };

            var exp = (Expression<Func<IEnumerable<Address>>>)
                      (() => obj.Addresses);

            var sut = new CollapseMembersExpressionVisitor();

            var result = sut.Modify(exp);

            Assert.Equal("Addresses", result.Member.Name);
            Assert.Equal(obj, result.Subject);
        }