public void GetFormatter_Invoke_ReturnsExpected()
        {
            var document = new ServiceDocument();
            AtomPub10ServiceDocumentFormatter formatter = Assert.IsType <AtomPub10ServiceDocumentFormatter>(document.GetFormatter());

            Assert.Same(document, formatter.Document);
            Assert.Equal("http://www.w3.org/2007/app", formatter.Version);
        }
        public void WriteTo()
        {
            var s = new ServiceDocument();
            var a = new AtomPub10ServiceDocumentFormatter(s);

            Assert.AreEqual("http://www.w3.org/2007/app", a.Version, "#1");
            Assert.IsTrue(a.CanRead(XmlReader.Create(new StringReader(app1))), "#2");
            var sw = new StringWriter();

            using (var xw = XmlWriter.Create(sw, settings))
                a.WriteTo(xw);
            Assert.AreEqual(app1, sw.ToString(), "#3");
        }
Ejemplo n.º 3
0
        public HttpResponseMessage Get()
        {
            var doc = new ServiceDocument();
            var ws  = new Workspace
            {
                Title   = new TextSyndicationContent("My Site"),
                BaseUri = new Uri(Request.RequestUri.GetLeftPart(UriPartial.Authority))
            };

            var posts = new ResourceCollectionInfo("Blog",
                                                   new Uri(Url.Link("DefaultApi", new { controller = "posts" })));

            posts.Accepts.Add("application/atom+xml;type=entry");

            // For WLW to work we need to include format in the categories URI.
            // Hoping to provide a better solution than this.
            var categoriesUri = new Uri(Url.Link("DefaultApi", new { controller = "tags", format = "atomcat" }));
            var categories    = new ReferencedCategoriesDocument(categoriesUri);

            posts.Categories.Add(categories);

            ws.Collections.Add(posts);

            doc.Workspaces.Add(ws);

            var response = new HttpResponseMessage(HttpStatusCode.OK);

            var formatter = new AtomPub10ServiceDocumentFormatter(doc);

            var stream = new MemoryStream();

            using (var writer = XmlWriter.Create(stream))
            {
                formatter.WriteTo(writer);
            }

            stream.Position = 0;
            var content = new StreamContent(stream);

            response.Content = content;
            response.Content.Headers.ContentType =
                new MediaTypeHeaderValue("application/atomsvc+xml");

            return(response);
        }
        public void WriteTo2()
        {
            var s  = new ServiceDocument();
            var ws = new Workspace("test title", null);
            var rc = new ResourceCollectionInfo("test resource", new Uri("urn:foo"));

            rc.Accepts.Add("application/atom+xml;type=entry");
            ws.Collections.Add(rc);
            s.Workspaces.Add(ws);
            var a = new AtomPub10ServiceDocumentFormatter(s);

            Assert.AreEqual("http://www.w3.org/2007/app", a.Version, "#1");
            Assert.IsTrue(a.CanRead(XmlReader.Create(new StringReader(app2))), "#2");
            var sw = new StringWriter();

            using (var xw = XmlWriter.Create(sw, settings))
                a.WriteTo(xw);
            Assert.AreEqual(app2, sw.ToString(), "#3");
        }
Ejemplo n.º 5
0
        //=============== Workspace service

        internal static AtomPub10ServiceDocumentFormatter BuildWorkspace(string repositoryId)
        {
            //var xmlns = new XmlSerializerNamespaces();
            //xmlns.Add("app", Workspace.APPNAMESPACE);
            //xmlns.Add("atom", Workspace.ATOMNAMESPACE);
            //xmlns.Add("cmis", Workspace.CMISNAMESPACE);

            var baseUri = GetBaseUri();

            var workspace = new Workspace("Main Repository", GetResourceCollections(baseUri, repositoryId));
            var repInfo   = new RepositoryInfo
            {
                Id             = repositoryId,
                Name           = "MainRep",
                Relationship   = enumRepositoryRelationship.self,
                Description    = "Main Repository",
                VendorName     = "Sense/Net Ltd.",
                ProductName    = "SenseNet Content Repository Prototype",
                ProductVersion = "0.01",
                RootFolderId   = "2",
                Capabilities   = new RepositoryCapabilities
                {
                    Multifiling           = false,
                    Unfiling              = true,
                    VersionSpecificFiling = false,
                    PWCUpdateable         = false,
                    AllVersionsSearchable = false,
                    Join     = enumCapabilityJoin.nojoin,
                    FullText = enumCapabilityFullText.none
                },
                CmisVersionsSupported = "0.5"
            };

            workspace.ElementExtensions.Add(repInfo, new XmlSerializer(typeof(RepositoryInfo)));

            var serviceDoc = new ServiceDocument(new Workspace[] { workspace });
            var formatter  = new AtomPub10ServiceDocumentFormatter(serviceDoc);

            return(formatter);
        }
        public void GetSchema()
        {
            IXmlSerializable i = new AtomPub10ServiceDocumentFormatter();

            Assert.IsNull(i.GetSchema());
        }