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

Commit

Permalink
Unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DecaTec committed Apr 12, 2017
1 parent 7ba7f73 commit 6666108
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 0 deletions.
26 changes: 26 additions & 0 deletions DecaTec.WebDav/LockToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,32 @@ namespace DecaTec.WebDav
/// </summary>
public class LockToken
{
/// <summary>
/// Constructs a <see cref="LockToken"/> based on the <paramref name="absoluteUri"/>.
/// </summary>
/// <param name="absoluteUri">The lock token in absolute-URI format as defined in https://tools.ietf.org/html/rfc3986#section-4.3. </param>
/// <remarks>Use the strong-typed constructors to create a new <see cref="LockToken"/>.</remarks>
public LockToken(string lockToken)
{
if (string.IsNullOrEmpty(lockToken))
throw new ArgumentException($"The {nameof(lockToken)} cannot be null");

if (AbsoluteUri.TryParse(lockToken, out var absoluteUri))
{
AbsoluteUri = absoluteUri;
var codedUrl = new CodedUrl(absoluteUri);
LockTokenHeaderFormat = codedUrl;
IfHeaderNoTagListFormat = new NoTagList(codedUrl);
}
else if (CodedUrl.TryParse(lockToken, out var codedUrl))
{
LockTokenHeaderFormat = codedUrl;
IfHeaderNoTagListFormat = new NoTagList(codedUrl);
}
else
IfHeaderNoTagListFormat = new NoTagList(lockToken);
}

/// <summary>
/// Constructs a <see cref="LockToken"/> based on the <paramref name="absoluteUri"/>.
/// </summary>
Expand Down
75 changes: 75 additions & 0 deletions UnitTests/DecaTec.WebDav.UnitTest/UnitTestLockToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@ public void UT_LockToken_IfHeaderNoTagListFormat_IfHeaderWithoutBrackets()
Assert.IsTrue(parseResult);
}

[TestMethod]
public void UT_LockToken_Construct_IfHeaderNoTagListFormat_IfHeaderWithoutBracketsWithString()
{
var lockTokenString = "urn:uuid:my-lock-token";

var lockToken = new LockToken(lockTokenString);
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());
}

[TestMethod]
public void UT_LockToken_IfHeaderNoTagListFormat_IfHeaderWithBrackets()
{
Expand All @@ -29,6 +44,21 @@ public void UT_LockToken_IfHeaderNoTagListFormat_IfHeaderWithBrackets()
Assert.IsTrue(parseResult);
}

[TestMethod]
public void UT_LockToken_Construct_IfHeaderNoTagListFormat_IfHeaderWithBracketsWithString()
{
var lockTokenString = "<urn:uuid:my-lock-token>";

var lockToken = new LockToken(lockTokenString);
var absoluteUri = lockToken.AbsoluteUri;
var noTagList = lockToken.IfHeaderNoTagListFormat;
var lockTokenHeaderFormat = lockToken.LockTokenHeaderFormat;

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

[TestMethod]
public void UT_LockToken_LockTokenHeaderFormat_LockTokenHeaderWithoutBrackets()
{
Expand All @@ -41,6 +71,21 @@ public void UT_LockToken_LockTokenHeaderFormat_LockTokenHeaderWithoutBrackets()
Assert.IsTrue(parseResult);
}

[TestMethod]
public void UT_LockToken_Construct_LockTokenHeaderFormat_LockTokenHeaderWithoutBracketsWithString()
{
var lockTokenString = "urn:uuid:my-lock-token";

var lockToken = new LockToken(lockTokenString);
var absoluteUri = lockToken.AbsoluteUri;
var codedUrl = lockToken.LockTokenHeaderFormat;
var ifHeaderNoTagListFormat = lockToken.IfHeaderNoTagListFormat;

Assert.AreEqual("urn:uuid:my-lock-token", absoluteUri.ToString());
Assert.AreEqual("<urn:uuid:my-lock-token>", codedUrl.ToString());
Assert.AreEqual("(<urn:uuid:my-lock-token>)", ifHeaderNoTagListFormat.ToString());
}

[TestMethod]
public void UT_LockToken_LockTokenHeaderFormat_LockTokenHeaderWithBrackets()
{
Expand All @@ -53,6 +98,21 @@ public void UT_LockToken_LockTokenHeaderFormat_LockTokenHeaderWithBrackets()
Assert.IsTrue(parseResult);
}

[TestMethod]
public void UT_LockToken_Construct_LockTokenHeaderFormat_LockTokenHeaderWithBracketsWithString()
{
var lockTokenString = "<urn:uuid:my-lock-token>";

var lockToken = new LockToken(lockTokenString);
var absoluteUri = lockToken.AbsoluteUri;
var lockTokenHeaderFormat = lockToken.LockTokenHeaderFormat;
var ifHeaderNoTagListFormat = lockToken.IfHeaderNoTagListFormat;

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

[TestMethod]
public void UT_LockToken_LockTokenHeaderFormat_LockTokenHeaderWithBothBrackets()
{
Expand All @@ -64,5 +124,20 @@ public void UT_LockToken_LockTokenHeaderFormat_LockTokenHeaderWithBothBrackets()
Assert.AreEqual("(<urn:uuid:my-lock-token>)", lockTokenHeaderFormat.ToString());
Assert.IsTrue(parseResult);
}

[TestMethod]
public void UT_LockToken_Construct_LockTokenHeaderFormat_LockTokenHeaderWithBothBracketsWithString()
{
var lockTokenString = "(<urn:uuid:my-lock-token>)";

var lockToken = new LockToken(lockTokenString);
var absoluteUri = lockToken.AbsoluteUri;
var codedUrl = lockToken.LockTokenHeaderFormat;
var lockTokenHeaderFormat = lockToken.IfHeaderNoTagListFormat;

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

0 comments on commit 6666108

Please sign in to comment.