Esempio n. 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);
        }
        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);
        }
Esempio n. 3
0
        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 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"));
        }