|
1 | | -using NUnit.Framework; |
| 1 | +using System.IO; |
| 2 | +using NUnit.Framework; |
2 | 3 | using TestStack.FluentMVCTesting.Tests.TestControllers; |
3 | 4 |
|
4 | 5 | namespace TestStack.FluentMVCTesting.Tests |
@@ -41,5 +42,109 @@ public void Throw_exception_for_child_action_call_to_non_child_action() |
41 | 42 | var exception = Assert.Throws<InvalidControllerActionException>(() => _controller.WithCallToChild(c => c.SomeAction())); |
42 | 43 | Assert.That(exception.Message, Is.EqualTo("Expected action SomeAction of controller ControllerExtensionsController to be a child action, but it didn't have the ChildActionOnly attribute.")); |
43 | 44 | } |
| 45 | + |
| 46 | + [Test] |
| 47 | + public void Check_for_existent_temp_data_property() |
| 48 | + { |
| 49 | + const string key = ""; |
| 50 | + _controller.TempData[key] = ""; |
| 51 | + |
| 52 | + _controller.ShouldHaveTempDataProperty(key); |
| 53 | + } |
| 54 | + |
| 55 | + [Test] |
| 56 | + public void Check_for_non_existent_temp_data_property() |
| 57 | + { |
| 58 | + const string key = ""; |
| 59 | + |
| 60 | + var exception = Assert.Throws<TempDataAssertionException>(() => |
| 61 | + _controller.ShouldHaveTempDataProperty(key)); |
| 62 | + |
| 63 | + Assert.That(exception.Message, Is.EqualTo(string.Format( |
| 64 | + "Expected TempData to have a non-null value with key \"{0}\", but none found.", key))); |
| 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 | + } |
| 114 | + |
| 115 | + [Test] |
| 116 | + public void Check_for_existent_temp_data_property_and_check_value_using_valid_predicate() |
| 117 | + { |
| 118 | + const string key = ""; |
| 119 | + const int value = 1; |
| 120 | + _controller.TempData[key] = value; |
| 121 | + |
| 122 | + _controller |
| 123 | + .ShouldHaveTempDataProperty<int>(key, x => x == value); |
| 124 | + } |
| 125 | + |
| 126 | + [Test] |
| 127 | + public void Check_for_existent_temp_data_property_and_check_value_using_invalid_predicate() |
| 128 | + { |
| 129 | + const string key = ""; |
| 130 | + _controller.TempData[key] = 1; |
| 131 | + |
| 132 | + var exception = Assert.Throws<TempDataAssertionException>(() => |
| 133 | + _controller.ShouldHaveTempDataProperty<int>(key, x => x == 0)); |
| 134 | + |
| 135 | + Assert.That(exception.Message, Is.EqualTo("Expected view model to pass the given condition, but it failed.")); |
| 136 | + } |
| 137 | + |
| 138 | + [Test] |
| 139 | + public void Check_for_non_existent_temp_data_property_when_supplied_with_predicate() |
| 140 | + { |
| 141 | + const string key = ""; |
| 142 | + |
| 143 | + var exception = Assert.Throws<TempDataAssertionException>(() => |
| 144 | + _controller.ShouldHaveTempDataProperty<int>(key, x => x == 0)); |
| 145 | + |
| 146 | + Assert.That(exception.Message, Is.EqualTo(string.Format( |
| 147 | + "Expected TempData to have a non-null value with key \"{0}\", but none found.", key))); |
| 148 | + } |
44 | 149 | } |
45 | 150 | } |
0 commit comments