Example #1
0
        public void Scopes_loadExtension()
        {
            IScopeManager <IDomainModel> scopes = new ScopeControler <IDomainModel>(null);

            var domain = new MockDomainModel("Test");
            var ext    = new MockDomainModel("test", "ext");

            scopes.RegisterScope(domain);
            scopes.OnSessionCreated(null, 2);
            scopes.EnableScope(domain);

            scopes.OnSessionCreated(null, 3);
            Assert.Equal(domain, scopes.GetActiveScope("Test", 3));
            scopes.RegisterScope(ext);
            Assert.Equal(domain, scopes.GetActiveScope("Test", 3));
            scopes.EnableScope(ext);
            Assert.Equal(domain, scopes.GetActiveScope("Test", 3));
            scopes.OnSessionCreated(null, 4);

            Assert.Equal(ext, scopes.GetActiveScope("Test", 4));
            Assert.Equal(domain, scopes.GetActiveScope("Test", 3));

            Assert.Equal(1, scopes.GetScopes(ScopesSelector.Enabled, 4).Count());
            Assert.Equal(2, scopes.GetScopes(ScopesSelector.Loaded, 4).Count());
            scopes.UnloadScope(ext);

            Assert.Equal(ext, scopes.GetActiveScope("Test", 4));
            ((ScopeControler <IDomainModel>)scopes).OnSessionCompleted(4);

            Assert.Equal(domain, scopes.GetActiveScope("Test", 3));

            ((ScopeControler <IDomainModel>)scopes).OnSessionCompleted(2);
            ((ScopeControler <IDomainModel>)scopes).OnSessionCompleted(3);
        }
        public void HostReturnsWarningsFromLogCall()
        {
            Engine          engine      = new Engine();
            Store           store       = new Store(typeof(MockDomainModel));
            MockDomainModel domainModel = GetModel(store);

            const string LogMessage = "Message1";
            const string LogTitle   = "Title1";

            using (Transaction t = store.TransactionManager.BeginTransaction())
            {
                ExtensibleMockModelElement serviceModel = new ExtensibleMockModelElement(store.DefaultPartition, string.Empty);
                TextTemplateHost           host         = new TextTemplateHost(domainModel, serviceModel, null);
                string transformResult = engine.ProcessTemplate(
                    GetStandardTemplateHeader() + @"
					<# LogWarning("""                     + LogMessage + @""",""" + LogTitle + @"""); #>",
                    host);
                Assert.AreEqual <int>(1, host.CompilerErrors.Count);
                Assert.IsTrue(host.CompilerErrors[0].IsWarning);
                Assert.IsTrue(host.CompilerErrors[0].ErrorNumber.Contains(LogMessage), "Could not find expected error in compiler errors.");
                Assert.IsTrue(host.CompilerErrors[0].ErrorText.Contains(LogTitle), "Could not find expected error in compiler errors.");

                t.Rollback();
            }
        }
Example #3
0
        public void Scopes_unloadDomain()
        {
            IScopeManager <IDomainModel> scopes = new ScopeControler <IDomainModel>(null);

            var domain = new MockDomainModel("Test");

            scopes.RegisterScope(domain);
            scopes.OnSessionCreated(null, 2);
            scopes.EnableScope(domain); // domain enable from session > 2

            scopes.OnSessionCreated(null, 3);
            Assert.NotNull(scopes.GetActiveScope("Test", 3));
            Assert.Null(scopes.GetActiveScope("Test", 1));

            scopes.UnloadScope(domain);
            Assert.Equal(1, scopes.GetScopes(ScopesSelector.Enabled, 3).Count());
            Assert.Equal(0, scopes.GetScopes(ScopesSelector.Enabled, 2).Count());

            ((ScopeControler <IDomainModel>)scopes).OnSessionCompleted(2);
            Assert.Equal(0, scopes.GetScopes(ScopesSelector.Enabled, 2).Count());

            Assert.Equal(1, scopes.GetScopes(ScopesSelector.Enabled, 3).Count());
            ((ScopeControler <IDomainModel>)scopes).OnSessionCompleted(3);
            Assert.Equal(0, scopes.GetScopes(ScopesSelector.Enabled, 3).Count());
        }
        private MockDomainModel GetModel(Store store)
        {
            MockDomainModel domainModel = null;

            foreach (DomainModel dm in store.DomainModels)
            {
                if (dm is MockDomainModel)
                {
                    domainModel = (MockDomainModel)dm;
                }
            }
            Assert.IsNotNull(domainModel);
            return(domainModel);
        }
Example #5
0
        public void Scopes_loadDomains()
        {
            IScopeManager <IDomainModel> scopes = new ScopeControler <IDomainModel>(null);

            var domain = new MockDomainModel("Test");

            scopes.RegisterScope(domain);
            Assert.Equal(0, scopes.GetScopes(ScopesSelector.Enabled).Count());
            Assert.Equal(0, scopes.GetScopes(ScopesSelector.Loaded).Count());
            Assert.Null(scopes.GetActiveScope("Test", 0));

            scopes.EnableScope(domain);
            Assert.Equal(1, scopes.GetScopes(ScopesSelector.Enabled).Count());
            Assert.Equal(1, scopes.GetScopes(ScopesSelector.Loaded).Count());
            Assert.NotNull(scopes.GetActiveScope("Test", 0));
        }
        private string IsValid(bool expectedValue)
        {
            Engine          engine      = new Engine();
            Store           store       = new Store(typeof(MockDomainModel));
            MockDomainModel domainModel = GetModel(store);

            using (Transaction t = store.TransactionManager.BeginTransaction())
            {
                ExtensibleMockModelElement serviceModel = new ExtensibleMockModelElement(store.DefaultPartition, string.Empty);
                MockCodeGenerationService  cgs          = new MockCodeGenerationService(expectedValue);
                TextTemplateHost           host         = new TextTemplateHost(domainModel, serviceModel, serviceModel, cgs);
                string transformResult = engine.ProcessTemplate(
                    GetStandardTemplateHeader().Replace("/n", "") + @"<#= this.IsValid(CurrentElement.InvalidArtifactLink).ToString()#>",
                    host);
                t.Rollback();
                return(transformResult.Trim());
            }
        }
        public void CanGetCSharpTypeOutput()
        {
            Engine          engine      = new Engine();
            Store           store       = new Store(typeof(MockDomainModel));
            MockDomainModel domainModel = GetModel(store);

            using (Transaction t = store.TransactionManager.BeginTransaction())
            {
                ExtensibleMockModelElement serviceModel = new ExtensibleMockModelElement(store.DefaultPartition, string.Empty);
                TextTemplateHost           host         = new TextTemplateHost(domainModel, serviceModel, null);
                string transformResult = engine.ProcessTemplate(
                    GetStandardTemplateHeader() + @"
					<#= Utility.GetCSharpTypeOutput(""System.String"") #>"                    ,
                    host);
                Assert.IsTrue(transformResult.Contains("string"));
                t.Rollback();
            }
        }
        public void InvokeHostWithModel()
        {
            Engine          engine      = new Engine();
            Store           store       = new Store(typeof(MockDomainModel));
            MockDomainModel domainModel = GetModel(store);

            using (Transaction t = store.TransactionManager.BeginTransaction())
            {
                ExtensibleMockModelElement serviceModel = new ExtensibleMockModelElement(store.DefaultPartition, string.Empty);
                TextTemplateHost           host         = new TextTemplateHost(domainModel, serviceModel, null);
                string templateContent = GetStandardTemplateHeader() + @"
					<#= this.Model.DomainModelInfo.Id #>"                    ;

                string transformResult = engine.ProcessTemplate(
                    templateContent,
                    host);
                Assert.AreEqual(domainModel.DomainModelInfo.Id, new Guid(transformResult));
                t.Rollback();
            }
        }
        public void HostReturnsEmptyContentOnCancelOutput()
        {
            Engine          engine      = new Engine();
            Store           store       = new Store(typeof(MockDomainModel));
            MockDomainModel domainModel = GetModel(store);

            using (Transaction t = store.TransactionManager.BeginTransaction())
            {
                ExtensibleMockModelElement serviceModel = new ExtensibleMockModelElement(store.DefaultPartition, string.Empty);
                TextTemplateHost           host         = new TextTemplateHost(domainModel, serviceModel, null);
                string templateContent = GetStandardTemplateHeader() + @"<# CancelOutput(); #>";

                string transformResult = engine.ProcessTemplate(templateContent, host);

                Assert.AreEqual <int>(0, host.CompilerErrors.Count);
                Assert.IsFalse(host.GenerateOutput);

                t.Rollback();
            }
        }
Example #10
0
        public void Scopes_activeDomain()
        {
            IScopeManager <IDomainModel> scopes = new ScopeControler <IDomainModel>(null);

            var domain = new MockDomainModel("Test");

            scopes.RegisterScope(domain);
            scopes.OnSessionCreated(null, 1);

            scopes.EnableScope(domain);

            Assert.Null(scopes.GetActiveScope("Test", 1)); // Valid after the current session
            Assert.Equal(0, scopes.GetScopes(ScopesSelector.Enabled, 1).Count());
            Assert.Equal(1, scopes.GetScopes(ScopesSelector.Loaded).Count());

            scopes.OnSessionCreated(null, 2);
            Assert.NotNull(scopes.GetActiveScope("Test", 2));
            Assert.Equal(1, scopes.GetScopes(ScopesSelector.Enabled, 2).Count());
            Assert.Equal(1, scopes.GetScopes(ScopesSelector.Loaded).Count());
        }
        public void CanAddProjectReference()
        {
            Engine          engine      = new Engine();
            Store           store       = new Store(typeof(MockDomainModel));
            MockDomainModel domainModel = GetModel(store);

            using (Transaction t = store.TransactionManager.BeginTransaction())
            {
                ExtensibleMockModelElement serviceModel = new ExtensibleMockModelElement(store.DefaultPartition, "test");
                serviceModel.ObjectExtender = new MockObjectExtender();
                TextTemplateHost host = new TextTemplateHost(domainModel, serviceModel, serviceModel);
                host.StandardAssemblyReferences.Add(typeof(Microsoft.Practices.Modeling.ExtensionProvider.Extension.ObjectExtender <ExtensibleMockModelElement>).Assembly.FullName);

                string transformResult = engine.ProcessTemplate(
                    GetStandardTemplateHeader() + @"
					<# AddProjectReference(CurrentExtender.ArtifactLink); #>"                    ,
                    host);
                Assert.AreEqual(1, host.ProjectReferences.Count);
                t.Rollback();
            }
        }
        public void HostReturnsErrorsInCollection()
        {
            Engine          engine      = new Engine();
            Store           store       = new Store(typeof(MockDomainModel));
            MockDomainModel domainModel = GetModel(store);

            using (Transaction t = store.TransactionManager.BeginTransaction())
            {
                ExtensibleMockModelElement serviceModel = new ExtensibleMockModelElement(store.DefaultPartition, string.Empty);
                TextTemplateHost           host         = new TextTemplateHost(domainModel, serviceModel, null);
                string transformResult = engine.ProcessTemplate(
                    GetStandardTemplateHeader() + @"
					<# throw new global::System.Exception(""TestException""); #>"                    ,
                    host);

                Assert.AreEqual <int>(2, host.CompilerErrors.Count);
                Assert.IsTrue(host.CompilerErrors[1].ErrorText.Contains("TestException"), "Could not find expected exception in compiler errors.");

                t.Rollback();
            }
        }