8000 feat: added nullable and parameter tests by TimothyMakkison · Pull Request #1863 · reactiveui/refit · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: added nullable and parameter tests #1863

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading
0