Exemplo n.º 1
0
        public void CanAddAttributeToGeneratedModelClass()
        {
            CodeDomClassModel generator = new CodeDomClassModel(this.csFilePath, "ClassAttributeTest");

            generator.AddClassAttribute(new AttributeModel("Serializable"));
            generator.AddClassAttribute(new AttributeModel("XmlRoot", new object[] { "add" }));
            this.namesp.References.Add(NamespaceReference.System);
            this.namesp.References.Add(NamespaceReference.SystemXmlSerialization);

            generator.GenerateCCsharpClass(this.namesp);

            using (StreamReader reader = File.OpenText(Path.Combine(this.csFilePath, "ClassAttributeTest.cs")))
            {
                string fileContents = reader.ReadToEnd();
                Assert.IsTrue(fileContents.Contains("[Serializable()]"));
                Assert.IsTrue(fileContents.Contains("[XmlRoot(\"add\")]"));
            }

            generator.CompileClassFromGeneratedCsFile(this.namesp);

            string assemblyName = Path.Combine(this.csFilePath, $"{this.namesp.Name}.dll");

            loadAssemblyInSecondaryAppDomain(
                assemblyName,
                generatedAssembly =>
            {
                Type generatedType = generatedAssembly.GetType($"{namesp.Name}.ClassAttributeTest");

                Assert.IsNotNull(generatedType);
            });
        }
Exemplo n.º 2
0
        public void CanCreateCsFile()
        {
            string finalFileName = Path.Combine(this.csFilePath, $"{className}.cs");

            CodeDomClassModel generator = new CodeDomClassModel(this.csFilePath, className);

            generator.GenerateCCsharpClass(this.namesp);

            Assert.IsTrue(File.Exists(finalFileName));
        }