Beispiel #1
0
        public async Task UT_WebDavClient_PropFind_AllPropDepthZero()
        {
            var mockHandler    = new MockHttpMessageHandler();
            var requestContent = "<?xml version=\"1.0\" encoding=\"utf-8\"?><D:propfind xmlns:D=\"DAV:\"><D:allprop /></D:propfind>";

            var requestHeaders = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>(WebDavConstants.Depth, WebDavDepthHeaderValue.Zero.ToString())
            };

            var responseContent = "<?xml version=\"1.0\" encoding=\"utf-8\"?><D:multistatus xmlns:D=\"DAV:\"><D:response><D:href>http://127.0.0.1/webdav</D:href><D:propstat><D:status>HTTP/1.1 200 OK</D:status><D:prop><D:getcontenttype/><D:getlastmodified>Sat, 08 Apr 2017 10:07:38 GMT</D:getlastmodified><D:lockdiscovery/><D:ishidden>0</D:ishidden><D:supportedlock><D:lockentry><D:lockscope><D:exclusive/></D:lockscope><D:locktype><D:write/></D:locktype></D:lockentry><D:lockentry><D:lockscope><D:shared/></D:lockscope><D:locktype><D:write/></D:locktype></D:lockentry></D:supportedlock><D:getetag/><D:displayname>/</D:displayname><D:getcontentlanguage/><D:getcontentlength>0</D:getcontentlength><D:iscollection>1</D:iscollection><D:creationdate>2017-04-06T09:32:20.983Z</D:creationdate><D:resourcetype><D:collection/></D:resourcetype></D:prop></D:propstat></D:response></D:multistatus>";

            mockHandler.When(WebDavMethod.PropFind, WebDavRootFolder).WithContent(requestContent).WithHeaders(requestHeaders).Respond(HttpStatusCode.OK, new StringContent(responseContent));

            using (var client = CreateWebDavClient(mockHandler))
            {
                PropFind pf       = PropFind.CreatePropFindAllProp();
                var      response = await client.PropFindAsync(WebDavRootFolder, WebDavDepthHeaderValue.Zero, pf);

                var multistatus = await WebDavResponseContentParser.ParseMultistatusResponseContentAsync(response.Content);

                Assert.IsTrue(response.IsSuccessStatusCode);
                Assert.IsNotNull(multistatus);
            }
        }
        public void UIT_WebDavClient_Copy()
        {
            using (var client = CreateWebDavClientWithDebugHttpMessageHandler())
            {
                var testCollectionSource      = UriHelper.CombineUrl(webDavRootFolder, TestCollection, true);
                var testCollectionDestination = UriHelper.CombineUrl(webDavRootFolder, TestCollection + "2", true);
                var testFile = UriHelper.CombineUrl(testCollectionSource, TestFile, true);

                // Create source collection.
                var response             = client.MkcolAsync(testCollectionSource).Result;
                var mkColResponseSuccess = response.IsSuccessStatusCode;

                // Put file.
                using (var fileStream = File.OpenRead(TestFile))
                {
                    var content = new StreamContent(fileStream);
                    response = client.PutAsync(testFile, content).Result;
                }

                var putResponseSuccess = response.IsSuccessStatusCode;

                // Copy.
                response = client.CopyAsync(testCollectionSource, testCollectionDestination).Result;
                var copyResponseSuccess = response.IsSuccessStatusCode;

                // PropFind.
                PropFind pf = PropFind.CreatePropFindAllProp();
                response = client.PropFindAsync(testCollectionDestination, WebDavDepthHeaderValue.Infinity, pf).Result;
                var propFindResponseSuccess = response.IsSuccessStatusCode;

                var multistatus = (Multistatus)WebDavResponseContentParser.ParseMultistatusResponseContentAsync(response.Content).Result;

                bool collectionfound = false;

                foreach (var item in multistatus.Response)
                {
                    if (item.Href.EndsWith(TestFile))
                    {
                        collectionfound = true;
                        break;
                    }
                }

                // Delete source and destination.
                response = client.DeleteAsync(testCollectionSource).Result;
                var deleteSourceResponseSuccess = response.IsSuccessStatusCode;

                response = client.DeleteAsync(testCollectionDestination).Result;
                var deleteDestinationResponseSuccess = response.IsSuccessStatusCode;

                Assert.IsTrue(mkColResponseSuccess);
                Assert.IsTrue(putResponseSuccess);
                Assert.IsTrue(copyResponseSuccess);
                Assert.IsTrue(propFindResponseSuccess);
                Assert.IsTrue(collectionfound);
                Assert.IsTrue(deleteSourceResponseSuccess);
                Assert.IsTrue(deleteDestinationResponseSuccess);
            }
        }
Beispiel #3
0
        public void UIT_WebDavClient_Move()
        {
            var client = CreateWebDavClientWithDebugHttpMessageHandler();
            var testCollectionSource      = UriHelper.CombineUrl(this.webDavRootFolder, TestCollection, true);
            var testCollectionDestination = UriHelper.CombineUrl(this.webDavRootFolder, TestCollection + "2", true);
            var testFile = UriHelper.CombineUrl(testCollectionSource, TestFile, true);

            // Create source collection.
            var response             = client.MkcolAsync(testCollectionSource).Result;
            var mkColResponseSuccess = response.IsSuccessStatusCode;

            // Put file.
            var content = new StreamContent(File.OpenRead(TestFile));

            response = client.PutAsync(testFile, content).Result;
            var putResponseSuccess = response.IsSuccessStatusCode;

            // Move.
            response = client.MoveAsync(testCollectionSource, testCollectionDestination).Result;
            var moveResponseSuccess = response.IsSuccessStatusCode;

            // PropFind.
            PropFind pf = PropFind.CreatePropFindAllProp();

            response = client.PropFindAsync(this.webDavRootFolder, WebDavDepthHeaderValue.Infinity, pf).Result;
            var propFindResponseSuccess = response.IsSuccessStatusCode;

            var multistatus = (Multistatus)WebDavResponseContentParser.ParseMultistatusResponseContentAsync(response.Content).Result;

            bool foundCollection1 = false;
            bool foundCollection2 = false;

            foreach (var item in multistatus.Response)
            {
                if (item.Href.EndsWith(TestCollection + "/"))
                {
                    foundCollection1 = true;
                }

                if (item.Href.EndsWith(TestCollection + "2/"))
                {
                    foundCollection2 = true;
                }
            }

            // Delete source and destination.
            // Delete file.
            response = client.DeleteAsync(testCollectionDestination).Result;
            var deleteResponseSuccess = response.IsSuccessStatusCode;

            Assert.IsTrue(mkColResponseSuccess);
            Assert.IsTrue(putResponseSuccess);
            Assert.IsTrue(moveResponseSuccess);
            Assert.IsTrue(propFindResponseSuccess);
            Assert.IsFalse(foundCollection1);
            Assert.IsTrue(foundCollection2);
            Assert.IsTrue(deleteResponseSuccess);
        }
Beispiel #4
0
        public void UT_WebDavHelper_GetUtf8EncodedXmlWebDavRequestStringFromPropWithXmlLangAttribute()
        {
            var serializer = new XmlSerializer(typeof(PropFind));
            var propFind   = PropFind.CreatePropFindAllProp();
            var str        = WebDavHelper.GetUtf8EncodedXmlWebDavRequestString(serializer, propFind);
            var expected   = "<?xml version=\"1.0\" encoding=\"utf-8\"?><D:propfind xmlns:D=\"DAV:\"><D:allprop /></D:propfind>";

            Assert.AreEqual(expected, str);
        }
Beispiel #5
0
        public void UIT_WebDavClient_PropFind_AllProp()
        {
            var      client   = CreateWebDavClientWithDebugHttpMessageHandler();
            PropFind pf       = PropFind.CreatePropFindAllProp();
            var      response = client.PropFindAsync(this.webDavRootFolder, WebDavDepthHeaderValue.Infinity, pf).Result;
            var      propFindResponseSuccess = response.IsSuccessStatusCode;
            var      multistatus             = WebDavResponseContentParser.ParseMultistatusResponseContentAsync(response.Content).Result;

            Assert.IsTrue(propFindResponseSuccess);
            Assert.IsNotNull(multistatus);
        }
        public async Task UIT_WebDavClient_PropFind_AllPropDepthZero()
        {
            using (var client = CreateWebDavClientWithDebugHttpMessageHandler())
            {
                PropFind pf       = PropFind.CreatePropFindAllProp();
                var      response = await client.PropFindAsync(webDavRootFolder, WebDavDepthHeaderValue.Zero, pf);

                var propFindResponseSuccess = response.IsSuccessStatusCode;
                var multistatus             = await WebDavResponseContentParser.ParseMultistatusResponseContentAsync(response.Content);

                Assert.IsTrue(propFindResponseSuccess);
                Assert.IsNotNull(multistatus);
            }
        }
        public async Task UIT_WebDavClient_Mkcol()
        {
            using (var client = CreateWebDavClientWithDebugHttpMessageHandler())
            {
                var testCollection = UriHelper.CombineUrl(webDavRootFolder, TestCollection, true);

                // Create collection.
                var response = await client.MkcolAsync(testCollection);

                var mkColResponseSuccess = response.IsSuccessStatusCode;

                // PropFind.
                PropFind pf = PropFind.CreatePropFindAllProp();
                response = await client.PropFindAsync(webDavRootFolder, WebDavDepthHeaderValue.Infinity, pf);

                var propFindResponseSuccess = response.IsSuccessStatusCode;

                var multistatus = await WebDavResponseContentParser.ParseMultistatusResponseContentAsync(response.Content);

                bool collectionFound = false;

                foreach (var item in multistatus.Response)
                {
                    if (item.Href.EndsWith(TestCollection + "/"))
                    {
                        collectionFound = true;
                        break;
                    }
                }

                // Delete collection.
                response = await client.DeleteAsync(testCollection);

                var deleteResponseSuccess = response.IsSuccessStatusCode;

                Assert.IsTrue(mkColResponseSuccess);
                Assert.IsTrue(propFindResponseSuccess);
                Assert.IsTrue(collectionFound);
                Assert.IsTrue(deleteResponseSuccess);
            }
        }
Beispiel #8
0
 /// <summary>
 /// Retrieves a list of files and directories of the directory at the <see cref="Uri"/> specified (using 'allprop').
 /// </summary>
 /// <param name="uri">The <see cref="Uri"/> of the directory which content should be listed. Has to be an absolute URI (including the base URI) or a relative URI (relative to base URI).</param>
 /// <returns>The <see cref="Task"/> representing the asynchronous operation.</returns>
 /// <remarks>This method uses a so called 'allprop'. A server should return all known properties to the server.
 /// If not all of the expected properties are return by the server, use an overload of this method specifying a <see cref="PropFind"/> explicitly.</remarks>
 public async Task <IList <WebDavSessionListItem> > ListAsync(Uri uri)
 {
     return(await ListAsync(uri, PropFind.CreatePropFindAllProp()));
 }
        public async Task UIT_WebDavClient_Move_Rename()
        {
            using (var client = CreateWebDavClientWithDebugHttpMessageHandler())
            {
                var testCollectionSource = UriHelper.CombineUrl(webDavRootFolder, TestCollection, true);
                var testFileToRename     = UriHelper.CombineUrl(testCollectionSource, TestFile, true);
                var testFileRenamed      = UriHelper.CombineUrl(testCollectionSource, "RenamedFile", true);

                // Create source collection.
                var response = await client.MkcolAsync(testCollectionSource);

                var mkColResponseSuccess = response.IsSuccessStatusCode;

                // Put file.
                using (var fileStream = File.OpenRead(TestFile))
                {
                    var content = new StreamContent(fileStream);
                    response = await client.PutAsync(testFileToRename, content);
                }

                var putResponseSuccess = response.IsSuccessStatusCode;

                // Move.
                response = await client.MoveAsync(testFileToRename, testFileRenamed);

                var moveResponseSuccess = response.IsSuccessStatusCode;

                // PropFind.
                PropFind pf = PropFind.CreatePropFindAllProp();
                response = await client.PropFindAsync(webDavRootFolder, WebDavDepthHeaderValue.Infinity, pf);

                var propFindResponseSuccess = response.IsSuccessStatusCode;

                var multistatus = await WebDavResponseContentParser.ParseMultistatusResponseContentAsync(response.Content);

                bool foundRenamedFile = false;
                bool foundFile        = false;

                foreach (var item in multistatus.Response)
                {
                    if (item.Href.EndsWith("RenamedFile"))
                    {
                        foundRenamedFile = true;
                    }

                    if (item.Href.EndsWith(TestFile))
                    {
                        foundFile = true;
                    }
                }

                // Delete source and destination.
                // Delete file.
                response = await client.DeleteAsync(testCollectionSource);

                var deleteResponseSuccess = response.IsSuccessStatusCode;

                Assert.IsTrue(mkColResponseSuccess);
                Assert.IsTrue(putResponseSuccess);
                Assert.IsTrue(moveResponseSuccess);
                Assert.IsTrue(propFindResponseSuccess);
                Assert.IsTrue(foundRenamedFile);
                Assert.IsFalse(foundFile);
                Assert.IsTrue(deleteResponseSuccess);
            }
        }