public void with_the_normal_casing()
        {
            var projection = new Projection <SomeTarget>();

            //projection.CamelCaseAttributeNames();
            projection.Value(x => x.Name);
            projection.Value(x => x.Age);
            projection.Child(x => x.Child).Configure(_ =>
            {
                _.Value(x => x.Name);
            });


            var node       = new DictionaryMediaNode();
            var someTarget = new SomeTarget
            {
                Active = true,
                Age    = 40,
                Name   = "Jeremy",
                Child  = new SomeChild {
                    Name = "Max"
                }
            };

            projection.As <IProjection <SomeTarget> >().Write(new ProjectionContext <SomeTarget>(new InMemoryServiceLocator(), someTarget), node);

            node.Values["Name"].ShouldEqual("Jeremy");
            node.Values["Age"].ShouldEqual(40);

            node.Values["Child"].As <IDictionary <string, object> >()["Name"].ShouldEqual("Max");
        }
Ejemplo n.º 2
0
        public void format_data_smoke_test()
        {
            var grid = new TargetGrid();

            grid.Column(x => x.Count);
            grid.Column(x => x.IsCool);
            grid.Column(x => x.Name);

            var data = new GridDefTarget[] {
                new GridDefTarget {
                    Count = 1, IsCool = true, Name = "Scooby"
                },
                new GridDefTarget {
                    Count = 2, IsCool = true, Name = "Velma"
                },
                new GridDefTarget {
                    Count = 3, IsCool = true, Name = "Daphne"
                },
            };

            IProjection <GridDefTarget> projection = grid.As <IGridDefinition <GridDefTarget> >().Projection.As <IProjection <GridDefTarget> >();


            var dicts = data.Select(x => {
                var node = new DictionaryMediaNode();

                projection.Write(new ProjectionContext <GridDefTarget>(new InMemoryServiceLocator(), x), node);

                return(node.Values);
            });

            dicts.Select(x => x["Name"]).ShouldHaveTheSameElementsAs("Scooby", "Velma", "Daphne");
            dicts.Select(x => x["Count"]).ShouldHaveTheSameElementsAs(1, 2, 3);
        }
Ejemplo n.º 3
0
        public void SetUp()
        {
            theProjection = new TargetProjection();
            theTarget     = new Target();

            MockFor <IServiceLocator>().Stub(x => x.GetInstance <TargetProjection>())
            .Return(theProjection);

            theNode = new DictionaryMediaNode();
        }
Ejemplo n.º 4
0
        protected override void beforeEach()
        {
            theProjection = new TargetProjection();
            theTarget     = new Target();

            MockFor <IServiceLocator>().Stub(x => x.GetInstance <TargetProjection>())
            .Return(theProjection);

            theNode = new DictionaryMediaNode();
        }
        public void creates_and_delegates_to_another_projection()
        {
            var context = MockRepository.GenerateMock <IProjectionContext <ProjectionModel> >();

            var projection = new DelegatingProjection <ProjectionModel, FakeProjector>();
            var theNode    = new DictionaryMediaNode();

            projection.Write(context, theNode);

            FakeProjector.theTarget.ShouldBeTheSameAs(context);
            FakeProjector.theNode.ShouldBeTheSameAs(theNode);
        }
        private IDictionary <string, object> project(Projection <Party> projection)
        {
            var node     = new DictionaryMediaNode();
            var services = new InMemoryServiceLocator();

            services.Add(new HeroRepository());

            var context = new ProjectionContext <Party>(services, theParty);

            projection.As <IProjection <Party> >().Write(context, node);

            return(node.Values);
        }
Ejemplo n.º 7
0
        public void SetUp()
        {
            theProjection = new Projection <Parent>(DisplayFormatting.RawValues);
            theParent     = new Parent();

            _dictionary = new Lazy <IDictionary <string, object> >(() =>
            {
                var runner = new ProjectionRunner(new FubuCore.Binding.InMemory.InMemoryServiceLocator());
                var node   = new DictionaryMediaNode();

                runner.Run(theProjection, theParent, node);

                return(node.Values);
            });
        }
        public void include_inside_a_projection()
        {
            var context = MockRepository.GenerateMock <IProjectionContext <ProjectionModel> >();

            var projection = new Projection <ProjectionModel>(DisplayFormatting.RawValues);

            projection.Include <FakeProjector>();

            var theNode = new DictionaryMediaNode();

            projection.As <IProjection <ProjectionModel> >().Write(context, theNode);

            FakeProjector.theTarget.ShouldBeTheSameAs(context);
            FakeProjector.theNode.ShouldBeTheSameAs(theNode);
        }
Ejemplo n.º 9
0
        public void creates_and_delegates_to_another_projection()
        {
            var context = MockRepository.GenerateMock <IProjectionContext <ProjectionModel> >();
            var stub    = new FakeProjector();

            context.Stub(x => x.Service <FakeProjector>()).Return(stub);

            var projection = new DelegatingProjection <ProjectionModel, FakeProjector>();
            var theNode    = new DictionaryMediaNode();

            projection.Write(context, theNode);

            stub.theTarget.ShouldBeTheSameAs(context);
            stub.theNode.ShouldBeTheSameAs(theNode);
        }
        public void should_just_use_IProjectMyself_Project_in_accessor_projection()
        {
            var projection = AccessorProjection <ComplexValueHolder, ComplexValue> .For(x => x.Value);

            var target = new ComplexValueHolder
            {
                Value = new ComplexValue {
                    Name = "Jeremy", Age = 38
                }
            };

            var context = new ProjectionContext <ComplexValueHolder>(new InMemoryServiceLocator(), target);

            var node = new DictionaryMediaNode();

            projection.As <IProjection <ComplexValueHolder> >().Write(context, node);

            node.Values["Value"].As <IDictionary <string, object> >()["Name"].ShouldEqual("Jeremy");
            node.Values["Value"].As <IDictionary <string, object> >()["Age"].ShouldEqual(38);
        }
Ejemplo n.º 11
0
        public void project_the_property_with_formatting_thru_display_formatter()
        {
            var projection = new Projection <Address>(DisplayFormatting.UseDisplayFormatting);

            projection.Value(x => x.Line1);

            var services  = MockRepository.GenerateMock <IServiceLocator>();
            var formatter = MockRepository.GenerateMock <IDisplayFormatter>();

            services.Stub(x => x.GetInstance <IDisplayFormatter>()).Return(formatter);

            var accessor          = ReflectionHelper.GetAccessor <Address>(x => x.Line1);
            var theFormattedValue = "formatted value";

            formatter.Stub(x => x.GetDisplayForValue(accessor, anAddress.Line1)).Return(theFormattedValue);

            var node = new DictionaryMediaNode();

            projection.As <IProjection <Address> >().Write(new ProjectionContext <Address>(services, aTarget), node);
            node.Values["Line1"].ShouldEqual(theFormattedValue);
        }
Ejemplo n.º 12
0
        public IDictionary <string, object> Write(IEnumerable <JavascriptRoute> routes)
        {
            var node = new DictionaryMediaNode();

            routes.Each(x => {
                var child = node.AddChild(x.Name);
                var chain = x.FindChain(_resolver);
                child.SetAttribute("name", x.Name);
                child.SetAttribute("method", x.Method);

                child.SetAttribute("url", _routeData.ToUrl(chain));

                var parameters = _routeData.ToParameters(chain);
                if (parameters.Any())
                {
                    child.SetAttribute("params", parameters);
                }
            });

            return(node.Values);
        }
Ejemplo n.º 13
0
        public void should_just_use_IValueProjector_when_overriden_in_accessor_projection()
        {
            var projection = AccessorProjection <CustomValueHolder, CustomValue> .For(x => x.Value);

            projection.ProjectWith <CustomValueProjector>();

            var target = new CustomValueHolder
            {
                Value = new CustomValue {
                    Name = "Jeremy", Age = 38
                }
            };

            var context = new ProjectionContext <CustomValueHolder>(new InMemoryServiceLocator(), target);

            var node = new DictionaryMediaNode();

            projection.As <IProjection <CustomValueHolder> >().Write(context, node);

            node.Values["Value"].As <IDictionary <string, object> >()["Name"].ShouldBe("Jeremy");
            node.Values["Value"].As <IDictionary <string, object> >()["Age"].ShouldBe(38);
        }
Ejemplo n.º 14
0
 public void SetUp()
 {
     theNode = new DictionaryMediaNode();
 }