From 66661084bd834275e1fbacf6621ee810c14c125e Mon Sep 17 00:00:00 2001 From: DecaTec Date: Wed, 12 Apr 2017 20:04:06 +0200 Subject: [PATCH] Unit tests --- DecaTec.WebDav/LockToken.cs | 26 +++++++ .../UnitTestLockToken.cs | 75 +++++++++++++++++++ 2 files changed, 101 insertions(+) diff --git a/DecaTec.WebDav/LockToken.cs b/DecaTec.WebDav/LockToken.cs index e75b224..c1629fd 100644 --- a/DecaTec.WebDav/LockToken.cs +++ b/DecaTec.WebDav/LockToken.cs @@ -8,6 +8,32 @@ namespace DecaTec.WebDav /// public class LockToken { + /// + /// Constructs a based on the . + /// + /// The lock token in absolute-URI format as defined in https://tools.ietf.org/html/rfc3986#section-4.3. + /// Use the strong-typed constructors to create a new . + 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); + } + /// /// Constructs a based on the . /// diff --git a/UnitTests/DecaTec.WebDav.UnitTest/UnitTestLockToken.cs b/UnitTests/DecaTec.WebDav.UnitTest/UnitTestLockToken.cs index 6a0ed49..ceebfea 100644 --- a/UnitTests/DecaTec.WebDav.UnitTest/UnitTestLockToken.cs +++ b/UnitTests/DecaTec.WebDav.UnitTest/UnitTestLockToken.cs @@ -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("", lockTokenHeaderFormat.ToString()); + Assert.AreEqual("()", noTagList.ToString()); + } + [TestMethod] public void UT_LockToken_IfHeaderNoTagListFormat_IfHeaderWithBrackets() { @@ -29,6 +44,21 @@ public void UT_LockToken_IfHeaderNoTagListFormat_IfHeaderWithBrackets() Assert.IsTrue(parseResult); } + [TestMethod] + public void UT_LockToken_Construct_IfHeaderNoTagListFormat_IfHeaderWithBracketsWithString() + { + var lockTokenString = ""; + + var lockToken = new LockToken(lockTokenString); + var absoluteUri = lockToken.AbsoluteUri; + var noTagList = lockToken.IfHeaderNoTagListFormat; + var lockTokenHeaderFormat = lockToken.LockTokenHeaderFormat; + + Assert.IsNull(absoluteUri); + Assert.AreEqual("", lockTokenHeaderFormat.ToString()); + Assert.AreEqual("()", noTagList.ToString()); + } + [TestMethod] public void UT_LockToken_LockTokenHeaderFormat_LockTokenHeaderWithoutBrackets() { @@ -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("", codedUrl.ToString()); + Assert.AreEqual("()", ifHeaderNoTagListFormat.ToString()); + } + [TestMethod] public void UT_LockToken_LockTokenHeaderFormat_LockTokenHeaderWithBrackets() { @@ -53,6 +98,21 @@ public void UT_LockToken_LockTokenHeaderFormat_LockTokenHeaderWithBrackets() Assert.IsTrue(parseResult); } + [TestMethod] + public void UT_LockToken_Construct_LockTokenHeaderFormat_LockTokenHeaderWithBracketsWithString() + { + var lockTokenString = ""; + + var lockToken = new LockToken(lockTokenString); + var absoluteUri = lockToken.AbsoluteUri; + var lockTokenHeaderFormat = lockToken.LockTokenHeaderFormat; + var ifHeaderNoTagListFormat = lockToken.IfHeaderNoTagListFormat; + + Assert.IsNull(absoluteUri); + Assert.AreEqual("", lockTokenHeaderFormat.ToString()); + Assert.AreEqual("()", ifHeaderNoTagListFormat.ToString()); + } + [TestMethod] public void UT_LockToken_LockTokenHeaderFormat_LockTokenHeaderWithBothBrackets() { @@ -64,5 +124,20 @@ public void UT_LockToken_LockTokenHeaderFormat_LockTokenHeaderWithBothBrackets() Assert.AreEqual("()", lockTokenHeaderFormat.ToString()); Assert.IsTrue(parseResult); } + + [TestMethod] + public void UT_LockToken_Construct_LockTokenHeaderFormat_LockTokenHeaderWithBothBracketsWithString() + { + var lockTokenString = "()"; + + 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("()", lockTokenHeaderFormat.ToString()); + } } }