Skip to content

Commit 5298c3b

Browse files
feat: added nullable and parameter tests
1 parent faa1f68 commit 5298c3b

8 files changed

+398
-0
lines changed
+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
namespace Refit.GeneratorTests;
2+
3+
public class ParameterTests
4+
{
5+
[Fact]
6+
public Task RouteParameter()
7+
{
8+
return Fixture.VerifyForBody(
9+
"""
10+
[Get("/users/{user}")]
11+
Task<string> Get(string user);
12+
""");
13+
}
14+
15+
[Fact]
16+
public Task NullableRouteParameter()
17+
{
18+
return Fixture.VerifyForBody(
19+
"""
20+
[Get("/users/{user}")]
21+
Task<string> Get(string? user);
22+
""");
23+
}
24+
25+
[Fact]
26+
public Task ValueTypeRouteParameter()
27+
{
28+
return Fixture.VerifyForBody(
29+
"""
30+
[Get("/users/{user}")]
31+
Task<string> Get(int user);
32+
""");
33+
}
34+
35+
[Fact]
36+
public Task NullableValueTypeRouteParameter()
37+
{
38+
return Fixture.VerifyForBody(
39+
"""
40+
[Get("/users/{user}")]
41+
Task<string> Get(int? user);
42+
""");
43+
}
44+
}

Refit.GeneratorTests/ReturnTypeTests.cs

+20
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,26 @@ public Task GenericTaskShouldWork()
1212
""");
1313
}
1414

15+
[Fact]
16+
public Task ReturnNullableObject()
17+
{
18+
return Fixture.VerifyForBody(
19+
"""
20+
[Get("/users")]
21+
Task<string?> Get();
22+
""");
23+
}
24+
25+
[Fact]
26+
public Task ReturnNullableValueType()
27+
{
28+
return Fixture.VerifyForBody(
29+
"""
30+
[Get("/users")]
31+
Task<int?> Get();
32+
""");
33+
}
34+
1535
[Fact]
1636
public Task VoidTaskShouldWork()
1737
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//HintName: IGeneratedClient.g.cs
2+
#nullable disable
3+
#pragma warning disable
4+
namespace Refit.Implementation
5+
{
6+
7+
partial class Generated
8+
{
9+
10+
/// <inheritdoc />
11+
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
12+
[global::System.Diagnostics.DebuggerNonUserCode]
13+
[global::RefitInternalGenerated.PreserveAttribute]
14+
[global::System.Reflection.Obfuscation(Exclude=true)]
15+
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
16+
partial class RefitGeneratorTestIGeneratedClient
17+
: global::RefitGeneratorTest.IGeneratedClient
18+
19+
{
20+
/// <inheritdoc />
21+
public global::System.Net.Http.HttpClient Client { get; }
22+
readonly global::Refit.IRequestBuilder requestBuilder;
23+
24+
/// <inheritdoc />
25+
public RefitGeneratorTestIGeneratedClient(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder)
26+
{
27+
Client = client;
28+
this.requestBuilder = requestBuilder;
29+
}
30+
31+
32+
private static readonly global::System.Type[] ______typeParameters = new global::System.Type[] {typeof(string) };
33+
34+
/// <inheritdoc />
35+
public async global::System.Threading.Tasks.Task<string> Get(string? @user)
36+
{
37+
var ______arguments = new object[] { @user };
38+
var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", ______typeParameters );
39+
40+
return await ((global::System.Threading.Tasks.Task<string>)______func(this.Client, ______arguments)).ConfigureAwait(false);
41+
}
42+
43+
private static readonly global::System.Type[] ______typeParameters0 = new global::System.Type[] {typeof(string) };
44+
45+
/// <inheritdoc />
46+
async global::System.Threading.Tasks.Task<string> global::RefitGeneratorTest.IGeneratedClient.Get(string? @user)
47+
{
48+
var ______arguments = new object[] { @user };
49+
var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", ______typeParameters0 );
50+
51+
return await ((global::System.Threading.Tasks.Task<string>)______func(this.Client, ______arguments)).ConfigureAwait(false);
52+
}
53+
}
54+
}
55+
}
56+
57+
#pragma warning restore
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//HintName: IGeneratedClient.g.cs
2+
#nullable disable
3+
#pragma warning disable
4+
namespace Refit.Implementation
5+
{
6+
7+
partial class Generated
8+
{
9+
10+
/// <inheritdoc />
11+
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
12+
[global::System.Diagnostics.DebuggerNonUserCode]
13+
[global::RefitInternalGenerated.PreserveAttribute]
14+
[global::System.Reflection.Obfuscation(Exclude=true)]
15+
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
16+
partial class RefitGeneratorTestIGeneratedClient
17+
: global::RefitGeneratorTest.IGeneratedClient
18+
19+
{
20+
/// <inheritdoc />
21+
public global::System.Net.Http.HttpClient Client { get; }
22+
readonly global::Refit.IRequestBuilder requestBuilder;
23+
24+
/// <inheritdoc />
25+
public RefitGeneratorTestIGeneratedClient(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder)
26+
{
27+
Client = client;
28+
this.requestBuilder = requestBuilder;
29+
}
30+
31+
32+
private static readonly global::System.Type[] ______typeParameters = new global::System.Type[] {typeof(int?) };
33+
34+
/// <inheritdoc />
35+
public async global::System.Threading.Tasks.Task<string> Get(int? @user)
36+
{
37+
var ______arguments = new object[] { @user };
38+
var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", ______typeParameters );
39+
40+
return await ((global::System.Threading.Tasks.Task<string>)______func(this.Client, ______arguments)).ConfigureAwait(false);
41+
}
42+
43+
private static readonly global::System.Type[] ______typeParameters0 = new global::System.Type[] {typeof(int?) };
44+
45+
/// <inheritdoc />
46+
async global::System.Threading.Tasks.Task<string> global::RefitGeneratorTest.IGeneratedClient.Get(int? @user)
47+
{
48+
var ______arguments = new object[] { @user };
49+
var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", ______typeParameters0 );
50+
51+
return await ((global::System.Threading.Tasks.Task<string>)______func(this.Client, ______arguments)).ConfigureAwait(false);
52+
}
53+
}
54+
}
55+
}
56+
57+
#pragma warning restore
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//HintName: IGeneratedClient.g.cs
2+
#nullable disable
3+
#pragma warning disable
4+
namespace Refit.Implementation
5+
{
6+
7+
partial class Generated
8+
{
9+
10+
/// <inheritdoc />
11+
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
12+
[global::System.Diagnostics.DebuggerNonUserCode]
13+
[global::RefitInternalGenerated.PreserveAttribute]
14+
[global::System.Reflection.Obfuscation(Exclude=true)]
15+
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
16+
partial class RefitGeneratorTestIGeneratedClient
17+
: global::RefitGeneratorTest.IGeneratedClient
18+
19+
{
20+
/// <inheritdoc />
21+
public global::System.Net.Http.HttpClient Client { get; }
22+
readonly global::Refit.IRequestBuilder requestBuilder;
23+
24+
/// <inheritdoc />
25+
public RefitGeneratorTestIGeneratedClient(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder)
26+
{
27+
Client = client;
28+
this.requestBuilder = requestBuilder;
29+
}
30+
31+
32+
private static readonly global::System.Type[] ______typeParameters = new global::System.Type[] {typeof(string) };
33+
34+
/// <inheritdoc />
35+
public async global::System.Threading.Tasks.Task<string> Get(string @user)
36+
{
37+
var ______arguments = new object[] { @user };
38+
var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", ______typeParameters );
39+
40+
return await ((global::System.Threading.Tasks.Task<string>)______func(this.Client, ______arguments)).ConfigureAwait(false);
41+
}
42+
43+
private static readonly global::System.Type[] ______typeParameters0 = new global::System.Type[] {typeof(string) };
44+
45+
/// <inheritdoc />
46+
async global::System.Threading.Tasks.Task<string> global::RefitGeneratorTest.IGeneratedClient.Get(string @user)
47+
{
48+
var ______arguments = new object[] { @user };
49+
var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", ______typeParameters0 );
50+
51+
return await ((global::System.Threading.Tasks.Task<string>)______func(this.Client, ______arguments)).ConfigureAwait(false);
52+
}
53+
}
54+
}
55+
}
56+
57+
#pragma warning restore
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//HintName: IGeneratedClient.g.cs
2+
#nullable disable
3+
#pragma warning disable
4+
namespace Refit.Implementation
5+
{
6+
7+
partial class Generated
8+
{
9+
10+
/// <inheritdoc />
11+
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
12+
[global::System.Diagnostics.DebuggerNonUserCode]
13+
[global::RefitInternalGenerated.PreserveAttribute]
14+
[global::System.Reflection.Obfuscation(Exclude=true)]
15+
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
16+
partial class RefitGeneratorTestIGeneratedClient
17+
: global::RefitGeneratorTest.IGeneratedClient
18+
19+
{
20+
/// <inheritdoc />
21+
public global::System.Net.Http.HttpClient Client { get; }
22+
readonly global::Refit.IRequestBuilder requestBuilder;
23+
24+
/// <inheritdoc />
25+
public RefitGeneratorTestIGeneratedClient(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder)
26+
{
27+
Client = client;
28+
this.requestBuilder = requestBuilder;
29+
}
30+
31+
32+
private static readonly global::System.Type[] ______typeParameters = new global::System.Type[] {typeof(int) };
33+
34+
/// <inheritdoc />
35+
public async global::System.Threading.Tasks.Task<string> Get(int @user)
36+
{
37+
var ______arguments = new object[] { @user };
38+
var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", ______typeParameters );
39+
40+
return await ((global::System.Threading.Tasks.Task<string>)______func(this.Client, ______arguments)).ConfigureAwait(false);
41+
}
42+
43+
private static readonly global::System.Type[] ______typeParameters0 = new global::System.Type[] {typeof(int) };
44+
45+
/// <inheritdoc />
46+
async global::System.Threading.Tasks.Task<string> global::RefitGeneratorTest.IGeneratedClient.Get(int @user)
47+
{
48+
var ______arguments = new object[] { @user };
49+
var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", ______typeParameters0 );
50+
51+
return await ((global::System.Threading.Tasks.Task<string>)______func(this.Client, ______arguments)).ConfigureAwait(false);
52+
}
53+
}
54+
}
55+
}
56+
57+
#pragma warning restore
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
//HintName: IGeneratedClient.g.cs
2+
#nullable disable
3+
#pragma warning disable
4+
namespace Refit.Implementation
5+
{
6+
7+
partial class Generated
8+
{
9+
10+
/// <inheritdoc />
11+
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
12+
[global::System.Diagnostics.DebuggerNonUserCode]
13+
[global::RefitInternalGenerated.PreserveAttribute]
14+
[global::System.Reflection.Obfuscation(Exclude=true)]
15+
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
16+
partial class RefitGeneratorTestIGeneratedClient
17+
: global::RefitGeneratorTest.IGeneratedClient
18+
19+
{
20+
/// <inheritdoc />
21+
public global::System.Net.Http.HttpClient Client { get; }
22+
readonly global::Refit.IRequestBuilder requestBuilder;
23+
24+
/// <inheritdoc />
25+
public RefitGeneratorTestIGeneratedClient(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder)
26+
{
27+
Client = client;
28+
this.requestBuilder = requestBuilder;
29+
}
30+
31+
32+
/// <inheritdoc />
33+
public async global::System.Threading.Tasks.Task<string> Get()
34+
{
35+
var ______arguments = global::System.Array.Empty<object>();
36+
var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty<global::System.Type>() );
37+
38+
return await ((global::System.Threading.Tasks.Task<string>)______func(this.Client, ______arguments)).ConfigureAwait(false);
39+
}
40+
41+
/// <inheritdoc />
42+
async global::System.Threading.Tasks.Task<string> global::RefitGeneratorTest.IGeneratedClient.Get()
43+
{
44+
var ______arguments = global::System.Array.Empty<object>();
45+
var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty<global::System.Type>() );
46+
47+
return await ((global::System.Threading.Tasks.Task<string>)______func(this.Client, ______arguments)).ConfigureAwait(false);
48+
}
49+
}
50+
}
51+
}
52+
53+
#pragma warning restore

0 commit comments

Comments
 (0)