public void OnPageExecuting_NullFilterFactory_Throws() { // Arrange var httpContext = new DefaultHttpContext(); var tempData = new TempDataDictionary(httpContext, Mock.Of <ITempDataProvider>()); tempData.Save(); var page = new TestPage(); var filter = CreatePageSaveTempDataPropertyFilter(tempData, filterFactory: false); var context = new PageHandlerExecutingContext( new PageContext() { ActionDescriptor = new CompiledPageActionDescriptor(), HttpContext = httpContext, RouteData = new RouteData(), }, Array.Empty <IFilterMetadata>(), null, new Dictionary <string, object>(), page); // Act & Assert var ex = Assert.Throws <InvalidOperationException>(() => filter.OnPageHandlerExecuting(context)); Assert.Contains("FilterFactory", ex.Message); }
public void OnPageExecuting_InitializesAndSavesProperties() { // Arrange var httpContext = new DefaultHttpContext(); var tempData = new TempDataDictionary(httpContext, Mock.Of <ITempDataProvider>()) { { "TempDataProperty-Test", "Value" } }; tempData.Save(); var pageModel = new TestPageModel(); var filter = CreatePageSaveTempDataPropertyFilter(tempData); filter.Subject = pageModel; var factory = filter.FilterFactory; var pageType = typeof(TestPageModel); var testProperty = pageType.GetProperty(nameof(TestPageModel.Test)); var test2Property = pageType.GetProperty(nameof(TestPageModel.Test2)); filter.Properties = new List <TempDataProperty> { new TempDataProperty("TempDataProperty-Test", testProperty, testProperty.GetValue, testProperty.SetValue), new TempDataProperty("TempDataProperty-Test2", test2Property, test2Property.GetValue, test2Property.SetValue) }; var context = new PageHandlerExecutingContext( new PageContext() { ActionDescriptor = new CompiledPageActionDescriptor(), HttpContext = httpContext, RouteData = new RouteData(), }, Array.Empty <IFilterMetadata>(), null, new Dictionary <string, object>(), pageModel); // Act filter.OnPageHandlerExecuting(context); // Assert Assert.Collection( filter.Properties.OrderBy(p => p.PropertyInfo.Name), p => Assert.Equal(testProperty, p.PropertyInfo), p => Assert.Equal(test2Property, p.PropertyInfo)); Assert.Same(filter.Properties, factory.Properties); }
public void TempData_TryGetValue_MarksKeyForDeletion() { var tempData = new TempDataDictionary(GetHttpContextAccessor(), new NullTempDataProvider()); object value; tempData["Foo"] = "Foo"; // Act tempData.TryGetValue("Foo", out value); tempData.Save(); // Assert Assert.False(tempData.ContainsKey("Foo")); }
public void TempData_TryGetValue_MarksKeyForDeletion() { var tempData = new TempDataDictionary(new DefaultHttpContext(), new NullTempDataProvider()); object value; tempData["Foo"] = "Foo"; // Act tempData.TryGetValue("Foo", out value); tempData.Save(); // Assert Assert.False(tempData.ContainsKey("Foo")); }
public void TempData_Save_RemovesKeysThatWereRead() { // Arrange var tempData = new TempDataDictionary(GetHttpContextAccessor(), new NullTempDataProvider()); tempData["Foo"] = "Foo"; tempData["Bar"] = "Bar"; // Act var value = tempData["Foo"]; tempData.Save(); // Assert Assert.False(tempData.ContainsKey("Foo")); Assert.True(tempData.ContainsKey("Bar")); }
public void TempData_Keep_RetainsAllKeysWhenSavingDictionary() { // Arrange var tempData = new TempDataDictionary(new DefaultHttpContext(), new NullTempDataProvider()); tempData["Foo"] = "Foo"; tempData["Bar"] = "Bar"; // Act tempData.Keep(); tempData.Save(); // Assert Assert.True(tempData.ContainsKey("Foo")); Assert.True(tempData.ContainsKey("Bar")); }
public void TempData_Peek_DoesNotMarkKeyForDeletion() { // Arrange var tempData = new TempDataDictionary(new DefaultHttpContext(), new NullTempDataProvider()); tempData["Bar"] = "barValue"; // Act var value = tempData.Peek("bar"); tempData.Save(); // Assert Assert.Equal("barValue", value); Assert.True(tempData.ContainsKey("Bar")); }
public void TryGetValueMarksKeyForDeletion() { NullTempDataProvider provider = new NullTempDataProvider(); TempDataDictionary tempData = new TempDataDictionary(); Mock <ControllerContext> controllerContext = new Mock <ControllerContext>(); object value; tempData["Foo"] = "Foo"; // Act tempData.TryGetValue("Foo", out value); tempData.Save(controllerContext.Object, provider); // Assert Assert.False(tempData.ContainsKey("Foo")); }
public void TempData_Save_RemovesKeysThatWereRead() { // Arrange var tempData = new TempDataDictionary(new DefaultHttpContext(), new NullTempDataProvider()); tempData["Foo"] = "Foo"; tempData["Bar"] = "Bar"; // Act var value = tempData["Foo"]; tempData.Save(); // Assert Assert.False(tempData.ContainsKey("Foo")); Assert.True(tempData.ContainsKey("Bar")); }
public void SaveRetainsAllKeys() { // Arrange NullTempDataProvider provider = new NullTempDataProvider(); TempDataDictionary tempData = new TempDataDictionary(); Mock <ControllerContext> controllerContext = new Mock <ControllerContext>(); tempData["Foo"] = "Foo"; tempData["Bar"] = "Bar"; // Act tempData.Save(controllerContext.Object, provider); // Assert Assert.True(tempData.ContainsKey("Foo")); Assert.True(tempData.ContainsKey("Bar")); }
/// <summary> /// When POSTing to MVC but rendering in WebForms we need to do some trickery, we'll create a dummy viewcontext with all of the /// current modelstate, tempdata, viewdata so that if we're rendering partial view macros within the webforms view, they will /// get all of this merged into them. /// </summary> /// <param name="context"></param> private static void EnsureViewContextForWebForms(ControllerContext context) { var tempDataDictionary = new TempDataDictionary(); tempDataDictionary.Save(context, new SessionStateTempDataProvider()); var viewCtx = new ViewContext(context, new DummyView(), new ViewDataDictionary(), tempDataDictionary, new StringWriter()); viewCtx.ViewData.ModelState.Merge(new ModelStateDictionary(context.Controller.ViewData.ModelState)); foreach (var d in context.Controller.ViewData) { viewCtx.ViewData[d.Key] = d.Value; } //now we need to add it to the special route tokens so it's picked up later context.HttpContext.Request.RequestContext.RouteData.DataTokens[Constants.DataTokenCurrentViewContext] = viewCtx; }
public void KeepRetainsAllKeysWhenSavingDictionary() { // Arrange NullTempDataProvider provider = new NullTempDataProvider(); TempDataDictionary tempData = new TempDataDictionary(); Mock<ControllerContext> controllerContext = new Mock<ControllerContext>(); controllerContext.Setup(c => c.HttpContext.Request).Returns(new Mock<HttpRequestBase>().Object); tempData["Foo"] = "Foo"; tempData["Bar"] = "Bar"; // Act tempData.Keep(); tempData.Save(controllerContext.Object, provider); // Assert Assert.IsTrue(tempData.ContainsKey("Foo"), "tempData should contain 'Foo'"); Assert.IsTrue(tempData.ContainsKey("Bar"), "tempData should contain 'Bar'"); }
public void TempData_RemovalOfKeysAreCaseInsensitive() { var tempData = new TempDataDictionary(new DefaultHttpContext(), new NullTempDataProvider()); tempData["Foo"] = "Foo"; tempData["Bar"] = "Bar"; // Act tempData.TryGetValue("foo", out var fooValue); var barValue = tempData["bar"]; tempData.Save(); // Assert Assert.False(tempData.ContainsKey("Foo")); Assert.False(tempData.ContainsKey("Boo")); }
public void GetValueProvider_CorrectlyRetainsOrRemovesKeys() { // Arrange string[] expectedRetainedKeys = new[] { "retainMe" }; TempDataDictionary tempData = new TempDataDictionary { { "retainMe", "retainMeValue" }, { "removeMe", "removeMeValue" }, { "previouslyRemoved", "previouslyRemovedValue" } }; object dummy = tempData["previouslyRemoved"]; // mark value for removal ControllerContext controllerContext = GetControllerContext(tempData); TempDataValueProviderFactory factory = new TempDataValueProviderFactory(); // Act IValueProvider valueProvider = factory.GetValueProvider(controllerContext); ValueProviderResult nonExistentResult = valueProvider.GetValue("nonExistent"); ValueProviderResult removeMeResult = valueProvider.GetValue("removeme"); // Assert Assert.Null(nonExistentResult); Assert.Equal("removeMeValue", removeMeResult.AttemptedValue); Assert.Equal(CultureInfo.InvariantCulture, removeMeResult.Culture); // Verify that keys have been removed or retained correctly by the provider Mock <ITempDataProvider> mockTempDataProvider = new Mock <ITempDataProvider>(); string[] retainedKeys = null; mockTempDataProvider .Setup( o => o.SaveTempData(controllerContext, It.IsAny <IDictionary <string, object> >()) ) .Callback( delegate(ControllerContext cc, IDictionary <string, object> d) { retainedKeys = d.Keys.ToArray(); } ); tempData.Save(controllerContext, mockTempDataProvider.Object); Assert.Equal(expectedRetainedKeys, retainedKeys); }
public void PeekDoesNotMarkKeyAsRead() { // Arrange NullTempDataProvider provider = new NullTempDataProvider(); TempDataDictionary tempData = new TempDataDictionary(); Mock <ControllerContext> controllerContext = new Mock <ControllerContext>(); tempData["Bar"] = "barValue"; // Act object value = tempData.Peek("bar"); tempData.Save(controllerContext.Object, provider); // Assert Assert.Equal("barValue", value); Assert.True(tempData.ContainsKey("Bar")); }
public void PeekDoesNotMarkKeyAsRead() { // Arrange NullTempDataProvider provider = new NullTempDataProvider(); TempDataDictionary tempData = new TempDataDictionary(); Mock <ControllerContext> controllerContext = new Mock <ControllerContext>(); tempData["Bar"] = "barValue"; // Act object value = tempData.Peek("bar"); tempData.Save(controllerContext.Object, provider); // Assert Assert.AreEqual("barValue", value, "Incorrect value read from Peek()."); Assert.IsTrue(tempData.ContainsKey("Bar"), "Peek() shouldn't have removed 'Bar' from TempData."); }
public void OnPageExecuting_ToPage_SetsPropertyValue() { // Arrange var httpContext = new DefaultHttpContext(); var tempData = new TempDataDictionary(httpContext, Mock.Of <ITempDataProvider>()) { { "TempDataProperty-Test", "Value" } }; tempData.Save(); var page = new TestPage() { ViewContext = CreateViewContext(httpContext, tempData) }; var filter = CreatePageSaveTempDataPropertyFilter(tempData); filter.Subject = page; var pageType = page.GetType(); var testProperty = pageType.GetProperty(nameof(TestPage.Test)); var test2Property = pageType.GetProperty(nameof(TestPage.Test2)); var context = new PageHandlerExecutingContext( new PageContext() { ActionDescriptor = new CompiledPageActionDescriptor(), HttpContext = httpContext, RouteData = new RouteData(), }, Array.Empty <IFilterMetadata>(), null, new Dictionary <string, object>(), page); // Act filter.OnPageHandlerExecuting(context); // Assert Assert.Equal("Value", page.Test); Assert.Null(page.Test2); }
public void TempData_EnumeratingDictionary_MarksKeysForDeletion() { // Arrange var tempData = new TempDataDictionary(GetHttpContextAccessor(), new NullTempDataProvider()); tempData["Foo"] = "Foo"; tempData["Bar"] = "Bar"; // Act var enumerator = tempData.GetEnumerator(); while (enumerator.MoveNext()) { var value = enumerator.Current; } tempData.Save(); // Assert Assert.False(tempData.ContainsKey("Foo")); Assert.False(tempData.ContainsKey("Bar")); }
public void KeepRetainsAllKeysWhenSavingDictionary() { // Arrange NullTempDataProvider provider = new NullTempDataProvider(); TempDataDictionary tempData = new TempDataDictionary(); Mock <ControllerContext> controllerContext = new Mock <ControllerContext>(); controllerContext.Setup(c => c.HttpContext.Request).Returns(new Mock <HttpRequestBase>().Object); tempData["Foo"] = "Foo"; tempData["Bar"] = "Bar"; // Act tempData.Keep(); tempData.Save(controllerContext.Object, provider); // Assert Assert.True(tempData.ContainsKey("Foo")); Assert.True(tempData.ContainsKey("Bar")); }
public void EnumeratingDictionaryMarksValuesForDeletion() { // Arrange NullTempDataProvider provider = new NullTempDataProvider(); TempDataDictionary tempData = new TempDataDictionary(); Mock<ControllerContext> controllerContext = new Mock<ControllerContext>(); tempData["Foo"] = "Foo"; tempData["Bar"] = "Bar"; // Act IEnumerator<KeyValuePair<string, object>> enumerator = tempData.GetEnumerator(); while (enumerator.MoveNext()) { object value = enumerator.Current; } tempData.Save(controllerContext.Object, provider); // Assert Assert.IsFalse(tempData.ContainsKey("Foo"), "tempData should not contain 'Foo'"); Assert.IsFalse(tempData.ContainsKey("Bar"), "tempData should not contain 'Bar'"); }
public void SaveRemovesKeysThatWereRead() { // Arrange NullTempDataProvider provider = new NullTempDataProvider(); TempDataDictionary tempData = new TempDataDictionary(); Mock <ControllerContext> controllerContext = new Mock <ControllerContext>(); tempData["Foo"] = "Foo"; tempData["Bar"] = "Bar"; // Act object value = tempData["Foo"]; tempData.Save(controllerContext.Object, provider); // Assert Assert.False(tempData.ContainsKey("Foo")); Assert.True(tempData.ContainsKey("Bar")); }
public void TempData_LoadAndSaveAreCaseInsensitive() { // Arrange var data = new Dictionary <string, object>(); data["Foo"] = "Foo"; data["Bar"] = "Bar"; var provider = new TestTempDataProvider(data); var tempData = new TempDataDictionary(new DefaultHttpContext(), provider); // Act tempData.Load(); var value = tempData["FOO"]; tempData.Save(); // Assert Assert.False(tempData.ContainsKey("foo")); Assert.True(tempData.ContainsKey("bar")); }
public void RemovalOfKeysAreCaseInsensitive() { NullTempDataProvider provider = new NullTempDataProvider(); TempDataDictionary tempData = new TempDataDictionary(); Mock <ControllerContext> controllerContext = new Mock <ControllerContext>(); object fooValue; tempData["Foo"] = "Foo"; tempData["Bar"] = "Bar"; // Act tempData.TryGetValue("foo", out fooValue); object barValue = tempData["bar"]; tempData.Save(controllerContext.Object, provider); // Assert Assert.False(tempData.ContainsKey("Foo")); Assert.False(tempData.ContainsKey("Boo")); }
public void GetValueProvider_CorrectlyRetainsOrRemovesKeys() { // Arrange string[] expectedRetainedKeys = new[] { "retainMe" }; TempDataDictionary tempData = new TempDataDictionary { { "retainMe", "retainMeValue" }, { "removeMe", "removeMeValue" }, { "previouslyRemoved", "previouslyRemovedValue" } }; object dummy = tempData["previouslyRemoved"]; // mark value for removal ControllerContext controllerContext = GetControllerContext(tempData); TempDataValueProviderFactory factory = new TempDataValueProviderFactory(); // Act IValueProvider valueProvider = factory.GetValueProvider(controllerContext); ValueProviderResult nonExistentResult = valueProvider.GetValue("nonExistent"); ValueProviderResult removeMeResult = valueProvider.GetValue("removeme"); // Assert Assert.Null(nonExistentResult); Assert.Equal("removeMeValue", removeMeResult.AttemptedValue); Assert.Equal(CultureInfo.InvariantCulture, removeMeResult.Culture); // Verify that keys have been removed or retained correctly by the provider Mock<ITempDataProvider> mockTempDataProvider = new Mock<ITempDataProvider>(); string[] retainedKeys = null; mockTempDataProvider .Setup(o => o.SaveTempData(controllerContext, It.IsAny<IDictionary<string, object>>())) .Callback( delegate(ControllerContext cc, IDictionary<string, object> d) { retainedKeys = d.Keys.ToArray(); }); tempData.Save(controllerContext, mockTempDataProvider.Object); Assert.Equal(expectedRetainedKeys, retainedKeys); }
public void KeepRetainsSpecificKeysWhenSavingDictionary() { // Arrange NullTempDataProvider provider = new NullTempDataProvider(); TempDataDictionary tempData = new TempDataDictionary(); Mock <ControllerContext> controllerContext = new Mock <ControllerContext>(); controllerContext.Setup(c => c.HttpContext.Request).Returns(new Mock <HttpRequestBase>().Object); tempData["Foo"] = "Foo"; tempData["Bar"] = "Bar"; // Act tempData.Keep("Foo"); object value = tempData["Bar"]; tempData.Save(controllerContext.Object, provider); // Assert Assert.IsTrue(tempData.ContainsKey("Foo"), "tempData should contain 'Foo'"); Assert.IsFalse(tempData.ContainsKey("Bar"), "tempData should not contain 'Bar'"); }
public void EnumeratingTempDataAsIEnmerableMarksValuesForDeletion() { // Arrange NullTempDataProvider provider = new NullTempDataProvider(); TempDataDictionary tempData = new TempDataDictionary(); Mock<ControllerContext> controllerContext = new Mock<ControllerContext>(); tempData["Foo"] = "Foo"; tempData["Bar"] = "Bar"; // Act IEnumerator enumerator = ((IEnumerable)tempData).GetEnumerator(); while (enumerator.MoveNext()) { object value = enumerator.Current; } tempData.Save(controllerContext.Object, provider); // Assert Assert.False(tempData.ContainsKey("Foo")); Assert.False(tempData.ContainsKey("Bar")); }
public void LoadAndSaveAreCaseInsensitive() { // Arrange Dictionary <string, object> data = new Dictionary <string, object>(); data["Foo"] = "Foo"; data["Bar"] = "Bar"; TestTempDataProvider provider = new TestTempDataProvider(data); Mock <ControllerContext> controllerContext = new Mock <ControllerContext>(); TempDataDictionary tempData = new TempDataDictionary(); // Act tempData.Load(controllerContext.Object, provider); object value = tempData["FOO"]; tempData.Save(controllerContext.Object, provider); // Assert Assert.False(tempData.ContainsKey("foo")); Assert.True(tempData.ContainsKey("bar")); }
public void TempData_EnumeratingDictionary_MarksKeysForDeletion() { // Arrange var tempData = new TempDataDictionary(new DefaultHttpContext(), new NullTempDataProvider()); tempData["Foo"] = "Foo"; tempData["Bar"] = "Bar"; // Act var enumerator = tempData.GetEnumerator(); while (enumerator.MoveNext()) { var value = enumerator.Current; } tempData.Save(); // Assert Assert.False(tempData.ContainsKey("Foo")); Assert.False(tempData.ContainsKey("Bar")); }
public void OnPageExecuting_ReadsTempDataPropertiesWithoutPrefix() { // Arrange var httpContext = new DefaultHttpContext(); var tempData = new TempDataDictionary(httpContext, Mock.Of <ITempDataProvider>()) { { "TempDataProperty-Test", "Prefix-Value" }, { "Test", "Value" } }; tempData.Save(); var model = new TestPageModel(); var filter = CreatePageSaveTempDataPropertyFilter(tempData, string.Empty); filter.Subject = model; var context = new PageHandlerExecutingContext( new PageContext() { ActionDescriptor = new CompiledPageActionDescriptor(), HttpContext = httpContext, RouteData = new RouteData(), }, Array.Empty <IFilterMetadata>(), null, new Dictionary <string, object>(), model); // Act filter.OnPageHandlerExecuting(context); // Assert Assert.Equal("Value", model.Test); Assert.Null(model.Test2); }
public void EnumeratingTempDataAsIEnmerableMarksValuesForDeletion() { // Arrange NullTempDataProvider provider = new NullTempDataProvider(); TempDataDictionary tempData = new TempDataDictionary(); Mock <ControllerContext> controllerContext = new Mock <ControllerContext>(); tempData["Foo"] = "Foo"; tempData["Bar"] = "Bar"; // Act IEnumerator enumerator = ((IEnumerable)tempData).GetEnumerator(); while (enumerator.MoveNext()) { object value = enumerator.Current; } tempData.Save(controllerContext.Object, provider); // Assert Assert.False(tempData.ContainsKey("Foo")); Assert.False(tempData.ContainsKey("Bar")); }
public void EnumeratingDictionaryMarksValuesForDeletion() { // Arrange NullTempDataProvider provider = new NullTempDataProvider(); TempDataDictionary tempData = new TempDataDictionary(); Mock <ControllerContext> controllerContext = new Mock <ControllerContext>(); tempData["Foo"] = "Foo"; tempData["Bar"] = "Bar"; // Act IEnumerator <KeyValuePair <string, object> > enumerator = tempData.GetEnumerator(); while (enumerator.MoveNext()) { object value = enumerator.Current; } tempData.Save(controllerContext.Object, provider); // Assert Assert.IsFalse(tempData.ContainsKey("Foo"), "tempData should not contain 'Foo'"); Assert.IsFalse(tempData.ContainsKey("Bar"), "tempData should not contain 'Bar'"); }
public void PeekDoesNotMarkKeyAsRead() { // Arrange NullTempDataProvider provider = new NullTempDataProvider(); TempDataDictionary tempData = new TempDataDictionary(); Mock<ControllerContext> controllerContext = new Mock<ControllerContext>(); tempData["Bar"] = "barValue"; // Act object value = tempData.Peek("bar"); tempData.Save(controllerContext.Object, provider); // Assert Assert.Equal("barValue", value); Assert.True(tempData.ContainsKey("Bar")); }
public void KeepRetainsSpecificKeysWhenSavingDictionary() { // Arrange NullTempDataProvider provider = new NullTempDataProvider(); TempDataDictionary tempData = new TempDataDictionary(); Mock<ControllerContext> controllerContext = new Mock<ControllerContext>(); controllerContext.Setup(c => c.HttpContext.Request).Returns(new Mock<HttpRequestBase>().Object); tempData["Foo"] = "Foo"; tempData["Bar"] = "Bar"; // Act tempData.Keep("Foo"); object value = tempData["Bar"]; tempData.Save(controllerContext.Object, provider); // Assert Assert.True(tempData.ContainsKey("Foo")); Assert.False(tempData.ContainsKey("Bar")); }
public void TempData_RemovalOfKeysAreCaseInsensitive() { var tempData = new TempDataDictionary(GetHttpContextAccessor(), new NullTempDataProvider()); object fooValue; tempData["Foo"] = "Foo"; tempData["Bar"] = "Bar"; // Act tempData.TryGetValue("foo", out fooValue); var barValue = tempData["bar"]; tempData.Save(); // Assert Assert.False(tempData.ContainsKey("Foo")); Assert.False(tempData.ContainsKey("Boo")); }
public void TempData_LoadAndSaveAreCaseInsensitive() { // Arrange var data = new Dictionary<string, object>(); data["Foo"] = "Foo"; data["Bar"] = "Bar"; var provider = new TestTempDataProvider(data); var tempData = new TempDataDictionary(GetHttpContextAccessor(), provider); // Act tempData.Load(); var value = tempData["FOO"]; tempData.Save(); // Assert Assert.False(tempData.ContainsKey("foo")); Assert.True(tempData.ContainsKey("bar")); }
public void TempData_Peek_DoesNotMarkKeyForDeletion() { // Arrange var tempData = new TempDataDictionary(GetHttpContextAccessor(), new NullTempDataProvider()); tempData["Bar"] = "barValue"; // Act var value = tempData.Peek("bar"); tempData.Save(); // Assert Assert.Equal("barValue", value); Assert.True(tempData.ContainsKey("Bar")); }
public void TempData_Keep_RetainsSpecificKeysWhenSavingDictionary() { // Arrange var tempData = new TempDataDictionary(GetHttpContextAccessor(), new NullTempDataProvider()); tempData["Foo"] = "Foo"; tempData["Bar"] = "Bar"; // Act var foo = tempData["Foo"]; var bar = tempData["Bar"]; tempData.Keep("Foo"); tempData.Save(); // Assert Assert.True(tempData.ContainsKey("Foo")); Assert.False(tempData.ContainsKey("Bar")); }
public void TryGetValueMarksKeyForDeletion() { NullTempDataProvider provider = new NullTempDataProvider(); TempDataDictionary tempData = new TempDataDictionary(); Mock<ControllerContext> controllerContext = new Mock<ControllerContext>(); object value; tempData["Foo"] = "Foo"; // Act tempData.TryGetValue("Foo", out value); tempData.Save(controllerContext.Object, provider); // Assert Assert.IsFalse(tempData.ContainsKey("Foo"), "tempData should not contain 'Foo'"); }
public void SaveRemovesKeysThatWereRead() { // Arrange NullTempDataProvider provider = new NullTempDataProvider(); TempDataDictionary tempData = new TempDataDictionary(); Mock<ControllerContext> controllerContext = new Mock<ControllerContext>(); tempData["Foo"] = "Foo"; tempData["Bar"] = "Bar"; // Act object value = tempData["Foo"]; tempData.Save(controllerContext.Object, provider); // Assert Assert.IsFalse(tempData.ContainsKey("Foo"), "tempData should not contain 'Foo'"); Assert.IsTrue(tempData.ContainsKey("Bar"), "tempData should contain 'Bar'"); }
public void SaveRetainsAllKeys() { // Arrange NullTempDataProvider provider = new NullTempDataProvider(); TempDataDictionary tempData = new TempDataDictionary(); Mock<ControllerContext> controllerContext = new Mock<ControllerContext>(); tempData["Foo"] = "Foo"; tempData["Bar"] = "Bar"; // Act tempData.Save(controllerContext.Object, provider); // Assert Assert.IsTrue(tempData.ContainsKey("Foo"), "tempData should contain 'Foo'"); Assert.IsTrue(tempData.ContainsKey("Bar"), "tempData should contain 'Bar'"); }
public void RemovalOfKeysAreCaseInsensitive() { NullTempDataProvider provider = new NullTempDataProvider(); TempDataDictionary tempData = new TempDataDictionary(); Mock<ControllerContext> controllerContext = new Mock<ControllerContext>(); object fooValue; tempData["Foo"] = "Foo"; tempData["Bar"] = "Bar"; // Act tempData.TryGetValue("foo", out fooValue); object barValue = tempData["bar"]; tempData.Save(controllerContext.Object, provider); // Assert Assert.IsFalse(tempData.ContainsKey("Foo"), "tempData should not contain 'Foo'"); Assert.IsFalse(tempData.ContainsKey("Boo"), "tempData should not contain 'Bar'"); }
public void PeekDoesNotMarkKeyAsRead() { // Arrange NullTempDataProvider provider = new NullTempDataProvider(); TempDataDictionary tempData = new TempDataDictionary(); Mock<ControllerContext> controllerContext = new Mock<ControllerContext>(); tempData["Bar"] = "barValue"; // Act object value = tempData.Peek("bar"); tempData.Save(controllerContext.Object, provider); // Assert Assert.AreEqual("barValue", value, "Incorrect value read from Peek()."); Assert.IsTrue(tempData.ContainsKey("Bar"), "Peek() shouldn't have removed 'Bar' from TempData."); }
public void LoadAndSaveAreCaseInsensitive() { // Arrange Dictionary<string, object> data = new Dictionary<string, object>(); data["Foo"] = "Foo"; data["Bar"] = "Bar"; TestTempDataProvider provider = new TestTempDataProvider(data); Mock<ControllerContext> controllerContext = new Mock<ControllerContext>(); TempDataDictionary tempData = new TempDataDictionary(); // Act tempData.Load(controllerContext.Object, provider); object value = tempData["FOO"]; tempData.Save(controllerContext.Object, provider); // Assert Assert.IsFalse(tempData.ContainsKey("foo"), "tempData should not contain 'Foo'"); Assert.IsTrue(tempData.ContainsKey("bar"), "tempData should contain 'Bar'"); }