Пример #1
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);
        }
Пример #2
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\" />");
        }
Пример #3
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;
        }
Пример #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;
        }
Пример #5
0
 public XmlMediaWriter(XmlMediaOptions options, ILinkSource <T> links, IUrlRegistry urls,
                       IProjection <T> projection)
     : base(new XmlMediaDocument(options), links, urls, projection, null)
 {
 }
Пример #6
0
 public void SetUp()
 {
     theDefaultOptions = new XmlMediaOptions();
 }
Пример #7
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(','));
        }
Пример #8
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);

            writer.AssertWasCalled(x => x.Write(options.Mimetype, document.Root.As<XmlMediaNode>().Element.OuterXml));
        }
Пример #9
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);
        }
Пример #10
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);
        }
        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");

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

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

            theOutput = new InMemoryOutputWriter();
            media.Write(theAddress, theOutput);

            Debug.WriteLine(theOutput);
        }