public void it_can_map_to_instance() { var src = new OnlyCollectionSource() { List = new List <string> { "blah", "goo" } }; var cfg = new DestinationConfiguration(typeof(MultiDestination)); cfg.From(typeof(OnlyCollectionSource)); var executable = cfg.ToExecutable(src.GetType()); var mapper = new DefaultMapCommand(executable, new TestContextualizer()); var dest = new MultiDestination() { Name = "ignore" }; var output = (MultiDestination)mapper.From(src, dest); output.Name.should_be_equal_to("ignore"); output.List.Count.should_be_equal_to(2); output.List[0].should_be_equal_to("blah"); output.List[1].should_be_equal_to("goo"); }
public void it_can_transparently_convert_values() { var src = new IntegerSource() { AnInt = 3 }; var cfg = new DestinationConfiguration(typeof(IntegerDest)); cfg.From(typeof(IntegerSource)); var executable = cfg.ToExecutable(src.GetType()); var mapper = new DefaultMapCommand(executable, new TestContextualizer()); var dest = (IntegerDest)mapper.From(src); dest.AnInt.should_be_equal_to(3); }
public void it_should_map_props_of_same_name() { var src = new SimpleSource() { Name = "mikey" }; var cfg = new DestinationConfiguration(typeof(SimpleDestination)); cfg.From(typeof(SimpleSource)); var executable = cfg.ToExecutable(src.GetType()); var mapper = new DefaultMapCommand(executable, new TestContextualizer()); var output = (SimpleDestination)mapper.From(src); output.Name.should_be_equal_to("mikey"); }
public void it_can_redirect_property_values() { var cfg = new DestinationConfiguration <TypicalViewModel>(new TestConfigurationFactory()); cfg.From(typeof(TypicalEvent)) .Redirecting <TypicalEvent>(its => its.Id, m => m.SomeId); Guid eventId = Guid.NewGuid(); var src = new TypicalEvent() { Id = eventId, Name = "bob" }; var executable = cfg.ToExecutable(src.GetType()); var mapper = new DefaultMapCommand(executable, new TestContextualizer()); var output = (TypicalViewModel)mapper.From(src); output.Name.should_be_equal_to("bob"); output.SomeId.should_be_equal_to(eventId); }
public void it_should_handle_collections_natively() { var src = new CollectionSource { Name = "mikey", List = new List <string> { "one", "two" } }; var cfg = new DestinationConfiguration(typeof(CollectionDestination)); cfg.From(typeof(CollectionSource)); var executable = cfg.ToExecutable(src.GetType()); var mapper = new DefaultMapCommand(executable, new TestContextualizer()); var dest = (CollectionDestination)mapper.From(src); dest.Name.should_be_equal_to("mikey"); dest.List.should_not_be_null(); dest.List.Count.should_be_equal_to(2); dest.List[0].should_be_equal_to("one"); dest.List[1].should_be_equal_to("two"); }
public void it_can_map_list_of_nullable_double_to_nonnullable_double_list() { var cfg = new DestinationConfiguration(typeof(CollectionDestination)); cfg.From(typeof(CollectionSource)); var src = new CollectionSource() { MyDoubles = new List <double?> { 2.1, null, 3.2 } }; var executable = cfg.ToExecutable(src.GetType()); var mapper = new DefaultMapCommand(executable, new TestContextualizer()); var output = (CollectionDestination)mapper.From(src); output.MyDoubles.Count.should_be_equal_to(3); output.MyDoubles[0].should_be_equal_to(2.1); output.MyDoubles[1].should_be_equal_to(0); output.MyDoubles[2].should_be_equal_to(3.2); }
public void manually_configuring_dest_property_is_not_overriden_by_convention() { var cfg = new DestinationConfiguration(typeof(TypicalViewModel)); cfg.From(typeof(TypicalEvent)); cfg.SetPropertyResolver(new PropertyNameCriterion("SomeId"), typeof(TypicalEvent), new StaticValueResolver(new Guid("8CF7C50E-792D-4A28-AB74-81879BC233A8"))); Action duplication = () => cfg.ApplyingConvention(new PropertyNameCriterion("SomeId"), new StaticValueResolver(new Guid("1B8CF33D-92B8-4E82-9E8F-5EEDE7BA14F0"))); duplication.should_not_throw_an <DittoConfigurationException>(); var source = new TypicalEvent() { Id = Guid.NewGuid(), Name = "mikey" }; var dest = new TypicalViewModel(); var exec = cfg.ToExecutable(typeof(TypicalEvent)); var command = new DefaultMapCommand(exec, contextualizer); command.Map(source, dest); dest.SomeId.should_be_equal_to(new Guid("8CF7C50E-792D-4A28-AB74-81879BC233A8")); }
public void it_should_map_props_of_same_name() { var src = new SimpleSource() {Name = "mikey"}; var cfg = new DestinationConfiguration(typeof(SimpleDestination)); cfg.From(typeof (SimpleSource)); var executable = cfg.ToExecutable(src.GetType()); var mapper = new DefaultMapCommand(executable,new TestContextualizer()); var output = (SimpleDestination) mapper.From(src); output.Name.should_be_equal_to("mikey"); }
public void manually_configuring_dest_property_is_not_overriden_by_convention() { var cfg = new DestinationConfiguration(typeof(TypicalViewModel)); cfg.From(typeof(TypicalEvent)); cfg.SetPropertyResolver(new PropertyNameCriterion("SomeId"), typeof(TypicalEvent), new StaticValueResolver(new Guid("8CF7C50E-792D-4A28-AB74-81879BC233A8"))); Action duplication = () => cfg.ApplyingConvention(new PropertyNameCriterion("SomeId"), new StaticValueResolver(new Guid("1B8CF33D-92B8-4E82-9E8F-5EEDE7BA14F0"))); duplication.should_not_throw_an<DittoConfigurationException>(); var source = new TypicalEvent() {Id = Guid.NewGuid(), Name = "mikey"}; var dest = new TypicalViewModel(); var exec = cfg.ToExecutable(typeof (TypicalEvent)); var command = new DefaultMapCommand(exec, contextualizer); command.Map(source, dest); dest.SomeId.should_be_equal_to(new Guid("8CF7C50E-792D-4A28-AB74-81879BC233A8")); }
public void it_should_handle_collections_natively() { var src = new CollectionSource {Name = "mikey", List = new List<string> {"one", "two"}}; var cfg = new DestinationConfiguration(typeof(CollectionDestination)); cfg.From(typeof (CollectionSource)); var executable = cfg.ToExecutable(src.GetType()); var mapper = new DefaultMapCommand(executable, new TestContextualizer()); var dest = (CollectionDestination)mapper.From(src); dest.Name.should_be_equal_to("mikey"); dest.List.should_not_be_null(); dest.List.Count.should_be_equal_to(2); dest.List[0].should_be_equal_to("one"); dest.List[1].should_be_equal_to("two"); }
public void it_can_transparently_convert_values() { var src = new IntegerSource() {AnInt = 3}; var cfg = new DestinationConfiguration(typeof(IntegerDest)); cfg.From(typeof (IntegerSource)); var executable = cfg.ToExecutable(src.GetType()); var mapper = new DefaultMapCommand(executable, new TestContextualizer()); var dest = (IntegerDest)mapper.From(src); dest.AnInt.should_be_equal_to(3); }
public void it_can_redirect_property_values() { var cfg = new DestinationConfiguration<TypicalViewModel>(new TestConfigurationFactory()); cfg.From(typeof (TypicalEvent)) .Redirecting<TypicalEvent>(its => its.Id, m => m.SomeId); Guid eventId=Guid.NewGuid(); var src = new TypicalEvent() { Id = eventId, Name = "bob" }; var executable = cfg.ToExecutable(src.GetType()); var mapper = new DefaultMapCommand(executable, new TestContextualizer()); var output = (TypicalViewModel) mapper.From(src); output.Name.should_be_equal_to("bob"); output.SomeId.should_be_equal_to(eventId); }
public void it_can_map_to_instance() { var src = new OnlyCollectionSource() { List = new List<string> { "blah", "goo" } }; var cfg = new DestinationConfiguration(typeof(MultiDestination)); cfg.From(typeof (OnlyCollectionSource)); var executable = cfg.ToExecutable(src.GetType()); var mapper = new DefaultMapCommand(executable, new TestContextualizer()); var dest = new MultiDestination(){Name = "ignore"}; var output = (MultiDestination)mapper.From(src, dest); output.Name.should_be_equal_to("ignore"); output.List.Count.should_be_equal_to(2); output.List[0].should_be_equal_to("blah"); output.List[1].should_be_equal_to("goo"); }
public void it_can_map_list_of_nullable_double_to_nonnullable_double_list() { var cfg = new DestinationConfiguration(typeof(CollectionDestination)); cfg.From(typeof (CollectionSource)); var src = new CollectionSource() {MyDoubles = new List<double?> {2.1, null, 3.2}}; var executable = cfg.ToExecutable(src.GetType()); var mapper = new DefaultMapCommand(executable, new TestContextualizer()); var output = (CollectionDestination) mapper.From(src); output.MyDoubles.Count.should_be_equal_to(3); output.MyDoubles[0].should_be_equal_to(2.1); output.MyDoubles[1].should_be_equal_to(0); output.MyDoubles[2].should_be_equal_to(3.2); }