示例#1
0
        public async Task AddLockToRootRecursiveWithPrincipalOwnerTest()
        {
            var response = await Client.LockAsync(
                "/",
                WebDavTimeoutHeaderValue.CreateInfiniteWebDavTimeout(),
                WebDavDepthHeaderValue.Infinity,
                new LockInfo()
            {
                LockScope = LockScope.CreateExclusiveLockScope(),
                LockType  = LockType.CreateWriteLockType(),
                OwnerRaw  = new XElement("{DAV:}owner", "principal"),
            })
                           .ConfigureAwait(false);

            var prop = await WebDavResponseContentParser.ParsePropResponseContentAsync(response.EnsureSuccessStatusCode().Content).ConfigureAwait(false);

            Assert.Collection(
                prop.LockDiscovery.ActiveLock,
                activeLock =>
            {
                Assert.Equal("/", activeLock.LockRoot.Href);
                Assert.Equal(WebDavDepthHeaderValue.Infinity.ToString(), activeLock.Depth, StringComparer.OrdinalIgnoreCase);
                Assert.IsType <Exclusive>(activeLock.LockScope.Item);
                Assert.Equal("<owner xmlns=\"DAV:\">principal</owner>", activeLock.OwnerRaw.ToString(SaveOptions.DisableFormatting));
                Assert.Equal(WebDavTimeoutHeaderValue.CreateInfiniteWebDavTimeout().ToString(), activeLock.Timeout, StringComparer.OrdinalIgnoreCase);
                Assert.NotNull(activeLock.LockToken?.Href);
                Assert.True(Uri.IsWellFormedUriString(activeLock.LockToken.Href, UriKind.RelativeOrAbsolute));
            });
        }
        public async Task UT_WebDavSession_LockSingleFile()
        {
            var testFileToLock      = UriHelper.CombineUrl(WebDavRootFolder, TestFile, true);
            var lockRequestContent  = "<?xml version=\"1.0\" encoding=\"utf-8\"?><D:lockinfo xmlns:D=\"DAV:\"><D:lockscope><D:exclusive /></D:lockscope><D:locktype><D:write /></D:locktype></D:lockinfo>";
            var lockResponseContent = "<?xml version=\"1.0\" encoding=\"utf-8\"?><D:prop xmlns:D=\"DAV:\"><D:lockdiscovery><D:activelock><D:locktype><D:write/></D:locktype><D:lockscope><D:exclusive/></D:lockscope><D:depth>infinity</D:depth><D:timeout>Infinite</D:timeout><D:locktoken><D:href>opaquelocktoken:d32688a4-478f-46eb-bcc4-cfe6129a207e.96bb01d2b440d8db</D:href></D:locktoken><D:lockroot><D:href>http://127.0.0.1/webdav/TextFile1.txt</D:href></D:lockroot></D:activelock></D:lockdiscovery></D:prop>";
            var infiniteTimeout     = WebDavTimeoutHeaderValue.CreateInfiniteWebDavTimeout();
            var depth = WebDavDepthHeaderValue.Infinity;

            var mockHandler = new MockHttpMessageHandler();

            var requestHeaders = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>(WebDavConstants.Depth, depth.ToString()),
                new KeyValuePair <string, string>(WebDavRequestHeader.Timeout, infiniteTimeout.ToString())
            };

            mockHandler.When(WebDavMethod.Lock, testFileToLock).WithHeaders(requestHeaders).WithContent(lockRequestContent).Respond(HttpStatusCode.OK, new StringContent(lockResponseContent));

            using (var session = CreateWebDavSession(mockHandler))
            {
                var success = await session.LockAsync(TestFile);

                Assert.IsTrue(success);
            }
        }
示例#3
0
        public async Task AddLockCreatesDocumentTest()
        {
            var response = await Client.LockAsync(
                "/test1.txt",
                WebDavTimeoutHeaderValue.CreateInfiniteWebDavTimeout(),
                WebDavDepthHeaderValue.Zero,
                new LockInfo()
            {
                LockScope = LockScope.CreateExclusiveLockScope(),
                LockType  = LockType.CreateWriteLockType(),
            }).ConfigureAwait(false);

            var prop = await WebDavResponseContentParser.ParsePropResponseContentAsync(response.EnsureSuccessStatusCode().Content).ConfigureAwait(false);

            Assert.NotNull(prop.LockDiscovery);
            Assert.Collection(
                prop.LockDiscovery.ActiveLock,
                activeLock =>
            {
                Assert.Equal("/test1.txt", activeLock.LockRoot.Href);
                Assert.Equal(WebDavDepthHeaderValue.Zero.ToString(), activeLock.Depth, StringComparer.OrdinalIgnoreCase);
                Assert.IsType <Exclusive>(activeLock.LockScope.Item);
                Assert.Null(activeLock.OwnerRaw);
                Assert.Equal(WebDavTimeoutHeaderValue.CreateInfiniteWebDavTimeout().ToString(), activeLock.Timeout, StringComparer.OrdinalIgnoreCase);
                Assert.NotNull(activeLock.LockToken?.Href);
                Assert.True(Uri.IsWellFormedUriString(activeLock.LockToken.Href, UriKind.RelativeOrAbsolute));
            });

            var ct   = CancellationToken.None;
            var root = await FileSystem.Root;
            var doc  = await root.GetChildAsync("test1.txt", ct).ConfigureAwait(false);

            Assert.NotNull(doc);
        }
示例#4
0
        public async Task AddLockToRootRecursiveWithTimeoutTest()
        {
            var response = await Client.LockAsync(
                "/",
                WebDavTimeoutHeaderValue.CreateWebDavTimeout(TimeSpan.FromSeconds(1)),
                WebDavDepthHeaderValue.Infinity,
                new LockInfo()
            {
                LockScope = LockScope.CreateExclusiveLockScope(),
                LockType  = LockType.CreateWriteLockType(),
            }).ConfigureAwait(false);

            var prop = await WebDavResponseContentParser.ParsePropResponseContentAsync(response.EnsureSuccessStatusCode().Content).ConfigureAwait(false);

            Assert.Collection(
                prop.LockDiscovery.ActiveLock,
                activeLock =>
            {
                Assert.Equal("/", activeLock.LockRoot.Href);
                Assert.Equal(WebDavDepthHeaderValue.Infinity.ToString(), activeLock.Depth, StringComparer.OrdinalIgnoreCase);
                Assert.IsType <Exclusive>(activeLock.LockScope.Item);
                Assert.Null(activeLock.OwnerRaw);
                Assert.Equal(WebDavTimeoutHeaderValue.CreateWebDavTimeout(TimeSpan.FromSeconds(1)).ToString(), activeLock.Timeout, StringComparer.OrdinalIgnoreCase);
                Assert.NotNull(activeLock.LockToken?.Href);
                Assert.True(Uri.IsWellFormedUriString(activeLock.LockToken.Href, UriKind.RelativeOrAbsolute));
            });
        }
示例#5
0
        public async Task AddLockToRootAndTryRefreshTest()
        {
            var lockResponse = await Client.LockAsync(
                "/",
                WebDavTimeoutHeaderValue.CreateInfiniteWebDavTimeout(),
                WebDavDepthHeaderValue.Infinity,
                new LockInfo()
            {
                LockScope = LockScope.CreateExclusiveLockScope(),
                LockType  = LockType.CreateWriteLockType(),
            })
                               .ConfigureAwait(false);

            lockResponse.EnsureSuccessStatusCode();
            var prop = await WebDavResponseContentParser.ParsePropResponseContentAsync(lockResponse.Content).ConfigureAwait(false);

            var lockToken = prop.LockDiscovery.ActiveLock.Single().LockToken;

            Assert.True(AbsoluteUri.TryParse(lockToken.Href, out var lockTokenUri));
            var refreshResponse = await Client.RefreshLockAsync(
                "/",
                WebDavTimeoutHeaderValue.CreateInfiniteWebDavTimeout(),
                new LockToken(lockTokenUri)).ConfigureAwait(false);

            refreshResponse.EnsureSuccessStatusCode();
            var refreshProp = await WebDavResponseContentParser.ParsePropResponseContentAsync(refreshResponse.Content).ConfigureAwait(false);

            Assert.NotNull(refreshProp.LockDiscovery);
        }
示例#6
0
        public void UIT_WebDavClient_LockAndPutWithToken()
        {
            var client = CreateWebDavClientWithDebugHttpMessageHandler();

            // Lock.
            var lockInfo = new LockInfo();

            lockInfo.LockScope = LockScope.CreateExclusiveLockScope();
            lockInfo.LockType  = LockType.CreateWriteLockType();
            lockInfo.OwnerHref = "*****@*****.**";
            var       response            = client.LockAsync(this.webDavRootFolder, WebDavTimeoutHeaderValue.CreateWebDavTimeout(TimeSpan.FromSeconds(15)), WebDavDepthHeaderValue.Infinity, lockInfo).Result;
            var       lockResponseSuccess = response.IsSuccessStatusCode;
            LockToken lockToken           = WebDavHelper.GetLockTokenFromWebDavResponseMessage(response);

            // Put file.
            var content    = new StreamContent(File.OpenRead(TestFile));
            var requestUrl = UriHelper.CombineUrl(this.webDavRootFolder, TestFile, true);

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

            // Delete file.
            response = client.DeleteAsync(requestUrl, lockToken).Result;
            var deleteResponseSuccess = response.IsSuccessStatusCode;

            // Unlock.
            response = client.UnlockAsync(this.webDavRootFolder, lockToken).Result;
            var unlockResponseSuccess = response.IsSuccessStatusCode;

            Assert.IsTrue(lockResponseSuccess);
            Assert.IsNotNull(lockToken);
            Assert.IsTrue(putResponseSuccess);
            Assert.IsTrue(deleteResponseSuccess);
            Assert.IsTrue(unlockResponseSuccess);
        }
示例#7
0
        public void UIT_WebDavClient_LockRefreshLockUnlock()
        {
            var client = CreateWebDavClientWithDebugHttpMessageHandler();

            // Lock.
            var lockInfo = new LockInfo();

            lockInfo.LockScope = LockScope.CreateExclusiveLockScope();
            lockInfo.LockType  = LockType.CreateWriteLockType();
            lockInfo.OwnerHref = "*****@*****.**";
            var       response            = client.LockAsync(this.webDavRootFolder, WebDavTimeoutHeaderValue.CreateWebDavTimeout(TimeSpan.FromSeconds(15)), WebDavDepthHeaderValue.Infinity, lockInfo).Result;
            var       lockResponseSuccess = response.IsSuccessStatusCode;
            LockToken lockToken           = WebDavHelper.GetLockTokenFromWebDavResponseMessage(response);

            // Refresh lock.
            response = client.RefreshLockAsync(this.webDavRootFolder, WebDavTimeoutHeaderValue.CreateWebDavTimeout(TimeSpan.FromSeconds(10)), lockToken).Result;
            var refreshLockResponseSuccess = response.IsSuccessStatusCode;

            // Unlock.
            response = client.UnlockAsync(this.webDavRootFolder, lockToken).Result;
            var unlockResponseSuccess = response.IsSuccessStatusCode;

            Assert.IsTrue(lockResponseSuccess);
            Assert.IsNotNull(lockToken);
            Assert.IsTrue(refreshLockResponseSuccess);
            Assert.IsTrue(unlockResponseSuccess);
        }
        public async Task UT_WebDavClient_LockRefreshLock()
        {
            var lockResponseContent = "<?xml version=\"1.0\" encoding=\"utf-8\"?><D:prop xmlns:D=\"DAV:\"><D:lockdiscovery><D:activelock><D:locktype><D:write/></D:locktype><D:lockscope><D:exclusive/></D:lockscope><D:depth>infinity</D:depth><D:owner><D:href>[email protected]</D:href></D:owner><D:timeout>Second-10</D:timeout><D:locktoken><D:href>opaquelocktoken:0af5a3d3-2ccd-42fb-b8c7-9c59c9b90944.22bc01d2b2e0e947</D:href></D:locktoken><D:lockroot><D:href>http://127.0.0.1/webdav/</D:href></D:lockroot></D:activelock></D:lockdiscovery></D:prop>";
            var oneMinuteTimeout    = WebDavTimeoutHeaderValue.CreateWebDavTimeout(TimeSpan.FromMinutes(1));
            var lockTokenString     = "(<opaquelocktoken:0af5a3d3-2ccd-42fb-b8c7-9c59c9b90944.22bc01d2b2e0e947>)";
            var parseResult         = NoTagList.TryParse(lockTokenString, out NoTagList noTagList);

            Assert.IsTrue(parseResult);
            var lockToken = new LockToken(noTagList.CodedUrl.AbsoluteUri);

            var mockHandler = new MockHttpMessageHandler();

            var requestHeaders = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>(WebDavRequestHeader.Timeout, oneMinuteTimeout.ToString()),
                new KeyValuePair <string, string>(WebDavRequestHeader.If, lockTokenString)
            };

            mockHandler.When(WebDavMethod.Lock, WebDavRootFolder).WithHeaders(requestHeaders).Respond(HttpStatusCode.OK, new StringContent(lockResponseContent));

            using (var client = CreateWebDavClient(mockHandler))
            {
                var response = await client.RefreshLockAsync(WebDavRootFolder, oneMinuteTimeout, lockToken);

                Assert.IsTrue(response.IsSuccessStatusCode);
            }
        }
        public async Task UT_WebDavClient_LockRootFolder()
        {
            var lockRequestContent  = "<?xml version=\"1.0\" encoding=\"utf-8\"?><D:lockinfo xmlns:D=\"DAV:\"><D:lockscope><D:exclusive /></D:lockscope><D:locktype><D:write /></D:locktype><D:owner><D:href>[email protected]</D:href></D:owner></D:lockinfo>";
            var lockResponseContent = "<?xml version=\"1.0\" encoding=\"utf-8\"?><D:prop xmlns:D=\"DAV:\"><D:lockdiscovery><D:activelock><D:locktype><D:write/></D:locktype><D:lockscope><D:exclusive/></D:lockscope><D:depth>infinity</D:depth><D:owner><D:href>[email protected]</D:href></D:owner><D:timeout>Second-60</D:timeout><D:locktoken><D:href>opaquelocktoken:a2324814-cbe3-4fb4-9c55-cba99a62ef5d.008f01d2b2dafba0</D:href></D:locktoken><D:lockroot><D:href>http://127.0.0.1/webdav/</D:href></D:lockroot></D:activelock></D:lockdiscovery></D:prop>";
            var oneMinuteTimeout    = WebDavTimeoutHeaderValue.CreateWebDavTimeout(TimeSpan.FromMinutes(1));
            var depth = WebDavDepthHeaderValue.Infinity;

            var lockInfo = new LockInfo()
            {
                LockScope = LockScope.CreateExclusiveLockScope(),
                LockType  = LockType.CreateWriteLockType(),
                OwnerHref = "*****@*****.**"
            };

            var mockHandler = new MockHttpMessageHandler();

            var requestHeaders = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>(WebDavConstants.Depth, depth.ToString()),
                new KeyValuePair <string, string>(WebDavRequestHeader.Timeout, oneMinuteTimeout.ToString())
            };

            mockHandler.When(WebDavMethod.Lock, WebDavRootFolder).WithHeaders(requestHeaders).WithContent(lockRequestContent).Respond(HttpStatusCode.OK, new StringContent(lockResponseContent));

            using (var client = CreateWebDavClient(mockHandler))
            {
                var response = await client.LockAsync(WebDavRootFolder, oneMinuteTimeout, depth, lockInfo);

                Assert.IsTrue(response.IsSuccessStatusCode);
            }
        }
        public async Task AddLockToRootAndQueryLockDiscoveryTest()
        {
            var lockResponse = await Client.LockAsync(
                "/",
                WebDavTimeoutHeaderValue.CreateInfiniteWebDavTimeout(),
                WebDavDepthHeaderValue.Infinity,
                new LockInfo()
            {
                LockScope = LockScope.CreateExclusiveLockScope(),
                LockType  = LockType.CreateWriteLockType(),
            })
            ;

            lockResponse.EnsureSuccessStatusCode();
            var propFindResponse = await Client.PropFindAsync(
                "/",
                WebDavDepthHeaderValue.Zero,
                new PropFind()
            {
                Item = new Prop()
                {
                    LockDiscovery = new LockDiscovery(),
                },
            });

            Assert.Equal(WebDavStatusCode.MultiStatus, propFindResponse.StatusCode);
            var multiStatus = await WebDavResponseContentParser.ParseMultistatusResponseContentAsync(propFindResponse.Content);

            Assert.Collection(
                multiStatus.Response,
                response =>
            {
                Assert.Equal("/", response.Href);
                Assert.Collection(
                    response.ItemsElementName,
                    n => Assert.Equal(ItemsChoiceType.propstat, n));
                Assert.Collection(
                    response.Items,
                    item =>
                {
                    var propStat = Assert.IsType <Propstat>(item);
                    var status   = WebDav.Server.Model.Status.Parse(propStat.Status);
                    Assert.Equal(200, status.StatusCode);
                    Assert.NotNull(propStat.Prop?.LockDiscovery?.ActiveLock);
                    Assert.Collection(
                        propStat.Prop.LockDiscovery.ActiveLock,
                        activeLock =>
                    {
                        Assert.Equal("/", activeLock.LockRoot.Href);
                        Assert.Equal(WebDavDepthHeaderValue.Infinity.ToString(), activeLock.Depth, StringComparer.OrdinalIgnoreCase);
                        Assert.IsType <Exclusive>(activeLock.LockScope.Item);
                        Assert.Null(activeLock.OwnerRaw);
                        Assert.Equal(WebDavTimeoutHeaderValue.CreateInfiniteWebDavTimeout().ToString(), activeLock.Timeout, StringComparer.OrdinalIgnoreCase);
                        Assert.NotNull(activeLock.LockToken?.Href);
                        Assert.True(Uri.IsWellFormedUriString(activeLock.LockToken.Href, UriKind.RelativeOrAbsolute));
                    });
                });
            });
        }
        public async Task UIT_WebDavClient_LockAndPutWithToken()
        {
            // This won't work on ownCloud/Nextcloud because they do not support WebDAV locking.
            // These unit integration test are skipped for ownCloud/Nextcloud.
            if (webDavRootFolder.Contains("nextcloud") || webDavRootFolder.Contains("owncloud"))
            {
                return;
            }

            using (var client = CreateWebDavClientWithDebugHttpMessageHandler())
            {
                // Lock.
                var lockInfo = new LockInfo()
                {
                    LockScope = LockScope.CreateExclusiveLockScope(),
                    LockType  = LockType.CreateWriteLockType(),
                    OwnerHref = "*****@*****.**"
                };

                var response = await client.LockAsync(webDavRootFolder, WebDavTimeoutHeaderValue.CreateWebDavTimeout(TimeSpan.FromSeconds(15)), WebDavDepthHeaderValue.Infinity, lockInfo);

                var       lockResponseSuccess = response.IsSuccessStatusCode;
                LockToken lockToken           = await WebDavHelper.GetLockTokenFromWebDavResponseMessage(response);

                var requestUrl = UriHelper.CombineUrl(webDavRootFolder, TestFile, true);

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

                var putResponseSuccess = response.IsSuccessStatusCode;

                // Delete file.
                response = await client.DeleteAsync(requestUrl, lockToken);

                var deleteResponseSuccess = response.IsSuccessStatusCode;

                // Unlock.
                response = await client.UnlockAsync(webDavRootFolder, lockToken);

                var unlockResponseSuccess = response.IsSuccessStatusCode;

                Assert.IsTrue(lockResponseSuccess);
                Assert.IsNotNull(lockToken);
                Assert.IsTrue(putResponseSuccess);
                Assert.IsTrue(deleteResponseSuccess);
                Assert.IsTrue(unlockResponseSuccess);
            }
        }
        public void UT_WebDavClient_RefreshLockAsync_WithoutLockToken()
        {
            var client   = CreateWebDavClient();
            var lockInfo = new LockInfo();

            try
            {
                client.RefreshLockAsync(FakeUrl, WebDavTimeoutHeaderValue.CreateInfiniteWebDavTimeout(), null).Wait();
            }
            catch (AggregateException ae)
            {
                Assert.AreEqual(ae.InnerException.GetType(), typeof(WebDavException));
            }
        }
        public void UT_WebDavClient_LockAsync_WithDepthOne()
        {
            var client   = CreateWebDavClient();
            var lockInfo = new LockInfo();

            try
            {
                client.LockAsync(FakeUrl, WebDavTimeoutHeaderValue.CreateInfiniteWebDavTimeout(), WebDavDepthHeaderValue.One, lockInfo).Wait();
            }
            catch (AggregateException ae)
            {
                Assert.AreEqual(ae.InnerException.GetType(), typeof(WebDavException));
            }
        }
        public async Task UIT_WebDavClient_LockRefreshLockUnlock()
        {
            // This won't work on ownCloud/Nextcloud because they do not support WebDAV locking.
            // These unit integration test are skipped for ownCloud/Nextcloud.
            if (webDavRootFolder.Contains("nextcloud") || webDavRootFolder.Contains("owncloud"))
            {
                return;
            }

            using (var client = CreateWebDavClientWithDebugHttpMessageHandler())
            {
                var userEmail = "*****@*****.**";

                // Lock.
                var lockInfo = new LockInfo()
                {
                    LockScope = LockScope.CreateExclusiveLockScope(),
                    LockType  = LockType.CreateWriteLockType(),
                    OwnerHref = userEmail
                };

                var response = await client.LockAsync(webDavRootFolder, WebDavTimeoutHeaderValue.CreateWebDavTimeout(TimeSpan.FromMinutes(1)), WebDavDepthHeaderValue.Infinity, lockInfo);

                var       lockResponseSuccess = response.IsSuccessStatusCode;
                LockToken lockToken           = await WebDavHelper.GetLockTokenFromWebDavResponseMessage(response);

                ActiveLock activeLock = await WebDavHelper.GetActiveLockFromWebDavResponseMessage(response);

                // Refresh lock.
                response = await client.RefreshLockAsync(webDavRootFolder, WebDavTimeoutHeaderValue.CreateWebDavTimeout(TimeSpan.FromSeconds(10)), lockToken);

                var refreshLockResponseSuccess = response.IsSuccessStatusCode;

                // Unlock.
                response = await client.UnlockAsync(webDavRootFolder, lockToken);

                var unlockResponseSuccess = response.IsSuccessStatusCode;

                Assert.IsTrue(lockResponseSuccess);
                Assert.IsNotNull(lockToken);
                Assert.AreEqual(userEmail, activeLock.OwnerHref);
                Assert.IsTrue(refreshLockResponseSuccess);
                Assert.IsTrue(unlockResponseSuccess);
            }
        }
示例#15
0
        public void UT_WebDavClient_LockWithDepthOneShouldThrowException_ShouldThrowWebDavException()
        {
            var testFileToLock   = UriHelper.CombineUrl(WebDavRootFolder, TestFile, true);
            var oneMinuteTimeout = WebDavTimeoutHeaderValue.CreateWebDavTimeout(TimeSpan.FromMinutes(1));
            var depth            = WebDavDepthHeaderValue.One;

            var lockInfo = new LockInfo()
            {
                LockScope = LockScope.CreateExclusiveLockScope(),
                LockType  = LockType.CreateWriteLockType(),
                OwnerHref = "*****@*****.**"
            };

            using (var client = CreateWebDavClient(new MockHttpMessageHandler()))
            {
                Assert.ThrowsExceptionAsync <WebDavException>(() => client.LockAsync(testFileToLock, oneMinuteTimeout, depth, lockInfo));
            }
        }
        public async Task AddLockToRootAndTryRefreshWrongLockTest()
        {
            var lockResponse = await Client.LockAsync(
                "/",
                WebDavTimeoutHeaderValue.CreateInfiniteWebDavTimeout(),
                WebDavDepthHeaderValue.Infinity,
                new LockInfo()
            {
                LockScope = LockScope.CreateExclusiveLockScope(),
                LockType  = LockType.CreateWriteLockType(),
            })
            ;

            lockResponse.EnsureSuccessStatusCode();
            Assert.True(AbsoluteUri.TryParse("urn:asasdasd", out var lockTokenUri));
            var refreshResult = await Client.RefreshLockAsync(
                "/",
                WebDavTimeoutHeaderValue.CreateInfiniteWebDavTimeout(),
                new LockToken(lockTokenUri));

            Assert.Equal(WebDavStatusCode.PreconditionFailed, refreshResult.StatusCode);
        }
示例#17
0
        public async Task GetAccessToLockedDocumentTest()
        {
            var response = await Client.LockAsync(
                "/test1.txt",
                WebDavTimeoutHeaderValue.CreateInfiniteWebDavTimeout(),
                WebDavDepthHeaderValue.Zero,
                new LockInfo()
            {
                LockScope = LockScope.CreateExclusiveLockScope(),
                LockType  = LockType.CreateWriteLockType(),
            }).ConfigureAwait(false);

            response.EnsureSuccessStatusCode();

            var lockToken = response.Headers.GetValues(WebDavRequestHeader.LockToken).Single();
            var ct        = CancellationToken.None;

            Client.DefaultRequestHeaders.Add("If", $"({lockToken})");
            var getResponse = await Client.GetAsync(
                "/test1.txt",
                ct).ConfigureAwait(false);

            getResponse.EnsureSuccessStatusCode();
        }
示例#18
0
 public void UT_WebDavClient_RefreshLockAsync_WithoutLockToken()
 {
     using (var client = CreateWebDavClient(new MockHttpMessageHandler()))
     {
         var lockInfo = new LockInfo();
         Assert.ThrowsExceptionAsync <WebDavException>(() => client.RefreshLockAsync(WebDavRootFolder, WebDavTimeoutHeaderValue.CreateInfiniteWebDavTimeout(), null));
     }
 }
示例#19
0
 public void UT_WebDavClient_LockAsync_WithDepthOne()
 {
     using (var client = CreateWebDavClient(new MockHttpMessageHandler()))
     {
         var lockInfo = new LockInfo();
         Assert.ThrowsExceptionAsync <WebDavException>(() => client.LockAsync(WebDavRootFolder, WebDavTimeoutHeaderValue.CreateInfiniteWebDavTimeout(), WebDavDepthHeaderValue.One, lockInfo));
     }
 }
        public void UT_WebDavTimeoutHeaderValue_ToString_Infinite()
        {
            var wdthv = WebDavTimeoutHeaderValue.CreateInfiniteWebDavTimeout();

            Assert.AreEqual(wdthv.ToString(), "Infinite");
        }
        public void UT_WebDavTimeoutHeaderValue_ToString_InfiniteWithAlternativeTimeout()
        {
            var wdthv = WebDavTimeoutHeaderValue.CreateInfiniteWebDavTimeoutWithAlternative(TimeSpan.FromSeconds(500));

            Assert.AreEqual(wdthv.ToString(), "Infinite, Second-500");
        }
        public void UT_WebDavTimeoutHeaderValue_ToString_Timeout()
        {
            var wdthv = WebDavTimeoutHeaderValue.CreateWebDavTimeout(TimeSpan.FromSeconds(500));

            Assert.AreEqual(wdthv.ToString(), "Second-500");
        }