コード例 #1
0
        public void TestEnumerationAndIsLeaf()
        {
            SmartPropertyBag animals = new SmartPropertyBag();

            animals.AddValue("Horses", 12);
            animals.AddString("Kingdom", "Animal");
            SmartPropertyBag dogs = new SmartPropertyBag();

            animals.AddChildSPB("Dogs", dogs);

            dogs.AddValue("Collies", 14);
            dogs.AddValue("Chows", 16);

            animals["Dogs.Collies"] = 18;

            SmartPropertyBag labs = new SmartPropertyBag();

            labs.AddValue("Black", 4);
            labs.AddValue("Brown", 2);
            labs.AddValue("Yellow", 1);
            labs.AddString("Temperament", "Mellow");
            labs.AddBoolean("Faithful", false);
            dogs.AddChildSPB("Labs", labs);

            DumpEnumerable(animals, 0);

            Assert.IsTrue(true, "Visual test not successfull");
        }
コード例 #2
0
        public void TestSubsidiaries()
        {
            SmartPropertyBag animals = new SmartPropertyBag();

            animals.AddValue("Horses", 12);
            animals.AddString("Kingdom", "Animal");
            SmartPropertyBag dogs = new SmartPropertyBag();

            animals.AddChildSPB("Dogs", dogs);

            dogs.AddValue("Collies", 14);
            dogs.AddValue("Chows", 16);

            Debug.WriteLine("Animals.Horses = " + animals["Horses"]);
            Debug.WriteLine("Animals.Kingdom = " + animals["Kingdom"]);
            Debug.WriteLine("Animals.Dogs.Collies = " + animals["Dogs.Collies"]);

            animals["Dogs.Collies"] = 18;
            Debug.WriteLine("Animals.Dogs.Collies = " + animals["Dogs.Collies"]);

            SmartPropertyBag labs = new SmartPropertyBag();

            labs.AddValue("Black", 4);
            labs.AddValue("Brown", 2);
            labs.AddValue("Yellow", 1);
            labs.AddString("Temperament", "Mellow");
            labs.AddBoolean("Faithful", false);
            dogs.AddChildSPB("Labs", labs);
            Debug.WriteLine(DiagnosticAids.DumpDictionary("", (IDictionary)animals.Memento.GetDictionary()));

            Assert.IsTrue((double)animals["Dogs.Labs.Black"] == 4, "Black Lab is not 4");
            Assert.IsTrue((double)animals["Dogs.Labs.Brown"] == 2, "Brown Lab is not 2");
            Assert.IsTrue((double)animals["Dogs.Labs.Yellow"] == 1, "Yellow Lab is not 1");
            Assert.IsTrue("Mellow".Equals((string)labs["Temperament"]), "The Labs temperament is not Mellow");
            Assert.IsTrue((double)animals["Dogs.Collies"] == 18, "Collies are not 18");
            Assert.IsTrue((double)animals["Dogs.Chows"] == 16, "Chows are not 16");
            Assert.IsTrue((double)animals["Horses"] == 12, "Horses are not 12");
            Assert.IsTrue("Animal".Equals((string)animals["Kingdom"]), "The Kingdom is not the Animal Kingdom");
            Assert.IsTrue(!(bool)labs["Faithful"], "Labs are not not faithful");


            Debug.WriteLine("Setting Animals.Dogs.Labs.Black to 19, Animals.Dogs.Labs.Temperament to \"Lovable\".");
            Debug.WriteLine("...and Animals.Dogs.Labs.Faithful to \"true\".");
            animals["Dogs.Labs.Black"]       = 19;
            animals["Dogs.Labs.Temperament"] = "Lovable";
            animals["Dogs.Labs.Faithful"]    = true;
            Debug.WriteLine(DiagnosticAids.DumpDictionary("", (IDictionary)animals.Memento.GetDictionary()));

            Assert.IsTrue((double)animals["Dogs.Labs.Black"] == 19, "Black Lab is not 19");
            Assert.IsTrue((double)animals["Dogs.Labs.Brown"] == 2, "Brown Lab is not 2");
            Assert.IsTrue((double)animals["Dogs.Labs.Yellow"] == 1, "Yellow Lab is not 1");
            Assert.IsTrue("Lovable".Equals((string)labs["Temperament"]), "The Labs temperament is not Lovable");
            Assert.IsTrue((double)animals["Dogs.Collies"] == 18, "Collies are not 18");
            Assert.IsTrue((double)animals["Dogs.Chows"] == 16, "Chows are not 16");
            Assert.IsTrue((double)animals["Horses"] == 12, "Horses are not 12");
            Assert.IsTrue("Animal".Equals((string)animals["Kingdom"]), "The Kingdom is the Animal Kingdom");
            Assert.IsTrue((bool)labs["Faithful"], "Labs are faithful");
        }
コード例 #3
0
        public void TestMementoRestorationAndEquality()
        {
            SmartPropertyBag spb1 = new SmartPropertyBag();

            spb1.AddValue("Fred", 12);
            //spb1.AddExpression("Bill","Math.Max(Fred,17)",new string[]{"Fred"});
            spb1.AddDelegate("Steve", new SmartPropertyBag.SPBDoubleDelegate(ComputeSteve));
            spb1.AddString("Donkey", "Kong");
            spb1.AddBoolean("HabaneroHot", true);

            Highpoint.Sage.Utility.Mementos.IMemento mem1 = spb1.Memento;

            SmartPropertyBag spb2 = new SmartPropertyBag();

            spb2.Memento = mem1;

            Assert.IsTrue(spb1 != spb2, "Object spb1 and spb2 cannot be the same instance");
            Assert.IsTrue(spb1.Equals(spb2), "SPB1 and SPB2 should be equal");
            Assert.IsTrue(spb1.Memento == spb2.Memento, "SPB1.Memento and SPB2.Memento should be equal");

            Debug.WriteLine(DiagnosticAids.DumpDictionary("Before", spb1.Memento.GetDictionary()));
            Debug.WriteLine(DiagnosticAids.DumpDictionary("After", spb2.Memento.GetDictionary()));
        }
コード例 #4
0
        public void TestRepeatedSnapshottingAndRestoration()
        {
            SmartPropertyBag animals = new SmartPropertyBag();

            animals.AddValue("Horses", 12);
            animals.AddString("Kingdom", "Animal");
            SmartPropertyBag dogs = new SmartPropertyBag();

            animals.AddChildSPB("Dogs", dogs);

            dogs.AddValue("Collies", 14);
            dogs.AddValue("Chows", 16);

            Debug.WriteLine("Animals.Horses = " + animals["Horses"]);
            Debug.WriteLine("Animals.Kingdom = " + animals["Kingdom"]);
            Debug.WriteLine("Animals.Dogs.Collies = " + animals["Dogs.Collies"]);

            animals["Dogs.Collies"] = 18;
            Debug.WriteLine("Animals.Dogs.Collies = " + animals["Dogs.Collies"]);

            SmartPropertyBag labs = new SmartPropertyBag();

            labs.AddValue("Black", 4);
            labs.AddValue("Brown", 2);
            labs.AddValue("Yellow", 1);
            labs.AddString("Temperament", "Mellow");
            labs.AddBoolean("Faithful", true);
            dogs.AddChildSPB("Labs", labs);

            Highpoint.Sage.Utility.Mementos.IMemento mem = dogs.Memento;
            DateTime start = DateTime.Now;

            for (int i = 0; i < 10000; i++)
            {
                dogs.Memento = mem;

                labs["Faithful"] = false;
                labs["Faithful"] = true;

                Assert.IsTrue((double)animals["Dogs.Labs.Black"] == 4, "Black Lab is not 4");
                Assert.IsTrue((double)animals["Dogs.Labs.Brown"] == 2, "Brown Lab is not 2");
                Assert.IsTrue((double)animals["Dogs.Labs.Yellow"] == 1, "Yellow Lab is not 1");
                Assert.IsTrue("Mellow".Equals((string)labs["Temperament"]), "The Lab's temperament is not Mellow");
                Assert.IsTrue((double)animals["Dogs.Collies"] == 18, "Collies are not 18");
                Assert.IsTrue((double)animals["Dogs.Chows"] == 16, "Chows are not 16");
                Assert.IsTrue((double)animals["Horses"] == 12, "Horses are not 12");
                Assert.IsTrue("Animal".Equals((string)animals["Kingdom"]), "The Kingdom is not the Animal Kingdom");
                Assert.IsTrue((bool)labs["Faithful"], "Labs are not faithful");

                //Debug.WriteLine(DiagnosticAids.DumpDictionary("",(IDictionary)animals.Memento.GetDictionary()));
                mem = dogs.Memento;
                labs["Faithful"] = false;
                labs["Faithful"] = true;
                if ((i % 100) == 0)
                {
                    Debug.WriteLine(((TimeSpan)(DateTime.Now - start)).TotalSeconds);
                    start = DateTime.Now;
                    //if ( i > 7500 ) System.Diagnostics.Debugger.Break();
                }
            }
        }
コード例 #5
0
        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()));
        }