public void TempDataDictionaryCreatesEmptyDictionaryIfProviderReturnsNull()
        {
            // Arrange
            TempDataDictionary   tempDataDictionary = new TempDataDictionary();
            NullTempDataProvider provider           = new NullTempDataProvider();

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

            // Assert
            Assert.Empty(tempDataDictionary);
        }
        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 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 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"));
        }
        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'");
        }
Example #6
0
        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 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 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 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.IsFalse(tempData.ContainsKey("Foo"), "tempData should not contain 'Foo'");
            Assert.IsFalse(tempData.ContainsKey("Bar"), "tempData should not contain '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 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"));
        }
Example #12
0
        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 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.False(tempData.ContainsKey("Foo"));
            Assert.False(tempData.ContainsKey("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"));
        }
Example #15
0
        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 SystemController()
 {
     TempDataProvider = new NullTempDataProvider();
 }
        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 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"));
        }