Exemple #1
0
        public object Buscar(string key)
        {
            var valor = _tempData[key];

            _tempData.Keep(key);
            return(valor);
        }
        public void Keep_DoesNotThrowException_WhenDataIsNotLoaded()
        {
            // Arrange
            var tempData = new TempDataDictionary(GetHttpContextAccessor(), new SessionStateTempDataProvider());

            // Act & Assert
            tempData.Keep();
        }
        public void Does_not_throw_when_key_has_been_kept()
        {
            string key = "testkey";

            var tempData = new TempDataDictionary
            {
                { key, new object() }
            };

            tempData.Keep(key);
            tempData.AssertKept(key);
        }
        public void Does_not_throw_when_key_has_been_kept()
        {
            string key = "testkey";

            var tempData = new TempDataDictionary
            {
                {key, new object()}
            };

            tempData.Keep(key);
            tempData.AssertKept(key);
        }
        public void Throws_when_key_has_not_been_kept()
        {
            string key = "testkey";

            var tempData = new TempDataDictionary
            {
                {key, new object()}
            };

            tempData.Keep("nottestkey");

            Assert.Throws<MvcContrib.TestHelper.AssertionException>(
                () => tempData.AssertKept(key), "Key 'testkey' not kept.");
        }
        public void Throws_when_key_has_not_been_kept()
        {
            string key = "testkey";

            var tempData = new TempDataDictionary
            {
                { key, new object() }
            };

            tempData.Keep("nottestkey");

            Assert.Throws <MvcContrib.TestHelper.AssertionException>(
                () => tempData.AssertKept(key), "Key 'testkey' not kept.");
        }
 public static string FeedbackMessage(this TempDataDictionary tempData, bool keep = false)
 {
     if (tempData != null)
     {
         var value = tempData[BaseController.FeedbackMessageKey];
         if (keep)
         {
             tempData.Keep(BaseController.FeedbackMessageKey);
         }
         if (value != null)
         {
             return(value.ToString());
         }
     }
     return(null);
 }
    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 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'");
        }
Exemple #10
0
        private static void _AddMessages(TempDataDictionary tempData, BarData bar, IEnumerable <string> messages)
        {
            var key = GetTempDataKeyFor(bar);

            if (tempData == null)
            {
                throw new ArgumentNullException("tempData");
            }

            if (!tempData.ContainsKey(key))
            {
                tempData[key] = new List <string>();
            }

            var statusData = tempData[key] as IList <string>;

            messages.ForEach(x => statusData.Add(x));
            tempData.Keep(key);             // Ensure list will be kept around..
        }
        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 static string SigningEmailAddress(this TempDataDictionary tempData, bool keep = true)
        {
            if (tempData == null || !tempData.ContainsKey(SigningEmailAddressKey))
            {
                return(null);
            }

            var value = tempData[SigningEmailAddressKey];

            if (keep)
            {
                tempData.Keep(SigningEmailAddressKey);
            }
            else
            {
                tempData.Remove(SigningEmailAddressKey);
            }

            return(value != null?value.ToString() : null);
        }
Exemple #13
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 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"));
        }
 /// <summary>
 /// Saves the message list to the <see cref="TempDataDictionary"/>.
 /// </summary>
 private void SaveMessageList()
 {
     _tempData[typeof(MessageManager).FullName] = _messageList;
     _tempData.Keep(typeof(MessageManager).FullName);
 }
        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"));
        }
        private static void _AddMessages(TempDataDictionary tempData, BarData bar, IEnumerable<string> messages)
        {
            var key = GetTempDataKeyFor(bar);

            if (tempData == null) throw new ArgumentNullException("tempData");

            if (!tempData.ContainsKey(key))
            {
                tempData[key] = new List<string>();
            }

            var statusData = tempData[key] as IList<string>;
            messages.ForEach(x => statusData.Add(x));
            tempData.Keep(key); // Ensure list will be kept around..
        }
        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"));
        }
Exemple #19
0
 public void Keep()
 {
     _tempData.Keep(Key);
 }
Exemple #20
0
 public static void Keep <T>(this TempDataDictionary tempData)
 {
     tempData.Keep(typeof(T).ToGenericTypeString());
 }