Exemplo n.º 1
0
        void no_work_done_if_from_is_null()
        {
            var entity = default(PersonEntity);

            _mapperContext.Map(default(Person), () => entity);

            Assert.Null(entity);
        }
        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);
        }
Exemplo n.º 3
0
        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);
        }
        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);
        }
Exemplo n.º 6
0
        void throws_where_not_registered()
        {
            var expectedMessage = string.Format(
                Resources.MapperNotRegisteredException,
                typeof(object).FullName,
                typeof(object).FullName
                );

            object result = null;

            var ex = Assert.Throws <MapperNotRegisteredException>(
                () => _mapperContext.Map(new object(), () => result)
                );

            Assert.Equal(
                expectedMessage,
                ex.Message
                );
        }
        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);
        }