|
| 1 | +// |
| 2 | +// Copyright (c) .NET Foundation and Contributors |
| 3 | +// See LICENSE file in the project root for full license information. |
| 4 | +// |
| 5 | + |
| 6 | +using nanoFramework.TestFramework; |
| 7 | +using System; |
| 8 | +using System.Net; |
| 9 | + |
| 10 | +namespace HttpUnitTests |
| 11 | +{ |
| 12 | + [TestClass] |
| 13 | + public class WebHeaderCollectionTests |
| 14 | + { |
| 15 | + [TestMethod] |
| 16 | + public void Add_Authorization_BearerWithSpaceAndNoValue() |
| 17 | + { |
| 18 | + var headers = new WebHeaderCollection(); |
| 19 | + headers.Add("Authorization: Bearer "); |
| 20 | + } |
| 21 | + |
| 22 | + [TestMethod] |
| 23 | + public void Add_Authorization_NoSpaceSingleChar() |
| 24 | + { |
| 25 | + var headers = new WebHeaderCollection(); |
| 26 | + headers.Add("Authorization: 1"); |
| 27 | + } |
| 28 | + |
| 29 | + [TestMethod] |
| 30 | + public void Add_Authorization_ValidBearer() |
| 31 | + { |
| 32 | + var headers = new WebHeaderCollection(); |
| 33 | + headers.Add("Authorization: Bearer a11111"); |
| 34 | + string value = headers["Authorization"]; |
| 35 | + Assert.AreEqual("Bearer a11111", value); |
| 36 | + } |
| 37 | + |
| 38 | + [TestMethod] |
| 39 | + public void Add_Authorization_ValidTestValue() |
| 40 | + { |
| 41 | + var headers = new WebHeaderCollection(); |
| 42 | + headers.Add("Authorization: test 1"); |
| 43 | + string value = headers["Authorization"]; |
| 44 | + Assert.AreEqual("test 1", value); |
| 45 | + } |
| 46 | + |
| 47 | + [TestMethod] |
| 48 | + public void Add_Authorization_ValidSingleLetterPair() |
| 49 | + { |
| 50 | + var headers = new WebHeaderCollection(); |
| 51 | + headers.Add("Authorization: a b"); |
| 52 | + string value = headers["Authorization"]; |
| 53 | + Assert.AreEqual("a b", value); |
| 54 | + } |
| 55 | + [TestMethod] |
| 56 | + public void Add_Authorization_EmptyValue() |
| 57 | + { |
| 58 | + var headers = new WebHeaderCollection(); |
| 59 | + headers.Add("Authorization:"); |
| 60 | + string value = headers["Authorization"]; |
| 61 | + Assert.AreEqual(string.Empty, value); |
| 62 | + } |
| 63 | + |
| 64 | + [TestMethod] |
| 65 | + public void Add_Authorization_ColonWithSpaceOnly() |
| 66 | + { |
| 67 | + var headers = new WebHeaderCollection(); |
| 68 | + headers.Add("Authorization: "); |
| 69 | + string value = headers["Authorization"]; |
| 70 | + Assert.AreEqual(string.Empty, value); |
| 71 | + } |
| 72 | + |
| 73 | + [TestMethod] |
| 74 | + public void Add_NullHeader_ThrowsArgumentNullException() |
| 75 | + { |
| 76 | + var headers = new WebHeaderCollection(); |
| 77 | + Assert.ThrowsException(typeof(ArgumentNullException), () => headers.Add(null)); |
| 78 | + } |
| 79 | + |
| 80 | + [TestMethod] |
| 81 | + public void Add_EmptyHeader_ThrowsArgumentNullException() |
| 82 | + { |
| 83 | + var headers = new WebHeaderCollection(); |
| 84 | + Assert.ThrowsException(typeof(ArgumentNullException), () => headers.Add(string.Empty)); |
| 85 | + } |
| 86 | + |
| 87 | + [TestMethod] |
| 88 | + public void Add_HeaderWithNoColon_ThrowsArgumentException() |
| 89 | + { |
| 90 | + var headers = new WebHeaderCollection(); |
| 91 | + Assert.ThrowsException(typeof(ArgumentException), () => headers.Add("Authorization")); |
| 92 | + } |
| 93 | + |
| 94 | + [TestMethod] |
| 95 | + public void Add_HeaderNameWithSpace_ThrowsArgumentException() |
| 96 | + { |
| 97 | + var headers = new WebHeaderCollection(); |
| 98 | + Assert.ThrowsException(typeof(ArgumentException), () => headers.Add("My Header: value")); |
| 99 | + } |
| 100 | + } |
| 101 | +} |
0 commit comments