public async Task ExecuteInMemoryTest() { var fileName = ".\\test-project.mdj"; var project = await DVDpro.StarUML.FileFormat.Project.LoadAsync(fileName); var generator = new EnumGenerator(); using (var ms = new System.IO.MemoryStream()) { using (var outStream = new CSharpWriter(ms)) { foreach (var model in project.GetChildrenByType <DVDpro.StarUML.FileFormat.Nodes.UmlModelNode>()) { var enumNode = model.GetChildrenByType <DVDpro.StarUML.FileFormat.Nodes.UmlEnumerationNode>().First(r => r.Name == "MasterEnum"); generator.Generate(outStream, enumNode); } outStream.Flush(); ms.Seek(0, System.IO.SeekOrigin.Begin); using (var reader = new System.IO.StreamReader(ms)) { var output = reader.ReadToEnd(); Assert.Equal("/// <summary>\r\n/// Test enum comment\r\n/// multiline\r\n/// </summary>\r\npublic enum MasterEnum\r\n{\r\n /// <summary>test literal comment</summary>\r\n Literal1 = 0x1,\r\n\r\n Literal2\r\n}\r\n", output); } } } }
public void WriteTo(CSharpContext context, CSharpPackage package, CSharpWriter writer) { using (var bodyWriter = new CSharpWriter()) { // render body first, so usings are resolved using (bodyWriter.WriteIndentedBlock(prefix: $"namespace {CSharpHelpers.CombineNamespaces(package.Namespace, this.RelativeNamespace)} ")) { foreach (var fragment in Fragments) { fragment.WriteTo(context, package, this, bodyWriter); } } bodyWriter.Flush(); // render usings if (Usings.Count > 0) { foreach (var @using in Usings) { writer.WriteIndented($"using {@using};"); } writer.WriteLine(); } // render body bodyWriter.WriteTo(writer); } }