|
| 1 | +using System.Web.Routing; |
| 2 | +using NUnit.Framework; |
| 3 | + |
| 4 | +namespace TestStack.FluentMVCTesting.Tests |
| 5 | +{ |
| 6 | + [TestFixture] |
| 7 | + class RouteValueDictionaryExtensionsTests |
| 8 | + { |
| 9 | + [Test] |
| 10 | + public void WithRouteValue_ThrowsWhenDictIsEmpty() |
| 11 | + { |
| 12 | + var dict = new RouteValueDictionary(); |
| 13 | + |
| 14 | + Assert.Throws<MissingRouteValueException>(() => dict.WithRouteValue("NotImportant")); |
| 15 | + } |
| 16 | + |
| 17 | + [Test] |
| 18 | + public void WithRouteValue_ThrowsWhenDictDoesntHaveValue() |
| 19 | + { |
| 20 | + var dict = new RouteValueDictionary(); |
| 21 | + dict.Add("Existing", "NotImportant"); |
| 22 | + |
| 23 | + Assert.Throws<MissingRouteValueException>(() => dict.WithRouteValue("NotExisting")); |
| 24 | + } |
| 25 | + |
| 26 | + [Test] |
| 27 | + public void WithRouteValue_ThrowsWhenDictHasIncorrectValue() |
| 28 | + { |
| 29 | + var dict = new RouteValueDictionary(); |
| 30 | + dict.Add("Existing", "Correct"); |
| 31 | + |
| 32 | + Assert.Throws<InvalidRouteValueException>(() => dict.WithRouteValue("Existing", "Incorrect")); |
| 33 | + } |
| 34 | + |
| 35 | + [Test] |
| 36 | + public void WithRouteValue_ThrowIfValueTypeMismatch() |
| 37 | + { |
| 38 | + var dict = new RouteValueDictionary(); |
| 39 | + dict.Add("Existing", 1); |
| 40 | + |
| 41 | + Assert.Throws<ValueTypeMismatchException>(() => dict.WithRouteValue("Existing", "1")); |
| 42 | + } |
| 43 | + |
| 44 | + [Test] |
| 45 | + public void WithRouteValue_DoesntThrowIfValueIsCorrect() |
| 46 | + { |
| 47 | + var dict = new RouteValueDictionary(); |
| 48 | + dict.Add("Existing", "Correct"); |
| 49 | + |
| 50 | + dict.WithRouteValue("Existing", "Correct"); |
| 51 | + |
| 52 | + Assert.Pass(); |
| 53 | + } |
| 54 | + |
| 55 | + [Test] |
| 56 | + public void WithRouteValue_CanUseIntType() |
| 57 | + { |
| 58 | + var dict = new RouteValueDictionary(); |
| 59 | + dict.Add("Existing", 10); |
| 60 | + |
| 61 | + dict.WithRouteValue("Existing", 10); |
| 62 | + |
| 63 | + Assert.Pass(); |
| 64 | + } |
| 65 | + } |
| 66 | +} |
0 commit comments