Esempio n. 1
0
        public void ShouldCreateLocatorScope()
        {
            var       locator     = _Context.Locator;
            ScopeTest noScopeTest = null;

            using (var scope = CreateScope())
            {
                noScopeTest = locator.Get <ScopeTest>();
                System.Threading.Thread.Sleep(1);
            }

            using (var scopedLocator = CreateScope())
            {
                var scopeTest = scopedLocator.Get <ScopeTest>();
                System.Threading.Thread.Sleep(1);
                var scopeTest2 = scopedLocator.Get <ScopeTest>();

                Assert.IsTrue(scopedLocator.Parent is null);

                using (var nestedScope = CreateScope(scopedLocator))
                {
                    Assert.IsNotNull(nestedScope.Parent);
                    Assert.IsNull(nestedScope.Parent.Parent);
                    Assert.AreEqual(nestedScope.Parent, scopedLocator);
                }

                Assert.AreEqual(scopeTest.TestVariable, scopeTest2.TestVariable);
                Assert.AreNotEqual(scopeTest2.TestVariable, noScopeTest.TestVariable);
            }

            var resolveTest = locator.Get <Abstractions.IAssemblyScanner>();

            Assert.IsNotNull(resolveTest, "final resolve");
        }
Esempio n. 2
0
        public void ExpectStuffInSingleScope()
        {
            var s = new ScopeTest("'a'");
            var p = s.Parser;

            p.ExpectScope("'"
                          , s.FullCallback);
            Assert.IsTrue(s.CallbackCalled);
            AssertCharacterPosition(new CharacterPosition(1, 4), p.CharacterPosition);
        }
Esempio n. 3
0
        public void ExpectEmptySingleScope()
        {
            var s = new ScopeTest("''");
            var p = s.Parser;

            p.ExpectScope("'"
                          , s.FullCallback);
            Assert.IsFalse(s.CallbackCalled);
            AssertCharacterPosition(new CharacterPosition(1, 3), p.CharacterPosition);
        }
Esempio n. 4
0
        public void StuffInScope()
        {
            var s = new ScopeTest("(a)");
            var p = s.Parser;
            var r = p.HasScope("("
                               , ")"
                               , s.FullCallback);

            Assert.IsTrue(r);
            Assert.IsTrue(s.CallbackCalled);
            AssertCharacterPosition(new CharacterPosition(1, 4), p.CharacterPosition);
        }
Esempio n. 5
0
        public void NoScopeAction()
        {
            var s = new ScopeTest("no scope");
            var p = s.Parser;
            var r = p.HasScope("("
                               , ")"
                               , new Action <Parser>(s.ActionCallback));

            Assert.IsFalse(r);
            Assert.IsFalse(s.CallbackCalled);
            AssertCharacterPosition(new CharacterPosition(1, 1), p.CharacterPosition);
        }
Esempio n. 6
0
        public void ExpectNoScopeAction()
        {
            try
            {
                var s = new ScopeTest("no scope");
                var p = s.Parser;
                p.ExpectScope("("
                              , ")"
                              , new Action <Parser>(s.ActionCallback));
            }
            catch (CompilerException e)
            {
                StringAssert.Contains(e.Message, "Expected");
                StringAssert.Contains(e.Message, "(");

                AssertCharacterPosition(new CharacterPosition(1, 1), e.CharacterPosition);
            }
        }