-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCSharpCodeBuilderTests.ComplexGeneration.cs
More file actions
86 lines (80 loc) · 3.59 KB
/
CSharpCodeBuilderTests.ComplexGeneration.cs
File metadata and controls
86 lines (80 loc) · 3.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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("/// <summary>")
.AppendLine("/// Represents a customer entity.")
.AppendLine("/// </summary>")
.AppendLine("public class Customer")
.Append("{")
.AppendLine("private readonly string _id;")
.AppendLine()
.AppendLine("/// <summary>")
.AppendLine("/// Initializes a new instance of the Customer class.")
.AppendLine("/// </summary>")
.AppendLine("/// <param name=\"id\">The customer identifier.</param>")
.AppendLine("public Customer(string id)")
.Append("{")
.AppendLine("_id = id ?? throw new ArgumentNullException(nameof(id));")
.Append("}")
.AppendLine()
.AppendLine("/// <summary>")
.AppendLine("/// Gets the customer identifier.")
.AppendLine("/// </summary>")
.AppendLine("public string Id => _id;")
.AppendLine()
.AppendLine("/// <summary>")
.AppendLine("/// Gets or sets the customer name.")
.AppendLine("/// </summary>")
.AppendLine("public string? Name { get; set; }")
.AppendLine()
.AppendLine("/// <summary>")
.AppendLine("/// Gets or sets the customer email address.")
.AppendLine("/// </summary>")
.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<Customer?> 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);
}
}