diff --git a/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderTests.AppendVariants.cs b/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderTests.AppendVariants.cs new file mode 100644 index 00000000..55281d77 --- /dev/null +++ b/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderTests.AppendVariants.cs @@ -0,0 +1,110 @@ +namespace NetEvolve.CodeBuilder.Tests.Integration; + +using System; + +public partial class CSharpCodeBuilderTests +{ + [Test] + public async Task GenerateFromMixedCharSources_Should_ProduceCorrectOutput() + { + var arrayFragment = "field one".ToCharArray(); + var memoryFragment = "field two".AsMemory(); + var spanFragment = "field three".AsSpan(); + + var builder = new CSharpCodeBuilder() + .AppendLine("public class MixedSourceFragment") + .Append("{") + .Append("public string A => \"") + .Append(arrayFragment) + .AppendLine("\";") + .Append("public string B => \"") + .Append(arrayFragment, 0, 5) + .AppendLine("\";") + .Append("public string C => \"") + .Append(memoryFragment) + .AppendLine("\";") + .Append("public string D => \"") + .Append(memoryFragment, 0, 5) + .AppendLine("\";") + .Append("public string E => \"") + .Append(spanFragment) + .AppendLine("\";") + .Append("public string F => \"") + .Append(spanFragment, 0, 5) + .AppendLine("\";") + .Append("public string G => \"") + .Append("full string field", 0, 4) + .AppendLine("\";") + .Append("}"); + + var result = builder.ToString(); + + _ = await Verify(result).ConfigureAwait(false); + } + + [Test] +#pragma warning disable S6640 // Unsafe code is intentional to exercise the pointer-based overloads + public unsafe Task GenerateFromPointerSource_Should_ProduceCorrectOutput() + { + var text = "pointer field"; + + string result; + fixed (char* pointer = text) + { + var builder = new CSharpCodeBuilder() + .AppendLine("public class PointerSourceFragment") + .Append("{") + .Append("public string Value => \"") + .Append(pointer, text.Length) + .AppendLine("\";") + .Append("}"); + + result = builder.ToString(); + } + + return Verify(result); + } +#pragma warning restore S6640 + + [Test] + public async Task GenerateWithEmptyAndNullSources_Should_BeIgnored() + { + var builder = new CSharpCodeBuilder() + .Append(default(char[])) + .Append(Array.Empty()) + .Append(default(char[]), 0, 0) + .Append(ReadOnlyMemory.Empty) + .Append(ReadOnlySpan.Empty) + .Append(default(string)) + .Append(string.Empty) + .Append("\0"); + + _ = await Assert.That(builder.ToString()).IsEqualTo(string.Empty); + } + + [Test] + public async Task GenerateNestedBracesFromRawCharsAndStrings_Should_ProduceCorrectOutput() + { + // Exercises the special handling of '{', '}', '[', ']', '\n', '\r' for both the + // char and string overloads of Append, as used when a generator emits raw braces + // received from an external template rather than literal source code. + var builder = new CSharpCodeBuilder() + .AppendLine("public class RawBraceFragment") + .Append('{') + .Append("public int[] Values") + .Append('[') + .Append("public int Value") + .Append('\n') + .Append(']') + .Append('\r') + .Append("[") + .Append("public int Other") + .AppendLine("\r\n") + .Append("]") + .Append('}'); + + var result = builder.ToString(); + + _ = await Verify(result).ConfigureAwait(false); + } +} diff --git a/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderTests.ConditionalApi.cs b/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderTests.ConditionalApi.cs new file mode 100644 index 00000000..4982f0eb --- /dev/null +++ b/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderTests.ConditionalApi.cs @@ -0,0 +1,92 @@ +namespace NetEvolve.CodeBuilder.Tests.Integration; + +public partial class CSharpCodeBuilderTests +{ + [Test] + public async Task GenerateConfigurableClass_AllFlagsEnabled_Should_ProduceCorrectOutput() + { + var result = BuildConfigurableClass(enabled: true); + + _ = await Verify(result).ConfigureAwait(false); + } + + [Test] + public async Task GenerateConfigurableClass_AllFlagsDisabled_Should_ProduceCorrectOutput() + { + var result = BuildConfigurableClass(enabled: false); + + _ = await Verify(result).ConfigureAwait(false); + } + + // Exercises every AppendIf/AppendLineIf overload for both the "condition true" and + // "condition false" branches, mirroring how a real source generator toggles optional + // code fragments (feature flags, generated attributes, diagnostics, ...). + private static string BuildConfigurableClass(bool enabled) + { + var repeatChar = '-'; + var charArray = "// array-comment".ToCharArray(); + var memory = "// memory-comment".AsMemory(); + var span = "// span-comment".AsSpan(); + + var builder = new CSharpCodeBuilder() + .AppendLineIf(enabled, "// generated diagnostics header") + .AppendLineIf(enabled) + .AppendLine("public class ConfigurableService") + .Append("{") + .AppendIf(enabled, repeatChar, 20) + .AppendLineIf(enabled) + .AppendIf(enabled, "public bool IsEnabled") + .AppendLineIf(enabled, " => true;") + .AppendLineIf(!enabled, "public bool IsEnabled => false;") + .AppendIf(enabled, true) + .AppendLineIf(enabled) + .AppendIf(!enabled, false) + .AppendLineIf(!enabled) + .AppendLineIf(enabled, charArray) + .AppendLineIf(enabled, charArray, 3, 5) + .AppendLineIf(enabled, memory) + .AppendLineIf(enabled, memory, 3, 6) + .AppendLineIf(enabled, span) + .AppendLineIf(enabled, span, 3, 6) + .AppendIf(enabled, memory) + .AppendIf(enabled, memory, 3, 6) + .AppendIf(enabled, span) + .AppendIf(enabled, span, 3, 6) + .AppendIf(enabled, charArray) + .AppendIf(enabled, charArray, 3, 5) + .AppendIf(enabled, 'x') + .AppendLineIf(enabled, 'y') + .AppendLineIf(enabled, 'z', 3) + .AppendIf(enabled, "trailing-marker", 0, 8) + .AppendLineIf(enabled, "trailing-marker-line", 0, 13) + .Append("}"); + + return builder.ToString(); + } + + [Test] +#pragma warning disable S6640 // Unsafe code is intentional to exercise the pointer-based overloads + public unsafe Task GenerateConfigurableClass_WithPointerFragments_Should_ProduceCorrectOutput() + { + var text = "// pointer-comment"; + + string result; + fixed (char* pointer = text) + { + var builder = new CSharpCodeBuilder() + .AppendLine("public class PointerBackedFragment") + .Append("{") + .AppendIf(true, pointer, text.Length) + .AppendLineIf(true) + .AppendIf(false, pointer, text.Length) + .AppendLineIf(true, pointer, text.Length) + .AppendLineIf(false, pointer, text.Length) + .Append("}"); + + result = builder.ToString(); + } + + return Verify(result); + } +#pragma warning restore S6640 +} diff --git a/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderTests.DocumentationApi.cs b/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderTests.DocumentationApi.cs new file mode 100644 index 00000000..8ba5d6dd --- /dev/null +++ b/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderTests.DocumentationApi.cs @@ -0,0 +1,93 @@ +namespace NetEvolve.CodeBuilder.Tests.Integration; + +using System; +using System.Collections.Generic; +using System.Threading; + +public partial class CSharpCodeBuilderTests +{ + [Test] + public async Task GenerateFullyDocumentedMethod_Should_ProduceCorrectOutput() + { + var builder = new CSharpCodeBuilder() + .AppendLine("namespace MyApplication.Documentation;") + .AppendLine() + .AppendXmlDoc("A raw single-line documentation remark placed above the type.") + .AppendXmlDocSummary(["Represents a fully documented service.", "Every XML doc tag is exercised."]) + .AppendXmlDocTypeParams([("TRequest", "The request type."), ("TResponse", "The response type.")]) + .AppendXmlDocRemarks(["This type demonstrates every supported XML documentation helper.", "Line two."]) + .AppendXmlDocExample([ + "var service = new DocumentedService();", + "service.Process(request);", + ]) + .AppendXmlDocSeeAlso("DocumentedServiceBase") + .AppendXmlDocSeeAlso("https://example.invalid/docs", isHref: true) + .AppendLine("public sealed class DocumentedService") + .Append("{") + .AppendXmlDocSummary("Processes the specified request.") + .AppendXmlDocParams([ + ("request", "The request to process."), + ("cancellationToken", "A cancellation token."), + ]) + .AppendXmlDocReturns("The response produced for the request.") + .AppendXmlDocExceptions([ + ("ArgumentNullException", "Thrown when request is null."), + ("OperationCanceledException", "Thrown when the operation is cancelled."), + ]) + .AppendXmlDocException("Thrown when the service has not been initialized.") + .AppendXmlDocSee("DocumentedServiceBase.Process") + .AppendXmlDocExample("var response = service.Process(request, default);") + .AppendLine("public TResponse Process(TRequest request, CancellationToken cancellationToken)") + .Append("{") + .AppendLine("throw new NotImplementedException();") + .Append("}") + .AppendLine() + .AppendXmlDocValue("Gets the number of processed requests.") + .AppendLine("public int ProcessedCount { get; }") + .AppendLine() + .AppendXmlDocInheritDoc() + .AppendLine("public override string? ToString() => base.ToString();") + .AppendLine() + .AppendXmlDocInheritDoc("DocumentedServiceBase.Dispose") + .AppendLine("public void Dispose() { }") + .AppendLine() + .AppendXmlDocCustomElement("note", "This is a custom documentation element.", "type=\"important\"") + .AppendXmlDocCustomElement("preliminary") + .Append("}"); + + var result = builder.ToString(); + + _ = await Verify(result).ConfigureAwait(false); + } + + [Test] + public async Task GenerateDocumentation_WithEmptyOrNullInputs_Should_BeIgnored() + { + var builder = new CSharpCodeBuilder() + .AppendXmlDoc(null) + .AppendXmlDoc(string.Empty) + .AppendXmlDocSummary(default(string)) + .AppendXmlDocSummary(default(IEnumerable)) + .AppendXmlDocSummary(Array.Empty()) + .AppendXmlDocParam(null, "description") + .AppendXmlDocParam("name", null) + .AppendXmlDocParams(null) + .AppendXmlDocReturns(null) + .AppendXmlDocRemarks(default(string)) + .AppendXmlDocRemarks(default(IEnumerable)) + .AppendXmlDocException(null, "description") + .AppendXmlDocException("Type", null) + .AppendXmlDocExceptions(null) + .AppendXmlDocExample(default(string)) + .AppendXmlDocExample(default(IEnumerable)) + .AppendXmlDocSee(null) + .AppendXmlDocSeeAlso(null) + .AppendXmlDocValue(null) + .AppendXmlDocTypeParam(null, "description") + .AppendXmlDocTypeParam("name", null) + .AppendXmlDocTypeParams(null) + .AppendXmlDocCustomElement(null); + + _ = await Assert.That(builder.ToString()).IsEqualTo(string.Empty); + } +} diff --git a/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderTests.FormatAndInterpolationApi.cs b/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderTests.FormatAndInterpolationApi.cs new file mode 100644 index 00000000..682a0d4a --- /dev/null +++ b/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderTests.FormatAndInterpolationApi.cs @@ -0,0 +1,72 @@ +namespace NetEvolve.CodeBuilder.Tests.Integration; + +using System; +using System.Globalization; + +public partial class CSharpCodeBuilderTests +{ + [Test] +#pragma warning disable CA1305, MA0011 // Culture is intentionally omitted on some calls to exercise the convenience overloads + public async Task GenerateFormattedMembers_Should_ProduceCorrectOutput() + { + var index = 3; + var typeName = "decimal"; + FormattableString formattable = $"public {typeName} FieldFormattable;"; + FormattableString lineFormattable = $"public {typeName} LineFieldFormattable;"; + + var builder = new CSharpCodeBuilder() + .AppendLine("public class FormattedMembersFragment") + .Append("{") + .AppendFormat("public {0} Field0;", typeName) + .AppendLine() + .AppendFormat("public {0} Field{1};", typeName, index) + .AppendLine() + .AppendFormat(CultureInfo.InvariantCulture, "public {0} Field{1}_{2};", typeName, index, index + 1) + .AppendLine() + .AppendFormat(formattable) + .AppendLine() + .AppendLineFormat("public {0} LineField0;", typeName) + .AppendLineFormat("public {0} LineField{1};", typeName, index) + .AppendLineFormat(CultureInfo.InvariantCulture, "public {0} LineField{1}_{2};", typeName, index, index + 1) + .AppendLineFormat(lineFormattable) + .Append("}"); + + var result = builder.ToString(); + + _ = await Verify(result).ConfigureAwait(false); + } +#pragma warning restore CA1305, MA0011 + + [Test] + public async Task GenerateFormattedMembers_WithNullFormattable_Should_OnlyAppendLineTerminator() + { + var builder = new CSharpCodeBuilder() + .AppendFormat(default(FormattableString)) + .AppendLine("marker") + .AppendLineFormat(default(FormattableString)); + + var result = builder.ToString(); + + _ = await Assert.That(result).Contains("marker"); + } + + [Test] + public async Task GenerateWithInterpolatedHandler_Should_ProduceCorrectOutput() + { + var className = "InterpolatedFragment"; + var propertyName = "Total"; + var value = 42; + + var builder = new CSharpCodeBuilder(); + _ = builder.AppendLineInterpolated($"public class {className}"); + _ = builder.Append("{"); + _ = builder.AppendInterpolated($"public int {propertyName} => {value, 6:D3};"); + _ = builder.AppendLine(); + _ = builder.AppendLineInterpolated($"public string Empty => \"{string.Empty}\";"); + _ = builder.Append("}"); + + var result = builder.ToString(); + + _ = await Verify(result).ConfigureAwait(false); + } +} diff --git a/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderTests.ScopeAndCapacityApi.cs b/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderTests.ScopeAndCapacityApi.cs new file mode 100644 index 00000000..ad9d135b --- /dev/null +++ b/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderTests.ScopeAndCapacityApi.cs @@ -0,0 +1,77 @@ +namespace NetEvolve.CodeBuilder.Tests.Integration; + +public partial class CSharpCodeBuilderTests +{ + [Test] + public async Task GenerateNestedScopes_WithScopeLine_Should_ProduceCorrectOutput() + { + var builder = new CSharpCodeBuilder().AppendLine("namespace MyApplication.Scopes;").AppendLine(); + + using (builder.ScopeLine("public static class ScopedFragment")) + { + using (builder.ScopeLine("public static void Run()")) + { + using (builder.Scope()) + { + _ = builder.AppendLine("// nested block, e.g. an if-body"); + } + + _ = builder.AppendLine("DoWork();"); + } + } + + var result = builder.ToString(); + + _ = await Verify(result).ConfigureAwait(false); + } + + [Test] + public async Task GenerateFragment_ReusingBuilderAfterClear_Should_ProduceCorrectOutput() + { + var builder = new CSharpCodeBuilder(16); + _ = builder.EnsureCapacity(256); + + _ = builder.AppendLine("public class DiscardedFragment").Append("{").Append("}"); + + _ = builder.Clear(); + +#pragma warning disable CS0618 // Intend() is obsolete; deliberately exercised here for coverage + _ = builder + .Indent() + .AppendLine("// manually indented comment before the class") + .AppendLine("public class ReusedFragment") + .Append("{") + .Intend() + .AppendLine("// manually indented comment inside the class") + .Append("}"); +#pragma warning restore CS0618 + + var result = builder.ToString(); + + _ = await Verify(result).ConfigureAwait(false); + } + + [Test] + public async Task EnsureCapacity_Should_IncreaseUnderlyingCapacity() + { + var builder = new CSharpCodeBuilder(4); + + _ = builder.EnsureCapacity(1024); + + _ = await Assert.That(builder.Capacity).IsGreaterThanOrEqualTo(1024); + } + + [Test] + public async Task Clear_Should_ResetLengthAndIndentation() + { + var builder = new CSharpCodeBuilder().AppendLine("public class Fragment").Append("{").AppendLine("Field();"); + + _ = builder.Clear(); + + _ = await Assert.That(builder.Length).IsEqualTo(0); + + _ = builder.AppendLine("// after clear, indentation should be back at zero"); + + _ = await Assert.That(builder.ToString()).DoesNotStartWith(" "); + } +} diff --git a/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateConfigurableClass_AllFlagsDisabled_Should_ProduceCorrectOutput.verified.txt b/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateConfigurableClass_AllFlagsDisabled_Should_ProduceCorrectOutput.verified.txt new file mode 100644 index 00000000..f1d0bd95 --- /dev/null +++ b/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateConfigurableClass_AllFlagsDisabled_Should_ProduceCorrectOutput.verified.txt @@ -0,0 +1,5 @@ +public class ConfigurableService +{ + public bool IsEnabled => false; + false +} diff --git a/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateConfigurableClass_AllFlagsEnabled_Should_ProduceCorrectOutput.verified.txt b/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateConfigurableClass_AllFlagsEnabled_Should_ProduceCorrectOutput.verified.txt new file mode 100644 index 00000000..1f3e1f6f --- /dev/null +++ b/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateConfigurableClass_AllFlagsEnabled_Should_ProduceCorrectOutput.verified.txt @@ -0,0 +1,17 @@ +// generated diagnostics header + +public class ConfigurableService +{ + -------------------- + public bool IsEnabled => true; + true + // array-comment + array + // memory-comment + memory + // span-comment + span-c + // memory-commentmemory// span-commentspan-c// array-commentarrayxy + zzz + trailingtrailing-mark +} diff --git a/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateConfigurableClass_WithPointerFragments_Should_ProduceCorrectOutput.verified.txt b/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateConfigurableClass_WithPointerFragments_Should_ProduceCorrectOutput.verified.txt new file mode 100644 index 00000000..6ecef118 --- /dev/null +++ b/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateConfigurableClass_WithPointerFragments_Should_ProduceCorrectOutput.verified.txt @@ -0,0 +1,5 @@ +public class PointerBackedFragment +{ + // pointer-comment + // pointer-comment +} diff --git a/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateFormattedMembers_Should_ProduceCorrectOutput.verified.txt b/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateFormattedMembers_Should_ProduceCorrectOutput.verified.txt new file mode 100644 index 00000000..35e19c8c --- /dev/null +++ b/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateFormattedMembers_Should_ProduceCorrectOutput.verified.txt @@ -0,0 +1,11 @@ +public class FormattedMembersFragment +{ + public decimal Field0; + public decimal Field3; + public decimal Field3_4; + public decimal FieldFormattable; + public decimal LineField0; + public decimal LineField3; + public decimal LineField3_4; + public decimal LineFieldFormattable; +} diff --git a/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateFragment_ReusingBuilderAfterClear_Should_ProduceCorrectOutput.verified.txt b/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateFragment_ReusingBuilderAfterClear_Should_ProduceCorrectOutput.verified.txt new file mode 100644 index 00000000..531d3540 --- /dev/null +++ b/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateFragment_ReusingBuilderAfterClear_Should_ProduceCorrectOutput.verified.txt @@ -0,0 +1,5 @@ + // manually indented comment before the class +public class ReusedFragment +{ + // manually indented comment inside the class +} diff --git a/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateFromMixedCharSources_Should_ProduceCorrectOutput.verified.txt b/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateFromMixedCharSources_Should_ProduceCorrectOutput.verified.txt new file mode 100644 index 00000000..c393931b --- /dev/null +++ b/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateFromMixedCharSources_Should_ProduceCorrectOutput.verified.txt @@ -0,0 +1,10 @@ +public class MixedSourceFragment +{ + public string A => "field one"; + public string B => "field"; + public string C => "field two"; + public string D => "field"; + public string E => "field three"; + public string F => "field"; + public string G => "full"; +} diff --git a/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateFromPointerSource_Should_ProduceCorrectOutput.verified.txt b/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateFromPointerSource_Should_ProduceCorrectOutput.verified.txt new file mode 100644 index 00000000..6bbeffce --- /dev/null +++ b/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateFromPointerSource_Should_ProduceCorrectOutput.verified.txt @@ -0,0 +1,4 @@ +public class PointerSourceFragment +{ + public string Value => "pointer field"; +} diff --git a/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateFullyDocumentedMethod_Should_ProduceCorrectOutput.verified.txt b/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateFullyDocumentedMethod_Should_ProduceCorrectOutput.verified.txt new file mode 100644 index 00000000..3c58352d --- /dev/null +++ b/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateFullyDocumentedMethod_Should_ProduceCorrectOutput.verified.txt @@ -0,0 +1,51 @@ +namespace MyApplication.Documentation; + +/// A raw single-line documentation remark placed above the type. +/// +/// Represents a fully documented service. +/// Every XML doc tag is exercised. +/// +/// The request type. +/// The response type. +/// +/// This type demonstrates every supported XML documentation helper. +/// Line two. +/// +/// +/// var service = new DocumentedService(); +/// service.Process(request); +/// +/// +/// +public sealed class DocumentedService +{ + /// + /// Processes the specified request. + /// + /// The request to process. + /// A cancellation token. + /// The response produced for the request. + /// Thrown when request is null. + /// Thrown when the operation is cancelled. + /// Thrown when the service has not been initialized. + /// + /// + /// var response = service.Process(request, default); + /// + public TResponse Process(TRequest request, CancellationToken cancellationToken) + { + throw new NotImplementedException(); + } + + /// Gets the number of processed requests. + public int ProcessedCount { get; } + + /// + public override string? ToString() => base.ToString(); + + /// + public void Dispose() { } + + /// This is a custom documentation element. + /// +} diff --git a/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateNestedBracesFromRawCharsAndStrings_Should_ProduceCorrectOutput.verified.txt b/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateNestedBracesFromRawCharsAndStrings_Should_ProduceCorrectOutput.verified.txt new file mode 100644 index 00000000..5ff49c6b --- /dev/null +++ b/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateNestedBracesFromRawCharsAndStrings_Should_ProduceCorrectOutput.verified.txt @@ -0,0 +1,11 @@ +public class RawBraceFragment +{ + public int[] Values[ + public int Value + ] + + [ + public int Other + + ] +} diff --git a/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateNestedScopes_WithScopeLine_Should_ProduceCorrectOutput.verified.txt b/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateNestedScopes_WithScopeLine_Should_ProduceCorrectOutput.verified.txt new file mode 100644 index 00000000..66f27b10 --- /dev/null +++ b/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateNestedScopes_WithScopeLine_Should_ProduceCorrectOutput.verified.txt @@ -0,0 +1,12 @@ +namespace MyApplication.Scopes; + +public static class ScopedFragment +{ + public static void Run() + { + { + // nested block, e.g. an if-body + } + DoWork(); + } +} diff --git a/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateWithInterpolatedHandler_Should_ProduceCorrectOutput.verified.txt b/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateWithInterpolatedHandler_Should_ProduceCorrectOutput.verified.txt new file mode 100644 index 00000000..8bf7467e --- /dev/null +++ b/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateWithInterpolatedHandler_Should_ProduceCorrectOutput.verified.txt @@ -0,0 +1,5 @@ +public class InterpolatedFragment +{ + public int Total => 042; + public string Empty => ""; +}