示例#1
0
        public void Does_Outer_Scope_Variable_ReAssignment_On_Multi_Link_Scope_Chain_Work_Correctly()
        {
            //given
            ScopeChain chain = new ScopeChain();

            chain.Push("link1");
            chain.SetVariable(":p1FirstName", "Charlie");
            chain.SetVariable(":p1LastName", "Brown");
            chain.SetVariable(":p1Age", 8);

            chain.Push("link2");
            chain.SetVariable(":p2FirstName", "Susie");
            chain.SetVariable(":p2LastName", "Derkins");
            chain.SetVariable(":p2Age", 6);

            chain.Push("link3");
            chain.SetVariable(":p3FirstName", "GI");
            chain.SetVariable(":p3LastName", "Joe");
            chain.SetVariable(":p3Age", 32);

            chain.Push("link4");
            chain.Push("link5");
            chain.Push("link6");
            chain.Push("link7");
            chain.Push("link8");
            chain.Push("link9");
            chain.Push("link10");

            //when
            chain.UpdateVariable(":p2Age", ((int)chain.AccessVariable(":p2Age")) + 1); //increment age to 7

            //then
            Assert.Equal(7, (int)chain.AccessVariable(":p2Age"));
        }
示例#2
0
        public void Does_variable_accessor_crawl_a_multi_link_scope_chain_correctly()
        {
            //given
            ScopeChain chain = new ScopeChain();
            var        p     = new Person()
            {
                Name = new Name()
                {
                    First = "Charlie", Last = "Brown"
                }
            };

            chain.Push(p);
            chain.SetVariable("test", "t1");
            var p2 = new { Name = new { First = "Susie", Last = "Derkins" } };

            chain.Push(p2);
            chain.SetVariable("test", "t2");
            var a = new Address()
            {
                Line1 = "111 Main St.", Line2 = "", City = "Dallas", State = "TX", Zip = "75075"
            };

            chain.Push(a);
            var p3 = new Name {
                First = "Spider", Last = "Man"
            };

            chain.Push(p3);
            var p4 = new Name {
                First = "Luke", Last = "Skywalker"
            };

            chain.Push(p4);
            var p5 = new { Name = new { First = "Peter", Last = "Pan" } };

            chain.Push(p5);
            var p6 = new Name {
                First = "Duke", Last = "Caboom"
            };

            chain.Push(p6);
            var p7 = new Name {
                First = "Buzz", Last = "Lightyear"
            };

            chain.Push(p7);

            //when
            var actual = chain.AccessVariable("test");

            //then
            Assert.Equal("t2", actual);
        }
示例#3
0
        public void Does_Variable_ReAssignment_Work_Correctly()
        {
            //given
            ScopeChain chain = new ScopeChain();

            chain.Push("link1");
            chain.SetVariable("v1", "foo");

            //when
            chain.UpdateVariable("v1", "bar");
            string v1 = (string)chain.AccessVariable("v1");

            //then
            Assert.Equal("bar", v1);
        }
示例#4
0
        public void Does_Variable_ReAssignment_On_Multi_Link_Scope_Chain_Work_Correctly()
        {
            //given
            ScopeChain chain = new ScopeChain();

            chain.Push("link1");
            chain.Push("link2");
            chain.Push("link3");
            int age = 99;

            chain.SetVariable(":age", age);

            //when
            chain.UpdateVariable(":age", ++age); //increment age to 100

            //then
            Assert.Equal(100, (int)chain.AccessVariable(":age"));
        }
示例#5
0
        public void Does_multi_link_scope_chain_return_closest_scoped_variable_by_name()
        {
            //given
            ScopeChain chain = new ScopeChain();
            var        p     = new Person()
            {
                Name = new Name()
                {
                    First = "Charlie", Last = "Brown"
                }
            };

            chain.Push(p);
            chain.SetVariable("test", "t1");
            var p2 = new { Name = new { First = "Susie", Last = "Derkins" } };

            chain.Push(p2);
            chain.SetVariable("test", "t2");
            var a = new Address()
            {
                Line1 = "111 Main St.", Line2 = "", City = "Dallas", State = "TX", Zip = "75075"
            };

            chain.Push(a);
            chain.SetVariable("test", "t3");
            var p3 = new Name {
                First = "Spider", Last = "Man"
            };

            chain.Push(p3);
            chain.SetVariable("test", "t4");

            //when
            var actual = chain.AccessVariable("test");

            //then
            Assert.Equal("t4", actual);
        }
示例#6
0
        public void Does_Variable_Scope_Multi_Demarcation_Work_Correctly()
        {
            //given
            ScopeChain chain = new ScopeChain();

            chain.Push("link1");
            chain.Push("link2");
            chain.SetVariable("v2", "x");
            chain.ApplyVariableScopeMarker();
            chain.SetVariable("v2", "y");
            chain.ApplyVariableScopeMarker();
            chain.ApplyVariableScopeMarker();
            chain.ApplyVariableScopeMarker();

            //when
            chain.DereferenceVariableScope();
            chain.DereferenceVariableScope();
            chain.DereferenceVariableScope();
            chain.DereferenceVariableScope();
            var v2 = (string)chain.AccessVariable("v2");

            //then
            Assert.Equal("x", v2);
        }