コード例 #1
0
        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);
        }
コード例 #2
0
        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");
        }
コード例 #3
0
        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");
        }
コード例 #4
0
 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>();
 }
コード例 #5
0
 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>();
 }
コード例 #6
0
 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();
 }
コード例 #7
0
        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();
        }
コード例 #8
0
 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[]));
 }
コード例 #9
0
        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>();
        }
コード例 #10
0
        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>();
        }
コード例 #11
0
        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);
        }
コード例 #12
0
        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[]));
        }
コード例 #13
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>();
        }
コード例 #14
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>();
        }
コード例 #15
0
        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");
        }
コード例 #16
0
        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);
        }
コード例 #17
0
        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");
        }
コード例 #18
0
        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");
        }
コード例 #19
0
        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");
        }
コード例 #20
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>();
        }
コード例 #21
0
 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);
 }
コード例 #22
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>();
 }