You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

FunctionCallTemplateEncodingTests.cs 2.8 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // Copyright (c) Microsoft Corporation. All rights reserved.
  2. // FunctionCallTemplateEncodingTests.cs
  3. using AutoGen.SourceGenerator.Template; // Needed for FunctionCallTemplate
  4. using Xunit; // Needed for Fact and Assert
  5. namespace AutoGen.SourceGenerator.Tests;
  6. [Trait("Category", "UnitV1")]
  7. public class FunctionCallTemplateEncodingTests
  8. {
  9. [Fact]
  10. public void FunctionDescription_Should_Encode_DoubleQuotes()
  11. {
  12. // Arrange
  13. var functionContracts = new List<SourceGeneratorFunctionContract>
  14. {
  15. new SourceGeneratorFunctionContract
  16. {
  17. Name = "TestFunction",
  18. Description = "This is a \"test\" function",
  19. Parameters = new SourceGeneratorParameterContract[]
  20. {
  21. new SourceGeneratorParameterContract
  22. {
  23. Name = "param1",
  24. Description = "This is a \"parameter\" description",
  25. Type = "string",
  26. IsOptional = false
  27. }
  28. },
  29. ReturnType = "void"
  30. }
  31. };
  32. var template = new FunctionCallTemplate
  33. {
  34. NameSpace = "TestNamespace",
  35. ClassName = "TestClass",
  36. FunctionContracts = functionContracts
  37. };
  38. // Act
  39. var result = template.TransformText();
  40. // Assert
  41. Assert.Contains("Description = @\"This is a \"\"test\"\" function\"", result);
  42. Assert.Contains("Description = @\"This is a \"\"parameter\"\" description\"", result);
  43. }
  44. [Fact]
  45. public void ParameterDescription_Should_Encode_DoubleQuotes()
  46. {
  47. // Arrange
  48. var functionContracts = new List<SourceGeneratorFunctionContract>
  49. {
  50. new SourceGeneratorFunctionContract
  51. {
  52. Name = "TestFunction",
  53. Description = "This is a test function",
  54. Parameters = new SourceGeneratorParameterContract[]
  55. {
  56. new SourceGeneratorParameterContract
  57. {
  58. Name = "param1",
  59. Description = "This is a \"parameter\" description",
  60. Type = "string",
  61. IsOptional = false
  62. }
  63. },
  64. ReturnType = "void"
  65. }
  66. };
  67. var template = new FunctionCallTemplate
  68. {
  69. NameSpace = "TestNamespace",
  70. ClassName = "TestClass",
  71. FunctionContracts = functionContracts
  72. };
  73. // Act
  74. var result = template.TransformText();
  75. // Assert
  76. Assert.Contains("Description = @\"This is a \"\"parameter\"\" description\"", result);
  77. }
  78. }