예제 #1
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);
        }
예제 #2
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"));
        }
예제 #3
0
        public void it_should_redirect_nested_mappings_to_dest_property()
        {
            container.Map <ComplexViewModel>()
            .From <ComplexEvent, TypicalEvent>()
            .Nesting <TypicalEvent, ViewModelComponent>(its => its.Component, cfg => { });
            var bindable = container.ToBinding();

            bindable.Bind();
            bindable.Assert();

            var source = new TypicalEvent()
            {
                Name = "RedirectingName",
            };
            var dest       = new ComplexViewModel();
            var executable = bindable.CreateCommand(typeof(TypicalEvent), typeof(ComplexViewModel));

            executable.Map(source, dest);
            dest.Component.should_not_be_null();
            dest.Component.Name.should_be_equal_to("RedirectingName");
        }
예제 #4
0
        public void it_should_redirect_nested_mappings_to_dest_property()
        {
            container.Map<ComplexViewModel>()
                .From<ComplexEvent,TypicalEvent>()
                .Nesting<TypicalEvent,ViewModelComponent>(its=>its.Component,cfg => { });
            var bindable = container.ToBinding();
            bindable.Bind();
            bindable.Assert();

            var source = new TypicalEvent() { Name = "RedirectingName",};
            var dest = new ComplexViewModel();
            var executable = bindable.CreateCommand(typeof (TypicalEvent), typeof (ComplexViewModel));
            executable.Map(source, dest);
            dest.Component.should_not_be_null();
            dest.Component.Name.should_be_equal_to("RedirectingName");
        }
예제 #5
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"));
        }
예제 #6
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);
 }