当前位置: 首页>>代码示例>>C#>>正文


C# TempDataDictionary.Save方法代码示例

本文整理汇总了C#中TempDataDictionary.Save方法的典型用法代码示例。如果您正苦于以下问题:C# TempDataDictionary.Save方法的具体用法?C# TempDataDictionary.Save怎么用?C# TempDataDictionary.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TempDataDictionary的用法示例。


在下文中一共展示了TempDataDictionary.Save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TempData_TryGetValue_MarksKeyForDeletion

        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"));
        }
开发者ID:4myBenefits,项目名称:Mvc,代码行数:13,代码来源:TempDataDictionaryTest.cs

示例2: TempData_Save_RemovesKeysThatWereRead

        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"));
        }
开发者ID:huoxudong125,项目名称:Mvc,代码行数:15,代码来源:TempDataDictionaryTest.cs

示例3: KeepRetainsAllKeysWhenSavingDictionary

        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'");
        }
开发者ID:adrianvallejo,项目名称:MVC3_Source,代码行数:17,代码来源:TempDataDictionaryTest.cs

示例4: TempData_EnumeratingDictionary_MarksKeysForDeletion

        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"));
        }
开发者ID:huoxudong125,项目名称:Mvc,代码行数:19,代码来源:TempDataDictionaryTest.cs

示例5: EnumeratingDictionaryMarksValuesForDeletion

        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'");
        }
开发者ID:consumentor,项目名称:Server,代码行数:19,代码来源:TempDataDictionaryTest.cs

示例6: GetValueProvider_CorrectlyRetainsOrRemovesKeys

        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);
        }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:41,代码来源:TempDataValueProviderFactoryTest.cs

示例7: EnumeratingTempDataAsIEnmerableMarksValuesForDeletion

        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"));
        }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:21,代码来源:TempDataDictionaryTest.cs

示例8: SaveRetainsAllKeys

        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'");
        }
开发者ID:consumentor,项目名称:Server,代码行数:15,代码来源:TempDataDictionaryTest.cs

示例9: PeekDoesNotMarkKeyAsRead

        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"));
        }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:16,代码来源:TempDataDictionaryTest.cs

示例10: TempData_RemovalOfKeysAreCaseInsensitive

        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"));
        }
开发者ID:huoxudong125,项目名称:Mvc,代码行数:16,代码来源:TempDataDictionaryTest.cs

示例11: TempData_LoadAndSaveAreCaseInsensitive

        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"));
        }
开发者ID:huoxudong125,项目名称:Mvc,代码行数:18,代码来源:TempDataDictionaryTest.cs

示例12: TempData_Peek_DoesNotMarkKeyForDeletion

        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"));
        }
开发者ID:huoxudong125,项目名称:Mvc,代码行数:14,代码来源:TempDataDictionaryTest.cs

示例13: TempData_Keep_RetainsSpecificKeysWhenSavingDictionary

        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"));
        }
开发者ID:huoxudong125,项目名称:Mvc,代码行数:17,代码来源:TempDataDictionaryTest.cs

示例14: TryGetValueMarksKeyForDeletion

        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'");
        }
开发者ID:consumentor,项目名称:Server,代码行数:14,代码来源:TempDataDictionaryTest.cs

示例15: SaveRemovesKeysThatWereRead

        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'");
        }
开发者ID:consumentor,项目名称:Server,代码行数:16,代码来源:TempDataDictionaryTest.cs


注:本文中的TempDataDictionary.Save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。