public static void clear() { TempData.Clear(); listErrors.Clear(); listWarnings.Clear(); listSuccess.Clear(); listInfos.Clear(); }
public OperationsHelper(OperationRouteValue routeValue, TempDataDictionary tempData, UrlHelper urlHelper) { _routeValue = routeValue; _tempData = tempData; _urlHelper = urlHelper; Changes = tempData.Get <List <OperationViewModel> >() ?? new List <OperationViewModel>(); CurrentOperation = (Operation)Enum.Parse(typeof(Operation), _routeValue.OperationId.ToString()); if (CurrentOperation.Equals(Operation.NotSet)) { _tempData.Clear(); CurrentOperation = AllowedOperations().First(); } }
public void TempDataIsADictionary() { // Arrange TempDataDictionary tempData = new TempDataDictionary(); // Act tempData["Key1"] = "Value1"; tempData.Add("Key2", "Value2"); ((ICollection<KeyValuePair<string, object>>)tempData).Add(new KeyValuePair<string,object>("Key3", "Value3")); // Assert (IDictionary) Assert.AreEqual(3, tempData.Count, "tempData should contain 3 items"); Assert.IsTrue(tempData.Remove("Key1"), "The key should be present"); Assert.IsFalse(tempData.Remove("Key4"), "The key should not be present"); Assert.IsTrue(tempData.ContainsValue("Value2"), "The value should be present"); Assert.IsFalse(tempData.ContainsValue("Value1"), "The value should not be present"); Assert.IsNull(tempData["Key6"], "The key should not be present"); IEnumerator tempDataEnumerator = tempData.GetEnumerator(); tempDataEnumerator.Reset(); while (tempDataEnumerator.MoveNext()) { KeyValuePair<string, object> pair = (KeyValuePair<string, object>)tempDataEnumerator.Current; Assert.IsTrue(((ICollection<KeyValuePair<string, object>>)tempData).Contains(pair), "The key/value pair should be present"); } // Assert (ICollection) foreach (string key in tempData.Keys) { Assert.IsTrue(((ICollection<KeyValuePair<string, object>>)tempData).Contains(new KeyValuePair<string, object>(key, tempData[key])), "The key/value pair should be present"); } foreach (string value in tempData.Values) { Assert.IsTrue(tempData.ContainsValue(value)); } foreach (string key in ((IDictionary<string, object>)tempData).Keys) { Assert.IsTrue(tempData.ContainsKey(key), "The key should be present"); } foreach (string value in ((IDictionary<string, object>)tempData).Values) { Assert.IsTrue(tempData.ContainsValue(value)); } KeyValuePair<string, object>[] keyValuePairArray = new KeyValuePair<string, object>[tempData.Count]; ((ICollection<KeyValuePair<string, object>>)tempData).CopyTo(keyValuePairArray, 0); Assert.IsFalse(((ICollection<KeyValuePair<string, object>>)tempData).IsReadOnly, "The dictionary should not be read-only."); Assert.IsFalse(((ICollection<KeyValuePair<string, object>>)tempData).Remove(new KeyValuePair<string, object>("Key5", "Value5")), "The key/value pair should not be present"); IEnumerator<KeyValuePair<string, object>> keyValuePairEnumerator = ((ICollection<KeyValuePair<string, object>>)tempData).GetEnumerator(); keyValuePairEnumerator.Reset(); while (keyValuePairEnumerator.MoveNext()) { KeyValuePair<string, object> pair = keyValuePairEnumerator.Current; Assert.IsTrue(((ICollection<KeyValuePair<string, object>>)tempData).Contains(pair), "The key/value pair should be present"); } // Act tempData.Clear(); // Assert Assert.AreEqual(0, tempData.Count, "tempData should not contain any items"); IEnumerator y = ((IEnumerable)tempData).GetEnumerator(); while (y.MoveNext()) { Assert.Fail("There should not be any elements in tempData"); } }
public void TempDataIsADictionary() { // Arrange TempDataDictionary tempData = new TempDataDictionary(); // Act tempData["Key1"] = "Value1"; tempData.Add("Key2", "Value2"); ((ICollection <KeyValuePair <string, object> >)tempData).Add(new KeyValuePair <string, object>("Key3", "Value3")); // Assert (IDictionary) Assert.Equal(3, tempData.Count); Assert.True(tempData.Remove("Key1")); Assert.False(tempData.Remove("Key4")); Assert.True(tempData.ContainsValue("Value2")); Assert.False(tempData.ContainsValue("Value1")); Assert.Null(tempData["Key6"]); IEnumerator tempDataEnumerator = tempData.GetEnumerator(); tempDataEnumerator.Reset(); while (tempDataEnumerator.MoveNext()) { KeyValuePair <string, object> pair = (KeyValuePair <string, object>)tempDataEnumerator.Current; Assert.True(((ICollection <KeyValuePair <string, object> >)tempData).Contains(pair)); } // Assert (ICollection) foreach (string key in tempData.Keys) { Assert.True(((ICollection <KeyValuePair <string, object> >)tempData).Contains(new KeyValuePair <string, object>(key, tempData[key]))); } foreach (string value in tempData.Values) { Assert.True(tempData.ContainsValue(value)); } foreach (string key in ((IDictionary <string, object>)tempData).Keys) { Assert.True(tempData.ContainsKey(key)); } foreach (string value in ((IDictionary <string, object>)tempData).Values) { Assert.True(tempData.ContainsValue(value)); } KeyValuePair <string, object>[] keyValuePairArray = new KeyValuePair <string, object> [tempData.Count]; ((ICollection <KeyValuePair <string, object> >)tempData).CopyTo(keyValuePairArray, 0); Assert.False(((ICollection <KeyValuePair <string, object> >)tempData).IsReadOnly); Assert.False(((ICollection <KeyValuePair <string, object> >)tempData).Remove(new KeyValuePair <string, object>("Key5", "Value5"))); IEnumerator <KeyValuePair <string, object> > keyValuePairEnumerator = ((ICollection <KeyValuePair <string, object> >)tempData).GetEnumerator(); keyValuePairEnumerator.Reset(); while (keyValuePairEnumerator.MoveNext()) { KeyValuePair <string, object> pair = keyValuePairEnumerator.Current; Assert.True(((ICollection <KeyValuePair <string, object> >)tempData).Contains(pair)); } // Act tempData.Clear(); // Assert Assert.Empty(tempData); }
public void TempDataIsADictionary() { // Arrange TempDataDictionary tempData = new TempDataDictionary(); // Act tempData["Key1"] = "Value1"; tempData.Add("Key2", "Value2"); ((ICollection<KeyValuePair<string, object>>)tempData).Add(new KeyValuePair<string, object>("Key3", "Value3")); // Assert (IDictionary) Assert.Equal(3, tempData.Count); Assert.True(tempData.Remove("Key1")); Assert.False(tempData.Remove("Key4")); Assert.True(tempData.ContainsValue("Value2")); Assert.False(tempData.ContainsValue("Value1")); Assert.Null(tempData["Key6"]); IEnumerator tempDataEnumerator = tempData.GetEnumerator(); tempDataEnumerator.Reset(); while (tempDataEnumerator.MoveNext()) { KeyValuePair<string, object> pair = (KeyValuePair<string, object>)tempDataEnumerator.Current; Assert.True(((ICollection<KeyValuePair<string, object>>)tempData).Contains(pair)); } // Assert (ICollection) foreach (string key in tempData.Keys) { Assert.True(((ICollection<KeyValuePair<string, object>>)tempData).Contains(new KeyValuePair<string, object>(key, tempData[key]))); } foreach (string value in tempData.Values) { Assert.True(tempData.ContainsValue(value)); } foreach (string key in ((IDictionary<string, object>)tempData).Keys) { Assert.True(tempData.ContainsKey(key)); } foreach (string value in ((IDictionary<string, object>)tempData).Values) { Assert.True(tempData.ContainsValue(value)); } KeyValuePair<string, object>[] keyValuePairArray = new KeyValuePair<string, object>[tempData.Count]; ((ICollection<KeyValuePair<string, object>>)tempData).CopyTo(keyValuePairArray, 0); Assert.False(((ICollection<KeyValuePair<string, object>>)tempData).IsReadOnly); Assert.False(((ICollection<KeyValuePair<string, object>>)tempData).Remove(new KeyValuePair<string, object>("Key5", "Value5"))); IEnumerator<KeyValuePair<string, object>> keyValuePairEnumerator = ((ICollection<KeyValuePair<string, object>>)tempData).GetEnumerator(); keyValuePairEnumerator.Reset(); while (keyValuePairEnumerator.MoveNext()) { KeyValuePair<string, object> pair = keyValuePairEnumerator.Current; Assert.True(((ICollection<KeyValuePair<string, object>>)tempData).Contains(pair)); } // Act tempData.Clear(); // Assert Assert.Empty(tempData); }
public void TempDataIsADictionary() { // Arrange TempDataDictionary tempData = new TempDataDictionary(); // Act tempData["Key1"] = "Value1"; tempData.Add("Key2", "Value2"); ((ICollection <KeyValuePair <string, object> >)tempData).Add(new KeyValuePair <string, object>("Key3", "Value3")); // Assert (IDictionary) Assert.AreEqual(3, tempData.Count, "tempData should contain 3 items"); Assert.IsTrue(tempData.Remove("Key1"), "The key should be present"); Assert.IsFalse(tempData.Remove("Key4"), "The key should not be present"); Assert.IsTrue(tempData.ContainsValue("Value2"), "The value should be present"); Assert.IsFalse(tempData.ContainsValue("Value1"), "The value should not be present"); Assert.IsNull(tempData["Key6"], "The key should not be present"); IEnumerator tempDataEnumerator = tempData.GetEnumerator(); tempDataEnumerator.Reset(); while (tempDataEnumerator.MoveNext()) { KeyValuePair <string, object> pair = (KeyValuePair <string, object>)tempDataEnumerator.Current; Assert.IsTrue(((ICollection <KeyValuePair <string, object> >)tempData).Contains(pair), "The key/value pair should be present"); } // Assert (ICollection) foreach (string key in tempData.Keys) { Assert.IsTrue(((ICollection <KeyValuePair <string, object> >)tempData).Contains(new KeyValuePair <string, object>(key, tempData[key])), "The key/value pair should be present"); } foreach (string value in tempData.Values) { Assert.IsTrue(tempData.ContainsValue(value)); } foreach (string key in ((IDictionary <string, object>)tempData).Keys) { Assert.IsTrue(tempData.ContainsKey(key), "The key should be present"); } foreach (string value in ((IDictionary <string, object>)tempData).Values) { Assert.IsTrue(tempData.ContainsValue(value)); } KeyValuePair <string, object>[] keyValuePairArray = new KeyValuePair <string, object> [tempData.Count]; ((ICollection <KeyValuePair <string, object> >)tempData).CopyTo(keyValuePairArray, 0); Assert.IsFalse(((ICollection <KeyValuePair <string, object> >)tempData).IsReadOnly, "The dictionary should not be read-only."); Assert.IsFalse(((ICollection <KeyValuePair <string, object> >)tempData).Remove(new KeyValuePair <string, object>("Key5", "Value5")), "The key/value pair should not be present"); IEnumerator <KeyValuePair <string, object> > keyValuePairEnumerator = ((ICollection <KeyValuePair <string, object> >)tempData).GetEnumerator(); keyValuePairEnumerator.Reset(); while (keyValuePairEnumerator.MoveNext()) { KeyValuePair <string, object> pair = keyValuePairEnumerator.Current; Assert.IsTrue(((ICollection <KeyValuePair <string, object> >)tempData).Contains(pair), "The key/value pair should be present"); } // Act tempData.Clear(); // Assert Assert.AreEqual(0, tempData.Count, "tempData should not contain any items"); IEnumerator y = ((IEnumerable)tempData).GetEnumerator(); while (y.MoveNext()) { Assert.Fail("There should not be any elements in tempData"); } }