WarningHeaderValueTest.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. //
  2. // WarningHeaderValueTest.cs
  3. //
  4. // Authors:
  5. // Marek Safar <[email protected]>
  6. //
  7. // Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com)
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. using System;
  29. using System.Collections;
  30. using System.Collections.Generic;
  31. using NUnit.Framework;
  32. using System.Net.Http.Headers;
  33. namespace MonoTests.System.Net.Http.Headers
  34. {
  35. [TestFixture]
  36. public class WarningHeaderValueTest
  37. {
  38. [Test]
  39. public void Ctor_InvalidArguments ()
  40. {
  41. try {
  42. new WarningHeaderValue (1000, "rb", "\"\"");
  43. Assert.Fail ("#1");
  44. } catch (ArgumentOutOfRangeException) {
  45. }
  46. try {
  47. new WarningHeaderValue (1, null, null);
  48. Assert.Fail ("#2");
  49. } catch (ArgumentException) {
  50. }
  51. try {
  52. new WarningHeaderValue (1, "a", null);
  53. Assert.Fail ("#3");
  54. } catch (ArgumentException) {
  55. }
  56. }
  57. [Test]
  58. public void Equals ()
  59. {
  60. var value = new WarningHeaderValue (13, "x", "\"v\"");
  61. Assert.AreEqual (value, new WarningHeaderValue (13, "X", "\"v\""), "#1");
  62. Assert.AreNotEqual (value, new WarningHeaderValue (13, "x", "\"V\""), "#2");
  63. Assert.AreNotEqual (value, new WarningHeaderValue (13, "y", "\"V\""), "#3");
  64. Assert.AreNotEqual (value, new WarningHeaderValue (1, "x", "\"V\""), "#4");
  65. value = new WarningHeaderValue (6, "DD", "\"c\"", DateTimeOffset.MaxValue);
  66. Assert.AreEqual (value, new WarningHeaderValue (6, "DD", "\"c\"", DateTimeOffset.MaxValue), "#5");
  67. Assert.AreNotEqual (value, new WarningHeaderValue (6, "y", "\"V\""), "#6");
  68. }
  69. [Test]
  70. public void Parse ()
  71. {
  72. var res = WarningHeaderValue.Parse ("1 n \"\"");
  73. Assert.IsNull (res.Date, "#1");
  74. Assert.AreEqual (1, res.Code, "#2");
  75. Assert.AreEqual ("n", res.Agent, "#3");
  76. Assert.AreEqual ("\"\"", res.Text, "#4");
  77. }
  78. [Test]
  79. public void Parse_Invalid ()
  80. {
  81. try {
  82. WarningHeaderValue.Parse (null);
  83. Assert.Fail ("#1");
  84. } catch (FormatException) {
  85. }
  86. try {
  87. WarningHeaderValue.Parse (" ");
  88. Assert.Fail ("#2");
  89. } catch (FormatException) {
  90. }
  91. try {
  92. WarningHeaderValue.Parse ("a");
  93. Assert.Fail ("#3");
  94. } catch (FormatException) {
  95. }
  96. }
  97. [Test]
  98. public void Properties ()
  99. {
  100. var value = new WarningHeaderValue (5, "ag", "\"tt\"");
  101. Assert.IsNull (value.Date, "#1");
  102. Assert.AreEqual (5, value.Code, "#2");
  103. Assert.AreEqual ("ag", value.Agent, "#3");
  104. Assert.AreEqual ("\"tt\"", value.Text, "#4");
  105. value = new WarningHeaderValue (5, "ag", "\"tt\"", DateTimeOffset.MinValue);
  106. Assert.AreEqual (DateTimeOffset.MinValue, value.Date, "#5");
  107. Assert.AreEqual (5, value.Code, "#6");
  108. Assert.AreEqual ("ag", value.Agent, "#7");
  109. Assert.AreEqual ("\"tt\"", value.Text, "#8");
  110. }
  111. [Test]
  112. public void TryParse ()
  113. {
  114. WarningHeaderValue res;
  115. Assert.IsTrue (WarningHeaderValue.TryParse ("22 a \"b\"", out res), "#1");
  116. Assert.IsNull (res.Date, "#2");
  117. Assert.AreEqual (22, res.Code, "#3");
  118. Assert.AreEqual ("a", res.Agent, "#4");
  119. Assert.AreEqual ("\"b\"", res.Text, "#5");
  120. }
  121. [Test]
  122. public void TryParse_Invalid ()
  123. {
  124. WarningHeaderValue res;
  125. Assert.IsFalse (WarningHeaderValue.TryParse ("", out res), "#1");
  126. Assert.IsNull (res, "#2");
  127. }
  128. }
  129. }