本文整理汇总了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"));
}
示例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"));
}
示例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'");
}
示例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"));
}
示例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'");
}
示例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);
}
示例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"));
}
示例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'");
}
示例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"));
}
示例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"));
}
示例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"));
}
示例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"));
}
示例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"));
}
示例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'");
}
示例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'");
}