Ejemplo n.º 1
0
        public void MetaDefaults_SubChildrenGetCorrectContextAndRoutedToSameContext()
        {
            var sut = new SemContextStub();

            bool itemFuncCalled = false;

            sut.ItemFunc = (s, context) =>
            {
                itemFuncCalled = true;
                Assert.AreEqual("v", context.GetInheritedAttribute("a"));
                return(MockRepository.GenerateStub <ISemanticContext>());
            };

            var underDefaults = sut.PushLine(0, "?set", null, new[] { new AhlAttribute("a", "v"), });

            Assert.IsFalse(itemFuncCalled);
            underDefaults.PushLine(1, null, "item", new AhlAttribute[0]);
            Assert.IsTrue(itemFuncCalled);
            underDefaults.FinishItem();

            bool itemFuncSecondCalled = false;

            sut.ItemFunc = (s, context) =>
            {
                itemFuncSecondCalled = true;
                Assert.IsNull(context.GetInheritedAttribute("a"));
                return(null);
            };
            sut.PushLine(2, null, "item2", new AhlAttribute[0]);
            Assert.IsTrue(itemFuncSecondCalled);
        }
Ejemplo n.º 2
0
 private static void CheckEnvironmentVariableExpansionInKey(string varValue, string rawAttributeValue, string expectedAttributeExpansion)
 {
     if (Environment.GetEnvironmentVariables().Contains("Test"))
     {
         Assert.Inconclusive("Environment variable with name 'test' already exists");
     }
     Environment.SetEnvironmentVariable("Test", varValue);
     try
     {
         var  sut            = new SemContextStub();
         bool itemFuncCalled = false;
         sut.ItemFunc = (s, context) =>
         {
             itemFuncCalled = true;
             Assert.AreEqual(expectedAttributeExpansion, s);
             return(null);
         };
         sut.PushLine(0, null, rawAttributeValue, new AhlAttribute[0]);
         Assert.IsTrue(itemFuncCalled);
     }
     finally
     {
         Environment.SetEnvironmentVariable("Test", "");
     }
 }
Ejemplo n.º 3
0
        public void OneLinerChild_RoutedCorrectly()
        {
            var mr  = new MockRepository();
            var sut = new SemContextStub();
            var expectedChildContext = MockRepository.GenerateStub <IAttributeContext>();

            sut.AttributeContextFactory = () => expectedChildContext;
            var sectionContext = mr.StrictMock <ISemanticContext>();

            sectionContext.Expect(sc => sc.FinishItem());
            var itemContext = mr.StrictMock <ISemanticContext>();

            itemContext.Expect(i => i.OnFinished += null).IgnoreArguments();

            sectionContext.Expect(sc => sc.PushLine(0, null, null, null))
            .Constraints(Is.Equal(0), Is.Same(null), Is.Equal("mykey"), Is.Anything())
            .Return(itemContext);
            sut.S1Func = _ => sectionContext;

            mr.ReplayAll();
            var result = sut.PushLine(0, "!s1", "mykey", new AhlAttribute[0]);

            Assert.AreSame(itemContext, result);
            itemContext.GetEventRaiser(i => i.OnFinished += null).Raise(itemContext, EventArgs.Empty);
            mr.VerifyAll();
        }
Ejemplo n.º 4
0
        public void VariableExpansion_EnvironmentVariableDoesNotExist_ExceptionThrown()
        {
            if (Environment.GetEnvironmentVariables().Contains("Test"))
            {
                Assert.Inconclusive("Environment variable with name 'test' already exists");
            }
            var sut = new SemContextStub();

            sut.PushLine(0, null, "$(swix.env.Test)", new AhlAttribute[0]);
        }
Ejemplo n.º 5
0
        public void VariableExpansion_AttributeExpansionWorks()
        {
            var sut = new SemContextStub();

            sut.Variables["My"] = "value";
            bool itemFuncCalled = false;

            sut.ItemFunc = (s, context) =>
            {
                itemFuncCalled = true;
                Assert.AreEqual("value+something+value", context.GetInheritedAttribute("a"));
                return(null);
            };
            sut.PushLine(0, null, "key", new[] { new AhlAttribute("a", "$(swix.var.My)+something+$(swix.var.My)") });
            Assert.IsTrue(itemFuncCalled);
        }
Ejemplo n.º 6
0
        private static void CheckVariableExpansionInKey(string rawAttributeValue, string varValue, string expectedAttributeExpansion)
        {
            var sut = new SemContextStub();

            sut.Variables["My"] = varValue;
            bool itemFuncCalled = false;

            sut.ItemFunc = (s, context) =>
            {
                itemFuncCalled = true;
                Assert.AreEqual(expectedAttributeExpansion, s);
                return(null);
            };
            sut.PushLine(0, null, rawAttributeValue, new AhlAttribute[0]);
            Assert.IsTrue(itemFuncCalled);
        }
Ejemplo n.º 7
0
        public void SectionLine_RoutedCorrectlyWithSameAttributes()
        {
            var sut = new SemContextStub();
            var attributeContext = MockRepository.GenerateStub <IAttributeContext>();

            sut.AttributeContextFactory = () => attributeContext;
            var expectedResult = MockRepository.GenerateStub <ISemanticContext>();

            bool called = false;

            sut.S1Func = context =>
            {
                called = true;
                Assert.AreSame(attributeContext, context);
                sut.S1Func = null;
                return(expectedResult);
            };
            var result = sut.PushLine(0, ":s1", null, new List <AhlAttribute>());

            Assert.IsTrue(called);
            Assert.AreSame(expectedResult, result);
        }
Ejemplo n.º 8
0
        public void MetaLine_RoutedCorrectlyWithSameAttributes()
        {
            var sut = new SemContextStub();
            var expectedChildContext = MockRepository.GenerateStub <IAttributeContext>();

            sut.AttributeContextFactory = () => expectedChildContext;
            var  expectedResult = MockRepository.GenerateStub <ISemanticContext>();
            bool called         = false;

            sut.M1Func = (key, context) =>
            {
                called = true;
                Assert.AreEqual("mykey", key);
                Assert.AreSame(expectedChildContext, context);
                sut.M1Func = null;
                return(expectedResult);
            };
            var result = sut.PushLine(0, "?m1", "mykey", new AhlAttribute[0]);

            Assert.IsTrue(called);
            Assert.AreSame(expectedResult, result);
        }
Ejemplo n.º 9
0
        public void VariableExpansion_UndeclaredVariable_ExceptionThrown()
        {
            var sut = new SemContextStub();

            sut.PushLine(0, null, "$(swix.var.var)", new AhlAttribute[0]);
        }
Ejemplo n.º 10
0
        public void SectionWithKey_ThrowsAnError()
        {
            var sut = new SemContextStub();

            sut.PushLine(0, ":s1", "a", Enumerable.Empty <AhlAttribute>());
        }
Ejemplo n.º 11
0
        public void UnsupportedSectionThrowsException()
        {
            var sut = new SemContextStub();

            sut.PushLine(0, ":sss", null, Enumerable.Empty <AhlAttribute>());
        }