public void can_map_from_property_of_diff_name()
 {
     var cfg = new DestinationConfiguration<TypicalViewModel>(configFactory);
     cfg.From(typeof (TypicalEvent)).Redirecting<TypicalEvent>(its => its.Id, its => its.SomeId);
     var bindable = configFactory.CreateBindableConfiguration(cfg.TakeSnapshot());
     Action validation = bindable.Assert;
     validation.should_not_throw_an<DittoConfigurationException>();
 }
 public void can_map_static_value_to_property()
 {
     var cfg = new DestinationConfiguration<TypicalViewModel>(configFactory);
     cfg.From(typeof (TypicalEvent)).UsingValue<TypicalEvent>(Guid.NewGuid(), its => its.SomeId);
     var bindable = configFactory.CreateBindableConfiguration(cfg.TakeSnapshot());
     Action validation = bindable.Assert;
     validation.should_not_throw_an<DittoConfigurationException>();
 }
 public collection_resolver_tests()
 {
     var factory = new TestConfigurationFactory();
     var cfg = new DestinationConfiguration(typeof (IntegerDest));
     cfg.From(typeof (IntegerSource));
     integerComponentElementConfig = factory.CreateBindableConfiguration(cfg.TakeSnapshot());
     contextualizer = new TestContextualizer();
 }
 public void it_should_determine_candidate_properties()
 {
     var modelConfig = new DestinationConfiguration(typeof(DestinationWithComponentArray));
     modelConfig.From(typeof (SourceWithComponentArray));
     var cfg = configFactory.CreateBindableConfiguration(modelConfig.TakeSnapshot());
     var binder = new ListPropertyBinder(null);
     var candidates = binder.GetCandidateDestinationProperties(cfg);
     candidates.should_have_item_matching(its => its.PropertyType == typeof (IntegerDest[]));
 }
        public void it_should_apply_conventions_to_types_of_properties()
        {
            var src1 = new PersonalInfo() { Age = 3, Name = "mikey" };
            var destination = new ManyDates();
            var dateTime = new DateTime(2009, 8, 1, 0, 0, 0);
            var cfg = new DestinationConfiguration(typeof(ManyDates));
            cfg.From(typeof (PersonalInfo), typeof (Parents))
                .ApplyingConvention(new TypePropertyCriterion(typeof (DateTime)), new StaticValueResolver(dateTime));
            var bindable = bindableFactory.CreateBindableConfiguration(cfg.TakeSnapshot());

            var executable = bindable.CreateExecutableMapping(typeof (PersonalInfo));
            executable.Execute(contextualizer.CreateContext(src1, destination));
            destination.DateTime1.should_be_equal_to(dateTime);
            destination.DateTime2.should_be_equal_to(dateTime);
            destination.Name.should_be_equal_to("mikey");
        }
        public void it_should_give_priority_to_manually_configured_mappings()
        {
            var src1 = new PersonalInfo() { Age = 3, Name = "mikey" };
            var destination = new SystemPerson() { MothersName = "ignoremeplease" };
            Guid systemId = Guid.NewGuid();
            Guid myManualSystemId = new Guid("EE99B786-B3A2-426A-BA46-53B990383DA1");
            var cfg = new DestinationConfiguration<SystemPerson>(new TestConfigurationFactory());
            cfg.From(typeof(PersonalInfo), typeof(Parents));
            cfg.ApplyingConvention(new StaticValueResolver(systemId), m => m.SystemId);
            cfg.UsingValue<PersonalInfo>(myManualSystemId, on => on.SystemId);
            var bindable = bindableFactory.CreateBindableConfiguration(cfg.TakeSnapshot());

            var executable = bindable.CreateExecutableMapping(typeof(PersonalInfo));

            executable.Execute(contextualizer.CreateContext(src1, destination));
            destination.SystemId.should_not_be_equal_to(systemId);
            destination.SystemId.should_be_equal_to(myManualSystemId);
        }
        public void it_should_apply_convention_during_mapping()
        {
            var src1 = new PersonalInfo() { Age = 3, Name = "mikey" };
            var destination = new SystemPerson(){MothersName = "ignoremeplease"};
            Guid systemId=Guid.NewGuid();
            var cfg = new DestinationConfiguration<SystemPerson>(new TestConfigurationFactory());
            cfg.From(typeof(PersonalInfo), typeof(Parents))
                .ApplyingConvention(new StaticValueResolver(systemId), m=>m.SystemId);

            var bindable = bindableFactory.CreateBindableConfiguration(cfg.TakeSnapshot());

            var executable = bindable.CreateExecutableMapping(typeof (PersonalInfo));

            executable.Execute(contextualizer.CreateContext(src1,destination));
            destination.Age.should_be_equal_to(3);
            destination.MothersName.should_be_equal_to("ignoremeplease");
            destination.SystemId.should_be_equal_to(systemId);
            destination.Name.should_be_equal_to("mikey");
        }
        public void it_should_map_nested_components_by_type()
        {
            var componentConfig = new DestinationConfiguration(typeof(ViewModelComponent));
            componentConfig.From(typeof(EventComponent));

            var modelConfig = new DestinationConfiguration(typeof(ComplexViewModel));
            modelConfig.From(typeof (ComplexEventWithDifferentNamedComponent));
            modelConfig.SetPropertyResolver(
                PropertyNameCriterion.From<ComplexViewModel>(m=>m.Component), typeof(ComplexEventWithDifferentNamedComponent),
                new RedirectingConfigurationResolver(MappableProperty.For<ComplexEventWithDifferentNamedComponent>(s => s.DifferentName), configFactory.CreateBindableConfiguration(componentConfig.TakeSnapshot())));

            var bindable = configFactory.CreateBindableConfiguration(modelConfig.TakeSnapshot());

            var source = new ComplexEventWithDifferentNamedComponent() { Name = "RootName", DifferentName= new EventComponent() { Name = "ComponentName" } };
            var dest = new ComplexViewModel();
            var executable = bindable.CreateExecutableMapping(typeof(ComplexEventWithDifferentNamedComponent));
            executable.Execute(contextualizer.CreateContext(source, dest));
            dest.Name.should_be_equal_to("RootName");
            dest.Component.should_not_be_null();
            dest.Component.Name.should_be_equal_to("ComponentName");
        }
Esempio n. 9
0
 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 destination_type_is_automatically_configured_as_source()
 {
     var cfg = new DestinationConfiguration(typeof(Person));
     cfg.IsSourcedBy(typeof(Person)).should_be_true();
 }
 public void missing_property_mapping_throws()
 {
     var cfg = new DestinationConfiguration(typeof(Person));
     cfg.From(typeof (PersonalInfo), typeof (Parents));
     var bindable = configFactory.CreateBindableConfiguration(cfg.TakeSnapshot());
     Action validation = bindable.Assert;
     validation.should_throw_an<DittoConfigurationException>();
     validation.should_throw_because<DittoConfigurationException>("The following properties are not mapped for '" + typeof(Person) + "':" + Environment.NewLine + "FathersName" + Environment.NewLine);
 }
 public void manually_configuring_dest_property_with_more_than_one_resolver()
 {
     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.SetPropertyResolver(new PropertyNameCriterion("SomeId"), typeof(TypicalEvent), new StaticValueResolver(new Guid("1B8CF33D-92B8-4E82-9E8F-5EEDE7BA14F0")));
     duplication.should_throw_because<DittoConfigurationException>("Destination property 'Ditto.Tests.TypicalViewModel:SomeId' already has a manually, or conventioned, configured resolver from source type 'Ditto.Tests.TypicalEvent'");
 }
        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"));
        }
Esempio n. 14
0
 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);
 }
Esempio n. 15
0
 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);
 }
Esempio n. 16
0
        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");
        }
Esempio n. 17
0
 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);
 }
Esempio n. 18
0
        public void it_should_include_conventions_in_validation()
        {
            var cfg = new DestinationConfiguration(typeof(SystemPerson));
            cfg.From(typeof (PersonalInfo), typeof (Parents))
                .ApplyingConvention(new PropertyNameCriterion("SystemId"), new IgnoreResolver());

            var bindable = bindableFactory.CreateBindableConfiguration(cfg.TakeSnapshot());
            Action validation = bindable.Assert;
            validation.should_not_throw_an<DittoConfigurationException>();
        }
Esempio n. 19
0
        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");
        }
Esempio n. 20
0
 public void it_should_support_other_property_specifications()
 {
     var cfg = new DestinationConfiguration(typeof(SystemPerson));
     cfg.From(typeof(PersonalInfo), typeof(Parents))
         .ApplyingConvention(new PrefixPropertyCriterion("System"), new IgnoreResolver());
     var bindable = bindableFactory.CreateBindableConfiguration(cfg.TakeSnapshot());
     Action validation = bindable.Assert;
     validation.should_not_throw_an<DittoConfigurationException>();
 }