public void TestLocateWithLoopImplicitIteratorName()
        {
            var im = new ZeroCode2.Interpreter.IteratorManager(new ZeroCode2.Models.Iterator())
            {
                Path = "@ViewModels"
            };
            var locator = new ZeroCode2.Models.PropertyLocator(im.Path, ModelCollector, null);

            locator.Locate();
            im.Root = locator.LocatedProperty();

            LoopStack = new Stack <ZeroCode2.Interpreter.IteratorManager>();
            LoopStack.Push(im);
            locator = new ZeroCode2.Models.PropertyLocator("$", ModelCollector, LoopStack);

            locator.Locate();
            var outp = locator.LocatedProperty();

            Assert.IsNotNull(outp);
            Assert.AreEqual("Person", outp.Name);

            locator = new ZeroCode2.Models.PropertyLocator("$.Test.Title", ModelCollector, LoopStack);
            locator.Locate();
            outp = locator.LocatedProperty();

            Assert.IsNotNull(outp);
            Assert.AreEqual("hello", outp.GetText());

            LoopStack = null;
        }
        public void TestLocateWithParameterPath()
        {
            var locator = new ZeroCode2.Models.PropertyLocator("#Parameters.appName", ModelCollector, LoopStack);

            locator.Locate();
            var outp = locator.LocatedProperty();

            Assert.IsNotNull(outp);
            Assert.AreEqual("My test application in Zero Code", outp.GetText());
        }
        public void TestLocateWithDirectModelDoubleInheritedValue()
        {
            var locator = new ZeroCode2.Models.PropertyLocator("@Models.Person.DoubleInheritance.Name", ModelCollector, LoopStack);

            locator.Locate();
            var outp = locator.LocatedProperty();

            Assert.IsNotNull(outp);
            Assert.AreEqual("Name", outp.GetText());
        }
        public void TestLocateWithDirectModelInheritedValue()
        {
            var locator = new ZeroCode2.Models.PropertyLocator("@Models.Stakeholder.Name.Length", ModelCollector, LoopStack);

            locator.Locate();
            var outp = locator.LocatedProperty();

            Assert.IsNotNull(outp);
            Assert.AreEqual("95", outp.GetText());
        }
        public void TestLocateWithDirectModelPathNotFound()
        {
            var locator = new ZeroCode2.Models.PropertyLocator("@Models.Stakeholder.Name.Nullable", ModelCollector, LoopStack);

            locator.Locate();
            var outp = locator.LocatedProperty();

            Assert.IsNull(outp);
            //Assert.AreEqual(outp.Value.GetText(), "Title");
        }
        public void TestLocateWithDirectModelPath3()
        {
            var path  = "@DataDictionary.IDField.Name";
            var value = "ID";

            var locator = new ZeroCode2.Models.PropertyLocator(path, ModelCollector, LoopStack);

            locator.Locate();
            var outp = locator.LocatedProperty();

            Assert.IsNotNull(outp);
            Assert.AreEqual(value, outp.GetText());
        }
        public void TestLocateWithDirectModelPath2()
        {
            var path  = "@Models.Stakeholder.Name.Title";
            var value = "Generic Title";

            var locator = new ZeroCode2.Models.PropertyLocator(path, ModelCollector, LoopStack);

            locator.Locate();
            var outp = locator.LocatedProperty();

            Assert.IsNotNull(outp);
            Assert.AreEqual(value, outp.GetText());
        }
        public void TestLocateWithDirectModelPath1()
        {
            var path  = "@Models.Person.ID.Name";
            var value = "ID of Person";

            var locator = new ZeroCode2.Models.PropertyLocator(path, ModelCollector, LoopStack);

            locator.Locate();
            var outp = locator.LocatedProperty();

            Assert.IsNotNull(outp);
            Assert.AreEqual(value, outp.GetText());
        }
        public void TestEnsureSingleModelPathGivesCorrectLoopID()
        {
            var im = new ZeroCode2.Interpreter.IteratorManager(new ZeroCode2.Models.Iterator())
            {
                Path = "@ViewModels"
            };
            var locator = new ZeroCode2.Models.PropertyLocator(im.Path, ModelCollector, null);

            locator.Locate();
            im.Root = locator.LocatedProperty();

            Assert.IsNotNull(im.LoopID);
            Assert.AreNotEqual(im.LoopID, im.Path);
            Assert.AreEqual("ViewModels", im.LoopID);

            LoopStack = null;
        }
        public void TestIterationWithLoopExplicit()
        {
            var im = new ZeroCode2.Interpreter.IteratorManager(new ZeroCode2.Models.Iterator())
            {
                Path = "@Models"
            };
            var locator = new ZeroCode2.Models.PropertyLocator(im.Path, ModelCollector, null);

            locator.Locate();
            im.Root = locator.LocatedProperty();

            LoopStack = new Stack <ZeroCode2.Interpreter.IteratorManager>();
            LoopStack.Push(im);

            locator = new ZeroCode2.Models.PropertyLocator("Models.Name.Title", ModelCollector, LoopStack);

            locator.Locate();
            var outp = locator.LocatedProperty();

            Assert.IsNotNull(outp);
            Assert.AreEqual("Name", outp.GetText());

            im.Iterate();

            locator = new ZeroCode2.Models.PropertyLocator("Models.Name.Title", ModelCollector, LoopStack);

            locator.Locate();
            outp = locator.LocatedProperty();

            Assert.IsNotNull(outp);
            Assert.AreEqual("Generic Title", outp.GetText());

            var hasMore = im.Iterate();

            locator = new ZeroCode2.Models.PropertyLocator("Models.Name.Title", ModelCollector, LoopStack);

            locator.Locate();
            outp = locator.LocatedProperty();

            Assert.IsNull(outp);
            Assert.IsFalse(hasMore);

            LoopStack = null;
        }
        public void TestLocateWithLoopExplicit()
        {
            var im = new ZeroCode2.Interpreter.IteratorManager(new ZeroCode2.Models.Iterator())
            {
                Path = "@ViewModels"
            };
            var locator = new ZeroCode2.Models.PropertyLocator(im.Path, ModelCollector, null);

            locator.Locate();
            im.Root = locator.LocatedProperty();

            LoopStack = new Stack <ZeroCode2.Interpreter.IteratorManager>();
            LoopStack.Push(im);
            locator = new ZeroCode2.Models.PropertyLocator("ViewModels.Name.Length", ModelCollector, LoopStack);

            locator.Locate();
            var outp = locator.LocatedProperty();

            LoopStack = null;

            Assert.IsNotNull(outp);
            Assert.AreEqual("75", outp.GetText());
        }
        public void TestLocateLoopOrderingWithOrderingStatement()
        {
            string[] fields = { "ID", "Code", "Description", "Budget", "Startdate", "Enddate", "Status" };
            var      im     = new ZeroCode2.Interpreter.IteratorManager(new ZeroCode2.Models.Iterator())
            {
                Path = "@Datamodel.Project.Properties"
            };
            var locator = new ZeroCode2.Models.PropertyLocator(im.Path, ModelCollector, null);

            locator.Locate();
            im.Root = locator.LocatedProperty();

            LoopStack = new Stack <ZeroCode2.Interpreter.IteratorManager>();
            LoopStack.Push(im);

            int i = 0;

            do
            {
                im.Iterate();
                Assert.IsTrue(i < fields.Length);

                locator = new ZeroCode2.Models.PropertyLocator("$", ModelCollector, LoopStack);

                locator.Locate();
                var outp = locator.LocatedProperty();

                Assert.IsNotNull(outp);
                Assert.AreEqual(fields[i], outp.Name);

                i++;
            } while (im.HasMore);

            Assert.IsTrue(i == fields.Length);

            LoopStack = null;
        }
        public void TestLocateLoopOrdering()
        {
            string[] fields = { "Name", "Title", "InheritedField", "CodeField", "DoubleInheritance", "Test" };
            var      im     = new ZeroCode2.Interpreter.IteratorManager(new ZeroCode2.Models.Iterator())
            {
                Path = "@ViewModels.Person"
            };
            var locator = new ZeroCode2.Models.PropertyLocator(im.Path, ModelCollector, null);

            locator.Locate();
            im.Root = locator.LocatedProperty();

            LoopStack = new Stack <ZeroCode2.Interpreter.IteratorManager>();
            LoopStack.Push(im);

            int i = 0;

            do
            {
                im.Iterate();
                Assert.IsTrue(i < fields.Length);

                locator = new ZeroCode2.Models.PropertyLocator("$", ModelCollector, LoopStack);

                locator.Locate();
                var outp = locator.LocatedProperty();

                Assert.IsNotNull(outp);
                Assert.AreEqual(fields[i], outp.Name);

                i++;
            } while (im.HasMore);

            Assert.IsTrue(i == fields.Length);

            LoopStack = null;
        }