Example #1
0
        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 void UT_NoTagList_ReturnsFalse_InvalidNoTagListFormatBrackets_ShouldReturnFalse()
        {
            var parseResult = NoTagList.TryParse("<urn:uuid:my-lock-token>", out var noTagList);

            Assert.IsFalse(parseResult);
            Assert.IsNull(noTagList);
        }
        public void UT_NoTagList_TryParse_InvalidNoTagListFormatParentheses_ShouldReturnFalse()
        {
            var parseResult = NoTagList.TryParse("(urn:uuid:my-lock-token)", out var noTagList);

            Assert.IsFalse(parseResult);
            Assert.IsNull(noTagList);
        }
        public void UT_NoTagList_TryParse_InvalidNoTagListFormatAbsoluteURI_ShouldReturnFalse()
        {
            var parseResult = NoTagList.TryParse("urn:uuid:my-lock-token", out var noTagList);

            Assert.IsFalse(parseResult);
            Assert.IsNull(noTagList);
        }
        public void UT_NoTagList_TryParse_ValidNoTagListFormat()
        {
            var expectedString = "(<urn:uuid:my-lock-token>)";
            var parseResult    = NoTagList.TryParse(expectedString, out var noTagList);

            Assert.AreEqual(expectedString, noTagList.ToString());
            Assert.IsTrue(parseResult);
            Assert.IsNotNull(noTagList);
        }
Example #6
0
        public void UT_LockToken_LockTokenHeaderFormat_LockTokenHeaderWithBothBracketsWithString()
        {
            var lockTokenString = "(<urn:uuid:my-lock-token>)";

            var parseResult = NoTagList.TryParse(lockTokenString, out var parsedNoTagList);
            var lockToken   = new LockToken(parsedNoTagList.CodedUrl.AbsoluteUri);

            var absoluteUri           = lockToken.AbsoluteUri;
            var lockTokenHeaderFormat = lockToken.LockTokenHeaderFormat;
            var noTagList             = lockToken.IfHeaderNoTagListFormat;

            Assert.AreEqual("urn:uuid:my-lock-token", absoluteUri.ToString());
            Assert.AreEqual("<urn:uuid:my-lock-token>", lockTokenHeaderFormat.ToString());
            Assert.AreEqual("(<urn:uuid:my-lock-token>)", noTagList.ToString());
            Assert.IsTrue(parseResult);
        }