本文整理汇总了C#中TempDataDictionary.Keep方法的典型用法代码示例。如果您正苦于以下问题:C# TempDataDictionary.Keep方法的具体用法?C# TempDataDictionary.Keep怎么用?C# TempDataDictionary.Keep使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TempDataDictionary
的用法示例。
在下文中一共展示了TempDataDictionary.Keep方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Keep_DoesNotThrowException_WhenDataIsNotLoaded
public void Keep_DoesNotThrowException_WhenDataIsNotLoaded()
{
// Arrange
var tempData = new TempDataDictionary(GetHttpContextAccessor(), new SessionStateTempDataProvider());
// Act & Assert
tempData.Keep();
}
示例2: Does_not_throw_when_key_has_been_kept
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);
}
示例3: Throws_when_key_has_not_been_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.");
}
示例4: 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'");
}
示例5: 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"));
}
示例6: TempData_Keep_RetainsAllKeysWhenSavingDictionary
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"));
}
示例7: KeepRetainsSpecificKeysWhenSavingDictionary
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"));
}
示例8: _AddMessages
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..
}