public void TestStringsAndBooleans() { SmartPropertyBag spb1 = new SmartPropertyBag(); spb1.AddString("Name", "Habanero"); spb1.AddBoolean("Hot", true); spb1.AddValue("Scovilles", 35000); SmartPropertyBag spb2 = new SmartPropertyBag(); spb2.AddString("Name", "Jalapeno"); spb2.AddBoolean("Hot", false); spb2.AddValue("Scovilles", 22000); spb2.AddAlias("OtherGuysName", spb1, "Name"); spb2.AddAlias("OtherGuysHot", spb1, "Hot"); spb2.AddAlias("OtherGuysScovilles", spb1, "Scovilles"); Debug.WriteLine(spb2["OtherGuysHot"]); spb1["Hot"] = false; Debug.WriteLine(spb2["OtherGuysHot"]); Assert.IsTrue(!(bool)spb2["OtherGuysHot"], "OtherGuysHot is not false"); spb1.AddAlias("OtherGuysName", spb2, "Name"); spb1.AddAlias("OtherGuysHot", spb2, "Hot"); spb1.AddAlias("OtherGuysScovilles", spb2, "Scovilles"); SmartPropertyBag spb0 = new SmartPropertyBag(); spb0.AddChildSPB("Jalapeno", spb2); spb0.AddChildSPB("Habanero", spb1); Highpoint.Sage.Utility.Mementos.IMemento mem1 = spb0.Memento; spb1["Hot"] = false; spb1["Name"] = "Habañero"; spb1["Scovilles"] = 32000; spb2["Hot"] = true; spb2["Name"] = "Jalapeño"; spb2["Scovilles"] = 16000; Assert.IsTrue(!(bool)spb0["Habanero.Hot"], "Habanero.Hot is hot"); Assert.IsTrue("Habañero".Equals((string)spb0["Habanero.Name"]), "Habanero.Name is not Habañero"); Assert.IsTrue((double)spb0["Habanero.Scovilles"] == 32000, "Habanero.Scovilles is not 32000"); Assert.IsTrue((bool)spb0["Jalapeno.Hot"], "Jalapeno.Hot is not hot"); Assert.IsTrue("Jalapeño".Equals((string)spb0["Jalapeno.Name"]), "Jalapeno.Name is not Jalapeño"); Assert.IsTrue((double)spb0["Jalapeno.Scovilles"] == 16000, "Jalapeno.Scovilles is not 16000"); Highpoint.Sage.Utility.Mementos.IMemento mem2 = spb0.Memento; Debug.WriteLine(DiagnosticAids.DumpDictionary("Before", mem1.GetDictionary())); Debug.WriteLine(DiagnosticAids.DumpDictionary("After", mem2.GetDictionary())); spb0["Jalapeno.Hot"] = false; spb0["Habanero.Hot"] = true; spb0["Jalapeno.Scovilles"] = 12000; spb0["Habanero.Scovilles"] = 29000; Highpoint.Sage.Utility.Mementos.IMemento mem3 = spb0.Memento; Assert.IsTrue((bool)spb0["Habanero.Hot"], "Habanero.Hot is not hot"); Assert.IsTrue((double)spb0["Habanero.Scovilles"] == 29000, "Habanero.Scovilles is not 29000"); Assert.IsTrue(!(bool)spb0["Jalapeno.Hot"], "Jalapeno.Hot is not hot"); Assert.IsTrue((double)spb0["Jalapeno.Scovilles"] == 12000, "Jalapeno.Scovilles is not 12000"); Debug.WriteLine(DiagnosticAids.DumpDictionary("After more...", mem3.GetDictionary())); }
public void TestMementoCaching() { m_steve = 12; SmartPropertyBag spb1 = new SmartPropertyBag(); spb1.AddValue("Fred", 12); spb1.AddDelegate("Steve", new SmartPropertyBag.SPBDoubleDelegate(ComputeSteve)); spb1.AddString("Name", "SPB1"); Highpoint.Sage.Utility.Mementos.IMemento mem1 = spb1.Memento; Debug.WriteLine(DiagnosticAids.DumpDictionary("mem1", mem1.GetDictionary())); Highpoint.Sage.Utility.Mementos.IMemento mem2 = spb1.Memento; Debug.WriteLine(DiagnosticAids.DumpDictionary("mem2", mem2.GetDictionary())); Debug.WriteLine("The new snapshot is " + (mem1 == mem2?"":"not ") + "equal to the one preceding it.\r\n"); Assert.IsTrue(mem2 == mem1, "Memento 1 is not equal Memento 2"); Assert.IsTrue((double)spb1["Steve"] == 12, "Steve is not 12"); Assert.IsTrue("SPB1".Equals(spb1["Name"]), "Name is not SPB1"); Debug.WriteLine("Changing \"Fred\" to 14 from 12."); spb1["Fred"] = 14; Highpoint.Sage.Utility.Mementos.IMemento mem3 = spb1.Memento; Debug.WriteLine(DiagnosticAids.DumpDictionary("mem3", mem3.GetDictionary())); Debug.WriteLine("The new snapshot is " + (mem2 == mem3?"":"not ") + "equal to the one preceding it.\r\n"); Assert.IsTrue(mem2 != mem3, "Memento 2 is not not equal to Memento 3"); Assert.IsTrue((double)spb1["Fred"] == 14, "Fred is not 14"); Debug.WriteLine("Changing \"Name\" to \"spb1\" from \"SPB1\"."); spb1["Name"] = "spb1"; Highpoint.Sage.Utility.Mementos.IMemento mem3a = spb1.Memento; Debug.WriteLine(DiagnosticAids.DumpDictionary("mem3a", mem3a.GetDictionary())); Debug.WriteLine("The new snapshot is " + (mem2 == mem3a?"":"not ") + "equal to the one preceding it.\r\n"); Assert.IsTrue(mem2 != mem3a, "Memento 2 is equal to memento 3a"); spb1.AddValue("_Connie", 99); SmartPropertyBag spb2 = new SmartPropertyBag(); spb2.AddValue("_Pete", 14); spb1.AddAlias("Pete", spb2, "_Pete"); Highpoint.Sage.Utility.Mementos.IMemento mem4 = spb1.Memento; Highpoint.Sage.Utility.Mementos.IMemento mem5 = spb1.Memento; Debug.WriteLine("The new snapshot is " + (mem4 == mem5?"":"not ") + "equal to the one preceding it.\r\n"); Assert.IsTrue(mem5 == mem4, "Memento 5 is not equal to memento 4"); Debug.WriteLine("\r\nChanging a value in a foreign alias."); spb2["_Pete"] = 16; Highpoint.Sage.Utility.Mementos.IMemento mem6 = spb1.Memento; Debug.WriteLine("The new snapshot is " + (mem5 == mem6?"":"not ") + "equal to the one preceding it.\r\n"); Assert.IsTrue(mem5 != mem6, "Memento is equal to memento 6"); Debug.WriteLine("Capturing another snapshot without change."); Highpoint.Sage.Utility.Mementos.IMemento mem7 = spb1.Memento; Debug.WriteLine("The new snapshot is " + (mem6 == mem7?"":"not ") + "equal to the one preceding it.\r\n"); Assert.IsTrue(mem6 == mem7, "Memento 6 is not equal to memento 7"); Debug.WriteLine("Changing the data driving a delegate-computed value."); m_steve = 14; Highpoint.Sage.Utility.Mementos.IMemento mem8 = spb1.Memento; Debug.WriteLine("The new snapshot is " + (mem8 == mem7?"":"not ") + "equal to the one preceding it.\r\n"); Assert.IsTrue(mem7 != mem8, "Memento 7 is equal to memento 8"); Debug.WriteLine("\r\nWe will now test snapshotting's functionality as it pertains to subsidiaries."); SmartPropertyBag spb1_1 = new SmartPropertyBag(); spb1.AddChildSPB("Sub", spb1_1); spb1_1.AddValue("marine", 12); Highpoint.Sage.Utility.Mementos.IMemento mem9 = spb1.Memento; Debug.WriteLine(DiagnosticAids.DumpDictionary("Main", mem9.GetDictionary())); Debug.WriteLine("Taking another immediately-following snapshot."); Highpoint.Sage.Utility.Mementos.IMemento mem10 = spb1.Memento; Debug.WriteLine("The new snapshot is " + (mem9 == mem10?"":"not ") + "equal to the one preceding it.\r\n"); Assert.IsTrue(mem10 == mem9, "Memento 10 is not equal to memento 9"); Debug.WriteLine("Changing a data member in a subsidiary."); spb1_1["marine"] = 21; Highpoint.Sage.Utility.Mementos.IMemento mem11 = spb1.Memento; Debug.WriteLine("The new snapshot is " + (mem10 == mem11?"":"not ") + "equal to the one preceding it.\r\n"); Assert.IsTrue(mem11 != mem10, "Memento 11 is equal to memento 10"); }