Exemplo n.º 1
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);
        }
Exemplo n.º 2
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 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);
            }
        }