Ejemplo n.º 1
0
        public void UploadFileWithZeroSize()
        {
            // Acquire ADMIN permissions
            Plug p = Utils.BuildPlugForAdmin();

            /// Create a random page
            string       id   = null;
            string       path = null;
            DreamMessage msg  = PageUtils.CreateRandomPage(p, out id, out path);

            // Create a file with zero size and upload it to page
            byte[] content  = new byte[0];
            string fileid   = null;
            string filename = null;

            msg = FileUtils.UploadRandomFile(p, id, content, string.Empty, out fileid, out filename);

            // Retrieve file
            msg = p.At("files", fileid).Get();

            // Assert OK HTTP status returned
            Assert.AreEqual(DreamStatus.Ok, msg.Status);

            // Assert uploaded file content equals retrieved file content
            Assert.IsTrue(Utils.ByteArraysAreEqual(content, msg.AsBytes()));

            // Delete the page
            PageUtils.DeletePageByID(p, id, true);
        }
Ejemplo n.º 2
0
        public void GetComment()
        {
            // GET:pages/{pageid}/comments/{commentnumber}/content
            // http://developer.mindtouch.com/Deki/API_Reference/GET%3apages%2f%2f%7bpageid%7d%2f%2fcomments%2f%2f%7bcommentnumber%7d%2f%2fcontent

            Plug p = Utils.BuildPlugForAdmin();

            string       id  = null;
            DreamMessage msg = PageUtils.CreateRandomPage(p, out id);

            string       content = Utils.GetSmallRandomText();
            DreamMessage postMsg = DreamMessage.Ok(MimeType.TEXT_UTF8, content);

            msg = p.At("pages", id, "comments").Post(postMsg);
            Assert.AreEqual(DreamStatus.Ok, msg.Status);
            string commentId = msg.ToDocument()["@id"].AsText;

            Assert.IsFalse(string.IsNullOrEmpty(commentId));
            Assert.IsTrue(msg.ToDocument()["content"].AsText == content);

            msg = p.At("pages", id, "comments", "1", "content").Get();
            Assert.AreEqual(DreamStatus.Ok, msg.Status);
            Assert.IsTrue(msg.AsText() == content);

            // GET:pages/{pageid}/comments/{commentnumber}
            // http://developer.mindtouch.com/Deki/API_Reference/GET%3apages%2f%2f%7bpageid%7d%2f%2fcomments%2f%2f%7bcommentnumber%7d

            msg = p.At("pages", id, "comments", "1").Get();
            Assert.AreEqual(DreamStatus.Ok, msg.Status);
            Assert.IsTrue(msg.ToDocument()["@id"].AsText == commentId);
            Assert.IsTrue(msg.ToDocument()["content"].AsText == content);

            PageUtils.DeletePageByID(p, id, true);
        }
Ejemplo n.º 3
0
        public void GetRevisionSort()
        {
            Plug         p     = Utils.BuildPlugForAdmin();
            int          count = 5;
            string       id    = null;
            DreamMessage msg   = PageUtils.CreateRandomPage(p, out id);

            string fileid   = null;
            string filename = "aa.txt";
            string filepath = Path.Combine(Path.GetTempPath(), filename);

            try {
                FileUtils.CreateFile(null, filepath);
                for (int i = 0; i < count; i++)
                {
                    msg = FileUtils.UploadFile(p, id, "", out fileid, filepath);
                    msg = p.At("pages", id, "files", "=" + filename).Invoke("HEAD", DreamMessage.Ok());
                    Assert.AreEqual(DreamStatus.Ok, msg.Status);
                }
                msg = p.At("files", fileid, "revisions").Get();
                List <XDoc> files = msg.ToDocument()["file"].ToList();
                for (int i = 0; i < count; i++)
                {
                    Assert.AreEqual(i + 1, files[i]["@revision"].AsInt);
                }

                PageUtils.DeletePageByID(p, id, true);
            } finally {
                File.Delete(filepath);
            }
        }
Ejemplo n.º 4
0
        public void GetSiteTagsWithPages()
        {
            // 1. Create random page
            // 2. Generate a random tag and attach it to page
            // (3) Assert tag exists with correct tag and page IDs
            // 4. Delete the page

            Plug         p         = Utils.BuildPlugForAdmin();
            string       page_id   = null;
            string       page_path = null;
            DreamMessage msg       = PageUtils.CreateRandomPage(p, out page_id, out page_path);

            Guid guid = Guid.NewGuid();

            XDoc tagsDoc = new XDoc("tags")
                           .Start("tag").Attr("value", guid.ToString()).End();

            msg = p.At("pages", page_id, "tags").Put(tagsDoc);
            Assert.IsTrue(msg.Status == DreamStatus.Ok, "PUT request failed");

            uint tag_id = msg.ToDocument()["tag/@id"].AsUInt ?? 0;

            msg = p.At("site", "tags").With("pages", true).Get();

            Assert.IsTrue(msg.Status == DreamStatus.Ok, "GET request failed");
            Assert.IsFalse(msg.ToDocument()[string.Format("tag[@id=\"{0}\"]/pages/page[@id=\"{1}\"]", tag_id, page_id)].IsEmpty, "Tag with specified tag/page ID does not exist!");

            PageUtils.DeletePageByID(p, page_id, true);
        }
Ejemplo n.º 5
0
        public void GetTagsByPartialName()
        {
            // 1. Create random page
            // 2. Generate a random text tag and attach it to page
            // (3) Assert the tag is returned when searching for the first 3 characters of the value
            // 4. Delete the page

            Plug         p       = Utils.BuildPlugForAdmin();
            string       page_id = null;
            string       path    = null;
            DreamMessage msg     = PageUtils.CreateRandomPage(p, out page_id, out path);

            string guid    = Guid.NewGuid().ToString();
            XDoc   tagsDoc = new XDoc("tags")
                             .Start("tag").Attr("value", guid).End();

            msg = p.At("pages", page_id, "tags").Put(tagsDoc);
            Assert.IsTrue(msg.Status == DreamStatus.Ok, "PUT request failed");
            uint tag_id = msg.ToDocument()["tag/@id"].AsUInt ?? 0;

            // GET:site/tags?q=partialName
            msg = p.At("site", "tags").With("pages", true).With("type", "text").With("q", guid.Substring(0, 3)).Get();
            Assert.IsTrue(msg.Status == DreamStatus.Ok, "GET request failed");
            Assert.IsFalse(msg.ToDocument()[string.Format("tag[@id=\"{0}\"]/pages/page[@id=\"{1}\"]", tag_id, page_id)].IsEmpty, "Tag was not returned!");

            PageUtils.DeletePageByID(p, page_id, true);
        }
Ejemplo n.º 6
0
        public void CheckDescription()
        {
            // GET:pages/{pageid}/files/{filename}/description
            // http://developer.mindtouch.com/Deki/API_Reference/GET%3apages%2f%2f%7bpageid%7d%2f%2ffiles%2f%2f%7bfilename%7d%2f%2fdescription

            Plug p = Utils.BuildPlugForAdmin();

            string       id  = null;
            DreamMessage msg = PageUtils.CreateRandomPage(p, out id);

            string description = "File description text";
            string fileid      = null;
            string filename    = null;

            FileUtils.UploadRandomFile(p, id, null, description, out fileid, out filename);

            msg = p.At("pages", id, "files", "=" + filename, "description").Get();
            Assert.AreEqual(DreamStatus.Ok, msg.Status);
            Assert.IsTrue(msg.AsText() == description);

            // GET:files/{fileid}/description
            // http://developer.mindtouch.com/Deki/API_Reference/GET%3afiles%2f%2f%7bfileid%7d%2f%2fdescription

            msg = p.At("files", fileid, "description").Get();
            Assert.AreEqual(DreamStatus.Ok, msg.Status);
            Assert.IsTrue(msg.AsText() == description);

            PageUtils.DeletePageByID(p, id, true);
        }
Ejemplo n.º 7
0
        public void RatePageInvalidScore()
        {
            // Build ADMIN plug
            Plug p = Utils.BuildPlugForAdmin();

            // Create a random page
            string       id   = null;
            string       path = null;
            DreamMessage msg  = PageUtils.CreateRandomPage(p, out id, out path);

            // Attempt to rate a page without the query parameter 'score'
            msg = p.At("pages", id, "ratings").PostAsync().Wait();
            Assert.AreEqual(DreamStatus.BadRequest, msg.Status, "Page rating did not return 400: " + msg.ToString());

            // Attempt to rate page a '2' and assert a 'Bad Request' HTTP response is returned
            msg = p.At("pages", id, "ratings").With("score", 2).PostAsync().Wait();
            Assert.AreEqual(DreamStatus.BadRequest, msg.Status, "Page rating did not return 400: " + msg.ToString());

            // Attempt to rate page a '0.5' and assert a 'Bad Request' HTTP response is returned
            msg = p.At("pages", id, "ratings").With("score", 0.5).PostAsync().Wait();
            Assert.AreEqual(DreamStatus.BadRequest, msg.Status, "Page rating did not return 400: " + msg.ToString());

            // Delete the page
            PageUtils.DeletePageByID(p, id, true);
        }
Ejemplo n.º 8
0
        public void DeleteFileThroughPage()
        {
            // DELETE:pages/{pageid}/files/{filename}
            // http://developer.mindtouch.com/Deki/API_Reference/DELETE%3apages%2f%2f%7bpageid%7d%2f%2ffiles%2f%2f%7bfilename%7d

            Plug p = Utils.BuildPlugForAdmin();

            string       id  = null;
            DreamMessage msg = PageUtils.CreateRandomPage(p, out id);

            string fileid   = null;
            string filename = null;

            FileUtils.UploadRandomFile(p, id, out fileid, out filename);

            msg = p.At("pages", id, "files", "=" + filename).Delete();
            Assert.AreEqual(DreamStatus.Ok, msg.Status);

            msg = p.At("pages", id, "files").Get();
            Assert.AreEqual(DreamStatus.Ok, msg.Status);
            Assert.IsTrue(msg.ToDocument()["@count"].AsInt == 0);

            msg = p.At("archive", "files").Get();
            Assert.AreEqual(DreamStatus.Ok, msg.Status);
            Assert.IsFalse(msg.ToDocument()[string.Format("file.archive[@id=\"{0}\"]", fileid)].IsEmpty);

            PageUtils.DeletePageByID(p, id, true);
        }
Ejemplo n.º 9
0
        public void PostBigDescription()
        {
            //Assumptions:
            //Actions:
            // create page
            // create big description
            // post file with big description to page
            //Expected result:
            // Ok

            Plug p = Utils.BuildPlugForAdmin();

            string       id  = null;
            DreamMessage msg = PageUtils.CreateRandomPage(p, out id);

            try
            {
                string description = Utils.GetSmallRandomText();// Utils.GetSmallRandomText();
                string fileid      = null;
                string filename    = null;
                msg = FileUtils.UploadRandomFile(p, id, null, description, out fileid, out filename);

                msg = p.At("pages", id, "files", "=" + filename, "description").Get();
                Assert.AreEqual(DreamStatus.Ok, msg.Status);
                Assert.IsTrue(msg.AsText() == description);
            }
            catch (DreamResponseException)
            {
                Assert.Fail();
            }

            PageUtils.DeletePageByID(p, id, true);
        }
Ejemplo n.º 10
0
        public void GetFileInfo()
        {
            // GET:archive/files/{fileid}/info
            // http://developer.mindtouch.com/Deki/API_Reference/GET%3aarchive%2f%2ffiles%2f%2f%7bfileid%7d%2f%2finfo

            // 1. Create a page
            // 2. Upload a file
            // 3. Delete file
            // (4) Assert fileID matches file.archiveID
            // 5. Delete page

            Plug p = Utils.BuildPlugForAdmin();

            string       id  = null;
            DreamMessage msg = PageUtils.CreateRandomPage(p, out id);

            string fileid = null;

            msg = FileUtils.UploadRandomFile(p, id, out fileid);

            msg = FileUtils.DeleteFile(p, fileid);

            msg = p.At("archive", "files", fileid, "info").Get();
            Assert.AreEqual(DreamStatus.Ok, msg.Status, "Page retrieval failed");
            Assert.IsTrue((msg.ToDocument()["@id"].AsText ?? String.Empty) == fileid, "File archive ID does not match file ID!");

            PageUtils.DeletePageByID(p, id, true);
        }
Ejemplo n.º 11
0
        public void TestRestoreTwoTimes()
        {
            //Assumptions:
            //
            //Actions:
            // create new page
            // delete page
            // restore page
            // restore page second time
            //Expected result:
            // not found

            Plug p = Utils.BuildPlugForAdmin();

            string       id  = null;
            DreamMessage msg = PageUtils.CreateRandomPage(p, out id);

            PageUtils.DeletePageByID(p, id, false);

            try
            {
                msg = p.At("archive", "pages", id, "restore").Post();
                Assert.AreEqual(DreamStatus.Ok, msg.Status);

                msg = p.At("archive", "pages", id, "restore").Post();
                Assert.IsTrue(false);
            }
            catch (DreamResponseException ex)
            {
                Assert.IsTrue(ex.Response.Status == DreamStatus.NotFound);
            }
        }
Ejemplo n.º 12
0
        public void TestRestoreWhenAlreadyExist()
        {
            //Assumptions:
            //
            //Actions:
            // create new page
            // delete page
            // create new page with same name
            // restore old page
            //Expected result:
            // conflict

            Plug p = Utils.BuildPlugForAdmin();

            string       id   = null;
            string       path = null;
            DreamMessage msg  = PageUtils.CreateRandomPage(p, out id, out path);

            PageUtils.DeletePageByID(p, id, false);

            msg = PageUtils.CreateRandomPage(p, path);

            try
            {
                msg = p.At("archive", "pages", id, "restore").Post();
                Assert.IsTrue(false);
            }
            catch (DreamResponseException ex)
            {
                Assert.IsTrue(ex.Response.Status == DreamStatus.Conflict);
            }
        }
Ejemplo n.º 13
0
        public void TestRestoreWithFile()
        {
            //Assumptions:
            //
            //Actions:
            // create new page
            // upload random file to the page
            // delete page
            // restore page
            //Expected result:
            // page has file

            Plug p = Utils.BuildPlugForAdmin();

            string       id  = null;
            DreamMessage msg = PageUtils.CreateRandomPage(p, out id);

            string fileid = null;

            msg = FileUtils.UploadRandomFile(p, id, out fileid);

            PageUtils.DeletePageByID(p, id, false);

            msg = p.At("archive", "pages", id, "restore").Post();
            Assert.AreEqual(DreamStatus.Ok, msg.Status);

            msg = p.At("pages", id).Get();
            Assert.AreEqual(DreamStatus.Ok, msg.Status);
            Assert.IsTrue(msg.ToDocument()["files/file/@id"].AsText == fileid);
        }
Ejemplo n.º 14
0
        public void PutFileProperties()
        {
            Plug p = Utils.BuildPlugForAdmin();

            string       id   = null;
            string       path = null;
            DreamMessage msg  = PageUtils.CreateRandomPage(p, out id, out path);

            string propertyContent = Utils.GetSmallRandomText();
            string propertyName    = Utils.GenerateUniqueName();

            string fileid = null;

            msg = FileUtils.UploadRandomFile(p, id, out fileid);

            msg = p.At("files", fileid, "properties").WithHeader("Slug", XUri.Encode(propertyName)).PostAsync(DreamMessage.Ok(MimeType.TEXT_UTF8, propertyContent)).Wait();
            Assert.AreEqual(DreamStatus.Ok, msg.Status);
            Assert.AreEqual(msg.ToDocument()["/property/contents"].AsText, propertyContent, "Contents don't match!");

            msg = p.At("files", fileid, "properties", propertyName).GetAsync().Wait();
            Assert.AreEqual(DreamStatus.Ok, msg.Status, "Non 200 status on get:property content: " + msg.ToString());
            Assert.AreEqual(propertyContent, msg.AsText(), "Contents don't match!");

            PageUtils.DeletePageByID(p, id, true);
        }