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);
        }
        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);
        }
        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\" />");
        }
Example #4
0
        public XmlMediaDocument(XmlMediaOptions options)
        {
            _document = new XmlDocument();
            if (options.Namespace.IsEmpty())
            {
                _document.WithRoot(options.Root);
            }
            else
            {
                var node = _document.CreateNode(XmlNodeType.Element, options.Root, options.Namespace);
                _document.AppendChild(node);
            }


            _topNode = options.NodeStyle == XmlNodeStyle.AttributeCentric
                           ? (IXmlMediaNode) new XmlAttCentricMediaNode(_document.DocumentElement)
                           : new XmlNodeCentricMediaNode(_document.DocumentElement);

            _topNode.LinkWriter = options.LinkWriter;

            _options = options;
        }
        public XmlMediaDocument(XmlMediaOptions options)
        {
            _document = new XmlDocument();
            if (options.Namespace.IsEmpty())
            {
                _document.WithRoot(options.Root);
            }
            else
            {
                var node = _document.CreateNode(XmlNodeType.Element, options.Root, options.Namespace);
                _document.AppendChild(node);
            }


            _topNode = options.NodeStyle == XmlNodeStyle.AttributeCentric
                           ? (IXmlMediaNode) new XmlAttCentricMediaNode(_document.DocumentElement)
                           : new XmlNodeCentricMediaNode(_document.DocumentElement);

            _topNode.LinkWriter = options.LinkWriter;

            _options = options;
        }
        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 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));
        }
        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(','));
        }
        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);
        }
 public XmlMediaWriter(XmlMediaOptions options, ILinkSource <T> links, IUrlRegistry urls,
                       IProjection <T> projection)
     : base(new XmlMediaDocument(options), links, urls, projection, null, null)
 {
 }
 public void SetUp()
 {
     theDefaultOptions = new XmlMediaOptions();
 }