public async Task AddLockToRootRecursiveWithTimeoutTest() { var response = await Client.LockAsync( "/", WebDavTimeoutHeaderValue.CreateWebDavTimeout(TimeSpan.FromSeconds(1)), WebDavDepthHeaderValue.Infinity, new LockInfo() { LockScope = LockScope.CreateExclusiveLockScope(), LockType = LockType.CreateWriteLockType(), }); var prop = await WebDavResponseContentParser.ParsePropResponseContentAsync(response.EnsureSuccessStatusCode().Content); 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)); }); }
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 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); }
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 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 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); } }
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 void UT_WebDavTimeoutHeaderValue_ToString_Timeout() { var wdthv = WebDavTimeoutHeaderValue.CreateWebDavTimeout(TimeSpan.FromSeconds(500)); Assert.AreEqual(wdthv.ToString(), "Second-500"); }