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"); }
public void project_with_the_for_attribute_method() { var projection = new Projection<Address>(DisplayFormatting.RawValues); projection.ForAttribute("anything").Use(context => "aaa" + context.ValueFor(x => x.Line1)); projection.As<IProjection<Address>>().Write(new ProjectionContext<Address>(null, aTarget), aNode); aNode.Element.GetAttribute("anything").ShouldEqual("aaa" + anAddress.Line1); }
public void project_with_the_for_attribute_and_func_to_massage_the_data() { var projection = new Projection<Address>(DisplayFormatting.RawValues); projection.ForAttribute("anything").ValueFrom(x => x.Line1).Use(value => "aaa" + value); projection.As<IProjection<Address>>().Write(new ProjectionContext<Address>(null, aTarget), aNode); aNode.Element.GetAttribute("anything").ShouldEqual("aaa" + anAddress.Line1); }
public void project_with_the_for_attribute_and_func_to_massage_the_data() { var projection = new Projection <Address>(DisplayFormatting.RawValues); projection.ForAttribute("anything").ValueFrom(x => x.Line1).Use(value => "aaa" + value); projection.As <IProjection <Address> >().Write(new ProjectionContext <Address>(null, aTarget), aNode); aNode.Element.GetAttribute("anything").ShouldEqual("aaa" + anAddress.Line1); }
public void project_with_the_for_attribute_method() { var projection = new Projection <Address>(DisplayFormatting.RawValues); projection.ForAttribute("anything").Use(context => "aaa" + context.ValueFor(x => x.Line1)); projection.As <IProjection <Address> >().Write(new ProjectionContext <Address>(null, aTarget), aNode); aNode.Element.GetAttribute("anything").ShouldEqual("aaa" + anAddress.Line1); }
public void accessors() { var projection = new Projection<Address>(DisplayFormatting.RawValues); projection.Value(x => x.Address1); projection.Value(x => x.Address2); projection.Value(x => x.City); projection.Value(x => x.State); projection.As<IProjection<Address>>().Accessors().Select(x => x.Name) .ShouldHaveTheSameElementsAs("Address1", "Address2", "City", "State"); }
public void accessors() { var projection = new Projection <Address>(DisplayFormatting.RawValues); projection.Value(x => x.Address1); projection.Value(x => x.Address2); projection.Value(x => x.City); projection.Value(x => x.State); projection.As <IProjection <Address> >().Accessors().Select(x => x.Name) .ShouldHaveTheSameElementsAs("Address1", "Address2", "City", "State"); }
public void write_node_with_inline_writer() { var projection = new Projection<Address>(DisplayFormatting.RawValues); projection.WriteWith((context, node) => { node.AddChild("address").SetAttribute("description", "I was here"); }); projection.As<IProjection<Address>>().Write(new ProjectionContext<Address>(null, aTarget), aNode); aNode.Element.InnerXml.ShouldEqual("<address description=\"I was here\" />"); }
public void write_node_with_inline_writer() { var projection = new Projection <Address>(DisplayFormatting.RawValues); projection.WriteWith((context, node) => { node.AddChild("address").SetAttribute("description", "I was here"); }); projection.As <IProjection <Address> >().Write(new ProjectionContext <Address>(null, aTarget), aNode); aNode.Element.InnerXml.ShouldEqual("<address description=\"I was here\" />"); }
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); }
public void write_a_node_with_multiple_properties() { var projection = new Projection<Address>(); projection.Value(x => x.Line1); projection.Value(x => x.City); projection.Value(x => x.State); projection.Value(x => x.ZipCode); projection.As<IValueProjection<Address>>().WriteValue(aTarget, aNode); aNode.Element.GetAttribute("Line1").ShouldEqual(anAddress.Line1); aNode.Element.GetAttribute("City").ShouldEqual(anAddress.City); aNode.Element.GetAttribute("State").ShouldEqual(anAddress.State); aNode.Element.GetAttribute("ZipCode").ShouldEqual(anAddress.ZipCode); }
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); }
public void write_a_node_with_multiple_properties() { var projection = new Projection<Address>(DisplayFormatting.RawValues); projection.Value(x => x.Line1); projection.Value(x => x.City); projection.Value(x => x.State); projection.Value(x => x.ZipCode); projection.As<IProjection<Address>>().Write(new ProjectionContext<Address>(null, aTarget), aNode); aNode.Element.GetAttribute("Line1").ShouldEqual(anAddress.Line1); aNode.Element.GetAttribute("City").ShouldEqual(anAddress.City); aNode.Element.GetAttribute("State").ShouldEqual(anAddress.State); aNode.Element.GetAttribute("ZipCode").ShouldEqual(anAddress.ZipCode); }
public void write_a_node_with_multiple_properties() { var projection = new Projection <Address>(); projection.Value(x => x.Line1); projection.Value(x => x.City); projection.Value(x => x.State); projection.Value(x => x.ZipCode); projection.As <IValueProjection <Address> >().WriteValue(aTarget, aNode); aNode.Element.GetAttribute("Line1").ShouldEqual(anAddress.Line1); aNode.Element.GetAttribute("City").ShouldEqual(anAddress.City); aNode.Element.GetAttribute("State").ShouldEqual(anAddress.State); aNode.Element.GetAttribute("ZipCode").ShouldEqual(anAddress.ZipCode); }
public void write_a_node_with_multiple_properties() { var projection = new Projection <Address>(DisplayFormatting.RawValues); projection.Value(x => x.Line1); projection.Value(x => x.City); projection.Value(x => x.State); projection.Value(x => x.ZipCode); projection.As <IProjection <Address> >().Write(new ProjectionContext <Address>(null, aTarget), aNode); aNode.Element.GetAttribute("Line1").ShouldEqual(anAddress.Line1); aNode.Element.GetAttribute("City").ShouldEqual(anAddress.City); aNode.Element.GetAttribute("State").ShouldEqual(anAddress.State); aNode.Element.GetAttribute("ZipCode").ShouldEqual(anAddress.ZipCode); }
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); }
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); }