public void TempData_Load_CreatesEmptyDictionaryIfProviderReturnsNull()
        {
            // Arrange
            var tempData = new TempDataDictionary(GetHttpContextAccessor(), new NullTempDataProvider());

            // Act
            tempData.Load();

            // Assert
            Assert.Empty(tempData);
        }
    public void TempData_Load_CreatesEmptyDictionaryIfProviderReturnsNull()
    {
        // Arrange
        var tempData = new TempDataDictionary(new DefaultHttpContext(), new NullTempDataProvider());

        // Act
        tempData.Load();

        // Assert
        Assert.Empty(tempData);
    }
        public void TempDataDictionaryCreatesEmptyDictionaryIfProviderReturnsNull()
        {
            // Arrange
            TempDataDictionary tempDataDictionary = new TempDataDictionary();
            NullTempDataProvider provider = new NullTempDataProvider();

            // Act
            tempDataDictionary.Load(null /* controllerContext */, provider);

            // Assert
            Assert.AreEqual(tempDataDictionary.Count, 0);
        }
        public void TempDataDictionaryCreatesEmptyDictionaryIfProviderReturnsNull()
        {
            // Arrange
            TempDataDictionary   tempDataDictionary = new TempDataDictionary();
            NullTempDataProvider provider           = new NullTempDataProvider();

            // Act
            tempDataDictionary.Load(null /* controllerContext */, provider);

            // Assert
            Assert.Empty(tempDataDictionary);
        }
    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 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 TempDataSavedWhenControllerThrows() {
            // Arrange
            BrokenController controller = new BrokenController() { ValidateRequest = false };
            Mock<HttpContextBase> mockContext = HttpContextHelpers.GetMockHttpContext();
            HttpSessionStateBase session = GetEmptySession();
            mockContext.Setup(o => o.Session).Returns(session);
            RouteData rd = new RouteData();
            rd.Values.Add("action", "Crash");
            controller.ControllerContext = new ControllerContext(mockContext.Object, rd, controller);

            // Assert
            ExceptionHelper.ExpectException<InvalidOperationException>(
                delegate {
                    ((IController)controller).Execute(controller.ControllerContext.RequestContext);
                });
            Assert.AreNotEqual(mockContext.Object.Session[SessionStateTempDataProvider.TempDataSessionStateKey], null);
            TempDataDictionary tempData = new TempDataDictionary();
            tempData.Load(controller.ControllerContext, controller.TempDataProvider);
            Assert.AreEqual(tempData["Key1"], "Value1");
        }
        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 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'");
        }