From e8fed51fd2e84aef2341f2a8b8a2c511382ed2db Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 22 Aug 2025 17:28:44 +0000 Subject: [PATCH 1/5] chore: Create integration test project with TUnit framework and basic end-to-end tests Co-authored-by: samtrion <3283596+samtrion@users.noreply.github.com> --- CodeBuilder.slnx | 1 + Directory.Packages.props | 1 + GitVersion.yml.backup | 6 + .../NetEvolve.CodeBuilder.csproj.backup | 9 + ...ilderIntegrationTests.ComplexGeneration.cs | 122 ++++++++++++ ...rIntegrationTests.ConditionalGeneration.cs | 181 ++++++++++++++++++ ...pCodeBuilderIntegrationTests.Formatting.cs | 139 ++++++++++++++ .../CSharpCodeBuilderIntegrationTests.cs | 6 + ...volve.CodeBuilder.Tests.Integration.csproj | 21 ++ 9 files changed, 486 insertions(+) create mode 100644 GitVersion.yml.backup create mode 100644 src/NetEvolve.CodeBuilder/NetEvolve.CodeBuilder.csproj.backup create mode 100644 tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderIntegrationTests.ComplexGeneration.cs create mode 100644 tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderIntegrationTests.ConditionalGeneration.cs create mode 100644 tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderIntegrationTests.Formatting.cs create mode 100644 tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderIntegrationTests.cs create mode 100644 tests/NetEvolve.CodeBuilder.Tests.Integration/NetEvolve.CodeBuilder.Tests.Integration.csproj diff --git a/CodeBuilder.slnx b/CodeBuilder.slnx index 14a4a5d..f575762 100644 --- a/CodeBuilder.slnx +++ b/CodeBuilder.slnx @@ -20,5 +20,6 @@ + diff --git a/Directory.Packages.props b/Directory.Packages.props index c0e4400..b91be2d 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -18,5 +18,6 @@ + diff --git a/GitVersion.yml.backup b/GitVersion.yml.backup new file mode 100644 index 0000000..02fccea --- /dev/null +++ b/GitVersion.yml.backup @@ -0,0 +1,6 @@ +{ + "major-version-bump-message": "breaking:", + "minor-version-bump-message": "feat:", + "patch-version-bump-message": "fix:", + "no-bump-message": ".*" +} \ No newline at end of file diff --git a/src/NetEvolve.CodeBuilder/NetEvolve.CodeBuilder.csproj.backup b/src/NetEvolve.CodeBuilder/NetEvolve.CodeBuilder.csproj.backup new file mode 100644 index 0000000..6d086c3 --- /dev/null +++ b/src/NetEvolve.CodeBuilder/NetEvolve.CodeBuilder.csproj.backup @@ -0,0 +1,9 @@ + + + $(_ProjectTargetFrameworks) + true + + + + + diff --git a/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderIntegrationTests.ComplexGeneration.cs b/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderIntegrationTests.ComplexGeneration.cs new file mode 100644 index 0000000..83be6cc --- /dev/null +++ b/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderIntegrationTests.ComplexGeneration.cs @@ -0,0 +1,122 @@ +namespace NetEvolve.CodeBuilder.Tests.Integration; + +using System; +using System.Globalization; + +public partial class CSharpCodeBuilderIntegrationTests +{ + [Test] + public async Task GenerateCompleteClass_Should_ProduceCorrectOutput() + { + var builder = new CSharpCodeBuilder(); + + // Build a complete class with using statements, namespace, and methods + builder + .AppendLine("using System;") + .AppendLine("using System.Collections.Generic;") + .AppendLine() + .AppendLine("namespace MyApplication.Models") + .Append("{") + .AppendLine("/// ") + .AppendLine("/// Represents a customer entity.") + .AppendLine("/// ") + .AppendLine("public class Customer") + .Append("{") + .AppendLine("private readonly string _id;") + .AppendLine() + .AppendLine("/// ") + .AppendLine("/// Initializes a new instance of the Customer class.") + .AppendLine("/// ") + .AppendLine("/// The customer identifier.") + .AppendLine("public Customer(string id)") + .Append("{") + .AppendLine("_id = id ?? throw new ArgumentNullException(nameof(id));") + .Append("}") + .AppendLine() + .AppendLine("/// ") + .AppendLine("/// Gets the customer identifier.") + .AppendLine("/// ") + .AppendLine("public string Id => _id;") + .AppendLine() + .AppendLine("/// ") + .AppendLine("/// Gets or sets the customer name.") + .AppendLine("/// ") + .AppendLine("public string? Name { get; set; }") + .AppendLine() + .AppendLine("/// ") + .AppendLine("/// Gets or sets the customer email address.") + .AppendLine("/// ") + .AppendLine("public string? Email { get; set; }") + .Append("}") + .Append("}"); + + var result = builder.ToString(); + + // Basic verification - check that the output contains expected elements + _ = await Assert.That(result).Contains("using System;"); + _ = await Assert.That(result).Contains("namespace MyApplication.Models"); + _ = await Assert.That(result).Contains("public class Customer"); + _ = await Assert.That(result).Contains("public Customer(string id)"); + _ = await Assert.That(result).Contains("public string Id => _id;"); + _ = await Assert.That(result).Contains("public string? Name { get; set; }"); + _ = await Assert.That(result).Contains("public string? Email { get; set; }"); + + // Ensure proper indentation is applied + _ = await Assert.That(result).Contains(" public class Customer"); + _ = await Assert.That(result).Contains(" private readonly string _id;"); + } + + [Test] + public async Task GenerateInterface_WithMultipleMethods_Should_ProduceCorrectOutput() + { + var builder = new CSharpCodeBuilder(); + + builder + .AppendLine("using System;") + .AppendLine("using System.Threading.Tasks;") + .AppendLine() + .AppendLine("namespace MyApplication.Services") + .Append("{") + .AppendLine("/// ") + .AppendLine("/// Defines the contract for customer service operations.") + .AppendLine("/// ") + .AppendLine("public interface ICustomerService") + .Append("{") + .AppendLine("/// ") + .AppendLine("/// Gets a customer by their identifier.") + .AppendLine("/// ") + .AppendLine("/// The customer identifier.") + .AppendLine("/// The customer if found; otherwise, null.") + .AppendLine("Task GetCustomerAsync(string id);") + .AppendLine() + .AppendLine("/// ") + .AppendLine("/// Creates a new customer.") + .AppendLine("/// ") + .AppendLine("/// The customer to create.") + .AppendLine("/// A task representing the asynchronous operation.") + .AppendLine("Task CreateCustomerAsync(Customer customer);") + .AppendLine() + .AppendLine("/// ") + .AppendLine("/// Updates an existing customer.") + .AppendLine("/// ") + .AppendLine("/// The customer to update.") + .AppendLine("/// A task representing the asynchronous operation.") + .AppendLine("Task UpdateCustomerAsync(Customer customer);") + .Append("}") + .Append("}"); + + var result = builder.ToString(); + + // Basic verification - check that the output contains expected elements + _ = await Assert.That(result).Contains("using System.Threading.Tasks;"); + _ = await Assert.That(result).Contains("namespace MyApplication.Services"); + _ = await Assert.That(result).Contains("public interface ICustomerService"); + _ = await Assert.That(result).Contains("Task GetCustomerAsync(string id);"); + _ = await Assert.That(result).Contains("Task CreateCustomerAsync(Customer customer);"); + _ = await Assert.That(result).Contains("Task UpdateCustomerAsync(Customer customer);"); + + // Ensure proper indentation is applied + _ = await Assert.That(result).Contains(" public interface ICustomerService"); + _ = await Assert.That(result).Contains(" Task GetCustomerAsync(string id);"); + } +} diff --git a/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderIntegrationTests.ConditionalGeneration.cs b/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderIntegrationTests.ConditionalGeneration.cs new file mode 100644 index 0000000..d50e026 --- /dev/null +++ b/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderIntegrationTests.ConditionalGeneration.cs @@ -0,0 +1,181 @@ +namespace NetEvolve.CodeBuilder.Tests.Integration; + +using System; +using System.Globalization; +using System.Linq; + +public partial class CSharpCodeBuilderIntegrationTests +{ + [Test] + public async Task GenerateMethodWithConditionalContent_Should_ProduceCorrectOutput() + { + var builder = new CSharpCodeBuilder(); + + var includeLogging = true; + var includeValidation = false; + var isAsync = true; + + builder.AppendLine("public class ServiceClass").Append("{"); + + if (isAsync) + { + builder.Append("public async Task"); + } + else + { + builder.Append("public void"); + } + + builder + .Append(" ProcessDataAsync(string input)") + .Append("{") + .AppendLineIf(includeValidation, "if (string.IsNullOrEmpty(input))") + .AppendLineIf(includeValidation, "{") + .AppendLineIf( + includeValidation, + " throw new ArgumentException(\"Input cannot be null or empty\", nameof(input));" + ) + .AppendLineIf(includeValidation, "}") + .AppendLineIf(includeValidation, "") + .AppendLineIf(includeLogging, "Console.WriteLine($\"Processing input: {input}\");") + .AppendLine("var result = input.ToUpperInvariant();") + .AppendLineIf(includeLogging, "Console.WriteLine($\"Processing complete: {result}\");") + .AppendLineIf(isAsync, "await Task.CompletedTask;") + .AppendLine("return result;") + .Append("}") + .Append("}"); + + var result = builder.ToString(); + + // Verify conditional content was applied correctly + _ = await Assert.That(result).Contains("public async Task ProcessDataAsync(string input)"); // async version + _ = await Assert.That(result).Contains("Console.WriteLine($\"Processing input: {input}\");"); // logging included + _ = await Assert.That(result).Contains("await Task.CompletedTask;"); // async included + _ = await Assert.That(result).DoesNotContain("if (string.IsNullOrEmpty(input))"); // validation excluded + _ = await Assert.That(result).Contains("input.ToUpperInvariant()"); // proper string case conversion + } + + [Test] + public async Task GenerateReflectionBasedCode_Should_ProduceCorrectOutput() + { + var builder = new CSharpCodeBuilder(); + + var properties = new[] + { + new + { + Name = "Id", + Type = "int", + HasGetter = true, + HasSetter = false, + }, + new + { + Name = "Name", + Type = "string?", + HasGetter = true, + HasSetter = true, + }, + new + { + Name = "Email", + Type = "string?", + HasGetter = true, + HasSetter = true, + }, + new + { + Name = "CreatedAt", + Type = "DateTime", + HasGetter = true, + HasSetter = false, + }, + }; + + builder.AppendLine("using System;").AppendLine().AppendLine("public class GeneratedEntity").Append("{"); + + // Generate backing fields for properties without setters + foreach (var prop in properties.Where(p => !p.HasSetter)) + { + builder + .AppendFormat( + CultureInfo.InvariantCulture, + "private readonly {0} _{1};", + prop.Type, + prop.Name.ToUpperInvariant() + ) + .AppendLine(); + } + + if (properties.Any(p => !p.HasSetter)) + { + builder.AppendLine(); + } + + // Generate constructor + var readOnlyProps = properties.Where(p => !p.HasSetter).ToArray(); + if (readOnlyProps.Length > 0) + { + builder.Append("public GeneratedEntity("); + for (int i = 0; i < readOnlyProps.Length; i++) + { + if (i > 0) + builder.Append(", "); + builder.AppendFormat( + CultureInfo.InvariantCulture, + "{0} {1}", + readOnlyProps[i].Type, + readOnlyProps[i].Name.ToUpperInvariant() + ); + } + builder.AppendLine(")").Append("{"); + + foreach (var prop in readOnlyProps) + { + builder + .AppendFormat( + CultureInfo.InvariantCulture, + "_{0} = {1};", + prop.Name.ToUpperInvariant(), + prop.Name.ToUpperInvariant() + ) + .AppendLine(); + } + + builder.Append("}").AppendLine(); + } + + // Generate properties + foreach (var prop in properties) + { + builder.AppendFormat(CultureInfo.InvariantCulture, "public {0} {1}", prop.Type, prop.Name); + + if (prop.HasGetter && prop.HasSetter) + { + builder.AppendLine(" { get; set; }"); + } + else if (prop.HasGetter && !prop.HasSetter) + { + builder + .AppendFormat(CultureInfo.InvariantCulture, " => _{0};", prop.Name.ToUpperInvariant()) + .AppendLine(); + } + + builder.AppendLine(); + } + + builder.Append("}"); + + var result = builder.ToString(); + + // Basic verification for reflection-based code generation + _ = await Assert.That(result).Contains("public class GeneratedEntity"); + _ = await Assert.That(result).Contains("private readonly int _ID;"); + _ = await Assert.That(result).Contains("private readonly DateTime _CREATEDAT;"); + _ = await Assert.That(result).Contains("public GeneratedEntity(int ID, DateTime CREATEDAT)"); + _ = await Assert.That(result).Contains("public int Id => _ID;"); + _ = await Assert.That(result).Contains("public string? Name { get; set; }"); + _ = await Assert.That(result).Contains("public string? Email { get; set; }"); + _ = await Assert.That(result).Contains("public DateTime CreatedAt => _CREATEDAT;"); + } +} diff --git a/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderIntegrationTests.Formatting.cs b/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderIntegrationTests.Formatting.cs new file mode 100644 index 0000000..868a904 --- /dev/null +++ b/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderIntegrationTests.Formatting.cs @@ -0,0 +1,139 @@ +namespace NetEvolve.CodeBuilder.Tests.Integration; + +using System; +using System.Globalization; + +public partial class CSharpCodeBuilderIntegrationTests +{ + [Test] + public async Task GenerateClassWithFormatting_UsingSpaces_Should_ProduceCorrectIndentation() + { + var builder = new CSharpCodeBuilder { UseTabs = false }; + + builder + .AppendLine("public class TestClass") + .Append("{") + .AppendLine("public void Method1()") + .Append("{") + .AppendLine("Console.WriteLine(\"Hello World\");") + .AppendLine("if (true)") + .Append("{") + .AppendLine("Console.WriteLine(\"Nested\");") + .Append("}") + .Append("}") + .AppendLine() + .AppendLine("public void Method2()") + .Append("{") + .AppendLine("try") + .Append("{") + .AppendLine("DoSomething();") + .Append("}") + .AppendLine("catch (Exception ex)") + .Append("{") + .AppendLine("Console.WriteLine($\"Error: {ex.Message}\");") + .Append("}") + .Append("}") + .Append("}"); + + var result = builder.ToString(); + + // Verify spaces-based indentation + _ = await Assert.That(result).Contains("public class TestClass"); + _ = await Assert.That(result).Contains(" public void Method1()"); // 4 spaces indentation + _ = await Assert.That(result).Contains(" Console.WriteLine(\"Hello World\");"); // 8 spaces indentation + _ = await Assert.That(result).Contains(" Console.WriteLine(\"Nested\");"); // 12 spaces indentation + } + + [Test] + public async Task GenerateClassWithFormatting_UsingTabs_Should_ProduceCorrectIndentation() + { + var builder = new CSharpCodeBuilder { UseTabs = true }; + + builder + .AppendLine("public class TestClass") + .Append("{") + .AppendLine("public void Method1()") + .Append("{") + .AppendLine("Console.WriteLine(\"Hello World\");") + .AppendLine("if (true)") + .Append("{") + .AppendLine("Console.WriteLine(\"Nested\");") + .Append("}") + .Append("}") + .AppendLine() + .AppendLine("public void Method2()") + .Append("{") + .AppendLine("try") + .Append("{") + .AppendLine("DoSomething();") + .Append("}") + .AppendLine("catch (Exception ex)") + .Append("{") + .AppendLine("Console.WriteLine($\"Error: {ex.Message}\");") + .Append("}") + .Append("}") + .Append("}"); + + var result = builder.ToString(); + + // Verify tabs-based indentation + _ = await Assert.That(result).Contains("public class TestClass"); + _ = await Assert.That(result).Contains("\tpublic void Method1()"); // 1 tab indentation + _ = await Assert.That(result).Contains("\t\tConsole.WriteLine(\"Hello World\");"); // 2 tabs indentation + _ = await Assert.That(result).Contains("\t\t\tConsole.WriteLine(\"Nested\");"); // 3 tabs indentation + } + + [Test] + public async Task GenerateEnum_WithDocumentation_Should_ProduceCorrectOutput() + { + var builder = new CSharpCodeBuilder(); + + builder + .AppendLine("using System;") + .AppendLine() + .AppendLine("namespace MyApplication.Enums") + .Append("{") + .AppendLine("/// ") + .AppendLine("/// Represents the status of an order.") + .AppendLine("/// ") + .AppendLine("[Flags]") + .AppendLine("public enum OrderStatus") + .Append("{") + .AppendLine("/// ") + .AppendLine("/// The order is pending.") + .AppendLine("/// ") + .AppendLine("Pending = 1,") + .AppendLine() + .AppendLine("/// ") + .AppendLine("/// The order is being processed.") + .AppendLine("/// ") + .AppendLine("Processing = 2,") + .AppendLine() + .AppendLine("/// ") + .AppendLine("/// The order has been shipped.") + .AppendLine("/// ") + .AppendLine("Shipped = 4,") + .AppendLine() + .AppendLine("/// ") + .AppendLine("/// The order has been delivered.") + .AppendLine("/// ") + .AppendLine("Delivered = 8") + .Append("}") + .Append("}"); + + var result = builder.ToString(); + + // Basic verification for enum generation + _ = await Assert.That(result).Contains("namespace MyApplication.Enums"); + _ = await Assert.That(result).Contains("[Flags]"); + _ = await Assert.That(result).Contains("public enum OrderStatus"); + _ = await Assert.That(result).Contains("Pending = 1,"); + _ = await Assert.That(result).Contains("Processing = 2,"); + _ = await Assert.That(result).Contains("Shipped = 4,"); + _ = await Assert.That(result).Contains("Delivered = 8"); + + // Ensure proper indentation is applied + _ = await Assert.That(result).Contains(" public enum OrderStatus"); + _ = await Assert.That(result).Contains(" Pending = 1,"); + } +} diff --git a/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderIntegrationTests.cs b/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderIntegrationTests.cs new file mode 100644 index 0000000..bbd3876 --- /dev/null +++ b/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderIntegrationTests.cs @@ -0,0 +1,6 @@ +namespace NetEvolve.CodeBuilder.Tests.Integration; + +using NetEvolve.Extensions.TUnit; + +[TestGroup(nameof(CSharpCodeBuilder))] +public partial class CSharpCodeBuilderIntegrationTests { } diff --git a/tests/NetEvolve.CodeBuilder.Tests.Integration/NetEvolve.CodeBuilder.Tests.Integration.csproj b/tests/NetEvolve.CodeBuilder.Tests.Integration/NetEvolve.CodeBuilder.Tests.Integration.csproj new file mode 100644 index 0000000..6a2296e --- /dev/null +++ b/tests/NetEvolve.CodeBuilder.Tests.Integration/NetEvolve.CodeBuilder.Tests.Integration.csproj @@ -0,0 +1,21 @@ + + + $(_TestTargetFrameworks) + Exe + true + $(NoWarn);CA2000;S2930 + true + + + + + + + + + + + + + + From d5f2b48e6207a123ea6f01c65aeeda2bec3ba87a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 22 Aug 2025 17:30:54 +0000 Subject: [PATCH 2/5] chore: Complete integration test project with documentation and snapshot test placeholders Co-authored-by: samtrion <3283596+samtrion@users.noreply.github.com> --- GitVersion.yml.backup | 6 -- .../NetEvolve.CodeBuilder.csproj.backup | 9 --- ...deBuilderIntegrationTests.SnapshotTests.cs | 63 +++++++++++++++++ .../README.md | 69 +++++++++++++++++++ 4 files changed, 132 insertions(+), 15 deletions(-) delete mode 100644 GitVersion.yml.backup delete mode 100644 src/NetEvolve.CodeBuilder/NetEvolve.CodeBuilder.csproj.backup create mode 100644 tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderIntegrationTests.SnapshotTests.cs create mode 100644 tests/NetEvolve.CodeBuilder.Tests.Integration/README.md diff --git a/GitVersion.yml.backup b/GitVersion.yml.backup deleted file mode 100644 index 02fccea..0000000 --- a/GitVersion.yml.backup +++ /dev/null @@ -1,6 +0,0 @@ -{ - "major-version-bump-message": "breaking:", - "minor-version-bump-message": "feat:", - "patch-version-bump-message": "fix:", - "no-bump-message": ".*" -} \ No newline at end of file diff --git a/src/NetEvolve.CodeBuilder/NetEvolve.CodeBuilder.csproj.backup b/src/NetEvolve.CodeBuilder/NetEvolve.CodeBuilder.csproj.backup deleted file mode 100644 index 6d086c3..0000000 --- a/src/NetEvolve.CodeBuilder/NetEvolve.CodeBuilder.csproj.backup +++ /dev/null @@ -1,9 +0,0 @@ - - - $(_ProjectTargetFrameworks) - true - - - - - diff --git a/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderIntegrationTests.SnapshotTests.cs b/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderIntegrationTests.SnapshotTests.cs new file mode 100644 index 0000000..61ee3ec --- /dev/null +++ b/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderIntegrationTests.SnapshotTests.cs @@ -0,0 +1,63 @@ +namespace NetEvolve.CodeBuilder.Tests.Integration; + +using System; + +// TODO: Enable when Verify.TUnit compatibility is resolved in the target framework environment +// using Verify.TUnit; + +public partial class CSharpCodeBuilderIntegrationTests +{ + // TODO: Uncomment and implement snapshot tests when Verify.TUnit is available + /* + [Test] + public async Task GenerateCompleteClass_Should_MatchSnapshot() + { + var builder = new CSharpCodeBuilder(); + + // Build a complete class structure + builder + .AppendLine("using System;") + .AppendLine("using System.Collections.Generic;") + .AppendLine() + .AppendLine("namespace MyApplication.Models") + .Append("{") + .AppendLine("public class Customer") + .Append("{") + .AppendLine("public string Id { get; set; }") + .AppendLine("public string Name { get; set; }") + .Append("}") + .Append("}"); + + var result = builder.ToString(); + + // This would create and verify against a .verified.txt snapshot file + await this.Verify(result); + } + + [Test] + public async Task GenerateWithDifferentFormats_Should_MatchSnapshots() + { + // Test with spaces + var spacesBuilder = new CSharpCodeBuilder { UseTabs = false }; + spacesBuilder + .AppendLine("public class TestClass") + .Append("{") + .AppendLine("public void Method() { }") + .Append("}"); + + await this.Verify(spacesBuilder.ToString()) + .UseParameters("spaces"); + + // Test with tabs + var tabsBuilder = new CSharpCodeBuilder { UseTabs = true }; + tabsBuilder + .AppendLine("public class TestClass") + .Append("{") + .AppendLine("public void Method() { }") + .Append("}"); + + await this.Verify(tabsBuilder.ToString()) + .UseParameters("tabs"); + } + */ +} \ No newline at end of file diff --git a/tests/NetEvolve.CodeBuilder.Tests.Integration/README.md b/tests/NetEvolve.CodeBuilder.Tests.Integration/README.md new file mode 100644 index 0000000..d61536f --- /dev/null +++ b/tests/NetEvolve.CodeBuilder.Tests.Integration/README.md @@ -0,0 +1,69 @@ +# NetEvolve.CodeBuilder.Tests.Integration + +This project contains integration tests for the NetEvolve.CodeBuilder library, focusing on end-to-end testing scenarios that validate the complete functionality of the code generation capabilities. + +## Test Framework + +- **TUnit**: Primary testing framework +- **Verify.TUnit**: For snapshot testing (to be enabled when environment supports it) +- **No Mocking**: Tests use real instances and validate actual output + +## Test Organization + +The integration tests are organized into partial classes for better maintainability: + +### CSharpCodeBuilderIntegrationTests.ComplexGeneration.cs +- Complete class generation with documentation +- Interface generation with multiple methods +- Real-world code generation scenarios + +### CSharpCodeBuilderIntegrationTests.ConditionalGeneration.cs +- Conditional content generation using AppendIf methods +- Reflection-based code generation patterns +- Dynamic property and method generation + +### CSharpCodeBuilderIntegrationTests.Formatting.cs +- Indentation testing (spaces vs tabs) +- Code formatting validation +- Enum generation with attributes + +### CSharpCodeBuilderIntegrationTests.SnapshotTests.cs +- Placeholder for snapshot tests using Verify.TUnit +- Will be enabled when framework compatibility is resolved + +## Test Scenarios + +The integration tests cover: + +1. **End-to-End Class Generation**: Complete C# classes with proper indentation, documentation, and structure +2. **Interface Generation**: Service interfaces with async methods and documentation +3. **Conditional Logic**: Using AppendIf and AppendLineIf for dynamic content +4. **Formatting Options**: Testing both space and tab-based indentation +5. **Complex Structures**: Enums with attributes, nested code blocks, exception handling + +## Running Tests + +```bash +# Run all integration tests +dotnet test tests/NetEvolve.CodeBuilder.Tests.Integration/ + +# Run specific test class +dotnet test tests/NetEvolve.CodeBuilder.Tests.Integration/ --filter "ClassName=CSharpCodeBuilderIntegrationTests" +``` + +## Adding New Tests + +When adding new integration tests: + +1. Follow the existing naming convention: `MethodName_Condition_Should_ExpectedResult` +2. Use the [Test] attribute from TUnit +3. Use partial classes to organize related tests +4. Validate both content and formatting in assertions +5. Include real-world scenarios that developers would encounter + +## Future Enhancements + +- Snapshot testing with Verify.TUnit when framework support is available +- Performance benchmarking for large code generation scenarios +- Cross-platform indentation testing +- Template-based code generation tests \ No newline at end of file From 1df8e442d73102bde76f98a562b724fc614816ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20St=C3=BChmer?= Date: Fri, 22 Aug 2025 22:17:06 +0200 Subject: [PATCH 3/5] chore(test): Updated tests --- Directory.Packages.props | 3 +- .../CSharpCodeBuilder.Documentation.cs | 1 - ...ilderIntegrationTests.ComplexGeneration.cs | 122 ------------------ ...deBuilderIntegrationTests.SnapshotTests.cs | 63 --------- ...SharpCodeBuilderTests.ComplexGeneration.cs | 86 ++++++++++++ ...CodeBuilderTests.ConditionalGeneration.cs} | 61 ++++----- ...s => CSharpCodeBuilderTests.Formatting.cs} | 58 +++------ .../CSharpCodeBuilderTests.SnapshotTests.cs | 43 ++++++ ...tionTests.cs => CSharpCodeBuilderTests.cs} | 2 +- ...volve.CodeBuilder.Tests.Integration.csproj | 1 + .../README.md | 69 ---------- .../Startup.cs | 22 ++++ ...uld_ProduceCorrectIndentation.verified.txt | 19 +++ ...uld_ProduceCorrectIndentation.verified.txt | 19 +++ ...eteClass_Should_MatchSnapshot.verified.txt | 11 ++ ...s_Should_ProduceCorrectOutput.verified.txt | 37 ++++++ ...n_Should_ProduceCorrectOutput.verified.txt | 31 +++++ ...s_Should_ProduceCorrectOutput.verified.txt | 32 +++++ ...t_Should_ProduceCorrectOutput.verified.txt | 11 ++ ...e_Should_ProduceCorrectOutput.verified.txt | 23 ++++ ...tchSnapshots_02b3255120757173.verified.txt | 4 + ...tchSnapshots_b6b4547aad375c78.verified.txt | 4 + 22 files changed, 389 insertions(+), 333 deletions(-) delete mode 100644 tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderIntegrationTests.ComplexGeneration.cs delete mode 100644 tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderIntegrationTests.SnapshotTests.cs create mode 100644 tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderTests.ComplexGeneration.cs rename tests/NetEvolve.CodeBuilder.Tests.Integration/{CSharpCodeBuilderIntegrationTests.ConditionalGeneration.cs => CSharpCodeBuilderTests.ConditionalGeneration.cs} (63%) rename tests/NetEvolve.CodeBuilder.Tests.Integration/{CSharpCodeBuilderIntegrationTests.Formatting.cs => CSharpCodeBuilderTests.Formatting.cs} (57%) create mode 100644 tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderTests.SnapshotTests.cs rename tests/NetEvolve.CodeBuilder.Tests.Integration/{CSharpCodeBuilderIntegrationTests.cs => CSharpCodeBuilderTests.cs} (68%) delete mode 100644 tests/NetEvolve.CodeBuilder.Tests.Integration/README.md create mode 100644 tests/NetEvolve.CodeBuilder.Tests.Integration/Startup.cs create mode 100644 tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateClassWithFormatting_UsingSpaces_Should_ProduceCorrectIndentation.verified.txt create mode 100644 tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateClassWithFormatting_UsingTabs_Should_ProduceCorrectIndentation.verified.txt create mode 100644 tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateCompleteClass_Should_MatchSnapshot.verified.txt create mode 100644 tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateCompleteClass_Should_ProduceCorrectOutput.verified.txt create mode 100644 tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateEnum_WithDocumentation_Should_ProduceCorrectOutput.verified.txt create mode 100644 tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateInterface_WithMultipleMethods_Should_ProduceCorrectOutput.verified.txt create mode 100644 tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateMethodWithConditionalContent_Should_ProduceCorrectOutput.verified.txt create mode 100644 tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateReflectionBasedCode_Should_ProduceCorrectOutput.verified.txt create mode 100644 tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateWithDifferentFormats_Should_MatchSnapshots_02b3255120757173.verified.txt create mode 100644 tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateWithDifferentFormats_Should_MatchSnapshots_b6b4547aad375c78.verified.txt diff --git a/Directory.Packages.props b/Directory.Packages.props index b91be2d..bd2f5e5 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -18,6 +18,7 @@ + - + \ No newline at end of file diff --git a/src/NetEvolve.CodeBuilder/CSharpCodeBuilder.Documentation.cs b/src/NetEvolve.CodeBuilder/CSharpCodeBuilder.Documentation.cs index 380d2a0..3ba57a8 100644 --- a/src/NetEvolve.CodeBuilder/CSharpCodeBuilder.Documentation.cs +++ b/src/NetEvolve.CodeBuilder/CSharpCodeBuilder.Documentation.cs @@ -1,6 +1,5 @@ namespace NetEvolve.CodeBuilder; -using System; using System.Collections.Generic; using System.Runtime.CompilerServices; diff --git a/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderIntegrationTests.ComplexGeneration.cs b/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderIntegrationTests.ComplexGeneration.cs deleted file mode 100644 index 83be6cc..0000000 --- a/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderIntegrationTests.ComplexGeneration.cs +++ /dev/null @@ -1,122 +0,0 @@ -namespace NetEvolve.CodeBuilder.Tests.Integration; - -using System; -using System.Globalization; - -public partial class CSharpCodeBuilderIntegrationTests -{ - [Test] - public async Task GenerateCompleteClass_Should_ProduceCorrectOutput() - { - var builder = new CSharpCodeBuilder(); - - // Build a complete class with using statements, namespace, and methods - builder - .AppendLine("using System;") - .AppendLine("using System.Collections.Generic;") - .AppendLine() - .AppendLine("namespace MyApplication.Models") - .Append("{") - .AppendLine("/// ") - .AppendLine("/// Represents a customer entity.") - .AppendLine("/// ") - .AppendLine("public class Customer") - .Append("{") - .AppendLine("private readonly string _id;") - .AppendLine() - .AppendLine("/// ") - .AppendLine("/// Initializes a new instance of the Customer class.") - .AppendLine("/// ") - .AppendLine("/// The customer identifier.") - .AppendLine("public Customer(string id)") - .Append("{") - .AppendLine("_id = id ?? throw new ArgumentNullException(nameof(id));") - .Append("}") - .AppendLine() - .AppendLine("/// ") - .AppendLine("/// Gets the customer identifier.") - .AppendLine("/// ") - .AppendLine("public string Id => _id;") - .AppendLine() - .AppendLine("/// ") - .AppendLine("/// Gets or sets the customer name.") - .AppendLine("/// ") - .AppendLine("public string? Name { get; set; }") - .AppendLine() - .AppendLine("/// ") - .AppendLine("/// Gets or sets the customer email address.") - .AppendLine("/// ") - .AppendLine("public string? Email { get; set; }") - .Append("}") - .Append("}"); - - var result = builder.ToString(); - - // Basic verification - check that the output contains expected elements - _ = await Assert.That(result).Contains("using System;"); - _ = await Assert.That(result).Contains("namespace MyApplication.Models"); - _ = await Assert.That(result).Contains("public class Customer"); - _ = await Assert.That(result).Contains("public Customer(string id)"); - _ = await Assert.That(result).Contains("public string Id => _id;"); - _ = await Assert.That(result).Contains("public string? Name { get; set; }"); - _ = await Assert.That(result).Contains("public string? Email { get; set; }"); - - // Ensure proper indentation is applied - _ = await Assert.That(result).Contains(" public class Customer"); - _ = await Assert.That(result).Contains(" private readonly string _id;"); - } - - [Test] - public async Task GenerateInterface_WithMultipleMethods_Should_ProduceCorrectOutput() - { - var builder = new CSharpCodeBuilder(); - - builder - .AppendLine("using System;") - .AppendLine("using System.Threading.Tasks;") - .AppendLine() - .AppendLine("namespace MyApplication.Services") - .Append("{") - .AppendLine("/// ") - .AppendLine("/// Defines the contract for customer service operations.") - .AppendLine("/// ") - .AppendLine("public interface ICustomerService") - .Append("{") - .AppendLine("/// ") - .AppendLine("/// Gets a customer by their identifier.") - .AppendLine("/// ") - .AppendLine("/// The customer identifier.") - .AppendLine("/// The customer if found; otherwise, null.") - .AppendLine("Task GetCustomerAsync(string id);") - .AppendLine() - .AppendLine("/// ") - .AppendLine("/// Creates a new customer.") - .AppendLine("/// ") - .AppendLine("/// The customer to create.") - .AppendLine("/// A task representing the asynchronous operation.") - .AppendLine("Task CreateCustomerAsync(Customer customer);") - .AppendLine() - .AppendLine("/// ") - .AppendLine("/// Updates an existing customer.") - .AppendLine("/// ") - .AppendLine("/// The customer to update.") - .AppendLine("/// A task representing the asynchronous operation.") - .AppendLine("Task UpdateCustomerAsync(Customer customer);") - .Append("}") - .Append("}"); - - var result = builder.ToString(); - - // Basic verification - check that the output contains expected elements - _ = await Assert.That(result).Contains("using System.Threading.Tasks;"); - _ = await Assert.That(result).Contains("namespace MyApplication.Services"); - _ = await Assert.That(result).Contains("public interface ICustomerService"); - _ = await Assert.That(result).Contains("Task GetCustomerAsync(string id);"); - _ = await Assert.That(result).Contains("Task CreateCustomerAsync(Customer customer);"); - _ = await Assert.That(result).Contains("Task UpdateCustomerAsync(Customer customer);"); - - // Ensure proper indentation is applied - _ = await Assert.That(result).Contains(" public interface ICustomerService"); - _ = await Assert.That(result).Contains(" Task GetCustomerAsync(string id);"); - } -} diff --git a/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderIntegrationTests.SnapshotTests.cs b/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderIntegrationTests.SnapshotTests.cs deleted file mode 100644 index 61ee3ec..0000000 --- a/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderIntegrationTests.SnapshotTests.cs +++ /dev/null @@ -1,63 +0,0 @@ -namespace NetEvolve.CodeBuilder.Tests.Integration; - -using System; - -// TODO: Enable when Verify.TUnit compatibility is resolved in the target framework environment -// using Verify.TUnit; - -public partial class CSharpCodeBuilderIntegrationTests -{ - // TODO: Uncomment and implement snapshot tests when Verify.TUnit is available - /* - [Test] - public async Task GenerateCompleteClass_Should_MatchSnapshot() - { - var builder = new CSharpCodeBuilder(); - - // Build a complete class structure - builder - .AppendLine("using System;") - .AppendLine("using System.Collections.Generic;") - .AppendLine() - .AppendLine("namespace MyApplication.Models") - .Append("{") - .AppendLine("public class Customer") - .Append("{") - .AppendLine("public string Id { get; set; }") - .AppendLine("public string Name { get; set; }") - .Append("}") - .Append("}"); - - var result = builder.ToString(); - - // This would create and verify against a .verified.txt snapshot file - await this.Verify(result); - } - - [Test] - public async Task GenerateWithDifferentFormats_Should_MatchSnapshots() - { - // Test with spaces - var spacesBuilder = new CSharpCodeBuilder { UseTabs = false }; - spacesBuilder - .AppendLine("public class TestClass") - .Append("{") - .AppendLine("public void Method() { }") - .Append("}"); - - await this.Verify(spacesBuilder.ToString()) - .UseParameters("spaces"); - - // Test with tabs - var tabsBuilder = new CSharpCodeBuilder { UseTabs = true }; - tabsBuilder - .AppendLine("public class TestClass") - .Append("{") - .AppendLine("public void Method() { }") - .Append("}"); - - await this.Verify(tabsBuilder.ToString()) - .UseParameters("tabs"); - } - */ -} \ No newline at end of file diff --git a/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderTests.ComplexGeneration.cs b/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderTests.ComplexGeneration.cs new file mode 100644 index 0000000..58d4ad1 --- /dev/null +++ b/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderTests.ComplexGeneration.cs @@ -0,0 +1,86 @@ +namespace NetEvolve.CodeBuilder.Tests.Integration; + +public partial class CSharpCodeBuilderTests +{ + [Test] + public async Task GenerateCompleteClass_Should_ProduceCorrectOutput() + { + // Build a complete class with using statements, namespace, and methods + var builder = new CSharpCodeBuilder() + .AppendLine("using System;") + .AppendLine("using System.Collections.Generic;") + .AppendLine() + .AppendLine("namespace MyApplication.Models") + .Append("{") + .AppendLine("/// ") + .AppendLine("/// Represents a customer entity.") + .AppendLine("/// ") + .AppendLine("public class Customer") + .Append("{") + .AppendLine("private readonly string _id;") + .AppendLine() + .AppendLine("/// ") + .AppendLine("/// Initializes a new instance of the Customer class.") + .AppendLine("/// ") + .AppendLine("/// The customer identifier.") + .AppendLine("public Customer(string id)") + .Append("{") + .AppendLine("_id = id ?? throw new ArgumentNullException(nameof(id));") + .Append("}") + .AppendLine() + .AppendLine("/// ") + .AppendLine("/// Gets the customer identifier.") + .AppendLine("/// ") + .AppendLine("public string Id => _id;") + .AppendLine() + .AppendLine("/// ") + .AppendLine("/// Gets or sets the customer name.") + .AppendLine("/// ") + .AppendLine("public string? Name { get; set; }") + .AppendLine() + .AppendLine("/// ") + .AppendLine("/// Gets or sets the customer email address.") + .AppendLine("/// ") + .Append("public string? Email { get; set; }") + .Append("}") + .Append("}"); + + var result = builder.ToString(); + + _ = await Verify(result); + } + + [Test] + public async Task GenerateInterface_WithMultipleMethods_Should_ProduceCorrectOutput() + { + var builder = new CSharpCodeBuilder() + .AppendLine("using System;") + .AppendLine("using System.Threading.Tasks;") + .AppendLine() + .AppendLine("namespace MyApplication.Services") + .Append("{") + .AppendXmlDocSummary("Defines the contract for customer service operations.") + .AppendLine("public interface ICustomerService") + .Append("{") + .AppendXmlDocSummary("Gets a customer by their identifier.") + .AppendXmlDocParam("id", "The customer identifier.") + .AppendXmlDocReturns("The customer if found; otherwise, null.") + .AppendLine("Task GetCustomerAsync(string id);") + .AppendLine() + .AppendXmlDocSummary("Creates a new customer.") + .AppendXmlDocParam("customer", "The customer to create.") + .AppendXmlDocReturns("A task representing the asynchronous operation.") + .AppendLine("Task CreateCustomerAsync(Customer customer);") + .AppendLine() + .AppendXmlDocSummary("Updates an existing customer.") + .AppendXmlDocParam("customer", "The customer to update.") + .AppendXmlDocReturns("A task representing the asynchronous operation.") + .Append("Task UpdateCustomerAsync(Customer customer);") + .Append("}") + .Append("}"); + + var result = builder.ToString(); + + _ = await Verify(result); + } +} diff --git a/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderIntegrationTests.ConditionalGeneration.cs b/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderTests.ConditionalGeneration.cs similarity index 63% rename from tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderIntegrationTests.ConditionalGeneration.cs rename to tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderTests.ConditionalGeneration.cs index d50e026..14003e7 100644 --- a/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderIntegrationTests.ConditionalGeneration.cs +++ b/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderTests.ConditionalGeneration.cs @@ -1,10 +1,9 @@ namespace NetEvolve.CodeBuilder.Tests.Integration; -using System; using System.Globalization; using System.Linq; -public partial class CSharpCodeBuilderIntegrationTests +public partial class CSharpCodeBuilderTests { [Test] public async Task GenerateMethodWithConditionalContent_Should_ProduceCorrectOutput() @@ -15,18 +14,18 @@ public async Task GenerateMethodWithConditionalContent_Should_ProduceCorrectOutp var includeValidation = false; var isAsync = true; - builder.AppendLine("public class ServiceClass").Append("{"); + _ = builder.AppendLine("public class ServiceClass").Append("{"); if (isAsync) { - builder.Append("public async Task"); + _ = builder.Append("public async Task"); } else { - builder.Append("public void"); + _ = builder.Append("public void"); } - builder + _ = builder .Append(" ProcessDataAsync(string input)") .Append("{") .AppendLineIf(includeValidation, "if (string.IsNullOrEmpty(input))") @@ -47,12 +46,7 @@ public async Task GenerateMethodWithConditionalContent_Should_ProduceCorrectOutp var result = builder.ToString(); - // Verify conditional content was applied correctly - _ = await Assert.That(result).Contains("public async Task ProcessDataAsync(string input)"); // async version - _ = await Assert.That(result).Contains("Console.WriteLine($\"Processing input: {input}\");"); // logging included - _ = await Assert.That(result).Contains("await Task.CompletedTask;"); // async included - _ = await Assert.That(result).DoesNotContain("if (string.IsNullOrEmpty(input))"); // validation excluded - _ = await Assert.That(result).Contains("input.ToUpperInvariant()"); // proper string case conversion + _ = await Verify(result); } [Test] @@ -92,12 +86,12 @@ public async Task GenerateReflectionBasedCode_Should_ProduceCorrectOutput() }, }; - builder.AppendLine("using System;").AppendLine().AppendLine("public class GeneratedEntity").Append("{"); + _ = builder.AppendLine("using System;").AppendLine().AppendLine("public class GeneratedEntity").Append("{"); // Generate backing fields for properties without setters foreach (var prop in properties.Where(p => !p.HasSetter)) { - builder + _ = builder .AppendFormat( CultureInfo.InvariantCulture, "private readonly {0} _{1};", @@ -109,30 +103,33 @@ public async Task GenerateReflectionBasedCode_Should_ProduceCorrectOutput() if (properties.Any(p => !p.HasSetter)) { - builder.AppendLine(); + _ = builder.AppendLine(); } // Generate constructor var readOnlyProps = properties.Where(p => !p.HasSetter).ToArray(); if (readOnlyProps.Length > 0) { - builder.Append("public GeneratedEntity("); - for (int i = 0; i < readOnlyProps.Length; i++) + _ = builder.Append("public GeneratedEntity("); + for (var i = 0; i < readOnlyProps.Length; i++) { if (i > 0) - builder.Append(", "); - builder.AppendFormat( + { + _ = builder.Append(", "); + } + + _ = builder.AppendFormat( CultureInfo.InvariantCulture, "{0} {1}", readOnlyProps[i].Type, readOnlyProps[i].Name.ToUpperInvariant() ); } - builder.AppendLine(")").Append("{"); + _ = builder.AppendLine(")").Append("{"); foreach (var prop in readOnlyProps) { - builder + _ = builder .AppendFormat( CultureInfo.InvariantCulture, "_{0} = {1};", @@ -142,40 +139,32 @@ public async Task GenerateReflectionBasedCode_Should_ProduceCorrectOutput() .AppendLine(); } - builder.Append("}").AppendLine(); + _ = builder.Append("}").AppendLine(); } // Generate properties foreach (var prop in properties) { - builder.AppendFormat(CultureInfo.InvariantCulture, "public {0} {1}", prop.Type, prop.Name); + _ = builder.AppendFormat(CultureInfo.InvariantCulture, "public {0} {1}", prop.Type, prop.Name); if (prop.HasGetter && prop.HasSetter) { - builder.AppendLine(" { get; set; }"); + _ = builder.AppendLine(" { get; set; }"); } else if (prop.HasGetter && !prop.HasSetter) { - builder + _ = builder .AppendFormat(CultureInfo.InvariantCulture, " => _{0};", prop.Name.ToUpperInvariant()) .AppendLine(); } - builder.AppendLine(); + _ = builder.AppendLine(); } - builder.Append("}"); + _ = builder.Append("}"); var result = builder.ToString(); - // Basic verification for reflection-based code generation - _ = await Assert.That(result).Contains("public class GeneratedEntity"); - _ = await Assert.That(result).Contains("private readonly int _ID;"); - _ = await Assert.That(result).Contains("private readonly DateTime _CREATEDAT;"); - _ = await Assert.That(result).Contains("public GeneratedEntity(int ID, DateTime CREATEDAT)"); - _ = await Assert.That(result).Contains("public int Id => _ID;"); - _ = await Assert.That(result).Contains("public string? Name { get; set; }"); - _ = await Assert.That(result).Contains("public string? Email { get; set; }"); - _ = await Assert.That(result).Contains("public DateTime CreatedAt => _CREATEDAT;"); + _ = await Verify(result); } } diff --git a/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderIntegrationTests.Formatting.cs b/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderTests.Formatting.cs similarity index 57% rename from tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderIntegrationTests.Formatting.cs rename to tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderTests.Formatting.cs index 868a904..d6994aa 100644 --- a/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderIntegrationTests.Formatting.cs +++ b/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderTests.Formatting.cs @@ -1,16 +1,13 @@ namespace NetEvolve.CodeBuilder.Tests.Integration; -using System; -using System.Globalization; - -public partial class CSharpCodeBuilderIntegrationTests +public partial class CSharpCodeBuilderTests { [Test] public async Task GenerateClassWithFormatting_UsingSpaces_Should_ProduceCorrectIndentation() { var builder = new CSharpCodeBuilder { UseTabs = false }; - builder + _ = builder .AppendLine("public class TestClass") .Append("{") .AppendLine("public void Method1()") @@ -18,30 +15,26 @@ public async Task GenerateClassWithFormatting_UsingSpaces_Should_ProduceCorrectI .AppendLine("Console.WriteLine(\"Hello World\");") .AppendLine("if (true)") .Append("{") - .AppendLine("Console.WriteLine(\"Nested\");") + .Append("Console.WriteLine(\"Nested\");") .Append("}") .Append("}") .AppendLine() .AppendLine("public void Method2()") .Append("{") - .AppendLine("try") + .Append("try") .Append("{") - .AppendLine("DoSomething();") + .Append("DoSomething();") .Append("}") - .AppendLine("catch (Exception ex)") + .Append("catch (Exception ex)") .Append("{") - .AppendLine("Console.WriteLine($\"Error: {ex.Message}\");") + .Append("Console.WriteLine($\"Error: {ex.Message}\");") .Append("}") .Append("}") .Append("}"); var result = builder.ToString(); - // Verify spaces-based indentation - _ = await Assert.That(result).Contains("public class TestClass"); - _ = await Assert.That(result).Contains(" public void Method1()"); // 4 spaces indentation - _ = await Assert.That(result).Contains(" Console.WriteLine(\"Hello World\");"); // 8 spaces indentation - _ = await Assert.That(result).Contains(" Console.WriteLine(\"Nested\");"); // 12 spaces indentation + _ = await Verify(result); } [Test] @@ -49,7 +42,7 @@ public async Task GenerateClassWithFormatting_UsingTabs_Should_ProduceCorrectInd { var builder = new CSharpCodeBuilder { UseTabs = true }; - builder + _ = builder .AppendLine("public class TestClass") .Append("{") .AppendLine("public void Method1()") @@ -57,30 +50,26 @@ public async Task GenerateClassWithFormatting_UsingTabs_Should_ProduceCorrectInd .AppendLine("Console.WriteLine(\"Hello World\");") .AppendLine("if (true)") .Append("{") - .AppendLine("Console.WriteLine(\"Nested\");") + .Append("Console.WriteLine(\"Nested\");") .Append("}") .Append("}") .AppendLine() .AppendLine("public void Method2()") .Append("{") - .AppendLine("try") + .Append("try") .Append("{") - .AppendLine("DoSomething();") + .Append("DoSomething();") .Append("}") - .AppendLine("catch (Exception ex)") + .Append("catch (Exception ex)") .Append("{") - .AppendLine("Console.WriteLine($\"Error: {ex.Message}\");") + .Append("Console.WriteLine($\"Error: {ex.Message}\");") .Append("}") .Append("}") .Append("}"); var result = builder.ToString(); - // Verify tabs-based indentation - _ = await Assert.That(result).Contains("public class TestClass"); - _ = await Assert.That(result).Contains("\tpublic void Method1()"); // 1 tab indentation - _ = await Assert.That(result).Contains("\t\tConsole.WriteLine(\"Hello World\");"); // 2 tabs indentation - _ = await Assert.That(result).Contains("\t\t\tConsole.WriteLine(\"Nested\");"); // 3 tabs indentation + _ = await Verify(result); } [Test] @@ -88,7 +77,7 @@ public async Task GenerateEnum_WithDocumentation_Should_ProduceCorrectOutput() { var builder = new CSharpCodeBuilder(); - builder + _ = builder .AppendLine("using System;") .AppendLine() .AppendLine("namespace MyApplication.Enums") @@ -117,23 +106,12 @@ public async Task GenerateEnum_WithDocumentation_Should_ProduceCorrectOutput() .AppendLine("/// ") .AppendLine("/// The order has been delivered.") .AppendLine("/// ") - .AppendLine("Delivered = 8") + .Append("Delivered = 8") .Append("}") .Append("}"); var result = builder.ToString(); - // Basic verification for enum generation - _ = await Assert.That(result).Contains("namespace MyApplication.Enums"); - _ = await Assert.That(result).Contains("[Flags]"); - _ = await Assert.That(result).Contains("public enum OrderStatus"); - _ = await Assert.That(result).Contains("Pending = 1,"); - _ = await Assert.That(result).Contains("Processing = 2,"); - _ = await Assert.That(result).Contains("Shipped = 4,"); - _ = await Assert.That(result).Contains("Delivered = 8"); - - // Ensure proper indentation is applied - _ = await Assert.That(result).Contains(" public enum OrderStatus"); - _ = await Assert.That(result).Contains(" Pending = 1,"); + _ = await Verify(result); } } diff --git a/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderTests.SnapshotTests.cs b/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderTests.SnapshotTests.cs new file mode 100644 index 0000000..a62998d --- /dev/null +++ b/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderTests.SnapshotTests.cs @@ -0,0 +1,43 @@ +namespace NetEvolve.CodeBuilder.Tests.Integration; + +public partial class CSharpCodeBuilderTests +{ + [Test] + public async Task GenerateCompleteClass_Should_MatchSnapshot() + { + var builder = new CSharpCodeBuilder(); + + // Build a complete class structure + _ = builder + .AppendLine("using System;") + .AppendLine("using System.Collections.Generic;") + .AppendLine() + .AppendLine("namespace MyApplication.Models") + .Append("{") + .AppendLine("public class Customer") + .Append("{") + .AppendLine("public string Id { get; set; }") + .Append("public string Name { get; set; }") + .Append("}") + .Append("}"); + + var result = builder.ToString(); + + _ = await Verify(result); + } + + [Test] + [MatrixDataSource] + public async Task GenerateWithDifferentFormats_Should_MatchSnapshots(bool useTabs) + { + // Test with spaces + var spacesBuilder = new CSharpCodeBuilder { UseTabs = useTabs }; + _ = spacesBuilder + .AppendLine("public class TestClass") + .Append("{") + .Append("public void Method() { }") + .Append("}"); + + _ = await Verify(spacesBuilder.ToString()).HashParameters().UseParameters(useTabs); + } +} diff --git a/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderIntegrationTests.cs b/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderTests.cs similarity index 68% rename from tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderIntegrationTests.cs rename to tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderTests.cs index bbd3876..87f9424 100644 --- a/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderIntegrationTests.cs +++ b/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderTests.cs @@ -3,4 +3,4 @@ namespace NetEvolve.CodeBuilder.Tests.Integration; using NetEvolve.Extensions.TUnit; [TestGroup(nameof(CSharpCodeBuilder))] -public partial class CSharpCodeBuilderIntegrationTests { } +public partial class CSharpCodeBuilderTests { } diff --git a/tests/NetEvolve.CodeBuilder.Tests.Integration/NetEvolve.CodeBuilder.Tests.Integration.csproj b/tests/NetEvolve.CodeBuilder.Tests.Integration/NetEvolve.CodeBuilder.Tests.Integration.csproj index 6a2296e..b7e1bdf 100644 --- a/tests/NetEvolve.CodeBuilder.Tests.Integration/NetEvolve.CodeBuilder.Tests.Integration.csproj +++ b/tests/NetEvolve.CodeBuilder.Tests.Integration/NetEvolve.CodeBuilder.Tests.Integration.csproj @@ -10,6 +10,7 @@ + diff --git a/tests/NetEvolve.CodeBuilder.Tests.Integration/README.md b/tests/NetEvolve.CodeBuilder.Tests.Integration/README.md deleted file mode 100644 index d61536f..0000000 --- a/tests/NetEvolve.CodeBuilder.Tests.Integration/README.md +++ /dev/null @@ -1,69 +0,0 @@ -# NetEvolve.CodeBuilder.Tests.Integration - -This project contains integration tests for the NetEvolve.CodeBuilder library, focusing on end-to-end testing scenarios that validate the complete functionality of the code generation capabilities. - -## Test Framework - -- **TUnit**: Primary testing framework -- **Verify.TUnit**: For snapshot testing (to be enabled when environment supports it) -- **No Mocking**: Tests use real instances and validate actual output - -## Test Organization - -The integration tests are organized into partial classes for better maintainability: - -### CSharpCodeBuilderIntegrationTests.ComplexGeneration.cs -- Complete class generation with documentation -- Interface generation with multiple methods -- Real-world code generation scenarios - -### CSharpCodeBuilderIntegrationTests.ConditionalGeneration.cs -- Conditional content generation using AppendIf methods -- Reflection-based code generation patterns -- Dynamic property and method generation - -### CSharpCodeBuilderIntegrationTests.Formatting.cs -- Indentation testing (spaces vs tabs) -- Code formatting validation -- Enum generation with attributes - -### CSharpCodeBuilderIntegrationTests.SnapshotTests.cs -- Placeholder for snapshot tests using Verify.TUnit -- Will be enabled when framework compatibility is resolved - -## Test Scenarios - -The integration tests cover: - -1. **End-to-End Class Generation**: Complete C# classes with proper indentation, documentation, and structure -2. **Interface Generation**: Service interfaces with async methods and documentation -3. **Conditional Logic**: Using AppendIf and AppendLineIf for dynamic content -4. **Formatting Options**: Testing both space and tab-based indentation -5. **Complex Structures**: Enums with attributes, nested code blocks, exception handling - -## Running Tests - -```bash -# Run all integration tests -dotnet test tests/NetEvolve.CodeBuilder.Tests.Integration/ - -# Run specific test class -dotnet test tests/NetEvolve.CodeBuilder.Tests.Integration/ --filter "ClassName=CSharpCodeBuilderIntegrationTests" -``` - -## Adding New Tests - -When adding new integration tests: - -1. Follow the existing naming convention: `MethodName_Condition_Should_ExpectedResult` -2. Use the [Test] attribute from TUnit -3. Use partial classes to organize related tests -4. Validate both content and formatting in assertions -5. Include real-world scenarios that developers would encounter - -## Future Enhancements - -- Snapshot testing with Verify.TUnit when framework support is available -- Performance benchmarking for large code generation scenarios -- Cross-platform indentation testing -- Template-based code generation tests \ No newline at end of file diff --git a/tests/NetEvolve.CodeBuilder.Tests.Integration/Startup.cs b/tests/NetEvolve.CodeBuilder.Tests.Integration/Startup.cs new file mode 100644 index 0000000..274fb46 --- /dev/null +++ b/tests/NetEvolve.CodeBuilder.Tests.Integration/Startup.cs @@ -0,0 +1,22 @@ +namespace NetEvolve.CodeBuilder.Tests.Integration; + +using System.Runtime.CompilerServices; +using VerifyTUnit; + +internal static class Startup +{ + [ModuleInitializer] + public static void Initialize() + { + Verifier.DerivePathInfo( + (sourceFile, projectDirectory, type, method) => + { + var directory = Path.Combine(projectDirectory, "_snapshots"); + _ = Directory.CreateDirectory(directory); + return new(directory, type.Name, method.Name); + } + ); + + VerifierSettings.AutoVerify(includeBuildServer: false); + } +} diff --git a/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateClassWithFormatting_UsingSpaces_Should_ProduceCorrectIndentation.verified.txt b/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateClassWithFormatting_UsingSpaces_Should_ProduceCorrectIndentation.verified.txt new file mode 100644 index 0000000..4a16bd3 --- /dev/null +++ b/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateClassWithFormatting_UsingSpaces_Should_ProduceCorrectIndentation.verified.txt @@ -0,0 +1,19 @@ +public class TestClass +{ + public void Method1() + { + Console.WriteLine("Hello World"); + if (true) + { + Console.WriteLine("Nested"); + } + } + public void Method2() + { + try{ + DoSomething(); + }catch (Exception ex){ + Console.WriteLine($"Error: {ex.Message}"); + } + } +} \ No newline at end of file diff --git a/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateClassWithFormatting_UsingTabs_Should_ProduceCorrectIndentation.verified.txt b/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateClassWithFormatting_UsingTabs_Should_ProduceCorrectIndentation.verified.txt new file mode 100644 index 0000000..94d0ddc --- /dev/null +++ b/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateClassWithFormatting_UsingTabs_Should_ProduceCorrectIndentation.verified.txt @@ -0,0 +1,19 @@ +public class TestClass +{ + public void Method1() + { + Console.WriteLine("Hello World"); + if (true) + { + Console.WriteLine("Nested"); + } + } + public void Method2() + { + try{ + DoSomething(); + }catch (Exception ex){ + Console.WriteLine($"Error: {ex.Message}"); + } + } +} \ No newline at end of file diff --git a/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateCompleteClass_Should_MatchSnapshot.verified.txt b/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateCompleteClass_Should_MatchSnapshot.verified.txt new file mode 100644 index 0000000..d164a1e --- /dev/null +++ b/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateCompleteClass_Should_MatchSnapshot.verified.txt @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace MyApplication.Models +{ + public class Customer + { + public string Id { get; set; } + public string Name { get; set; } + } +} \ No newline at end of file diff --git a/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateCompleteClass_Should_ProduceCorrectOutput.verified.txt b/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateCompleteClass_Should_ProduceCorrectOutput.verified.txt new file mode 100644 index 0000000..4a96ddd --- /dev/null +++ b/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateCompleteClass_Should_ProduceCorrectOutput.verified.txt @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; + +namespace MyApplication.Models +{ + /// + /// Represents a customer entity. + /// + public class Customer + { + private readonly string _id; + + /// + /// Initializes a new instance of the Customer class. + /// + /// The customer identifier. + public Customer(string id) + { + _id = id ?? throw new ArgumentNullException(nameof(id)); + + } + /// + /// Gets the customer identifier. + /// + public string Id => _id; + + /// + /// Gets or sets the customer name. + /// + public string? Name { get; set; } + + /// + /// Gets or sets the customer email address. + /// + public string? Email { get; set; } + } +} \ No newline at end of file diff --git a/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateEnum_WithDocumentation_Should_ProduceCorrectOutput.verified.txt b/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateEnum_WithDocumentation_Should_ProduceCorrectOutput.verified.txt new file mode 100644 index 0000000..3a00a9e --- /dev/null +++ b/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateEnum_WithDocumentation_Should_ProduceCorrectOutput.verified.txt @@ -0,0 +1,31 @@ +using System; + +namespace MyApplication.Enums +{ + /// + /// Represents the status of an order. + /// + [Flags] + public enum OrderStatus + { + /// + /// The order is pending. + /// + Pending = 1, + + /// + /// The order is being processed. + /// + Processing = 2, + + /// + /// The order has been shipped. + /// + Shipped = 4, + + /// + /// The order has been delivered. + /// + Delivered = 8 + } +} \ No newline at end of file diff --git a/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateInterface_WithMultipleMethods_Should_ProduceCorrectOutput.verified.txt b/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateInterface_WithMultipleMethods_Should_ProduceCorrectOutput.verified.txt new file mode 100644 index 0000000..b927e3c --- /dev/null +++ b/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateInterface_WithMultipleMethods_Should_ProduceCorrectOutput.verified.txt @@ -0,0 +1,32 @@ +using System; +using System.Threading.Tasks; + +namespace MyApplication.Services +{ + /// + /// Defines the contract for customer service operations. + /// + public interface ICustomerService + { + /// + /// Gets a customer by their identifier. + /// + /// The customer identifier. + /// The customer if found; otherwise, null. + Task GetCustomerAsync(string id); + + /// + /// Creates a new customer. + /// + /// The customer to create. + /// A task representing the asynchronous operation. + Task CreateCustomerAsync(Customer customer); + + /// + /// Updates an existing customer. + /// + /// The customer to update. + /// A task representing the asynchronous operation. + Task UpdateCustomerAsync(Customer customer); + } +} \ No newline at end of file diff --git a/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateMethodWithConditionalContent_Should_ProduceCorrectOutput.verified.txt b/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateMethodWithConditionalContent_Should_ProduceCorrectOutput.verified.txt new file mode 100644 index 0000000..9e7e44b --- /dev/null +++ b/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateMethodWithConditionalContent_Should_ProduceCorrectOutput.verified.txt @@ -0,0 +1,11 @@ +public class ServiceClass +{ + public async Task ProcessDataAsync(string input){ + Console.WriteLine($"Processing input: {input}"); + var result = input.ToUpperInvariant(); + Console.WriteLine($"Processing complete: {result}"); + await Task.CompletedTask; + return result; + + } +} \ No newline at end of file diff --git a/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateReflectionBasedCode_Should_ProduceCorrectOutput.verified.txt b/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateReflectionBasedCode_Should_ProduceCorrectOutput.verified.txt new file mode 100644 index 0000000..f4150dc --- /dev/null +++ b/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateReflectionBasedCode_Should_ProduceCorrectOutput.verified.txt @@ -0,0 +1,23 @@ +using System; + +public class GeneratedEntity +{ + private readonly int _ID; + private readonly DateTime _CREATEDAT; + + public GeneratedEntity(int ID, DateTime CREATEDAT) + { + _ID = ID; + _CREATEDAT = CREATEDAT; + + } + public int Id => _ID; + + public string? Name { get; set; } + + public string? Email { get; set; } + + public DateTime CreatedAt => _CREATEDAT; + + +} \ No newline at end of file diff --git a/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateWithDifferentFormats_Should_MatchSnapshots_02b3255120757173.verified.txt b/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateWithDifferentFormats_Should_MatchSnapshots_02b3255120757173.verified.txt new file mode 100644 index 0000000..271daf7 --- /dev/null +++ b/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateWithDifferentFormats_Should_MatchSnapshots_02b3255120757173.verified.txt @@ -0,0 +1,4 @@ +public class TestClass +{ + public void Method() { } +} \ No newline at end of file diff --git a/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateWithDifferentFormats_Should_MatchSnapshots_b6b4547aad375c78.verified.txt b/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateWithDifferentFormats_Should_MatchSnapshots_b6b4547aad375c78.verified.txt new file mode 100644 index 0000000..76924e7 --- /dev/null +++ b/tests/NetEvolve.CodeBuilder.Tests.Integration/_snapshots/CSharpCodeBuilderTests.GenerateWithDifferentFormats_Should_MatchSnapshots_b6b4547aad375c78.verified.txt @@ -0,0 +1,4 @@ +public class TestClass +{ + public void Method() { } +} \ No newline at end of file From bae46c7c0857269789ad24e95dc77cd8aaa60075 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20St=C3=BChmer?= Date: Sat, 23 Aug 2025 12:37:27 +0200 Subject: [PATCH 4/5] style: Reformatted code --- Directory.Packages.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index bd2f5e5..715be31 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -21,4 +21,4 @@ - \ No newline at end of file + From d2ddbac4865460b563749e474def42de9556c5ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20St=C3=BChmer?= Date: Mon, 25 Aug 2025 09:38:00 +0200 Subject: [PATCH 5/5] fix: Warnings from the Code Review --- Directory.Build.props | 2 +- .../CSharpCodeBuilderTests.ConditionalGeneration.cs | 11 +++-------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 3c5fd1e..2d8f37c 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -9,7 +9,7 @@ 2024 <_DefaultTargetFrameworks>net8.0;net9.0;net10.0 <_ProjectTargetFrameworks>netstandard2.0;netstandard2.1;$(_DefaultTargetFrameworks) - <_TestTargetFrameworks>net6.0;net7.0;$(_DefaultTargetFrameworks) + <_TestTargetFrameworks>$(_DefaultTargetFrameworks) false diff --git a/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderTests.ConditionalGeneration.cs b/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderTests.ConditionalGeneration.cs index 14003e7..6afe86d 100644 --- a/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderTests.ConditionalGeneration.cs +++ b/tests/NetEvolve.CodeBuilder.Tests.Integration/CSharpCodeBuilderTests.ConditionalGeneration.cs @@ -1,4 +1,4 @@ -namespace NetEvolve.CodeBuilder.Tests.Integration; +namespace NetEvolve.CodeBuilder.Tests.Integration; using System.Globalization; using System.Linq; @@ -127,15 +127,10 @@ public async Task GenerateReflectionBasedCode_Should_ProduceCorrectOutput() } _ = builder.AppendLine(")").Append("{"); - foreach (var prop in readOnlyProps) + foreach (var propertyName in readOnlyProps.Select(x => x.Name.ToUpperInvariant())) { _ = builder - .AppendFormat( - CultureInfo.InvariantCulture, - "_{0} = {1};", - prop.Name.ToUpperInvariant(), - prop.Name.ToUpperInvariant() - ) + .AppendFormat(CultureInfo.InvariantCulture, "_{0} = {1};", propertyName, propertyName) .AppendLine(); }