Пример #1
0
        private MyArtifactLink CreateLink(ExtensibleMockModelElement element, string lang)
        {
            MyArtifactLink link = new MyArtifactLink(element);

            link.Data.Add(typeof(ProjectNode).FullName, GetTestProjectNode(lang));
            link.Data.Add(typeof(IServiceProvider).FullName, new MockServiceProvider());
            return(link);
        }
		public void TestMyCodeGeneratorGetsCalled()
		{
			MyArtifactLink link = new MyArtifactLink(ItemPath);
			CodeGenerationService codeGenerator = CreateCodeGenerator(ItemPath, out rdt);
			
			Assert.IsTrue(codeGenerator.GenerateArtifact(link) > 0);
			Assert.AreEqual<string>(MyCodeGenerator.HelloWorld, GetGeneratedCode());
		}
        public void ShouldGetGetBaseTypesFromReferencedType()
        {
            MyArtifactLink link  = new MyArtifactLink("SampleData\\BaseTypes.xsd", "LandmarkPoint");
            IList <string> types = XmlSchemaUtility.GetBaseTypesFromReferencedType(@"xsd:\\SampleData\BaseTypes.xsd?LandmarkPoint", link);

            Assert.IsTrue(types.Count > 0);
            Assert.AreEqual <string>(link.Namespace + ".LandmarkBase", types[0]);
        }
Пример #4
0
        public void TestMyCodeGeneratorGetsCalled()
        {
            MyArtifactLink        link          = new MyArtifactLink(ItemPath);
            CodeGenerationService codeGenerator = CreateCodeGenerator(ItemPath, out rdt);

            Assert.IsTrue(codeGenerator.GenerateArtifact(link) > 0);
            Assert.AreEqual <string>(MyCodeGenerator.HelloWorld, GetGeneratedCode());
        }
		public void ShouldGetGetBaseTypesFromReferencedType()
		{
			MyArtifactLink link = new MyArtifactLink("SampleData\\BaseTypes.xsd", "LandmarkPoint");
			IList<string> types = XmlSchemaUtility.GetBaseTypesFromReferencedType(@"xsd:\\SampleData\BaseTypes.xsd?LandmarkPoint", link);

			Assert.IsTrue(types.Count > 0);
			Assert.AreEqual<string>(link.Namespace + ".LandmarkBase", types[0]);
		}
		public void ShouldGetGetXmlSchemaSource()
		{
			MyArtifactLink link = new MyArtifactLink("SampleData\\SimpleSchema1.xsd", "element1");
			string schemaSource = XmlSchemaUtility.GetXmlSchemaSource(@"xsd:\\SampleData\SimpleSchema1.xsd?element1", link);

			Assert.IsTrue(Path.IsPathRooted(schemaSource));
			Assert.IsTrue(File.Exists(schemaSource));
		}
        public void ShouldGetGetXmlSchemaSource()
        {
            MyArtifactLink link         = new MyArtifactLink("SampleData\\SimpleSchema1.xsd", "element1");
            string         schemaSource = XmlSchemaUtility.GetXmlSchemaSource(@"xsd:\\SampleData\SimpleSchema1.xsd?element1", link);

            Assert.IsTrue(Path.IsPathRooted(schemaSource));
            Assert.IsTrue(File.Exists(schemaSource));
        }
Пример #8
0
        public void ShouldGenerateWithErrorsOnInvalidSchema()
        {
            MyArtifactLink link = new MyArtifactLink("SampleData\\InvalidSchema.xsd", "SomeElement");
            XmlSchemaCodeGenerationStrategy strategy = new XmlSchemaCodeGenerationStrategy();
            CodeGenerationResults           content  = strategy.Generate(link);

            Assert.AreEqual <int>(0, content.Count);
            Assert.AreEqual <int>(1, strategy.Errors.Count);
        }
Пример #9
0
        public void ShouldUpdateArtifactLinkData()
        {
            MyArtifactLink link = new MyArtifactLink();

            Utility.SetData <string>(link, "foo");
            string data = Utility.GetData <string>(link);

            Assert.AreEqual <string>("foo", data);
        }
			public MyContainer(int instances)
			{
				links = new List<IArtifactLink>();
				IArtifactLink link = new MyArtifactLink();
				for (int i = 0; i < instances; i++)
				{
					links.Add(link);
				}
			}
Пример #11
0
        public void ShouldGenerateOnceWithMultipleSameFiles()
        {
            MyArtifactLink        link          = new MyArtifactLink(ItemPath);
            CodeGenerationService codeGenerator = CreateCodeGenerator(ItemPath, out rdt);

            Assert.AreEqual <int>(1, codeGenerator.GenerateArtifact(link));
            Assert.AreEqual <int>(0, codeGenerator.GenerateArtifact(link));
            Assert.AreEqual <string>(MyCodeGenerator.HelloWorld, GetGeneratedCode());
        }
		public void ShouldGenerateWithErrorsOnInvalidSchema()
		{
			MyArtifactLink link = new MyArtifactLink("SampleData\\InvalidSchema.xsd", "SomeElement");
			XmlSchemaCodeGenerationStrategy strategy = new XmlSchemaCodeGenerationStrategy();
			CodeGenerationResults content = strategy.Generate(link);

			Assert.AreEqual<int>(0, content.Count);
			Assert.AreEqual<int>(1, strategy.Errors.Count);
		}
            public MyContainer(int instances)
            {
                links = new List <IArtifactLink>();
                IArtifactLink link = new MyArtifactLink();

                for (int i = 0; i < instances; i++)
                {
                    links.Add(link);
                }
            }
Пример #14
0
        public void ShouldResolveToVBTemplateWhenProjectIsVB()
        {
            string message = "Hello World";
            ExtensibleMockModelElement         myModelElement = new ExtensibleMockModelElement(partition, message);
            MyArtifactLink                     link           = CreateLink(myModelElement, EnvDTE.CodeModelLanguageConstants.vsCMLanguageVB);
            TextTemplateCodeGenerationStrategy strategy       = new TextTemplateCodeGenerationStrategy();

            strategy.ResourceResolver = link;
            IDictionary <string, string> result = strategy.Generate(link);

            StringAssert.Contains(result[link.ItemPath], @"Generated from VB");
        }
Пример #15
0
        public void TestMyTemplateGetsCalled()
        {
            string message = "Hello World";
            ExtensibleMockModelElement myModelElement = new ExtensibleMockModelElement(partition, message);
            MyArtifactLink             link           = CreateLink(myModelElement);

            TextTemplateCodeGenerationStrategy strategy = new TextTemplateCodeGenerationStrategy();

            strategy.ResourceResolver = link;
            IDictionary <string, string> result = strategy.Generate(link);

            Assert.AreEqual <string>(message, result[link.ItemPath]);
        }
Пример #16
0
        public void ShouldGenerateWithSimpleSchema()
        {
            MyArtifactLink link = new MyArtifactLink("SampleData\\SimpleSchema1.xsd", "element1");
            XmlSchemaCodeGenerationStrategy strategy = new XmlSchemaCodeGenerationStrategy();
            CodeGenerationResults           content  = strategy.Generate(link);

            Assert.AreEqual <int>(3, content.Count);
            Assert.AreEqual <int>(0, strategy.Errors.Count);

            CompilerResults results = DynamicCompilation.CompileAssemblyFromSource(JoinContent(content), ((List <string>)strategy.AssemblyReferences).ToArray());

            Assert.AreEqual <int>(3, results.CompiledAssembly.GetTypes().Length);
            TypeAsserter.AssertAttribute <DataContractAttribute>(results.CompiledAssembly.GetType("element1"));
        }
Пример #17
0
        public void ShouldGenerateOneXmlRootAttribute()
        {
            MyArtifactLink link = new MyArtifactLink("SampleData\\OneXmlRootAttribute.xsd", "ImplementsAbstractCT");

            Utility.SetData(link, true, XmlSchemaCodeGenerationStrategy.UseXmlSerializerDataKey);
            XmlSchemaCodeGenerationStrategy strategy = new XmlSchemaCodeGenerationStrategy();
            CodeGenerationResults           content  = strategy.Generate(link);

            CompilerResults results = DynamicCompilation.CompileAssemblyFromSource(JoinContent(content), ((List <string>)strategy.AssemblyReferences).ToArray());

            TypeAsserter.AssertAttribute <XmlRootAttribute>(results.CompiledAssembly.GetType("ImplementsAbstractCT"));
            Type type = results.CompiledAssembly.GetType("MyAbstractCT");

            Assert.AreEqual <int>(0, type.GetCustomAttributes(typeof(XmlRootAttribute), true).Length);
        }
Пример #18
0
        public void ShouldGenerateTypesRefsFromAttributes()
        {
            MyArtifactLink link = new MyArtifactLink("SampleData\\TypeRefsInAttributes.wsdl", "AttachmentAddRq");

            Utility.SetData(link, true, XmlSchemaCodeGenerationStrategy.UseXmlSerializerDataKey);
            XmlSchemaCodeGenerationStrategy strategy = new XmlSchemaCodeGenerationStrategy();
            CodeGenerationResults           content  = strategy.Generate(link);

            Assert.AreEqual <int>(69, content.Count);
            Assert.AreEqual <int>(0, strategy.Errors.Count);

            CompilerResults results = DynamicCompilation.CompileAssemblyFromSource(JoinContent(content), ((List <string>)strategy.AssemblyReferences).ToArray());

            Assert.AreEqual <int>(69, results.CompiledAssembly.GetTypes().Length);
            Assert.IsNotNull(results.CompiledAssembly.GetType("AddressType", false, false));
        }
Пример #19
0
        public void TestArtifactIsGenerated()
        {
            MockServiceProvider serviceProvider = new MockServiceProvider();
            MockVSHierarchy     root            = new MockVSHierarchy();
            MockVsSolution      solution        = new MockVsSolution(root);
            MockVSHierarchy     project         = new MockVSHierarchy("Project1.project");

            root.AddProject(project);
            serviceProvider.AddService(typeof(SVsSolution), solution);
            CodeGenerationService target    = new CodeGenerationService(serviceProvider);
            MyArtifactLink        validLink = new MyArtifactLink(project.GUID, "item1.cs");

            Assert.IsFalse(target.IsArtifactAlreadyGenerated(validLink));
            project.AddChild("item1.cs");
            Assert.IsTrue(target.IsArtifactAlreadyGenerated(validLink));
        }
Пример #20
0
        public void TestValidateDelete()
        {
            MockServiceProvider serviceProvider = new MockServiceProvider();
            MockVSHierarchy     root            = new MockVSHierarchy();
            MockVsSolution      solution        = new MockVsSolution(root);
            MockVSHierarchy     project         = new MockVSHierarchy("Project1.project");

            root.AddProject(project);
            serviceProvider.AddService(typeof(SVsSolution), solution);
            TestableCodeGenerationService target = new TestableCodeGenerationService(serviceProvider);
            MyArtifactLink validLink             = new MyArtifactLink(project.GUID, "item1.cs");
            HierarchyNode  node = target.ValidateDelete(validLink);

            Assert.IsNull(node);
            Assert.AreEqual <int>(0, target.LogEntries.Count);
            project.AddChild("item1.cs");
            node = target.ValidateDelete(validLink);
            Assert.IsNotNull(node);
            Assert.AreEqual <int>(1, target.LogEntries.Count);
        }
Пример #21
0
        public void TestValidate()
        {
            MockServiceProvider serviceProvider = new MockServiceProvider();
            MockVSHierarchy     root            = new MockVSHierarchy();
            MockVsSolution      solution        = new MockVsSolution(root);
            MockVSHierarchy     project         = new MockVSHierarchy("Project1.project");

            root.AddProject(project);
            serviceProvider.AddService(typeof(SVsSolution), solution);
            CodeGenerationService target    = new CodeGenerationService(serviceProvider);
            MyArtifactLink        validLink = new MyArtifactLink(project.GUID, "item1.cs");

            Assert.IsTrue(target.IsValid(validLink));
            MyArtifactLink invalidLink1 = new MyArtifactLink(Guid.NewGuid(), "item2.cs");

            Assert.IsFalse(target.IsValid(invalidLink1));
            MyArtifactLink invalidLink2 = new MyArtifactLink(project.GUID, "it:em3.cs");

            Assert.IsFalse(target.IsValid(invalidLink2));
            MyArtifactLink invalidLink3 = new MyArtifactLink(Guid.NewGuid(), "<item3.cs>");

            Assert.IsFalse(target.IsValid(invalidLink3));
        }
		public void ShouldGenerateOneXmlRootAttribute()
		{
			MyArtifactLink link = new MyArtifactLink("SampleData\\OneXmlRootAttribute.xsd", "ImplementsAbstractCT");
			Utility.SetData(link, true, XmlSchemaCodeGenerationStrategy.UseXmlSerializerDataKey);
			XmlSchemaCodeGenerationStrategy strategy = new XmlSchemaCodeGenerationStrategy();
			CodeGenerationResults content = strategy.Generate(link);

			CompilerResults results = DynamicCompilation.CompileAssemblyFromSource(JoinContent(content), ((List<string>)strategy.AssemblyReferences).ToArray());

			TypeAsserter.AssertAttribute<XmlRootAttribute>(results.CompiledAssembly.GetType("ImplementsAbstractCT"));
			Type type = results.CompiledAssembly.GetType("MyAbstractCT");
			Assert.AreEqual<int>(0, type.GetCustomAttributes(typeof(XmlRootAttribute), true).Length);
		}
		public void ShouldGenerateTypesRefsFromAttributes()
		{
			MyArtifactLink link = new MyArtifactLink("SampleData\\TypeRefsInAttributes.wsdl", "AttachmentAddRq");
			Utility.SetData(link, true, XmlSchemaCodeGenerationStrategy.UseXmlSerializerDataKey);
			XmlSchemaCodeGenerationStrategy strategy = new XmlSchemaCodeGenerationStrategy();
			CodeGenerationResults content = strategy.Generate(link);

			Assert.AreEqual<int>(69, content.Count);
			Assert.AreEqual<int>(0, strategy.Errors.Count);

			CompilerResults results = DynamicCompilation.CompileAssemblyFromSource(JoinContent(content), ((List<string>)strategy.AssemblyReferences).ToArray());
			Assert.AreEqual<int>(69, results.CompiledAssembly.GetTypes().Length);
			Assert.IsNotNull(results.CompiledAssembly.GetType("AddressType", false, false));
		}
		public void ShouldGenerateOnceWithMultipleSameFiles()
		{
			MyArtifactLink link = new MyArtifactLink(ItemPath);
			CodeGenerationService codeGenerator = CreateCodeGenerator(ItemPath, out rdt);

			Assert.AreEqual<int>(1, codeGenerator.GenerateArtifact(link));
			Assert.AreEqual<int>(0, codeGenerator.GenerateArtifact(link));
			Assert.AreEqual<string>(MyCodeGenerator.HelloWorld, GetGeneratedCode());
		}
Пример #25
0
		public void ShouldUpdateArtifactLinkData()
		{
			MyArtifactLink link = new MyArtifactLink();
			Utility.SetData<string>(link, "foo");
			string data = Utility.GetData<string>(link);

			Assert.AreEqual<string>("foo", data);
		}
		private MyArtifactLink CreateLink(ExtensibleMockModelElement element, string lang)
		{
			MyArtifactLink link = new MyArtifactLink(element);
			link.Data.Add(typeof(ProjectNode).FullName, GetTestProjectNode(lang));
			link.Data.Add(typeof(IServiceProvider).FullName, new MockServiceProvider());
			return link;
		}
		public void TestValidate()
		{
			MockServiceProvider serviceProvider = new MockServiceProvider();
			MockVSHierarchy root = new MockVSHierarchy();
			MockVsSolution solution = new MockVsSolution(root);
			MockVSHierarchy project = new MockVSHierarchy("Project1.project");
			root.AddProject(project);
			serviceProvider.AddService(typeof(SVsSolution), solution);
			CodeGenerationService target = new CodeGenerationService(serviceProvider);
			MyArtifactLink validLink = new MyArtifactLink(project.GUID, "item1.cs");

			Assert.IsTrue(target.IsValid(validLink));
			MyArtifactLink invalidLink1 = new MyArtifactLink(Guid.NewGuid(), "item2.cs");
			Assert.IsFalse(target.IsValid(invalidLink1));
			MyArtifactLink invalidLink2 = new MyArtifactLink(project.GUID, "it:em3.cs");
			Assert.IsFalse(target.IsValid(invalidLink2));
			MyArtifactLink invalidLink3 = new MyArtifactLink(Guid.NewGuid(), "<item3.cs>");
			Assert.IsFalse(target.IsValid(invalidLink3));
		}
		public void TestValidateEmptyRename()
		{
			MockServiceProvider serviceProvider = new MockServiceProvider();
			MockVSHierarchy root = new MockVSHierarchy();
			MockVsSolution solution = new MockVsSolution(root);
			MockVSHierarchy project = new MockVSHierarchy("Project1.project");
			root.AddProject(project);
			serviceProvider.AddService(typeof(SVsSolution), solution);
			TestableCodeGenerationService target = new TestableCodeGenerationService(serviceProvider);
			string oldName = "item1";
			string newName = "";
			MyArtifactLink validLink = new MyArtifactLink(project.GUID, oldName + ".cs");
			HierarchyNode node = target.ValidateRename(validLink, newName, oldName);

			Assert.IsNull(node);
			project.AddChild(oldName + ".cs");
			node = target.ValidateRename(validLink, oldName, oldName);
			Assert.IsNull(node);
			Assert.AreEqual<int>(0, target.LogEntries.Count);
			node = target.ValidateRename(validLink, newName, oldName);
			Assert.IsNotNull(node);
			Assert.AreEqual<int>(1, target.LogEntries.Count);
		}
		public void ShouldGenerateWithSimpleSchema()
		{
			MyArtifactLink link = new MyArtifactLink("SampleData\\SimpleSchema1.xsd", "element1");
			XmlSchemaCodeGenerationStrategy strategy = new XmlSchemaCodeGenerationStrategy();
			CodeGenerationResults content = strategy.Generate(link);

			Assert.AreEqual<int>(3, content.Count);
			Assert.AreEqual<int>(0, strategy.Errors.Count);

			CompilerResults results = DynamicCompilation.CompileAssemblyFromSource(JoinContent(content), ((List<string>)strategy.AssemblyReferences).ToArray());
			Assert.AreEqual<int>(3, results.CompiledAssembly.GetTypes().Length);
			TypeAsserter.AssertAttribute<DataContractAttribute>(results.CompiledAssembly.GetType("element1"));
		}
		public void TestArtifactIsGenerated()
		{
			MockServiceProvider serviceProvider = new MockServiceProvider();
			MockVSHierarchy root = new MockVSHierarchy();
			MockVsSolution solution = new MockVsSolution(root);
			MockVSHierarchy project = new MockVSHierarchy("Project1.project");
			root.AddProject(project);
			serviceProvider.AddService(typeof(SVsSolution), solution);
			CodeGenerationService target = new CodeGenerationService(serviceProvider);
			MyArtifactLink validLink = new MyArtifactLink(project.GUID, "item1.cs");

			Assert.IsFalse(target.IsArtifactAlreadyGenerated(validLink));
			project.AddChild("item1.cs");
			Assert.IsTrue(target.IsArtifactAlreadyGenerated(validLink));
		}