Skip to content

Commit

Permalink
feat: run csharpier (#1715)
Browse files Browse the repository at this point in the history
Co-authored-by: Chris Pulman <chris.pulman@yahoo.com>
  • Loading branch information
TimothyMakkison and ChrisPulman authored Jun 14, 2024
1 parent 8b0ba96 commit dcb9da2
Show file tree
Hide file tree
Showing 48 changed files with 2,180 additions and 951 deletions.
1 change: 0 additions & 1 deletion InterfaceStubGenerator.Shared/ITypeSymbolExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.CodeAnalysis;

namespace Refit.Generator
Expand Down
11 changes: 5 additions & 6 deletions InterfaceStubGenerator.Shared/InterfaceStubGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Collections.Immutable;
using System.Linq;
using System.Text;

using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
Expand Down Expand Up @@ -171,8 +170,8 @@ ImmutableArray<InterfaceDeclarationSyntax> candidateInterfaces
continue;

// The interface has no refit methods, but its base interfaces might
var hasDerivedRefit = ifaceSymbol.AllInterfaces
.SelectMany(i => i.GetMembers().OfType<IMethodSymbol>())
var hasDerivedRefit = ifaceSymbol
.AllInterfaces.SelectMany(i => i.GetMembers().OfType<IMethodSymbol>())
.Any(m => IsRefitMethod(m, httpMethodBaseAttributeSymbol));

if (hasDerivedRefit)
Expand Down Expand Up @@ -292,7 +291,7 @@ public static void Initialize()

var keyName = group.Key.Name;
int value;
while(keyCount.TryGetValue(keyName, out value))
while (keyCount.TryGetValue(keyName, out value))
{
keyName = $"{keyName}{++value}";
}
Expand Down Expand Up @@ -398,8 +397,8 @@ partial class {ns}{classDeclaration}
.ToList();

// get methods for all inherited
var derivedMethods = interfaceSymbol.AllInterfaces
.SelectMany(i => i.GetMembers().OfType<IMethodSymbol>())
var derivedMethods = interfaceSymbol
.AllInterfaces.SelectMany(i => i.GetMembers().OfType<IMethodSymbol>())
.ToList();

// Look for disposable
Expand Down
85 changes: 42 additions & 43 deletions Refit.Benchmarks/EndToEndBenchmark.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Net;

using AutoFixture;
using BenchmarkDotNet.Attributes;

Expand Down Expand Up @@ -142,9 +141,9 @@ public async Task Task_Async()
await refitClient[Serializer][HttpStatusCode].GetUsersTaskAsync();
break;
case HttpVerb.Post:
await refitClient[Serializer][HttpStatusCode].PostUsersTaskAsync(
users[ModelCount]
);
await refitClient[Serializer]
[HttpStatusCode]
.PostUsersTaskAsync(users[ModelCount]);
break;
default:
throw new ArgumentOutOfRangeException(nameof(Verb));
Expand All @@ -164,13 +163,13 @@ public async Task<string> TaskString_Async()
switch (Verb)
{
case HttpVerb.Get:
return await refitClient[Serializer][
HttpStatusCode
].GetUsersTaskStringAsync();
return await refitClient[Serializer]
[HttpStatusCode]
.GetUsersTaskStringAsync();
case HttpVerb.Post:
return await refitClient[Serializer][
HttpStatusCode
].PostUsersTaskStringAsync(users[ModelCount]);
return await refitClient[Serializer]
[HttpStatusCode]
.PostUsersTaskStringAsync(users[ModelCount]);
default:
throw new ArgumentOutOfRangeException(nameof(Verb));
}
Expand All @@ -191,13 +190,13 @@ public async Task<Stream> TaskStream_Async()
switch (Verb)
{
case HttpVerb.Get:
return await refitClient[Serializer][
HttpStatusCode
].GetUsersTaskStreamAsync();
return await refitClient[Serializer]
[HttpStatusCode]
.GetUsersTaskStreamAsync();
case HttpVerb.Post:
return await refitClient[Serializer][
HttpStatusCode
].PostUsersTaskStreamAsync(users[ModelCount]);
return await refitClient[Serializer]
[HttpStatusCode]
.PostUsersTaskStreamAsync(users[ModelCount]);
default:
throw new ArgumentOutOfRangeException(nameof(Verb));
}
Expand All @@ -218,13 +217,13 @@ public async Task<HttpContent> TaskHttpContent_Async()
switch (Verb)
{
case HttpVerb.Get:
return await refitClient[Serializer][
HttpStatusCode
].GetUsersTaskHttpContentAsync();
return await refitClient[Serializer]
[HttpStatusCode]
.GetUsersTaskHttpContentAsync();
case HttpVerb.Post:
return await refitClient[Serializer][
HttpStatusCode
].PostUsersTaskHttpContentAsync(users[ModelCount]);
return await refitClient[Serializer]
[HttpStatusCode]
.PostUsersTaskHttpContentAsync(users[ModelCount]);
default:
throw new ArgumentOutOfRangeException(nameof(Verb));
}
Expand All @@ -243,13 +242,13 @@ public async Task<HttpResponseMessage> TaskHttpResponseMessage_Async()
switch (Verb)
{
case HttpVerb.Get:
return await refitClient[Serializer][
HttpStatusCode
].GetUsersTaskHttpResponseMessageAsync();
return await refitClient[Serializer]
[HttpStatusCode]
.GetUsersTaskHttpResponseMessageAsync();
case HttpVerb.Post:
return await refitClient[Serializer][
HttpStatusCode
].PostUsersTaskHttpResponseMessageAsync(users[ModelCount]);
return await refitClient[Serializer]
[HttpStatusCode]
.PostUsersTaskHttpResponseMessageAsync(users[ModelCount]);
default:
throw new ArgumentOutOfRangeException(nameof(Verb));
}
Expand All @@ -261,13 +260,13 @@ public IObservable<HttpResponseMessage> ObservableHttpResponseMessage()
switch (Verb)
{
case HttpVerb.Get:
return refitClient[Serializer][
HttpStatusCode
].GetUsersObservableHttpResponseMessage();
return refitClient[Serializer]
[HttpStatusCode]
.GetUsersObservableHttpResponseMessage();
case HttpVerb.Post:
return refitClient[Serializer][
HttpStatusCode
].PostUsersObservableHttpResponseMessage(users[ModelCount]);
return refitClient[Serializer]
[HttpStatusCode]
.PostUsersObservableHttpResponseMessage(users[ModelCount]);
default:
throw new ArgumentOutOfRangeException(nameof(Verb));
}
Expand All @@ -283,9 +282,9 @@ public async Task<List<User>> TaskT_Async()
case HttpVerb.Get:
return await refitClient[Serializer][HttpStatusCode].GetUsersTaskTAsync();
case HttpVerb.Post:
return await refitClient[Serializer][HttpStatusCode].PostUsersTaskTAsync(
users[ModelCount]
);
return await refitClient[Serializer]
[HttpStatusCode]
.PostUsersTaskTAsync(users[ModelCount]);
default:
throw new ArgumentOutOfRangeException(nameof(Verb));
}
Expand All @@ -304,13 +303,13 @@ public async Task<ApiResponse<List<User>>> TaskApiResponseT_Async()
switch (Verb)
{
case HttpVerb.Get:
return await refitClient[Serializer][
HttpStatusCode
].GetUsersTaskApiResponseTAsync();
return await refitClient[Serializer]
[HttpStatusCode]
.GetUsersTaskApiResponseTAsync();
case HttpVerb.Post:
return await refitClient[Serializer][
HttpStatusCode
].PostUsersTaskApiResponseTAsync(users[ModelCount]);
return await refitClient[Serializer]
[HttpStatusCode]
.PostUsersTaskApiResponseTAsync(users[ModelCount]);
default:
throw new ArgumentOutOfRangeException(nameof(Verb));
}
Expand Down
1 change: 0 additions & 1 deletion Refit.HttpClientFactory/HttpClientFactoryExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Linq;
using System.Net.Http;
using System.Reflection;

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Http;

Expand Down
17 changes: 10 additions & 7 deletions Refit.Newtonsoft.Json/NewtonsoftJsonContentSerializer.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Net.Http;
using System.Reflection;
using System.Text;

using Newtonsoft.Json;

namespace Refit
Expand All @@ -13,12 +12,15 @@ namespace Refit
/// Creates a new <see cref="NewtonsoftJsonContentSerializer"/> instance with the specified parameters
/// </remarks>
/// <param name="jsonSerializerSettings">The serialization settings to use for the current instance</param>
public sealed class NewtonsoftJsonContentSerializer(JsonSerializerSettings? jsonSerializerSettings) : IHttpContentSerializer
public sealed class NewtonsoftJsonContentSerializer(
JsonSerializerSettings? jsonSerializerSettings
) : IHttpContentSerializer
{
/// <summary>
/// The <see cref="Lazy{T}"/> instance providing the JSON serialization settings to use
/// </summary>
readonly Lazy<JsonSerializerSettings> jsonSerializerSettings = new(
readonly Lazy<JsonSerializerSettings> jsonSerializerSettings =
new(
() =>
jsonSerializerSettings
?? JsonConvert.DefaultSettings?.Invoke()
Expand Down Expand Up @@ -78,10 +80,11 @@ public HttpContent ToHttpContent<T>(T item)
return propertyInfo switch
{
null => throw new ArgumentNullException(nameof(propertyInfo)),
_ => propertyInfo
.GetCustomAttributes<JsonPropertyAttribute>(true)
.Select(a => a.PropertyName)
.FirstOrDefault()
_
=> propertyInfo
.GetCustomAttributes<JsonPropertyAttribute>(true)
.Select(a => a.PropertyName)
.FirstOrDefault()
};
}
}
Expand Down
10 changes: 3 additions & 7 deletions Refit.Tests/AuthenticatedClientHandlerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using RichardSzalay.MockHttp;

using Refit; // for the code gen
using RichardSzalay.MockHttp;
using Xunit;

namespace Refit.Tests;
Expand Down Expand Up @@ -44,8 +43,7 @@ [HeaderCollection] IDictionary<string, string> headers
);
}

public interface IInheritedAuthenticatedServiceWithHeaders
: IAuthenticatedServiceWithHeaders
public interface IInheritedAuthenticatedServiceWithHeaders : IAuthenticatedServiceWithHeaders
{
[Get("/get-inherited-thing")]
Task<string> GetInheritedThing();
Expand All @@ -61,9 +59,7 @@ public interface IAuthenticatedServiceWithHeaders
[Fact]
public void DefaultHandlerIsHttpClientHandler()
{
var handler = new AuthenticatedHttpClientHandler(
((_, _) => Task.FromResult(string.Empty))
);
var handler = new AuthenticatedHttpClientHandler(((_, _) => Task.FromResult(string.Empty)));

Assert.IsType<HttpClientHandler>(handler.InnerHandler);
}
Expand Down
9 changes: 7 additions & 2 deletions Refit.Tests/CamelCaseUrlParameterKeyFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@ public void FormatKey_Returns_ExpectedValue()
{
var urlParameterKeyFormatter = new CamelCaseUrlParameterKeyFormatter();

var refitSettings = new RefitSettings { UrlParameterKeyFormatter = urlParameterKeyFormatter };
var refitSettings = new RefitSettings
{
UrlParameterKeyFormatter = urlParameterKeyFormatter
};
var fixture = new RequestBuilderImplementation<IDummyHttpApi>(refitSettings);
var factory = fixture.BuildRequestFactoryForMethod(nameof(IDummyHttpApi.ComplexQueryObjectWithDictionary));
var factory = fixture.BuildRequestFactoryForMethod(
nameof(IDummyHttpApi.ComplexQueryObjectWithDictionary)
);

var complexQuery = new CamelCaselTestsRequest
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Collections.Generic;
using System.Text;
using System;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using Newtonsoft.Json.Serialization;

namespace Refit.Tests;
Expand Down
15 changes: 3 additions & 12 deletions Refit.Tests/ExceptionFactoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;

using Refit; // for the code gen

using RichardSzalay.MockHttp;

using Xunit;

namespace Refit.Tests;
Expand Down Expand Up @@ -83,9 +80,7 @@ public async Task ProvideFactoryWhichAlwaysReturnsException_WithResult()

var fixture = RestService.For<IMyService>("http://api", settings);

var thrownException = await Assert.ThrowsAsync<Exception>(
() => fixture.GetWithResult()
);
var thrownException = await Assert.ThrowsAsync<Exception>(() => fixture.GetWithResult());
Assert.Equal(exception, thrownException);

handler.VerifyNoOutstandingExpectation();
Expand All @@ -102,15 +97,11 @@ public async Task ProvideFactoryWhichAlwaysReturnsException_WithoutResult()
ExceptionFactory = _ => Task.FromResult<Exception>(exception)
};

handler
.Expect(HttpMethod.Put, "http://api/put-without-result")
.Respond(HttpStatusCode.OK);
handler.Expect(HttpMethod.Put, "http://api/put-without-result").Respond(HttpStatusCode.OK);

var fixture = RestService.For<IMyService>("http://api", settings);

var thrownException = await Assert.ThrowsAsync<Exception>(
() => fixture.PutWithoutResult()
);
var thrownException = await Assert.ThrowsAsync<Exception>(() => fixture.PutWithoutResult());
Assert.Equal(exception, thrownException);

handler.VerifyNoOutstandingExpectation();
Expand Down
2 changes: 0 additions & 2 deletions Refit.Tests/FormValueMultimapTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
using System.Linq;
using System.Runtime.Serialization;
using System.Text.Json.Serialization;

using Newtonsoft.Json;

using Xunit;

namespace Refit.Tests;
Expand Down
6 changes: 1 addition & 5 deletions Refit.Tests/GitHubApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Threading;
using System.Threading.Tasks;
using Refit; // InterfaceStubGenerator looks for this

using static System.Math; // This is here to verify https://github.com/reactiveui/refit/issues/283

namespace Refit.Tests;
Expand Down Expand Up @@ -64,10 +63,7 @@ public interface IGitHubApi
IObservable<User> GetUserCamelCase(string userName);

[Get("/orgs/{orgname}/members")]
Task<List<User>> GetOrgMembers(
string orgName,
CancellationToken cancellationToken = default
);
Task<List<User>> GetOrgMembers(string orgName, CancellationToken cancellationToken = default);

[Get("/search/users")]
Task<UserSearchResult> FindUsers(string q);
Expand Down
Loading

0 comments on commit dcb9da2

Please sign in to comment.