Esempio n. 1
0
        public SingleThreadedTests()
        {
            srsly = new RedisJsonSerializer();

            this.items = new RedisSessionStateItemCollection(
                new Dictionary <string, string> {
                { "a", srsly.SerializeOne("x") },
                { "b", srsly.SerializeOne("y") },
                { "c", srsly.SerializeOne("z") }
            },
                "fakeCollection");
        }
Esempio n. 2
0
        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(myList))
                {
                    listCameBack = true;
                }
                else if (changed.Key == "otherRefType" &&
                         changed.Value == srsly.SerializeOne(myOtherList))
                {
                    otherListCameBack = true;
                }
            }

            Assert.True(listCameBack, "failed to return string list");
            Assert.True(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.False(listCameBack, "incorrectly returned string list");
            Assert.False(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(myOtherList))
                {
                    otherListCameBack = true;
                }
            }

            Assert.True(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(myList))
                {
                    listCameBack = true;
                }
            }

            Assert.False(listCameBack, "list that was modified then reset should not come back");
        }