public void WhenTypeAttributeIsNotFound_ThenThrows()
        {
            var processor = new ModelElementDirectiveProcessor();

            processor.StartProcessingRun(provider, null, new CompilerErrorCollection());
            Assert.Throws<DirectiveProcessorException>(() => processor.ProcessDirective("ModelElement", new Dictionary<string, string>()));
        }
        public void WhenTypeAttributeIsNotFound_ThenThrows()
        {
            var processor = new ModelElementDirectiveProcessor();

            processor.StartProcessingRun(provider, null, new CompilerErrorCollection());
            Assert.Throws <DirectiveProcessorException>(() => processor.ProcessDirective("ModelElement", new Dictionary <string, string>()));
        }
        public void WhenGettingReferenceWithEmptyElementAssemblyPath_ThenThrows()
        {
            var processor = new ModelElementDirectiveProcessor();
            CallContext.LogicalSetData(ModelElementDirectiveProcessor.KeyCallContextElementAssemblyPath, "");

            Assert.Throws<DirectiveProcessorException>(() => processor.GetReferencesForProcessingRun());
        }
        public void WhenGettingReferenceWithNonExistingElementAssemblyPath_ThenThrows()
        {
            var processor = new ModelElementDirectiveProcessor();

            CallContext.LogicalSetData(ModelElementDirectiveProcessor.KeyCallContextElementAssemblyPath, "C:\\Temp\\" + Guid.NewGuid().ToString("X") + ".dll");

            Assert.Throws <DirectiveProcessorException>(() => processor.GetReferencesForProcessingRun());
        }
        public void WhenGettingReferenceWithEmptyElementAssemblyPath_ThenThrows()
        {
            var processor = new ModelElementDirectiveProcessor();

            CallContext.LogicalSetData(ModelElementDirectiveProcessor.KeyCallContextElementAssemblyPath, "");

            Assert.Throws <DirectiveProcessorException>(() => processor.GetReferencesForProcessingRun());
        }
        public void WhenGettingImportsAndElementNamespaceWasDefined_ThenReturnsDefaultImportsAndElementNamespace()
        {
            var processor = new ModelElementDirectiveProcessor();

            CallContext.LogicalSetData(ModelElementDirectiveProcessor.KeyCallContextElementNamespace, "FooNamespace");
            var imports = processor.GetImportsForProcessingRun();

            Assert.True(imports.Contains("FooNamespace"));
        }
        public void WhenGettingImports_ThenReturnsDefaultImports()
        {
            var processor = new ModelElementDirectiveProcessor();

            var imports = processor.GetImportsForProcessingRun();

            Assert.True(imports.Contains(typeof(System.Linq.IQueryable).Namespace));
            Assert.True(imports.Contains(typeof(System.Collections.Generic.IEnumerable <>).Namespace));
            Assert.True(imports.Contains(typeof(Microsoft.VisualStudio.Modeling.Integration.IModelBus).Namespace));
        }
        public void WhenGettingReferenceAndElementAssemblyPathWasDefined_ThenReturnsDefaultReferencesAndElementReference()
        {
            var processor = new ModelElementDirectiveProcessor();

            var elementAssemblyPath = Path.GetTempFileName();

            CallContext.LogicalSetData(ModelElementDirectiveProcessor.KeyCallContextElementAssemblyPath, elementAssemblyPath);
            var references = processor.GetReferencesForProcessingRun();

            Assert.True(references.Contains(elementAssemblyPath));
        }
        public void WhenTypeAttributeIsFound_ThenElementPropertyIsGenerated()
        {
            var processor = new ModelElementDirectiveProcessor();

            processor.StartProcessingRun(provider, null, new CompilerErrorCollection());
            processor.ProcessDirective("ModelElement", directiveAttributes);
            var result = processor.GetClassCodeForProcessingRun();

            Assert.NotNull(result);
            Assert.True(result.Contains("public new Foo.Bar Element"));
            Assert.True(result.Contains("return ((Foo.Bar)(base.Element));"));
        }
        public void WhenTypeAttributeIsFound_ThenElementPropertyIsGenerated()
        {
            var processor = new ModelElementDirectiveProcessor();

            processor.StartProcessingRun(provider, null, new CompilerErrorCollection());
            processor.ProcessDirective("ModelElement", directiveAttributes);
            var result = processor.GetClassCodeForProcessingRun();

            Assert.NotNull(result);
            Assert.True(result.Contains("public new Foo.Bar Element"));
            Assert.True(result.Contains("return ((Foo.Bar)(base.Element));"));
        }
        public void WhenGettingReference_ThenReturnsDefaultReferences()
        {
            var processor           = new ModelElementDirectiveProcessor();
            var elementAssemblyPath = this.GetType().Assembly.ManifestModule.FullyQualifiedName;

            CallContext.LogicalSetData(ModelElementDirectiveProcessor.KeyCallContextElementAssemblyPath, elementAssemblyPath);

            var references = processor.GetReferencesForProcessingRun();

            Assert.True(references.Contains(typeof(IQueryable).Assembly.Location));
            Assert.True(references.Contains(typeof(IVsHierarchy).Assembly.Location));
            Assert.True(references.Contains(typeof(ModelElement).Assembly.Location));
            Assert.True(references.Contains(typeof(IModelBus).Assembly.Location));
            Assert.True(references.Contains(typeof(ModelBusEnabledTextTransformation).Assembly.Location));
        }
        public void WhenGettingReferenceWithoutElementAssemblyPath_ThenThrows()
        {
            var processor = new ModelElementDirectiveProcessor();

            Assert.Throws<DirectiveProcessorException>(() => processor.GetReferencesForProcessingRun());
        }
        public void WhenDirectiveNameIsModeling_ThenDirectiveIsSupported()
        {
            var processor = new ModelElementDirectiveProcessor();

            Assert.True(processor.IsDirectiveSupported("ModelElement"));
        }
        public void WhenDirectiveNameIsNotModelElement_ThenDirectiveIsNotSupported()
        {
            var processor = new ModelElementDirectiveProcessor();

            Assert.False(processor.IsDirectiveSupported("Foo"));
        }
        public void WhenGettingImportsAndElementNamespaceWasDefined_ThenReturnsDefaultImportsAndElementNamespace()
        {
            var processor = new ModelElementDirectiveProcessor();

            CallContext.LogicalSetData(ModelElementDirectiveProcessor.KeyCallContextElementNamespace, "FooNamespace");
            var imports = processor.GetImportsForProcessingRun();

            Assert.True(imports.Contains("FooNamespace"));
        }
        public void WhenGettingImports_ThenReturnsDefaultImports()
        {
            var processor = new ModelElementDirectiveProcessor();

            var imports = processor.GetImportsForProcessingRun();

            Assert.True(imports.Contains(typeof(System.Linq.IQueryable).Namespace));
            Assert.True(imports.Contains(typeof(System.Collections.Generic.IEnumerable<>).Namespace));
            Assert.True(imports.Contains(typeof(Microsoft.VisualStudio.Modeling.Integration.IModelBus).Namespace));
        }
        public void WhenDirectiveNameIsNotModelElement_ThenDirectiveIsNotSupported()
        {
            var processor = new ModelElementDirectiveProcessor();

            Assert.False(processor.IsDirectiveSupported("Foo"));
        }
        public void WhenGettingReferenceWithNonExistingElementAssemblyPath_ThenThrows()
        {
            var processor = new ModelElementDirectiveProcessor();
            CallContext.LogicalSetData(ModelElementDirectiveProcessor.KeyCallContextElementAssemblyPath, "C:\\Temp\\" + Guid.NewGuid().ToString("X") + ".dll");

            Assert.Throws<DirectiveProcessorException>(() => processor.GetReferencesForProcessingRun());
        }
        public void WhenDirectiveNameIsModeling_ThenDirectiveIsSupported()
        {
            var processor = new ModelElementDirectiveProcessor();

            Assert.True(processor.IsDirectiveSupported("ModelElement"));
        }
        public void WhenGettingReferenceWithoutElementAssemblyPath_ThenThrows()
        {
            var processor = new ModelElementDirectiveProcessor();

            Assert.Throws <DirectiveProcessorException>(() => processor.GetReferencesForProcessingRun());
        }
        public void WhenGettingReference_ThenReturnsDefaultReferences()
        {
            var processor = new ModelElementDirectiveProcessor();
            var elementAssemblyPath = this.GetType().Assembly.ManifestModule.FullyQualifiedName;
            CallContext.LogicalSetData(ModelElementDirectiveProcessor.KeyCallContextElementAssemblyPath, elementAssemblyPath);

            var references = processor.GetReferencesForProcessingRun();

            Assert.True(references.Contains(typeof(IQueryable).Assembly.Location));
            Assert.True(references.Contains(typeof(IVsHierarchy).Assembly.Location));
            Assert.True(references.Contains(typeof(ModelElement).Assembly.Location));
            Assert.True(references.Contains(typeof(IModelBus).Assembly.Location));
            Assert.True(references.Contains(typeof(ModelBusEnabledTextTransformation).Assembly.Location));
        }
        public void WhenGettingReferenceAndElementAssemblyPathWasDefined_ThenReturnsDefaultReferencesAndElementReference()
        {
            var processor = new ModelElementDirectiveProcessor();

            var elementAssemblyPath = Path.GetTempFileName();
            CallContext.LogicalSetData(ModelElementDirectiveProcessor.KeyCallContextElementAssemblyPath, elementAssemblyPath);
            var references = processor.GetReferencesForProcessingRun();

            Assert.True(references.Contains(elementAssemblyPath));
        }