Skip to content

Commit a15b386

Browse files
Add snapshots for client generation tests
Add snapshots for all of the client generation tests.
1 parent 98891e4 commit a15b386

File tree

243 files changed

+32132
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

243 files changed

+32132
-1
lines changed

test/Swashbuckle.AspNetCore.IntegrationTests/CodeGenerationTests.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#if NET10_0_OR_GREATER
22

33
using System.Reflection;
4+
using System.Security.Cryptography;
5+
using System.Text;
46
using Microsoft.AspNetCore.Http;
57
using Microsoft.Kiota.Abstractions.Authentication;
68
using Microsoft.Kiota.Http.HttpClientLibrary;
@@ -58,7 +60,7 @@ public static TheoryData<ClientGeneratorTool, string> SnapshotTestCases()
5860

5961
[Theory]
6062
[MemberData(nameof(SnapshotTestCases))]
61-
public async Task OpenApiDocument_Generates_Valid_Client_Code_From_Snapshot(ClientGeneratorTool tool, string snapshot)
63+
public async Task GeneratesValidClient(ClientGeneratorTool tool, string snapshot)
6264
{
6365
// Arrange
6466
var generator = new ClientGenerator(outputHelper);
@@ -70,6 +72,19 @@ public async Task OpenApiDocument_Generates_Valid_Client_Code_From_Snapshot(Clie
7072

7173
// Act and Assert
7274
await generator.CompileAsync(project.Path);
75+
76+
var hash = SHA256.HashData(Encoding.UTF8.GetBytes($"{tool}:{snapshot}"));
77+
var hashString = Convert.ToHexString(hash).ToLowerInvariant()[..16];
78+
79+
outputHelper.WriteLine($"{nameof(tool)}={tool}, {nameof(snapshot)}={snapshot} [{hashString}]");
80+
81+
await VerifyDirectory(
82+
project.Path,
83+
pattern: "*.cs",
84+
include: (p) => !p.Contains("bin") && !p.Contains("obj"),
85+
options: new() { RecurseSubdirectories = true })
86+
.UseDirectory("snapshots")
87+
.UseFileName($"{nameof(GeneratesValidClient)}_{hashString}");
7388
}
7489

7590
[Fact]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// <auto-generated/>
2+
#pragma warning disable CS0618
3+
using Microsoft.Kiota.Abstractions.Extensions;
4+
using Microsoft.Kiota.Abstractions;
5+
using Microsoft.Kiota.Serialization.Form;
6+
using Microsoft.Kiota.Serialization.Json;
7+
using Microsoft.Kiota.Serialization.Multipart;
8+
using Microsoft.Kiota.Serialization.Text;
9+
using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products;
10+
using System.Collections.Generic;
11+
using System.IO;
12+
using System.Threading.Tasks;
13+
using System;
14+
namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests
15+
{
16+
/// <summary>
17+
/// The main entry point of the SDK, exposes the configuration and the fluent API.
18+
/// </summary>
19+
[global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")]
20+
public partial class KiotaOpenApiClient : BaseRequestBuilder
21+
{
22+
/// <summary>The products property</summary>
23+
public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.ProductsRequestBuilder Products
24+
{
25+
get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.ProductsRequestBuilder(PathParameters, RequestAdapter);
26+
}
27+
/// <summary>
28+
/// Instantiates a new <see cref="global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.KiotaOpenApiClient"/> and sets the default values.
29+
/// </summary>
30+
/// <param name="requestAdapter">The request adapter to use to execute the requests.</param>
31+
public KiotaOpenApiClient(IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}", new Dictionary<string, object>())
32+
{
33+
ApiClientBuilder.RegisterDefaultSerializer<JsonSerializationWriterFactory>();
34+
ApiClientBuilder.RegisterDefaultSerializer<TextSerializationWriterFactory>();
35+
ApiClientBuilder.RegisterDefaultSerializer<FormSerializationWriterFactory>();
36+
ApiClientBuilder.RegisterDefaultSerializer<MultipartSerializationWriterFactory>();
37+
ApiClientBuilder.RegisterDefaultDeserializer<JsonParseNodeFactory>();
38+
ApiClientBuilder.RegisterDefaultDeserializer<TextParseNodeFactory>();
39+
ApiClientBuilder.RegisterDefaultDeserializer<FormParseNodeFactory>();
40+
}
41+
}
42+
}
43+
#pragma warning restore CS0618
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// <auto-generated/>
2+
#pragma warning disable CS0618
3+
using Microsoft.Kiota.Abstractions.Extensions;
4+
using Microsoft.Kiota.Abstractions.Serialization;
5+
using System.Collections.Generic;
6+
using System.IO;
7+
using System;
8+
namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models
9+
{
10+
[global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")]
11+
#pragma warning disable CS1591
12+
public partial class Product : IParsable
13+
#pragma warning restore CS1591
14+
{
15+
/// <summary>The description property</summary>
16+
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
17+
#nullable enable
18+
public string? Description { get; set; }
19+
#nullable restore
20+
#else
21+
public string Description { get; set; }
22+
#endif
23+
/// <summary>The id property</summary>
24+
public int? Id { get; set; }
25+
/// <summary>
26+
/// Creates a new instance of the appropriate class based on discriminator value
27+
/// </summary>
28+
/// <returns>A <see cref="global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product"/></returns>
29+
/// <param name="parseNode">The parse node to use to read the discriminator value and create the object</param>
30+
public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product CreateFromDiscriminatorValue(IParseNode parseNode)
31+
{
32+
if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode));
33+
return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product();
34+
}
35+
/// <summary>
36+
/// The deserialization information for the current model
37+
/// </summary>
38+
/// <returns>A IDictionary&lt;string, Action&lt;IParseNode&gt;&gt;</returns>
39+
public virtual IDictionary<string, Action<IParseNode>> GetFieldDeserializers()
40+
{
41+
return new Dictionary<string, Action<IParseNode>>
42+
{
43+
{ "description", n => { Description = n.GetStringValue(); } },
44+
{ "id", n => { Id = n.GetIntValue(); } },
45+
};
46+
}
47+
/// <summary>
48+
/// Serializes information the current object
49+
/// </summary>
50+
/// <param name="writer">Serialization writer to use to serialize this model</param>
51+
public virtual void Serialize(ISerializationWriter writer)
52+
{
53+
if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer));
54+
writer.WriteStringValue("description", Description);
55+
writer.WriteIntValue("id", Id);
56+
}
57+
}
58+
}
59+
#pragma warning restore CS0618
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// <auto-generated/>
2+
#pragma warning disable CS0618
3+
using Microsoft.Kiota.Abstractions.Extensions;
4+
using Microsoft.Kiota.Abstractions.Serialization;
5+
using Microsoft.Kiota.Abstractions;
6+
using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models;
7+
using System.Collections.Generic;
8+
using System.IO;
9+
using System.Threading.Tasks;
10+
using System.Threading;
11+
using System;
12+
namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products
13+
{
14+
/// <summary>
15+
/// Builds and executes requests for operations under \products
16+
/// </summary>
17+
[global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")]
18+
public partial class ProductsRequestBuilder : BaseRequestBuilder
19+
{
20+
/// <summary>
21+
/// Instantiates a new <see cref="global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.ProductsRequestBuilder"/> and sets the default values.
22+
/// </summary>
23+
/// <param name="pathParameters">Path parameters for the request</param>
24+
/// <param name="requestAdapter">The request adapter to use to execute the requests.</param>
25+
public ProductsRequestBuilder(Dictionary<string, object> pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/products", pathParameters)
26+
{
27+
}
28+
/// <summary>
29+
/// Instantiates a new <see cref="global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.ProductsRequestBuilder"/> and sets the default values.
30+
/// </summary>
31+
/// <param name="rawUrl">The raw URL to use for the request builder.</param>
32+
/// <param name="requestAdapter">The request adapter to use to execute the requests.</param>
33+
public ProductsRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/products", rawUrl)
34+
{
35+
}
36+
/// <returns>A List&lt;global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product&gt;</returns>
37+
/// <param name="cancellationToken">Cancellation token to use when cancelling requests</param>
38+
/// <param name="requestConfiguration">Configuration for the request such as headers, query parameters, and middleware options.</param>
39+
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
40+
#nullable enable
41+
public async Task<List<global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product>?> GetAsync(Action<RequestConfiguration<DefaultQueryParameters>>? requestConfiguration = default, CancellationToken cancellationToken = default)
42+
{
43+
#nullable restore
44+
#else
45+
public async Task<List<global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product>> GetAsync(Action<RequestConfiguration<DefaultQueryParameters>> requestConfiguration = default, CancellationToken cancellationToken = default)
46+
{
47+
#endif
48+
var requestInfo = ToGetRequestInformation(requestConfiguration);
49+
var collectionResult = await RequestAdapter.SendCollectionAsync<global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product>(requestInfo, global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product.CreateFromDiscriminatorValue, default, cancellationToken).ConfigureAwait(false);
50+
return collectionResult?.AsList();
51+
}
52+
/// <returns>A <see cref="RequestInformation"/></returns>
53+
/// <param name="requestConfiguration">Configuration for the request such as headers, query parameters, and middleware options.</param>
54+
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
55+
#nullable enable
56+
public RequestInformation ToGetRequestInformation(Action<RequestConfiguration<DefaultQueryParameters>>? requestConfiguration = default)
57+
{
58+
#nullable restore
59+
#else
60+
public RequestInformation ToGetRequestInformation(Action<RequestConfiguration<DefaultQueryParameters>> requestConfiguration = default)
61+
{
62+
#endif
63+
var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters);
64+
requestInfo.Configure(requestConfiguration);
65+
requestInfo.Headers.TryAdd("Accept", "application/json");
66+
return requestInfo;
67+
}
68+
/// <summary>
69+
/// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored.
70+
/// </summary>
71+
/// <returns>A <see cref="global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.ProductsRequestBuilder"/></returns>
72+
/// <param name="rawUrl">The raw URL to use for the request builder.</param>
73+
public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.ProductsRequestBuilder WithUrl(string rawUrl)
74+
{
75+
return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.ProductsRequestBuilder(rawUrl, RequestAdapter);
76+
}
77+
/// <summary>
78+
/// Configuration for the request such as headers, query parameters, and middleware options.
79+
/// </summary>
80+
[Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")]
81+
[global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")]
82+
public partial class ProductsRequestBuilderGetRequestConfiguration : RequestConfiguration<DefaultQueryParameters>
83+
{
84+
}
85+
}
86+
}
87+
#pragma warning restore CS0618
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// <auto-generated/>
2+
#pragma warning disable CS0618
3+
using Microsoft.Kiota.Abstractions.Extensions;
4+
using Microsoft.Kiota.Abstractions;
5+
using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.AsParameters;
6+
using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.Fruit;
7+
using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromFileAndEnum;
8+
using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromFileAndString;
9+
using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromObjectAndString;
10+
using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.MultipleForms;
11+
using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.SingleForm;
12+
using System.Collections.Generic;
13+
using System.IO;
14+
using System.Threading.Tasks;
15+
using System;
16+
namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations
17+
{
18+
/// <summary>
19+
/// Builds and executes requests for operations under \annotations
20+
/// </summary>
21+
[global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")]
22+
public partial class AnnotationsRequestBuilder : BaseRequestBuilder
23+
{
24+
/// <summary>The AsParameters property</summary>
25+
public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.AsParameters.AsParametersRequestBuilder AsParameters
26+
{
27+
get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.AsParameters.AsParametersRequestBuilder(PathParameters, RequestAdapter);
28+
}
29+
/// <summary>The fruit property</summary>
30+
public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.Fruit.FruitRequestBuilder Fruit
31+
{
32+
get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.Fruit.FruitRequestBuilder(PathParameters, RequestAdapter);
33+
}
34+
/// <summary>The IFromFileAndEnum property</summary>
35+
public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromFileAndEnum.IFromFileAndEnumRequestBuilder IFromFileAndEnum
36+
{
37+
get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromFileAndEnum.IFromFileAndEnumRequestBuilder(PathParameters, RequestAdapter);
38+
}
39+
/// <summary>The IFromFileAndString property</summary>
40+
public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromFileAndString.IFromFileAndStringRequestBuilder IFromFileAndString
41+
{
42+
get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromFileAndString.IFromFileAndStringRequestBuilder(PathParameters, RequestAdapter);
43+
}
44+
/// <summary>The IFromObjectAndString property</summary>
45+
public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromObjectAndString.IFromObjectAndStringRequestBuilder IFromObjectAndString
46+
{
47+
get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromObjectAndString.IFromObjectAndStringRequestBuilder(PathParameters, RequestAdapter);
48+
}
49+
/// <summary>The multipleForms property</summary>
50+
public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.MultipleForms.MultipleFormsRequestBuilder MultipleForms
51+
{
52+
get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.MultipleForms.MultipleFormsRequestBuilder(PathParameters, RequestAdapter);
53+
}
54+
/// <summary>The singleForm property</summary>
55+
public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.SingleForm.SingleFormRequestBuilder SingleForm
56+
{
57+
get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.SingleForm.SingleFormRequestBuilder(PathParameters, RequestAdapter);
58+
}
59+
/// <summary>
60+
/// Instantiates a new <see cref="global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.AnnotationsRequestBuilder"/> and sets the default values.
61+
/// </summary>
62+
/// <param name="pathParameters">Path parameters for the request</param>
63+
/// <param name="requestAdapter">The request adapter to use to execute the requests.</param>
64+
public AnnotationsRequestBuilder(Dictionary<string, object> pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/annotations", pathParameters)
65+
{
66+
}
67+
/// <summary>
68+
/// Instantiates a new <see cref="global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.AnnotationsRequestBuilder"/> and sets the default values.
69+
/// </summary>
70+
/// <param name="rawUrl">The raw URL to use for the request builder.</param>
71+
/// <param name="requestAdapter">The request adapter to use to execute the requests.</param>
72+
public AnnotationsRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/annotations", rawUrl)
73+
{
74+
}
75+
}
76+
}
77+
#pragma warning restore CS0618

0 commit comments

Comments
 (0)