|
| 1 | +namespace NetEvolve.CodeBuilder.Tests.Integration; |
| 2 | + |
| 3 | +public partial class CSharpCodeBuilderTests |
| 4 | +{ |
| 5 | + [Test] |
| 6 | + public async Task GenerateCompleteClass_Should_ProduceCorrectOutput() |
| 7 | + { |
| 8 | + // Build a complete class with using statements, namespace, and methods |
| 9 | + var builder = new CSharpCodeBuilder() |
| 10 | + .AppendLine("using System;") |
| 11 | + .AppendLine("using System.Collections.Generic;") |
| 12 | + .AppendLine() |
| 13 | + .AppendLine("namespace MyApplication.Models") |
| 14 | + .Append("{") |
| 15 | + .AppendLine("/// <summary>") |
| 16 | + .AppendLine("/// Represents a customer entity.") |
| 17 | + .AppendLine("/// </summary>") |
| 18 | + .AppendLine("public class Customer") |
| 19 | + .Append("{") |
| 20 | + .AppendLine("private readonly string _id;") |
| 21 | + .AppendLine() |
| 22 | + .AppendLine("/// <summary>") |
| 23 | + .AppendLine("/// Initializes a new instance of the Customer class.") |
| 24 | + .AppendLine("/// </summary>") |
| 25 | + .AppendLine("/// <param name=\"id\">The customer identifier.</param>") |
| 26 | + .AppendLine("public Customer(string id)") |
| 27 | + .Append("{") |
| 28 | + .AppendLine("_id = id ?? throw new ArgumentNullException(nameof(id));") |
| 29 | + .Append("}") |
| 30 | + .AppendLine() |
| 31 | + .AppendLine("/// <summary>") |
| 32 | + .AppendLine("/// Gets the customer identifier.") |
| 33 | + .AppendLine("/// </summary>") |
| 34 | + .AppendLine("public string Id => _id;") |
| 35 | + .AppendLine() |
| 36 | + .AppendLine("/// <summary>") |
| 37 | + .AppendLine("/// Gets or sets the customer name.") |
| 38 | + .AppendLine("/// </summary>") |
| 39 | + .AppendLine("public string? Name { get; set; }") |
| 40 | + .AppendLine() |
| 41 | + .AppendLine("/// <summary>") |
| 42 | + .AppendLine("/// Gets or sets the customer email address.") |
| 43 | + .AppendLine("/// </summary>") |
| 44 | + .Append("public string? Email { get; set; }") |
| 45 | + .Append("}") |
| 46 | + .Append("}"); |
| 47 | + |
| 48 | + var result = builder.ToString(); |
| 49 | + |
| 50 | + _ = await Verify(result); |
| 51 | + } |
| 52 | + |
| 53 | + [Test] |
| 54 | + public async Task GenerateInterface_WithMultipleMethods_Should_ProduceCorrectOutput() |
| 55 | + { |
| 56 | + var builder = new CSharpCodeBuilder() |
| 57 | + .AppendLine("using System;") |
| 58 | + .AppendLine("using System.Threading.Tasks;") |
| 59 | + .AppendLine() |
| 60 | + .AppendLine("namespace MyApplication.Services") |
| 61 | + .Append("{") |
| 62 | + .AppendXmlDocSummary("Defines the contract for customer service operations.") |
| 63 | + .AppendLine("public interface ICustomerService") |
| 64 | + .Append("{") |
| 65 | + .AppendXmlDocSummary("Gets a customer by their identifier.") |
| 66 | + .AppendXmlDocParam("id", "The customer identifier.") |
| 67 | + .AppendXmlDocReturns("The customer if found; otherwise, null.") |
| 68 | + .AppendLine("Task<Customer?> GetCustomerAsync(string id);") |
| 69 | + .AppendLine() |
| 70 | + .AppendXmlDocSummary("Creates a new customer.") |
| 71 | + .AppendXmlDocParam("customer", "The customer to create.") |
| 72 | + .AppendXmlDocReturns("A task representing the asynchronous operation.") |
| 73 | + .AppendLine("Task CreateCustomerAsync(Customer customer);") |
| 74 | + .AppendLine() |
| 75 | + .AppendXmlDocSummary("Updates an existing customer.") |
| 76 | + .AppendXmlDocParam("customer", "The customer to update.") |
| 77 | + .AppendXmlDocReturns("A task representing the asynchronous operation.") |
| 78 | + .Append("Task UpdateCustomerAsync(Customer customer);") |
| 79 | + .Append("}") |
| 80 | + .Append("}"); |
| 81 | + |
| 82 | + var result = builder.ToString(); |
| 83 | + |
| 84 | + _ = await Verify(result); |
| 85 | + } |
| 86 | +} |
0 commit comments