Beispiel #1
0
        public void the_root_element_should_match_the_option_root()
        {
            var options = new XmlMediaOptions {
                NodeStyle = XmlNodeStyle.AttributeCentric,
                Root      = "Something",
                Namespace = "http://mynamespace.xsd"
            };
            var document = new XmlMediaDocument(options);

            var root = document.Root.ShouldBeOfType <XmlMediaNode>().Element;

            root.Name.ShouldEqual(options.Root);
        }
Beispiel #2
0
        public void the_root_has__the_link_writer_from_the_options()
        {
            var options = new XmlMediaOptions {
                NodeStyle  = XmlNodeStyle.AttributeCentric,
                Root       = "Something",
                LinkWriter = new StubLinkWriter()
            };

            var document = new XmlMediaDocument(options);

            var root = document.Root.ShouldBeOfType <XmlMediaNode>();

            root.LinkWriter.ShouldBeTheSameAs(options.LinkWriter);
        }
Beispiel #3
0
        public void root_element_with_a_namespace()
        {
            var options = new XmlMediaOptions
            {
                NodeStyle = XmlNodeStyle.AttributeCentric,
                Root      = "Something",
                Namespace = "http://mynamespace.xsd"
            };
            var document = new XmlMediaDocument(options);

            var root = document.Root.ShouldBeOfType <XmlMediaNode>().Element;

            root.OuterXml.ShouldEqual("<Something xmlns=\"http://mynamespace.xsd\" />");
        }
Beispiel #4
0
        public void should_list_the_mime_type_from_the_xml_options_if_there_are_multiples()
        {
            var options = new XmlMediaOptions
            {
                NodeStyle  = XmlNodeStyle.AttributeCentric,
                Root       = "Something",
                LinkWriter = new StubLinkWriter(),
                Mimetype   = "vnd.dovetail.resource,text/xml,application/xml"
            };

            var document = new XmlMediaDocument(options);

            document.Mimetypes.ShouldHaveTheSameElementsAs(options.Mimetype.ToDelimitedArray(','));
        }
Beispiel #5
0
        public void should_list_the_mime_type_from_the_xml_options()
        {
            var options = new XmlMediaOptions
            {
                NodeStyle  = XmlNodeStyle.AttributeCentric,
                Root       = "Something",
                LinkWriter = new StubLinkWriter(),
                Mimetype   = "vnd.dovetail.resource"
            };

            var document = new XmlMediaDocument(options);

            document.Mimetypes.Single().ShouldEqual(options.Mimetype);
        }
Beispiel #6
0
        public void write_should_use_the_mime_type_from_the_options()
        {
            var writer = MockRepository.GenerateMock <IOutputWriter>();

            var options = new XmlMediaOptions
            {
                NodeStyle  = XmlNodeStyle.AttributeCentric,
                Root       = "Something",
                LinkWriter = new StubLinkWriter()
            };

            var document = new XmlMediaDocument(options);

            document.Write(writer, "text/xml");

            writer.AssertWasCalled(x => x.Write(options.Mimetype, document.Root.As <XmlMediaNode>().Element.OuterXml));
        }
Beispiel #7
0
        public void SetUp()
        {
            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.StateOrProvince).Name("State");

            theXmlMediaOptions = new XmlMediaOptions()
            {
                Root = "Address"
            };
            theDocument = new XmlMediaDocument(theXmlMediaOptions);

            var urls = new StubUrlRegistry();

            var linkSource = new LinksSource <Address>();

            linkSource.ToSubject().Rel("self");
            linkSource.To(a => new AddressAction("change")).Rel("change");
            linkSource.To(a => new AddressAction("delete")).Rel("delete");

            theOutput = new InMemoryOutputWriter();

            var media = new MediaWriter <Address>(theDocument, linkSource, urls, projection, null, theOutput);


            theAddress = new Address()
            {
                Address1        = "22 Cherry Lane",
                Address2        = "Apt A",
                City            = "Austin",
                StateOrProvince = "Texas"
            };



            media.Write("text/plain", theAddress);

            Debug.WriteLine(theOutput);
        }
        public void create_a_media_write_node_for_xml()
        {
            var             resource = new Resource <Address>();
            XmlMediaOptions options  = null;

            resource.WriteToXml(o =>
            {
                options     = o;
                o.Namespace = "something.xsd";
            });

            resource.Links.ToSubject();
            resource.ProjectValue(x => x.Line1);

            resource.As <IResourceRegistration>().Modify(theConnegGraph, theBehaviorGraph);

            var connegOutput = theBehaviorGraph
                               .BehaviorFor <RestController1>(x => x.Find(null))
                               .Output;

            var writerNode = connegOutput.Writers.Last().As <MediaWriterNode>();

            // Assert the xml media
            var objectDef = writerNode.As <IContainerModel>().ToObjectDef()
                            .FindDependencyDefinitionFor <IMediaWriter <Address> >();


            var document = objectDef.DependencyFor <IMediaDocument>().ShouldBeOfType <ConfiguredDependency>();

            document.DependencyType.ShouldEqual(typeof(IMediaDocument));
            document.Definition.Type.ShouldEqual(typeof(XmlMediaDocument));
            document.Definition.DependencyFor <XmlMediaOptions>().ShouldBeOfType <ValueDependency>()
            .Value.ShouldBeTheSameAs(options);

            objectDef.DependencyFor <ILinkSource <Address> >().ShouldBeOfType <ValueDependency>()
            .Value.ShouldBeTheSameAs(resource.Links);


            objectDef.DependencyFor <IProjection <Address> >().ShouldBeOfType <ValueDependency>()
            .Value.ShouldBeOfType <Projection <Address> >();
        }
Beispiel #9
0
        public void WriteToXml(Action <XmlMediaOptions> configure)
        {
            var options = new XmlMediaOptions();

            configure(options);

            modify = node =>
            {
                var writerNode = new MediaWriterNode(typeof(T));
                writerNode.Document.UseType <XmlMediaDocument>().DependencyByValue(options);
                if (_links.IsValueCreated)
                {
                    writerNode.Links.UseValue(_links.Value);
                }
                if (_projection.IsValueCreated)
                {
                    writerNode.Projection.UseValue(_projection.Value);
                }

                node.Writers.AddToEnd(writerNode);
            };
        }
Beispiel #10
0
 public void SetUp()
 {
     theDefaultOptions = new XmlMediaOptions();
 }