public void OnBeforeTestExecute() { srsly = new RedisJSONSerializer(); this.items = new RedisSessionStateItemCollection( new Dictionary <string, byte[]> { { "a", Encoding.UTF8.GetBytes(srsly.SerializeOne("a", "x")) }, { "b", Encoding.UTF8.GetBytes(srsly.SerializeOne("b", "y")) }, { "c", Encoding.UTF8.GetBytes(srsly.SerializeOne("c", "z")) } }, "fakeCollection"); }
public void AddRemoveAndDirtyCheckReferenceTypesTest() { // add a list to session this.items["refType"] = new List <string>(); // get a reference to it List <string> myList = this.items["refType"] as List <string>; // alternatively, make a list List <int> myOtherList = new List <int>(); // add it to session this.items["otherRefType"] = myOtherList; bool listCameBack = false; bool otherListCameBack = false; // test that these come back from the enumerator foreach (KeyValuePair <string, string> changed in this.items.GetChangedObjectsEnumerator()) { if (changed.Key == "refType" && changed.Value == srsly.SerializeOne(changed.Key, myList)) { listCameBack = true; } else if (changed.Key == "otherRefType" && changed.Value == srsly.SerializeOne(changed.Key, myOtherList)) { otherListCameBack = true; } } Assert.IsTrue(listCameBack, "failed to return string list"); Assert.IsTrue(otherListCameBack, "failed to return int list"); // test that if we get the changed objects again, they won't come back listCameBack = false; otherListCameBack = false; foreach (KeyValuePair <string, string> changed in this.items.GetChangedObjectsEnumerator()) { if (changed.Key == "refType") { listCameBack = true; } else if (changed.Key == "otherRefType") { otherListCameBack = true; } } Assert.IsFalse(listCameBack, "incorrectly returned string list"); Assert.IsFalse(otherListCameBack, "incorrectly returned int list"); // now let's modify a list myOtherList.Add(1); otherListCameBack = false; foreach (KeyValuePair <string, string> changed in this.items.GetChangedObjectsEnumerator()) { if (changed.Key == "otherRefType" && changed.Value == srsly.SerializeOne(changed.Key, myOtherList)) { otherListCameBack = true; } } Assert.IsTrue(otherListCameBack, "list that was modified not returned when it should have been"); // ok, let's see if modifying the list, then undoing that modification results // in it being returned (it shouldn't) myList.Add("a"); myList.Clear(); listCameBack = false; foreach (KeyValuePair <string, string> changed in this.items.GetChangedObjectsEnumerator()) { if (changed.Key == "refType" && changed.Value == srsly.SerializeOne(changed.Key, myList)) { listCameBack = true; } } Assert.IsFalse(listCameBack, "list that was modified then reset should not come back"); }