Skip to content
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
3 changes: 3 additions & 0 deletions Refit.Tests/GitHubApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ public interface IGitHubApi
[Get("/users/{username}")]
IObservable<ApiResponse<User>> GetUserObservableWithMetadata(string userName);

[Get("/users/{username}")]
IObservable<IApiResponse<User>> GetUserIApiResponseObservableWithMetadata(string userName);

[Post("/users")]
Task<User> CreateUser(User user);

Expand Down
6 changes: 0 additions & 6 deletions Refit.Tests/InterfaceStubGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,6 @@ static InterfaceStubGeneratorTests()
.AddAssemblies(ImmutableArray.Create("System.Web"))
.AddPackages(ImmutableArray.Create(new PackageIdentity("System.Net.Http", "4.3.4")));
#endif

// Initialise Verify
DerivePathInfo((file, _, type, method) => new(Path.Combine(Path.GetDirectoryName(file), "_snapshots"), type.Name, method.Name));

VerifySourceGenerators.Initialize();
VerifyDiffPlex.Initialize(OutputType.Compact);
}

public static async Task<VerifyResult> VerifyGenerator(string input)
Expand Down
19 changes: 19 additions & 0 deletions Refit.Tests/ModuleInitializer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Runtime.CompilerServices;
using VerifyTests.DiffPlex;

namespace Refit.Tests;

static class ModuleInitializer
{
// ModuleInitializer should only be used in apps
#pragma warning disable CA2255
[ModuleInitializer]
#pragma warning restore CA2255
public static void Init()
{
DerivePathInfo((file, _, type, method) => new(Path.Combine(Path.GetDirectoryName(file), "_snapshots"), type.Name, method.Name));

VerifySourceGenerators.Initialize();
VerifyDiffPlex.Initialize(OutputType.Compact);
}
}
5 changes: 5 additions & 0 deletions Refit.Tests/ModuleInitializerAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// ReSharper disable once CheckNamespace
namespace System.Runtime.CompilerServices;

[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
sealed class ModuleInitializerAttribute : Attribute;
49 changes: 49 additions & 0 deletions Refit.Tests/RestService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1030,6 +1030,55 @@ public async Task HitTheGitHubUserApiAsObservableApiResponse()
mockHttp.VerifyNoOutstandingExpectation();
}

[Fact]
public async Task HitTheGitHubUserApiAsObservableIApiResponse()
{
var mockHttp = new MockHttpMessageHandler();

var settings = new RefitSettings
{
HttpMessageHandlerFactory = () => mockHttp,
ContentSerializer = new NewtonsoftJsonContentSerializer(
new JsonSerializerSettings()
{
ContractResolver = new SnakeCasePropertyNamesContractResolver()
}
)
};

var responseMessage = new HttpResponseMessage()
{
StatusCode = HttpStatusCode.OK,
Content = new StringContent(
"{ 'login':'octocat', 'avatar_url':'http://foo/bar' }",
System.Text.Encoding.UTF8,
"application/json"
),
};
responseMessage.Headers.Add("Cookie", "Value");

mockHttp
.Expect(HttpMethod.Get, "https://api.github.com/users/octocat")
.Respond(req => responseMessage);

var fixture = RestService.For<IGitHubApi>("https://api.github.com", settings);

var result = await fixture
.GetUserIApiResponseObservableWithMetadata("octocat")
.Timeout(TimeSpan.FromSeconds(10));

Assert.True(result.Headers.Any());
Assert.True(result.IsSuccessStatusCode);
Assert.NotNull(result.ReasonPhrase);
Assert.NotNull(result.RequestMessage);
Assert.False(result.StatusCode == default);
Assert.NotNull(result.Version);
Assert.Equal("octocat", result.Content.Login);
Assert.False(string.IsNullOrEmpty(result.Content.AvatarUrl));

mockHttp.VerifyNoOutstandingExpectation();
}

[Fact]
public async Task HitTheGitHubUserApi()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,79 +141,90 @@ public RefitTestsIGitHubApi(global::System.Net.Http.HttpClient client, global::R
return (global::System.IObservable<global::Refit.ApiResponse<global::Refit.Tests.User>>)______func(this.Client, ______arguments);
}

private static readonly global::System.Type[] ______typeParameters6 = new global::System.Type[] {typeof(global::Refit.Tests.User) };
private static readonly global::System.Type[] ______typeParameters6 = new global::System.Type[] {typeof(string) };

/// <inheritdoc />
public global::System.IObservable<global::Refit.IApiResponse<global::Refit.Tests.User>> GetUserIApiResponseObservableWithMetadata(string @userName)
{
var ______arguments = new object[] { @userName };
var ______func = requestBuilder.BuildRestResultFuncForMethod("GetUserIApiResponseObservableWithMetadata", ______typeParameters6 );

return (global::System.IObservable<global::Refit.IApiResponse<global::Refit.Tests.User>>)______func(this.Client, ______arguments);
}

private static readonly global::System.Type[] ______typeParameters7 = new global::System.Type[] {typeof(global::Refit.Tests.User) };

/// <inheritdoc />
public async global::System.Threading.Tasks.Task<global::Refit.Tests.User> CreateUser(global::Refit.Tests.User @user)
{
var ______arguments = new object[] { @user };
var ______func = requestBuilder.BuildRestResultFuncForMethod("CreateUser", ______typeParameters6 );
var ______func = requestBuilder.BuildRestResultFuncForMethod("CreateUser", ______typeParameters7 );

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

private static readonly global::System.Type[] ______typeParameters7 = new global::System.Type[] {typeof(global::Refit.Tests.User) };
private static readonly global::System.Type[] ______typeParameters8 = new global::System.Type[] {typeof(global::Refit.Tests.User) };

/// <inheritdoc />
public async global::System.Threading.Tasks.Task<global::Refit.ApiResponse<global::Refit.Tests.User>> CreateUserWithMetadata(global::Refit.Tests.User @user)
{
var ______arguments = new object[] { @user };
var ______func = requestBuilder.BuildRestResultFuncForMethod("CreateUserWithMetadata", ______typeParameters7 );
var ______func = requestBuilder.BuildRestResultFuncForMethod("CreateUserWithMetadata", ______typeParameters8 );

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

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

/// <inheritdoc />
async global::System.Threading.Tasks.Task<global::Refit.Tests.User> global::Refit.Tests.IGitHubApi.GetUser(string @userName)
{
var ______arguments = new object[] { @userName };
var ______func = requestBuilder.BuildRestResultFuncForMethod("GetUser", ______typeParameters8 );
var ______func = requestBuilder.BuildRestResultFuncForMethod("GetUser", ______typeParameters9 );

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

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

/// <inheritdoc />
global::System.IObservable<global::Refit.Tests.User> global::Refit.Tests.IGitHubApi.GetUserObservable(string @userName)
{
var ______arguments = new object[] { @userName };
var ______func = requestBuilder.BuildRestResultFuncForMethod("GetUserObservable", ______typeParameters9 );
var ______func = requestBuilder.BuildRestResultFuncForMethod("GetUserObservable", ______typeParameters10 );

return (global::System.IObservable<global::Refit.Tests.User>)______func(this.Client, ______arguments);
}

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

/// <inheritdoc />
global::System.IObservable<global::Refit.Tests.User> global::Refit.Tests.IGitHubApi.GetUserCamelCase(string @userName)
{
var ______arguments = new object[] { @userName };
var ______func = requestBuilder.BuildRestResultFuncForMethod("GetUserCamelCase", ______typeParameters10 );
var ______func = requestBuilder.BuildRestResultFuncForMethod("GetUserCamelCase", ______typeParameters11 );

return (global::System.IObservable<global::Refit.Tests.User>)______func(this.Client, ______arguments);
}

private static readonly global::System.Type[] ______typeParameters11 = new global::System.Type[] {typeof(string), typeof(global::System.Threading.CancellationToken) };
private static readonly global::System.Type[] ______typeParameters12 = new global::System.Type[] {typeof(string), typeof(global::System.Threading.CancellationToken) };

/// <inheritdoc />
async global::System.Threading.Tasks.Task<global::System.Collections.Generic.List<global::Refit.Tests.User>> global::Refit.Tests.IGitHubApi.GetOrgMembers(string @orgName, global::System.Threading.CancellationToken @cancellationToken)
{
var ______arguments = new object[] { @orgName, @cancellationToken };
var ______func = requestBuilder.BuildRestResultFuncForMethod("GetOrgMembers", ______typeParameters11 );
var ______func = requestBuilder.BuildRestResultFuncForMethod("GetOrgMembers", ______typeParameters12 );

return await ((global::System.Threading.Tasks.Task<global::System.Collections.Generic.List<global::Refit.Tests.User>>)______func(this.Client, ______arguments)).ConfigureAwait(false);
}

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

/// <inheritdoc />
async global::System.Threading.Tasks.Task<global::Refit.Tests.UserSearchResult> global::Refit.Tests.IGitHubApi.FindUsers(string @q)
{
var ______arguments = new object[] { @q };
var ______func = requestBuilder.BuildRestResultFuncForMethod("FindUsers", ______typeParameters12 );
var ______func = requestBuilder.BuildRestResultFuncForMethod("FindUsers", ______typeParameters13 );

return await ((global::System.Threading.Tasks.Task<global::Refit.Tests.UserSearchResult>)______func(this.Client, ______arguments)).ConfigureAwait(false);
}
Expand Down Expand Up @@ -254,46 +265,57 @@ public RefitTestsIGitHubApi(global::System.Net.Http.HttpClient client, global::R
return await ((global::System.Threading.Tasks.Task<global::Refit.ApiResponse<global::Refit.Tests.User>>)______func(this.Client, ______arguments)).ConfigureAwait(false);
}

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

/// <inheritdoc />
async global::System.Threading.Tasks.Task<global::Refit.ApiResponse<global::Refit.Tests.User>> global::Refit.Tests.IGitHubApi.GetUserWithMetadata(string @userName)
{
var ______arguments = new object[] { @userName };
var ______func = requestBuilder.BuildRestResultFuncForMethod("GetUserWithMetadata", ______typeParameters13 );
var ______func = requestBuilder.BuildRestResultFuncForMethod("GetUserWithMetadata", ______typeParameters14 );

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

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

/// <inheritdoc />
global::System.IObservable<global::Refit.ApiResponse<global::Refit.Tests.User>> global::Refit.Tests.IGitHubApi.GetUserObservableWithMetadata(string @userName)
{
var ______arguments = new object[] { @userName };
var ______func = requestBuilder.BuildRestResultFuncForMethod("GetUserObservableWithMetadata", ______typeParameters14 );
var ______func = requestBuilder.BuildRestResultFuncForMethod("GetUserObservableWithMetadata", ______typeParameters15 );

return (global::System.IObservable<global::Refit.ApiResponse<global::Refit.Tests.User>>)______func(this.Client, ______arguments);
}

private static readonly global::System.Type[] ______typeParameters15 = new global::System.Type[] {typeof(global::Refit.Tests.User) };
private static readonly global::System.Type[] ______typeParameters16 = new global::System.Type[] {typeof(string) };

/// <inheritdoc />
global::System.IObservable<global::Refit.IApiResponse<global::Refit.Tests.User>> global::Refit.Tests.IGitHubApi.GetUserIApiResponseObservableWithMetadata(string @userName)
{
var ______arguments = new object[] { @userName };
var ______func = requestBuilder.BuildRestResultFuncForMethod("GetUserIApiResponseObservableWithMetadata", ______typeParameters16 );

return (global::System.IObservable<global::Refit.IApiResponse<global::Refit.Tests.User>>)______func(this.Client, ______arguments);
}

private static readonly global::System.Type[] ______typeParameters17 = new global::System.Type[] {typeof(global::Refit.Tests.User) };

/// <inheritdoc />
async global::System.Threading.Tasks.Task<global::Refit.Tests.User> global::Refit.Tests.IGitHubApi.CreateUser(global::Refit.Tests.User @user)
{
var ______arguments = new object[] { @user };
var ______func = requestBuilder.BuildRestResultFuncForMethod("CreateUser", ______typeParameters15 );
var ______func = requestBuilder.BuildRestResultFuncForMethod("CreateUser", ______typeParameters17 );

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

private static readonly global::System.Type[] ______typeParameters16 = new global::System.Type[] {typeof(global::Refit.Tests.User) };
private static readonly global::System.Type[] ______typeParameters18 = new global::System.Type[] {typeof(global::Refit.Tests.User) };

/// <inheritdoc />
async global::System.Threading.Tasks.Task<global::Refit.ApiResponse<global::Refit.Tests.User>> global::Refit.Tests.IGitHubApi.CreateUserWithMetadata(global::Refit.Tests.User @user)
{
var ______arguments = new object[] { @user };
var ______func = requestBuilder.BuildRestResultFuncForMethod("CreateUserWithMetadata", ______typeParameters16 );
var ______func = requestBuilder.BuildRestResultFuncForMethod("CreateUserWithMetadata", ______typeParameters18 );

return await ((global::System.Threading.Tasks.Task<global::Refit.ApiResponse<global::Refit.Tests.User>>)______func(this.Client, ______arguments)).ConfigureAwait(false);
}
Expand Down
Loading