Skip to content

Commit

Permalink
Fix new package errors
Browse files Browse the repository at this point in the history
update project to meet updated coding standards
  • Loading branch information
ChrisPulman committed Sep 20, 2023
1 parent 8ea6ce7 commit 22e3f48
Show file tree
Hide file tree
Showing 22 changed files with 479 additions and 543 deletions.
Binary file added Images/main.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions src/Directory.build.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
<DebugType>Embedded</DebugType>
<Authors>.NET Foundation and Contributors</Authors>
<Copyright>Copyright (c) .NET Foundation and Contributors</Copyright>
<PackageIcon>main.png</PackageIcon>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<!-- Optional: Publish the repository URL in the built .nupkg (in the NuSpec <Repository> element) -->
<PublishRepositoryUrl>true</PublishRepositoryUrl>
Expand All @@ -27,8 +29,23 @@
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
</ItemGroup>

<ItemGroup Condition="'$(IsTestProject)' == 'true'">
<PackageReference Include="ReactiveUI.Testing" Version="19.*" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="xunit" Version="2.5.1" />
<PackageReference Include="xunit.runner.console" Version="2.5.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.1" />
<PackageReference Include="Xunit.StaFact" Version="1.1.11" />
<PackageReference Include="Verify.Xunit" Version="21.1.4" />
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="PublicApiGenerator" Version="11.0.0" />
<PackageReference Include="coverlet.msbuild" Version="6.0.0" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)..\images\main.png" Pack="true" PackagePath="\"/>
<None Include="$(MSBuildThisFileDirectory)..\LICENSE" Pack="true" PackagePath="LICENSE" />
<None Include="$(MSBuildThisFileDirectory)..\README.md" Pack="true" PackagePath="\" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/Fusillade.Tests/API/ApiApprovalBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ public abstract class ApiApprovalBase
/// <param name="assembly">The assembly.</param>
/// <param name="filePath">The file path.</param>
/// <returns>A <see cref="Task"/> representing the result of the asynchronous operation.</returns>
protected static Task CheckApproval(Assembly assembly, [CallerFilePath] string? filePath = null)
protected static Task CheckApproval(Assembly assembly, [CallerFilePath] string filePath = null)
{
if (filePath is null)
{
return Task.CompletedTask;
}

var generatorOptions = new ApiGeneratorOptions { WhitelistedNamespacePrefixes = new[] { "Fusillade" } };
var generatorOptions = new ApiGeneratorOptions { AllowNamespacePrefixes = new[] { "Fusillade" } };
var apiText = assembly.GeneratePublicApi(generatorOptions);
return Verifier.Verify(apiText, null, filePath)
.UniqueForRuntimeAndVersion()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ namespace Fusillade
}
public abstract class LimitingHttpMessageHandler : System.Net.Http.DelegatingHandler
{
public LimitingHttpMessageHandler() { }
public LimitingHttpMessageHandler(System.Net.Http.HttpMessageHandler innerHandler) { }
protected LimitingHttpMessageHandler() { }
protected LimitingHttpMessageHandler(System.Net.Http.HttpMessageHandler innerHandler) { }
public abstract void ResetLimit(long? maxBytesToRead = default);
}
public static class NetCache
Expand All @@ -28,10 +28,10 @@ namespace Fusillade
}
public enum Priority
{
Explicit = 0,
Speculative = 10,
UserInitiated = 100,
Background = 20,
Explicit = 0,
UserInitiated = 100,
}
public class RateLimitedHttpMessageHandler : Fusillade.LimitingHttpMessageHandler
{
Expand Down

This file was deleted.

16 changes: 3 additions & 13 deletions src/Fusillade.Tests/Fusillade.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">$(TargetFrameworks);net462</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">$(TargetFrameworks);net472</TargetFrameworks>
<NoWarn>$(NoWarn);1591;CA1707;SA1633</NoWarn>
<IsPackable>false</IsPackable>
<LangVersion>latest</LangVersion>
Expand All @@ -14,16 +14,6 @@

<ItemGroup>
<PackageReference Include="akavache" Version="9.*" />
<PackageReference Include="ReactiveUI.Testing" Version="19.*" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.console" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0" />
<PackageReference Include="Xunit.StaFact" Version="1.1.11" />
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.Reactive.Testing" Version="6.0.0" />
<PackageReference Include="PublicApiGenerator" Version="10.3.0" />
<PackageReference Include="coverlet.msbuild" Version="6.0.0" PrivateAssets="All" />
<PackageReference Include="Verify.Xunit" Version="20.7.0" />

</ItemGroup>
</Project>
28 changes: 16 additions & 12 deletions src/Fusillade.Tests/Http/HttpSchedulerCachingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ public async Task CachingFunctionShouldBeCalledWithContent()

var contentResponses = new List<byte[]>();

#if NET462
var fixture = new RateLimitedHttpMessageHandler(innerHandler, Priority.UserInitiated, cacheResultFunc: async (rq, re, key, ct) => contentResponses.Add(await re.Content.ReadAsByteArrayAsync().ConfigureAwait(false)));
#if NET472
var fixture = new RateLimitedHttpMessageHandler(innerHandler, Priority.UserInitiated, cacheResultFunc: async (rq, re, key, ct) => contentResponses.Add(await re.Content.ReadAsByteArrayAsync()));
#else
var fixture = new RateLimitedHttpMessageHandler(innerHandler, Priority.UserInitiated, cacheResultFunc: async (rq, re, key, ct) => contentResponses.Add(await re.Content.ReadAsByteArrayAsync(ct).ConfigureAwait(false)));
var fixture = new RateLimitedHttpMessageHandler(innerHandler, Priority.UserInitiated, cacheResultFunc: async (rq, re, key, ct) => contentResponses.Add(await re.Content.ReadAsByteArrayAsync(ct)));
#endif

var client = new HttpClient(fixture);
var str = await client.GetStringAsync(new Uri("http://lol/bar")).ConfigureAwait(false);
var str = await client.GetStringAsync(new Uri("http://lol/bar"));

Assert.Equal("foo", str);
Assert.Equal(1, contentResponses.Count);
Expand All @@ -72,7 +72,7 @@ public async Task CachingFunctionShouldPreserveHeaders()
StatusCode = HttpStatusCode.OK,
};
ret.Headers.ETag = new EntityTagHeaderValue("\"worifjw\"");
ret.Headers.ETag = new("\"worifjw\"");
return Observable.Return(ret);
});

Expand All @@ -84,7 +84,7 @@ public async Task CachingFunctionShouldPreserveHeaders()
});

var client = new HttpClient(fixture);
var resp = await client.GetAsync(new Uri("http://lol/bar")).ConfigureAwait(false);
var resp = await client.GetAsync(new Uri("http://lol/bar"));
Assert.Equal("\"worifjw\"", etagResponses[0]);
}

Expand All @@ -99,27 +99,31 @@ public async Task RoundTripIntegrationTest()

var cachingHandler = new RateLimitedHttpMessageHandler(new HttpClientHandler(), Priority.UserInitiated, cacheResultFunc: async (rq, resp, key, ct) =>
{
var data = await resp.Content.ReadAsByteArrayAsync().ConfigureAwait(false);
#if NET472
var data = await resp.Content.ReadAsByteArrayAsync();
#else
var data = await resp.Content.ReadAsByteArrayAsync(ct);
#endif
await cache.Insert(key, data);
});

var client = new HttpClient(cachingHandler);
var origData = await client.GetStringAsync(new Uri("http://httpbin.org/get")).ConfigureAwait(false);
var origData = await client.GetStringAsync(new Uri("http://httpbin.org/get"));

Assert.True(origData.Contains("origin"));
Assert.Equal(1, (await cache.GetAllKeys()).Count());

var offlineHandler = new OfflineHttpMessageHandler(async (rq, key, ct) => await cache.Get(key));

client = new HttpClient(offlineHandler);
var newData = await client.GetStringAsync(new Uri("http://httpbin.org/get")).ConfigureAwait(false);
var newData = await client.GetStringAsync(new Uri("http://httpbin.org/get"));

Assert.Equal(origData, newData);

bool shouldDie = true;
try
{
await client.GetStringAsync(new Uri("http://httpbin.org/gzip")).ConfigureAwait(false);
await client.GetStringAsync(new Uri("http://httpbin.org/gzip"));
}
catch (Exception ex)
{
Expand Down Expand Up @@ -165,8 +169,8 @@ public async Task OnlyCacheRelevantMethods(string method, bool shouldCache)
});

var client = new HttpClient(fixture);
var request = new HttpRequestMessage(new HttpMethod(method), "http://lol/bar");
await client.SendAsync(request).ConfigureAwait(false);
var request = new HttpRequestMessage(new(method), "http://lol/bar");
await client.SendAsync(request);

Assert.Equal(shouldCache, cached);
}
Expand Down
30 changes: 15 additions & 15 deletions src/Fusillade.Tests/Http/HttpSchedulerSharedTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public async Task HttpSchedulerShouldCompleteADummyRequest()
var result = await client.SendAsync(rq).ToObservable()
.Timeout(TimeSpan.FromSeconds(2.0), RxApp.TaskpoolScheduler);

var bytes = await result.Content.ReadAsByteArrayAsync().ConfigureAwait(false);
var bytes = await result.Content.ReadAsByteArrayAsync();

Console.WriteLine(Encoding.UTF8.GetString(bytes));
Assert.Equal(HttpStatusCode.OK, result.StatusCode);
Expand Down Expand Up @@ -163,17 +163,17 @@ public async Task RateLimitedSchedulerShouldStopAfterContentLimitReached()

// Under the limit => succeed
var rq = new HttpRequestMessage(HttpMethod.Get, "/");
var resp = await client.SendAsync(rq).ConfigureAwait(false);
var resp = await client.SendAsync(rq);
Assert.Equal(HttpStatusCode.OK, resp.StatusCode);

// Crossing the limit => succeed
rq = new HttpRequestMessage(HttpMethod.Get, "/");
resp = await client.SendAsync(rq).ConfigureAwait(false);
resp = await client.SendAsync(rq);
Assert.Equal(HttpStatusCode.OK, resp.StatusCode);

// Over the limit => cancelled
rq = new HttpRequestMessage(HttpMethod.Get, "/");
await Assert.ThrowsAsync<TaskCanceledException>(() => client.SendAsync(rq)).ConfigureAwait(false);
await Assert.ThrowsAsync<TaskCanceledException>(() => client.SendAsync(rq));
}

/// <summary>
Expand Down Expand Up @@ -217,8 +217,8 @@ public async Task ConcurrentRequestsToTheSameResourceAreDebounced()
gate.OnNext(Unit.Default);
gate.OnNext(Unit.Default);

var resp1 = await resp1Task.ConfigureAwait(false);
var resp2 = await resp2Task.ConfigureAwait(false);
var resp1 = await resp1Task;
var resp2 = await resp2Task;

Assert.Equal(HttpStatusCode.OK, resp1.StatusCode);
Assert.Equal(HttpStatusCode.OK, resp2.StatusCode);
Expand Down Expand Up @@ -279,8 +279,8 @@ public async Task DebouncedRequestsDontGetUnfairlyCancelled()
gate.OnNext(Unit.Default);
gate.OnNext(Unit.Default);

await Assert.ThrowsAsync<TaskCanceledException>(() => resp1Task).ConfigureAwait(false);
var resp2 = await resp2Task.ConfigureAwait(false);
await Assert.ThrowsAsync<TaskCanceledException>(() => resp1Task);
var resp2 = await resp2Task;

Assert.Equal(HttpStatusCode.OK, resp2.StatusCode);
Assert.Equal(1, messageCount);
Expand Down Expand Up @@ -327,8 +327,8 @@ public async Task RequestsToDifferentPathsArentDebounced()
gate.OnNext(Unit.Default);
gate.OnNext(Unit.Default);

var resp1 = await resp1Task.ConfigureAwait(false);
var resp2 = await resp2Task.ConfigureAwait(false);
var resp1 = await resp1Task;
var resp2 = await resp2Task;

Assert.Equal(HttpStatusCode.OK, resp1.StatusCode);
Assert.Equal(HttpStatusCode.OK, resp2.StatusCode);
Expand All @@ -354,7 +354,7 @@ public async Task FullyCancelledDebouncedRequestsGetForRealCancelled()
StatusCode = HttpStatusCode.OK,
};
ret.Headers.ETag = new EntityTagHeaderValue("\"worifjw\"");
ret.Headers.ETag = new("\"worifjw\"");
messageCount++;
return gate.Take(1)
Expand Down Expand Up @@ -395,8 +395,8 @@ public async Task FullyCancelledDebouncedRequestsGetForRealCancelled()
gate.OnNext(Unit.Default);
gate.OnNext(Unit.Default);

await Assert.ThrowsAsync<TaskCanceledException>(() => resp1Task).ConfigureAwait(false);
await Assert.ThrowsAsync<TaskCanceledException>(() => resp2Task).ConfigureAwait(false);
await Assert.ThrowsAsync<TaskCanceledException>(() => resp1Task);
await Assert.ThrowsAsync<TaskCanceledException>(() => resp2Task);

Assert.Equal(1, messageCount);
Assert.Equal(0, finalMessageCount);
Expand All @@ -420,8 +420,8 @@ public async Task DownloadARelease()
});

var client = new HttpClient(fixture);
var result = await client.SendAsync(new HttpRequestMessage(HttpMethod.Get, new Uri(input))).ConfigureAwait(false);
var bytes = await result.Content.ReadAsByteArrayAsync().ConfigureAwait(false);
var result = await client.SendAsync(new HttpRequestMessage(HttpMethod.Get, new Uri(input)));
var bytes = await result.Content.ReadAsByteArrayAsync();

Assert.True(result.IsSuccessStatusCode);
Assert.Equal(8089690, bytes.Length);
Expand Down
2 changes: 1 addition & 1 deletion src/Fusillade.Tests/Http/TestHttpMessageHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Fusillade.Tests
/// </summary>
public class TestHttpMessageHandler : HttpMessageHandler
{
private Func<HttpRequestMessage, IObservable<HttpResponseMessage>> _block;
private readonly Func<HttpRequestMessage, IObservable<HttpResponseMessage>> _block;

/// <summary>
/// Initializes a new instance of the <see cref="TestHttpMessageHandler"/> class.
Expand Down
13 changes: 11 additions & 2 deletions src/Fusillade.sln
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30611.23
# Visual Studio Version 17
VisualStudioVersion = 17.7.34031.279
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Fusillade", "Fusillade\Fusillade.csproj", "{26493C47-6A4A-4F2A-9F92-046AA8CD95CC}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Fusillade.Tests", "Fusillade.Tests\Fusillade.Tests.csproj", "{BA0745E4-4566-4655-B83C-B4398F67DC39}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{6B92A58B-DD1B-4AFF-A3CA-D51CBEB7B43D}"
ProjectSection(SolutionItems) = preProject
..\.gitattributes = ..\.gitattributes
..\.gitignore = ..\.gitignore
analyzers.ruleset = analyzers.ruleset
..\.github\workflows\ci-build.yml = ..\.github\workflows\ci-build.yml
..\CODE_OF_CONDUCT.md = ..\CODE_OF_CONDUCT.md
..\CONTRIBUTING.md = ..\CONTRIBUTING.md
Directory.build.props = Directory.build.props
Directory.build.targets = Directory.build.targets
global.json = global.json
..\LICENSE = ..\LICENSE
..\README.md = ..\README.md
..\.github\workflows\release.yml = ..\.github\workflows\release.yml
stylecop.json = stylecop.json
..\version.json = ..\version.json
EndProjectSection
EndProject
Global
Expand Down
21 changes: 9 additions & 12 deletions src/Fusillade/ConcatenateMixin.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021 .NET Foundation and Contributors. All rights reserved.
// Copyright (c) 2023 .NET Foundation and Contributors. All rights reserved.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.
Expand All @@ -9,17 +9,14 @@
using System.Reactive.Linq;
using System.Text;

namespace Fusillade
namespace Fusillade;

internal static class ConcatenateMixin
{
internal static class ConcatenateMixin
{
public static string ConcatenateAll<T>(this IEnumerable<T> enumerables, Func<T, string> selector, char separator = '|')
public static string ConcatenateAll<T>(this IEnumerable<T> enumerables, Func<T, string> selector, char separator = '|') =>
enumerables.Aggregate(new StringBuilder(), (acc, x) =>
{
return enumerables.Aggregate(new StringBuilder(), (acc, x) =>
{
acc.Append(selector(x)).Append(separator);
return acc;
}).ToString();
}
}
acc.Append(selector(x)).Append(separator);
return acc;
}).ToString();
}
Loading

0 comments on commit 22e3f48

Please sign in to comment.