private void TestBuildCode(string classFileName, string xmlFileName, string contentTypeName) { ContentType contentType; var expectedOutput = ""; using (var inputReader = File.OpenText(@"..\..\TestFiles\" + xmlFileName + ".xml")) { contentType = new ContentTypeSerializer().Deserialize(inputReader); } using (var goldReader = File.OpenText(@"..\..\TestFiles\" + classFileName + ".cs")) { expectedOutput = goldReader.ReadToEnd(); } var configuration = new CodeGeneratorConfiguration(); configuration.TypeMappings.Add(new TypeMapping("1413afcb-d19a-4173-8e9a-68288d2a73b8", "Int32")); var typeConfig = configuration.Get(contentTypeName); typeConfig.BaseClass = "Umbraco.Core.Models.TypedModelBase"; typeConfig.Namespace = "Umbraco.CodeGen.Models"; var sb = new StringBuilder(); var writer = new StringWriter(sb); var dataTypeProvider = new TestDataTypeProvider(); var generator = new CodeGenerator(typeConfig, dataTypeProvider, new AnnotatedCodeGeneratorFactory()); generator.Generate(contentType, writer); writer.Flush(); Console.WriteLine(sb.ToString()); Assert.AreEqual(expectedOutput, sb.ToString()); }
protected void TestBuildCode(string classFileName, DocumentType contentType, string contentTypeName) { string expectedOutput; using (var goldReader = File.OpenText(@"..\..\TestFiles\" + classFileName + ".cs")) { expectedOutput = goldReader.ReadToEnd(); } var configuration = CodeGeneratorConfiguration.Create(); var typeConfig = configuration.Get(contentTypeName); typeConfig.BaseClass = "Umbraco.Core.Models.TypedModelBase"; typeConfig.Namespace = "Umbraco.CodeGen.Models"; configuration.TypeMappings.Add(new TypeMapping("Umbraco.Integer", "Int32")); OnConfiguring(configuration, contentTypeName); var sb = new StringBuilder(); var writer = new StringWriter(sb); var dataTypeProvider = new TestDataTypeProvider(); var generator = new CodeGenerator(typeConfig, dataTypeProvider, CreateGeneratorFactory()); generator.Generate(contentType, writer); writer.Flush(); Console.WriteLine(sb.ToString()); Assert.AreEqual(expectedOutput, sb.ToString()); }