|
1 | | -using System; |
| 1 | +using System.IO; |
2 | 2 | using NUnit.Framework; |
3 | 3 | using TestStack.FluentMVCTesting.Tests.TestControllers; |
4 | 4 |
|
@@ -56,11 +56,60 @@ public void Check_for_existent_temp_data_property() |
56 | 56 | public void Check_for_non_existent_temp_data_property() |
57 | 57 | { |
58 | 58 | const string key = ""; |
| 59 | + |
59 | 60 | var exception = Assert.Throws<TempDataAssertionException>(() => |
60 | 61 | _controller.ShouldHaveTempDataProperty(key)); |
61 | 62 |
|
62 | 63 | Assert.That(exception.Message, Is.EqualTo(string.Format( |
63 | 64 | "Expected TempData to have a non-null value with key \"{0}\", but none found.", key))); |
64 | 65 | } |
| 66 | + |
| 67 | + [Test] |
| 68 | + public void Check_for_existent_temp_data_property_and_check_value() |
| 69 | + { |
| 70 | + const string key = ""; |
| 71 | + const int value = 10; |
| 72 | + _controller.TempData[key] = value; |
| 73 | + |
| 74 | + _controller.ShouldHaveTempDataProperty(key, value); |
| 75 | + } |
| 76 | + |
| 77 | + [Test] |
| 78 | + public void Check_for_existent_temp_data_property_and_check_invalid_value() |
| 79 | + { |
| 80 | + const string key = ""; |
| 81 | + const int actualValue = 0; |
| 82 | + const int expectedValue = 1; |
| 83 | + _controller.TempData[key] = actualValue; |
| 84 | + |
| 85 | + var exception = Assert.Throws<TempDataAssertionException>(() => |
| 86 | + _controller.ShouldHaveTempDataProperty(key, expectedValue)); |
| 87 | + |
| 88 | + Assert.That(exception.Message, Is.EqualTo(string.Format("Expected value for key \"{0}\" to be \"{1}\", but instead found \"{2}\"", key, expectedValue, actualValue))); |
| 89 | + } |
| 90 | + |
| 91 | + [Test] |
| 92 | + public void Check_for_existent_temp_data_property_and_check_invalid_value_of_different_types() |
| 93 | + { |
| 94 | + const string key = ""; |
| 95 | + const int actualValue = 0; |
| 96 | + const string expectedValue = "one"; |
| 97 | + _controller.TempData[key] = actualValue; |
| 98 | + |
| 99 | + var exception = Assert.Throws<TempDataAssertionException>(() => |
| 100 | + _controller.ShouldHaveTempDataProperty(key, expectedValue)); |
| 101 | + |
| 102 | + Assert.That(exception.Message, Is.EqualTo(string.Format("Expected value to be of type {0}, but instead was {1}.", expectedValue.GetType().FullName, actualValue.GetType().FullName))); |
| 103 | + } |
| 104 | + |
| 105 | + [Test] |
| 106 | + public void Check_for_existent_temp_data_property_and_check_value_valid_using_referential_equality() |
| 107 | + { |
| 108 | + const string key = ""; |
| 109 | + MemoryStream expectedValue = new MemoryStream(); |
| 110 | + _controller.TempData[key] = expectedValue; |
| 111 | + |
| 112 | + _controller.ShouldHaveTempDataProperty(key, expectedValue); |
| 113 | + } |
65 | 114 | } |
66 | 115 | } |
0 commit comments