Skip to content

Commit

Permalink
feat: added nullable and parameter tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TimothyMakkison committed Oct 6, 2024
1 parent d03121d commit 3ca3ad7
Show file tree
Hide file tree
Showing 8 changed files with 398 additions and 0 deletions.
44 changes: 44 additions & 0 deletions Refit.GeneratorTests/ParameterTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
namespace Refit.GeneratorTests;

public class ParameterTests
{
[Fact]
public Task RouteParameter()
{
return Fixture.VerifyForBody(
"""
[Get("/users/{user}")]
Task<string> Get(string user);
""");
}

[Fact]
public Task NullableRouteParameter()
{
return Fixture.VerifyForBody(
"""
[Get("/users/{user}")]
Task<string> Get(string? user);
""");
}

[Fact]
public Task ValueTypeRouteParameter()
{
return Fixture.VerifyForBody(
"""
[Get("/users/{user}")]
Task<string> Get(int user);
""");
}

[Fact]
public Task NullableValueTypeRouteParameter()
{
return Fixture.VerifyForBody(
"""
[Get("/users/{user}")]
Task<string> Get(int? user);
""");
}
}
20 changes: 20 additions & 0 deletions Refit.GeneratorTests/ReturnTypeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,26 @@ public Task GenericTaskShouldWork()
""");
}

[Fact]
public Task ReturnNullableObject()
{
return Fixture.VerifyForBody(
"""
[Get("/users")]
Task<string?> Get();
""");
}

[Fact]
public Task ReturnNullableValueType()
{
return Fixture.VerifyForBody(
"""
[Get("/users")]
Task<int?> Get();
""");
}

[Fact]
public Task VoidTaskShouldWork()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//HintName: IGeneratedClient.g.cs
#nullable disable
#pragma warning disable
namespace Refit.Implementation
{

partial class Generated
{

/// <inheritdoc />
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
[global::System.Diagnostics.DebuggerNonUserCode]
[global::RefitInternalGenerated.PreserveAttribute]
[global::System.Reflection.Obfuscation(Exclude=true)]
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
partial class RefitGeneratorTestIGeneratedClient
: global::RefitGeneratorTest.IGeneratedClient

{
/// <inheritdoc />
public global::System.Net.Http.HttpClient Client { get; }
readonly global::Refit.IRequestBuilder requestBuilder;

/// <inheritdoc />
public RefitGeneratorTestIGeneratedClient(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder)
{
Client = client;
this.requestBuilder = requestBuilder;
}


private static readonly global::System.Type[] ______typeParameters = new global::System.Type[] {typeof(string) };

/// <inheritdoc />
public async global::System.Threading.Tasks.Task<string> Get(string? @user)
{
var ______arguments = new object[] { @user };
var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", ______typeParameters );

return await ((global::System.Threading.Tasks.Task<string>)______func(this.Client, ______arguments)).ConfigureAwait(false);
}

private static readonly global::System.Type[] ______typeParameters0 = new global::System.Type[] {typeof(string) };

/// <inheritdoc />
async global::System.Threading.Tasks.Task<string> global::RefitGeneratorTest.IGeneratedClient.Get(string? @user)
{
var ______arguments = new object[] { @user };
var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", ______typeParameters0 );

return await ((global::System.Threading.Tasks.Task<string>)______func(this.Client, ______arguments)).ConfigureAwait(false);
}
}
}
}

#pragma warning restore
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//HintName: IGeneratedClient.g.cs
#nullable disable
#pragma warning disable
namespace Refit.Implementation
{

partial class Generated
{

/// <inheritdoc />
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
[global::System.Diagnostics.DebuggerNonUserCode]
[global::RefitInternalGenerated.PreserveAttribute]
[global::System.Reflection.Obfuscation(Exclude=true)]
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
partial class RefitGeneratorTestIGeneratedClient
: global::RefitGeneratorTest.IGeneratedClient

{
/// <inheritdoc />
public global::System.Net.Http.HttpClient Client { get; }
readonly global::Refit.IRequestBuilder requestBuilder;

/// <inheritdoc />
public RefitGeneratorTestIGeneratedClient(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder)
{
Client = client;
this.requestBuilder = requestBuilder;
}


private static readonly global::System.Type[] ______typeParameters = new global::System.Type[] {typeof(int?) };

/// <inheritdoc />
public async global::System.Threading.Tasks.Task<string> Get(int? @user)
{
var ______arguments = new object[] { @user };
var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", ______typeParameters );

return await ((global::System.Threading.Tasks.Task<string>)______func(this.Client, ______arguments)).ConfigureAwait(false);
}

private static readonly global::System.Type[] ______typeParameters0 = new global::System.Type[] {typeof(int?) };

/// <inheritdoc />
async global::System.Threading.Tasks.Task<string> global::RefitGeneratorTest.IGeneratedClient.Get(int? @user)
{
var ______arguments = new object[] { @user };
var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", ______typeParameters0 );

return await ((global::System.Threading.Tasks.Task<string>)______func(this.Client, ______arguments)).ConfigureAwait(false);
}
}
}
}

#pragma warning restore
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//HintName: IGeneratedClient.g.cs
#nullable disable
#pragma warning disable
namespace Refit.Implementation
{

partial class Generated
{

/// <inheritdoc />
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
[global::System.Diagnostics.DebuggerNonUserCode]
[global::RefitInternalGenerated.PreserveAttribute]
[global::System.Reflection.Obfuscation(Exclude=true)]
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
partial class RefitGeneratorTestIGeneratedClient
: global::RefitGeneratorTest.IGeneratedClient

{
/// <inheritdoc />
public global::System.Net.Http.HttpClient Client { get; }
readonly global::Refit.IRequestBuilder requestBuilder;

/// <inheritdoc />
public RefitGeneratorTestIGeneratedClient(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder)
{
Client = client;
this.requestBuilder = requestBuilder;
}


private static readonly global::System.Type[] ______typeParameters = new global::System.Type[] {typeof(string) };

/// <inheritdoc />
public async global::System.Threading.Tasks.Task<string> Get(string @user)
{
var ______arguments = new object[] { @user };
var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", ______typeParameters );

return await ((global::System.Threading.Tasks.Task<string>)______func(this.Client, ______arguments)).ConfigureAwait(false);
}

private static readonly global::System.Type[] ______typeParameters0 = new global::System.Type[] {typeof(string) };

/// <inheritdoc />
async global::System.Threading.Tasks.Task<string> global::RefitGeneratorTest.IGeneratedClient.Get(string @user)
{
var ______arguments = new object[] { @user };
var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", ______typeParameters0 );

return await ((global::System.Threading.Tasks.Task<string>)______func(this.Client, ______arguments)).ConfigureAwait(false);
}
}
}
}

#pragma warning restore
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//HintName: IGeneratedClient.g.cs
#nullable disable
#pragma warning disable
namespace Refit.Implementation
{

partial class Generated
{

/// <inheritdoc />
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
[global::System.Diagnostics.DebuggerNonUserCode]
[global::RefitInternalGenerated.PreserveAttribute]
[global::System.Reflection.Obfuscation(Exclude=true)]
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
partial class RefitGeneratorTestIGeneratedClient
: global::RefitGeneratorTest.IGeneratedClient

{
/// <inheritdoc />
public global::System.Net.Http.HttpClient Client { get; }
readonly global::Refit.IRequestBuilder requestBuilder;

/// <inheritdoc />
public RefitGeneratorTestIGeneratedClient(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder)
{
Client = client;
this.requestBuilder = requestBuilder;
}


private static readonly global::System.Type[] ______typeParameters = new global::System.Type[] {typeof(int) };

/// <inheritdoc />
public async global::System.Threading.Tasks.Task<string> Get(int @user)
{
var ______arguments = new object[] { @user };
var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", ______typeParameters );

return await ((global::System.Threading.Tasks.Task<string>)______func(this.Client, ______arguments)).ConfigureAwait(false);
}

private static readonly global::System.Type[] ______typeParameters0 = new global::System.Type[] {typeof(int) };

/// <inheritdoc />
async global::System.Threading.Tasks.Task<string> global::RefitGeneratorTest.IGeneratedClient.Get(int @user)
{
var ______arguments = new object[] { @user };
var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", ______typeParameters0 );

return await ((global::System.Threading.Tasks.Task<string>)______func(this.Client, ______arguments)).ConfigureAwait(false);
}
}
}
}

#pragma warning restore
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//HintName: IGeneratedClient.g.cs
#nullable disable
#pragma warning disable
namespace Refit.Implementation
{

partial class Generated
{

/// <inheritdoc />
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
[global::System.Diagnostics.DebuggerNonUserCode]
[global::RefitInternalGenerated.PreserveAttribute]
[global::System.Reflection.Obfuscation(Exclude=true)]
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
partial class RefitGeneratorTestIGeneratedClient
: global::RefitGeneratorTest.IGeneratedClient

{
/// <inheritdoc />
public global::System.Net.Http.HttpClient Client { get; }
readonly global::Refit.IRequestBuilder requestBuilder;

/// <inheritdoc />
public RefitGeneratorTestIGeneratedClient(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder)
{
Client = client;
this.requestBuilder = requestBuilder;
}


/// <inheritdoc />
public async global::System.Threading.Tasks.Task<string> Get()
{
var ______arguments = global::System.Array.Empty<object>();
var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty<global::System.Type>() );

return await ((global::System.Threading.Tasks.Task<string>)______func(this.Client, ______arguments)).ConfigureAwait(false);
}

/// <inheritdoc />
async global::System.Threading.Tasks.Task<string> global::RefitGeneratorTest.IGeneratedClient.Get()
{
var ______arguments = global::System.Array.Empty<object>();
var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty<global::System.Type>() );

return await ((global::System.Threading.Tasks.Task<string>)______func(this.Client, ______arguments)).ConfigureAwait(false);
}
}
}
}

#pragma warning restore
Loading

0 comments on commit 3ca3ad7

Please sign in to comment.