Esempio n. 1
0
        protected override void Establish_context()
        {
            Mapper.Configuration.AllowNullCollections = false;
            Mapper.CreateMap<Source, Destination>();

            _source = new Source { Name = null, Data = null };
        }
 protected override void Because_of()
 {
     var source = new Source
     {
     };
     _destination = Mapper.Map<Source, Destination>(source);
 }
 public void PublicSetterInParentWorks()
 {
     var source = new Source {ParentProperty = "ParentProperty", ChildProperty = 1};
     var target = Mapper.Map<Source, Child>(source);
     target.ParentProperty.ShouldEqual(source.ParentProperty);
     target.ChildProperty.ShouldEqual(source.ChildProperty);
 }
 public void PrivateSetterInGrandGrandparentWorks()
 {
     var source = new Source {ParentProperty = "ParentProperty", ChildProperty = 1};
     var target = Mapper.Map<Source, GrandGrandChildPrivate>(source);
     target.ParentProperty.ShouldEqual(source.ParentProperty);
     target.ChildProperty.ShouldEqual(source.ChildProperty);
 }
 public void PrivateSetterInGrandGrandparentWorks()
 {
     var source = new Source {ParentProperty = "ParentProperty", ChildProperty = 1};
     var target = Mapper.Map<Source, GrandGrandChildPrivate>(source);
     Assert.That(target.ParentProperty, Is.EqualTo(source.ParentProperty) );
     Assert.That(target.ChildProperty, Is.EqualTo(source.ChildProperty) );
 }
        public void Should_map_over_constructor()
        {
            var source = new Source { Value = "value" };

            var dest = Mapper.Map<Destination>(source);

            dest.Value.ShouldEqual(source.Value);
        }
 protected override void Because_of()
 {
     var source = new Source
                      {
                          Values = new[] {1, 2, 3, 4},
                          Values2 = new[] {5, 6},
                      };
     _destination = Mapper.Map<Source, Destination>(source);
 }
Esempio n. 8
0
 protected override void Because_of()
 {
     var source = new Source();
     _destination = new Dest
     {
         Value1 = "Foo",
         Value2 = 10,
         Unmapped = "Asdf"
     };
     Mapper.Map(source, _destination);
 }
 protected override void Because_of()
 {
     _source = Mapper.Map<Destination, Source>(new Destination
     {
         UserId = SomeId
     });
     _destination = Mapper.Map<Source, Destination>(new Source
     {
         AccountId = SomeOtherId
     });
 }
Esempio n. 10
0
        public void TestCase()
        {
            var source = new Source() { Name = "Test" };
            var destination = new Destination();

            AutoMapper.Mapper.Map<Source, Destination>(source, destination); // Works

            var subDestination = new SubDestination();

            AutoMapper.Mapper.Map<Source, Destination>(source, subDestination); // Fails
        }
Esempio n. 11
0
 protected override void Because_of()
 {
     var source = new Source()
     {
         Id = 1,
         ListProperty = _sourceList,
     };
     _destination = new Destination()
     {
         Id = 2,
         ListProperty = new List<int>() { 4, 5, 6 }.Where(a=>true)
     };
     _destination = Mapper.Map<Source, Destination>(source, _destination);
 }
		public void Should_map_all_null_values_to_its_substitute()
		{
            Mapper.CreateMap<Source, Destination>()
                .ForAllMembers(opt => opt.NullSubstitute(string.Empty));

		    var src = new Source
		    {
		        Value1 = 5
		    };

		    var dest = Mapper.Map<Source, Destination>(src);

		    dest.Value1.ShouldEqual("5");
		    dest.Value2.ShouldEqual(string.Empty);
		    dest.Value3.ShouldEqual(string.Empty);
		}
		public void Should_map_all_null_values_to_its_substitute()
		{
            var config = new MapperConfiguration(cfg => cfg.CreateMap(typeof(Source), typeof(Destination))
                .ForAllMembers(opt => opt.NullSubstitute(string.Empty)));

		    var src = new Source
		    {
		        Value1 = 5
		    };

		    var mapper = config.CreateMapper();
		    var dest = mapper.Map<Source, Destination>(src);

		    dest.Value1.ShouldEqual("5");
		    dest.Value2.ShouldEqual(string.Empty);
		    dest.Value3.ShouldEqual(string.Empty);
		}
Esempio n. 14
0
 public void should_map_over_enumerable_empty()
 {
     var source = new Source { Values = new[] { "1", "2" } };
     var dest = Mapper.Map<DestWithIEnumerableInitializer>(source);
 }
Esempio n. 15
0
 public void should_map_array_inside_object()
 {
     var source = new Source { Values = new[] { "1", "2" } };
     var dest = Mapper.Map<Dest>(source);
 }
Esempio n. 16
0
 public int Resolve(Source source, Destination destination, int destMember, ResolutionContext context)
 {
     return(1000);
 }
 protected override void Because_of()
 {
     var source = new Source { Inner = new Inner { Member = SomeValue } };
     //_dest = Mapper.Map<Source, SourceDto>(source);
     _dest = new[] { source }.AsQueryable().ProjectTo<SourceDto>(Configuration).First();
 }