Skip to content
This repository has been archived by the owner on Feb 14, 2022. It is now read-only.

Commit

Permalink
Unit tests; documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
DecaTec committed Aug 17, 2017
1 parent 75d20bd commit 24ec0e4
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 44 deletions.
6 changes: 3 additions & 3 deletions DecaTec.WebDav/DecaTec.WebDav.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard1.1</TargetFramework>
<PackageId>PortableWebDavLibrary</PackageId>
<Version>1.1.1.0</Version>
<Version>1.1.2.0</Version>
<Authors>DecaTec</Authors>
<Company>DecaTec</Company>
<Product>PortableWebDavLibrary</Product>
Expand All @@ -16,8 +16,8 @@
<PackageTags>WebDAV, portable, NETStandard, NETCore, UWP, dotnet, portable-webdav-library, Xamarin, Mono, multiplatform</PackageTags>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageReleaseNotes>Full documentation with changelog is available at https://decatec.de/ext/PortableWebDAVLibrary/Doc</PackageReleaseNotes>
<AssemblyVersion>1.1.1.0</AssemblyVersion>
<FileVersion>1.1.1.0</FileVersion>
<AssemblyVersion>1.1.2.0</AssemblyVersion>
<FileVersion>1.1.2.0</FileVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down
68 changes: 35 additions & 33 deletions DecaTec.WebDav/Tools/WebDavHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,6 @@ namespace DecaTec.WebDav.Tools
/// </summary>
public static class WebDavHelper
{
/// <summary>
/// Gets the <see cref="ActiveLock"/> from a <see cref="WebDavResponseMessage"/>.
/// </summary>
/// <param name="responseMessage">The <see cref="WebDavResponseMessage"/> whose <see cref="ActiveLock"/> should be retrieved.</param>
/// <returns>The <see cref="ActiveLock"/> of the <see cref="WebDavResponseMessage"/> or null if the <see cref="WebDavResponseMessage"/> does not contain a lock token.</returns>
/// <exception cref="ArgumentNullException">Thrown if the <paramref name="responseMessage"/> is null.</exception>
public static ActiveLock GetActiveLockFromWebDavResponseMessage(WebDavResponseMessage responseMessage)
{
if (responseMessage == null)
throw new ArgumentNullException(nameof(responseMessage));

var prop = WebDavResponseContentParser.ParsePropResponseContentAsync(responseMessage.Content).Result;
var activeLock = prop.LockDiscovery?.ActiveLock.FirstOrDefault();

if (activeLock == null)
return null;

// If lock token was not be found in the response content, it should be submitted by response header.
if (activeLock.LockToken == null)
// Try to get lock token from response header.
if (responseMessage.Headers.TryGetValues(WebDavRequestHeader.LockToken, out IEnumerable<string> lockTokenHeaderValues))
{
// We assume only one Lock-Token header is sent, based on the spec: https://tools.ietf.org/html/rfc4918#section-9.10.1
var lockTokenHeaderValue = lockTokenHeaderValues.FirstOrDefault();

// Make sure the lockTokenHeaderValue is valid according to spec (https://tools.ietf.org/html/rfc4918#section-10.5).
if (lockTokenHeaderValue != null && CodedUrl.TryParse(lockTokenHeaderValue, out var _))
activeLock.LockToken = new WebDavLockToken { Href = lockTokenHeaderValue };
}

return activeLock;
}

/// <summary>
/// Gets a UTF-8 encoded string by serializing the object specified.
/// </summary>
Expand Down Expand Up @@ -135,6 +102,41 @@ public static LockToken GetLockTokenFromWebDavResponseMessage(WebDavResponseMess
return null;
}

/// <summary>
/// Gets the <see cref="ActiveLock"/> from a <see cref="WebDavResponseMessage"/>.
/// </summary>
/// <param name="responseMessage">The <see cref="WebDavResponseMessage"/> whose <see cref="ActiveLock"/> should be retrieved.</param>
/// <returns>The <see cref="ActiveLock"/> of the <see cref="WebDavResponseMessage"/> or null if the <see cref="WebDavResponseMessage"/> does not contain a lock token.</returns>
/// <exception cref="ArgumentNullException">Thrown if the <paramref name="responseMessage"/> is null.</exception>
public static ActiveLock GetActiveLockFromWebDavResponseMessage(WebDavResponseMessage responseMessage)
{
if (responseMessage == null)
throw new ArgumentNullException(nameof(responseMessage));

var prop = WebDavResponseContentParser.ParsePropResponseContentAsync(responseMessage.Content).Result;
var activeLock = prop.LockDiscovery?.ActiveLock.FirstOrDefault();

if (activeLock == null)
return null;

// If lock token was not be found in the response content, it should be submitted by response header.
if (activeLock.LockToken == null)
{
// Try to get lock token from response header.
if (responseMessage.Headers.TryGetValues(WebDavRequestHeader.LockToken, out IEnumerable<string> lockTokenHeaderValues))
{
// We assume only one Lock-Token header is sent, based on the spec: https://tools.ietf.org/html/rfc4918#section-9.10.1
var lockTokenHeaderValue = lockTokenHeaderValues.FirstOrDefault();

// Make sure the lockTokenHeaderValue is valid according to spec (https://tools.ietf.org/html/rfc4918#section-10.5).
if (lockTokenHeaderValue != null && CodedUrl.TryParse(lockTokenHeaderValue, out var _))
activeLock.LockToken = new WebDavLockToken { Href = lockTokenHeaderValue };
}
}

return activeLock;
}

/// <summary>
/// Extracts the property names (known and unknown) from a <see cref="HttpContent"/>.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@
</para>
</listItem>

<listItem>
<para>
<link xlink:href="e528ad2f-0c4b-4aff-a9a0-14d1c61df5e7" />
</para>
</listItem>

</list>

</content>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="e528ad2f-0c4b-4aff-a9a0-14d1c61df5e7" revisionNumber="1">
<developerConceptualDocument
xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5"
xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction></introduction>

<section>
<title>Changes in release v1.1.2.0</title>
<content>

<list class="bullet">

<listItem>
<para>
WebDavHelper: Added method to receive the ActiveLock from a WebDavResponseMessage.
</para>
</listItem>

</list>

</content>
</section>

<relatedTopics>
<link xlink:href="55c4b378-829f-44e2-af56-20a587c2d24b" />
</relatedTopics>
</developerConceptualDocument>
</topic>
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,15 @@
<HelpKeyword index="K" term="version, 1.1.0.0" />
</HelpKeywords>
</Topic>
<Topic id="a81c2bc3-db0e-42dd-a55c-7f34d5e597f2" visible="True" isSelected="true" title="Version 1.1.1.0" linkText="Version 1.1.1.0">
<Topic id="a81c2bc3-db0e-42dd-a55c-7f34d5e597f2" visible="True" title="Version 1.1.1.0" linkText="Version 1.1.1.0">
<HelpKeywords>
<HelpKeyword index="K" term="version, 1.1.1.0" />
</HelpKeywords>
</Topic>
<Topic id="e528ad2f-0c4b-4aff-a9a0-14d1c61df5e7" visible="True" isSelected="true" title="Version 1.1.2.0" linkText="Version 1.1.2.0">
<HelpKeywords>
<HelpKeyword index="K" term="version, 1.1.2.0" />
</HelpKeywords>
</Topic>
</Topic>
</Topics>
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
<None Include="Content\VersionHistory\v1.0.1.0.aml" />
<None Include="Content\VersionHistory\v1.1.0.0.aml" />
<None Include="Content\VersionHistory\v1.1.1.0.aml" />
<None Include="Content\VersionHistory\v1.1.2.0.aml" />
<None Include="Content\VersionHistory\VersionHistory.aml" />
<None Include="Content\Welcome.aml" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static void ClassSetup(TestContext ctx)
{
throw new FileNotFoundException("The configuration file cannot be found. Make sure that there is a file 'TestConfiguration.txt' in the test's output folder containing data about the WebDAV server to test against.", ConfigurationFile, ex);
}
}
}

private WebDavClient CreateWebDavClientWithDebugHttpMessageHandler()
{
Expand All @@ -73,7 +73,7 @@ private WebDavClient CreateWebDavClientWithDebugHttpMessageHandler()
var debugHttpMessageHandler = new DebugHttpMessageHandler(httpClientHandler);
var wdc = new WebDavClient(debugHttpMessageHandler);
return wdc;
}
}

#region Copy

Expand All @@ -87,7 +87,7 @@ public void UIT_WebDavClient_Copy()
var testFile = UriHelper.CombineUrl(testCollectionSource, TestFile, true);

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

// Put file.
Expand All @@ -96,11 +96,11 @@ public void UIT_WebDavClient_Copy()
var content = new StreamContent(fileStream);
response = client.PutAsync(testFile, content).Result;
}

var putResponseSuccess = response.IsSuccessStatusCode;

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

// PropFind.
Expand Down Expand Up @@ -506,19 +506,21 @@ public void UIT_WebDavClient_LockRefreshLockUnlock()
return;

using (var client = CreateWebDavClientWithDebugHttpMessageHandler())
{
{
var userEmail = "[email protected]";

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

var response = client.LockAsync(webDavRootFolder, WebDavTimeoutHeaderValue.CreateWebDavTimeout(TimeSpan.FromMinutes(1)), WebDavDepthHeaderValue.Infinity, lockInfo).Result;
var lockResponseSuccess = response.IsSuccessStatusCode;
LockToken lockToken = WebDavHelper.GetLockTokenFromWebDavResponseMessage(response);
ActiveLock activeLock = WebDavHelper.GetActiveLockFromWebDavResponseMessage(response);

// Refresh lock.
response = client.RefreshLockAsync(webDavRootFolder, WebDavTimeoutHeaderValue.CreateWebDavTimeout(TimeSpan.FromSeconds(10)), lockToken).Result;
Expand All @@ -530,6 +532,7 @@ public void UIT_WebDavClient_LockRefreshLockUnlock()

Assert.IsTrue(lockResponseSuccess);
Assert.IsNotNull(lockToken);
Assert.AreEqual(userEmail, activeLock.OwnerHref);
Assert.IsTrue(refreshLockResponseSuccess);
Assert.IsTrue(unlockResponseSuccess);
}
Expand Down
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
v1.1.2.0
- WebDavHelper: Added method to receive the ActiveLock from a WebDavResponseMessage.

v1.1.1.0
- WebDavClient: Added missing overload for Mkcol accepting an URI/URL and a CancellationToken.

Expand Down

0 comments on commit 24ec0e4

Please sign in to comment.