Skip to content
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

Update Refit.Tests to use net 4.8 #1953

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ jobs:
configuration: Release
productNamespacePrefix: "Refit"
srcFolder: "./"
installWorkflows: false
installWorkflows: true
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)buildtask.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<RefitTargets>net462;netstandard2.0;net6.0;net8.0</RefitTargets>
<RefitTargets>net462;netstandard2.0;net8.0;net9.0</RefitTargets>
<NoWarn>IDE0040;CA1054;CA1510</NoWarn>
</PropertyGroup>

Expand All @@ -43,7 +43,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All"/>
<PackageReference Include="Nerdbank.GitVersioning" Version="3.6.146" PrivateAssets="all" />
<PackageReference Include="Nerdbank.GitVersioning" Version="3.7.115" PrivateAssets="all" />
</ItemGroup>

<Target Name="AddCommitHashToAssemblyAttributes" BeforeTargets="GetAssemblyAttributes">
Expand Down
25 changes: 25 additions & 0 deletions InterfaceStubGenerator.Shared/UniqueNameBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
namespace Refit.Generator;

// <Summary>
// UniqueNameBuilder.
// </Summary>
public class UniqueNameBuilder()

Check warning on line 6 in InterfaceStubGenerator.Shared/UniqueNameBuilder.cs

View workflow job for this annotation

GitHub Actions / build / build

Missing XML comment for publicly visible type or member 'UniqueNameBuilder'

Check warning on line 6 in InterfaceStubGenerator.Shared/UniqueNameBuilder.cs

View workflow job for this annotation

GitHub Actions / build / build

Missing XML comment for publicly visible type or member 'UniqueNameBuilder.UniqueNameBuilder()'
{
private readonly HashSet<string> _usedNames = new(StringComparer.Ordinal);
private readonly UniqueNameBuilder? _parentScope;
Expand All @@ -11,10 +14,23 @@
_parentScope = parentScope;
}

/// <summary>
/// Reserve a name.
/// </summary>
/// <param name="name"></param>
public void Reserve(string name) => _usedNames.Add(name);

/// <summary>
/// Create a new scope.
/// </summary>
/// <returns>Unique Name Builder.</returns>
public UniqueNameBuilder NewScope() => new(this);

/// <summary>
/// Generate a unique name.
/// </summary>
/// <param name="name">THe name.</param>
/// <returns></returns>
public string New(string name)
{
var i = 0;
Expand All @@ -30,8 +46,17 @@
return uniqueName;
}

/// <summary>
/// Reserve names.
/// </summary>
/// <param name="names">The name.</param>
public void Reserve(IEnumerable<string> names)
{
if (names == null)
{
return;
}

foreach (var name in names)
{
_usedNames.Add(name);
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) .NET Foundation and Contributors
Copyright (c) ReactiveUI 2012 - 2025

All rights reserved.

Expand Down
6 changes: 4 additions & 2 deletions Refit.Benchmarks/Refit.Benchmarks.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="..\Refit\targets\refit.props" />

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<IsPackable>false</IsPackable>
<NoWarn>$(NoWarn);CS1591</NoWarn>
</PropertyGroup>
Expand All @@ -18,6 +18,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" />
<PackageReference Include="AutoFixture" Version="4.18.1" />
<PackageReference Include="BenchmarkDotNet" Version="0.14.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.12.0-3.24523.4" />
Expand Down
87 changes: 47 additions & 40 deletions Refit.GeneratorTests/Refit.GeneratorTests.csproj
Original file line number Diff line number Diff line change
@@ -1,47 +1,54 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="..\Refit\targets\refit.props" />
<Import Project="..\Refit\targets\refit.props" />

<PropertyGroup>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PropertyGroup>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<NoWarn>$(NoWarn);CS1591;CA1819;CA2000;CA2007;CA1056;CA1707;CA1861;xUnit1031</NoWarn>
</PropertyGroup>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<NoWarn>$(NoWarn);CS1591;CA1819;CA2000;CA2007;CA1056;CA1707;CA1861;xUnit1031</NoWarn>
</PropertyGroup>
<ItemGroup Condition="$(TargetFramework.StartsWith('net9.0'))">
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="9.0.1" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="System.Formats.Asn1" Version="8.0.1" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" />
<PackageReference Include="System.Collections.Immutable" Version="8.0.0" />
<PackageReference Include="Verify.DiffPlex" Version="3.1.2" />
<PackageReference Include="Verify.SourceGenerators" Version="2.5.0" />
<PackageReference Include="Verify.Xunit" Version="27.1.0" />
<PackageReference Include="System.Reactive" Version="6.0.1" />
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="2.2.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.11.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing" Version="1.1.2" />
<ProjectReference Include="..\Refit.Newtonsoft.Json\Refit.Newtonsoft.Json.csproj" />
<ProjectReference Include="..\Refit.Xml\Refit.Xml.csproj" />
<ProjectReference Include="..\InterfaceStubGenerator.Roslyn38\InterfaceStubGenerator.Roslyn38.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="true" />
<ProjectReference Include="..\InterfaceStubGenerator.Roslyn41\InterfaceStubGenerator.Roslyn41.csproj" />
<ProjectReference Include="..\Refit\Refit.csproj" />
</ItemGroup>
<ItemGroup Condition="$(TargetFramework.StartsWith('net8.0'))">
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="8.0.12" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Formats.Asn1" Version="9.0.1" />
<PackageReference Include="coverlet.collector" Version="6.0.4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.2" />
<PackageReference Include="System.Collections.Immutable" Version="9.0.1" />
<PackageReference Include="Verify.DiffPlex" Version="3.1.2" />
<PackageReference Include="Verify.SourceGenerators" Version="2.5.0" />
<PackageReference Include="Verify.Xunit" Version="28.10.1" />
<PackageReference Include="System.Reactive" Version="6.0.1" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.11.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing" Version="1.1.2" />
<ProjectReference Include="..\Refit.Newtonsoft.Json\Refit.Newtonsoft.Json.csproj" />
<ProjectReference Include="..\Refit.Xml\Refit.Xml.csproj" />
<ProjectReference Include="..\InterfaceStubGenerator.Roslyn38\InterfaceStubGenerator.Roslyn38.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="true" />
<ProjectReference Include="..\InterfaceStubGenerator.Roslyn41\InterfaceStubGenerator.Roslyn41.csproj" />
<ProjectReference Include="..\Refit\Refit.csproj" />
</ItemGroup>

<ItemGroup>
<None Include="..\Refit.GeneratorTests\_snapshots\**">
<Link>%(RecursiveDir)\resources\%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<Using Include="Xunit" />
</ItemGroup>
<ItemGroup>
<None Include="..\Refit.GeneratorTests\_snapshots\**">
<Link>%(RecursiveDir)\resources\%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<Using Include="Xunit" />
</ItemGroup>

<ItemGroup>
<Folder Include="_snapshots\" />
</ItemGroup>

<ItemGroup>
<Folder Include="_snapshots\" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion Refit.HttpClientFactory/Refit.HttpClientFactory.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<ItemGroup>
<ProjectReference Include="..\Refit\Refit.csproj" PrivateAssets="Analyzers" />
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Http" Version="9.0.1" />
</ItemGroup>

</Project>
12 changes: 6 additions & 6 deletions Refit.Tests/API/ApiApprovalTests.Refit.DotNet8_0.verified.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Refit
public class AliasAsAttribute : System.Attribute
{
public AliasAsAttribute(string name) { }
public string Name { get; set; }
public string Name { get; protected set; }
}
[System.Serializable]
public class ApiException : System.Exception
Expand Down Expand Up @@ -66,7 +66,7 @@ namespace Refit
public class AttachmentNameAttribute : System.Attribute
{
public AttachmentNameAttribute(string name) { }
public string Name { get; set; }
public string Name { get; protected set; }
}
[System.AttributeUsage(System.AttributeTargets.Parameter)]
public class AuthorizeAttribute : System.Attribute
Expand Down Expand Up @@ -179,7 +179,7 @@ namespace Refit
{
protected HttpMethodAttribute(string path) { }
public abstract System.Net.Http.HttpMethod Method { get; }
public virtual string Path { get; set; }
public virtual string Path { get; protected set; }
}
public static class HttpRequestMessageOptions
{
Expand Down Expand Up @@ -334,10 +334,10 @@ namespace Refit
public QueryAttribute(string delimiter, string prefix) { }
public QueryAttribute(string delimiter, string prefix, string format) { }
public Refit.CollectionFormat CollectionFormat { get; set; }
public string Delimiter { get; set; }
public string Delimiter { get; protected set; }
public string? Format { get; set; }
public bool IsCollectionFormatSpecified { get; }
public string? Prefix { get; set; }
public string? Prefix { get; protected set; }
}
[System.AttributeUsage(System.AttributeTargets.Method)]
public class QueryUriFormatAttribute : System.Attribute
Expand Down Expand Up @@ -428,7 +428,7 @@ namespace Refit
[System.Serializable]
public class ValidationApiException : Refit.ApiException
{
public Refit.ProblemDetails? Content { get; }
public new Refit.ProblemDetails? Content { get; }
public static Refit.ValidationApiException Create(Refit.ApiException exception) { }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(@"Refit.Newtonsoft.Json, PublicKey=00240000048000009400000006020000002400005253413100040000010001009dc017250415a0d51fddb74de84257c388028f04893673ca5c8f9e7145aea2b11443cb49dd79386d2255179a79ec516466b621f77e43386e711b775f77bb0e4b217f8c208c054e5f515ae33ee76bac1b56cdc20e1c151cf026a9b7f8362f1963825e546e16b360dfc63fe670403c9d6152c24491dd5dfb9ff68fe102ef3e1aed")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(@"Refit.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001009dc017250415a0d51fddb74de84257c388028f04893673ca5c8f9e7145aea2b11443cb49dd79386d2255179a79ec516466b621f77e43386e711b775f77bb0e4b217f8c208c054e5f515ae33ee76bac1b56cdc20e1c151cf026a9b7f8362f1963825e546e16b360dfc63fe670403c9d6152c24491dd5dfb9ff68fe102ef3e1aed")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(@"Refit.Xml, PublicKey=00240000048000009400000006020000002400005253413100040000010001009dc017250415a0d51fddb74de84257c388028f04893673ca5c8f9e7145aea2b11443cb49dd79386d2255179a79ec516466b621f77e43386e711b775f77bb0e4b217f8c208c054e5f515ae33ee76bac1b56cdc20e1c151cf026a9b7f8362f1963825e546e16b360dfc63fe670403c9d6152c24491dd5dfb9ff68fe102ef3e1aed")]
[assembly: System.Runtime.Versioning.TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName=".NET 6.0")]
[assembly: System.Runtime.Versioning.TargetFramework(".NETCoreApp,Version=v9.0", FrameworkDisplayName=".NET 9.0")]
namespace Refit
{
[System.AttributeUsage(System.AttributeTargets.Property | System.AttributeTargets.Parameter)]
public class AliasAsAttribute : System.Attribute
{
public AliasAsAttribute(string name) { }
public string Name { get; set; }
public string Name { get; protected set; }
}
[System.Serializable]
public class ApiException : System.Exception
Expand Down Expand Up @@ -66,7 +66,7 @@ namespace Refit
public class AttachmentNameAttribute : System.Attribute
{
public AttachmentNameAttribute(string name) { }
public string Name { get; set; }
public string Name { get; protected set; }
}
[System.AttributeUsage(System.AttributeTargets.Parameter)]
public class AuthorizeAttribute : System.Attribute
Expand Down Expand Up @@ -179,7 +179,7 @@ namespace Refit
{
protected HttpMethodAttribute(string path) { }
public abstract System.Net.Http.HttpMethod Method { get; }
public virtual string Path { get; set; }
public virtual string Path { get; protected set; }
}
public static class HttpRequestMessageOptions
{
Expand Down Expand Up @@ -334,10 +334,10 @@ namespace Refit
public QueryAttribute(string delimiter, string prefix) { }
public QueryAttribute(string delimiter, string prefix, string format) { }
public Refit.CollectionFormat CollectionFormat { get; set; }
public string Delimiter { get; set; }
public string Delimiter { get; protected set; }
public string? Format { get; set; }
public bool IsCollectionFormatSpecified { get; }
public string? Prefix { get; set; }
public string? Prefix { get; protected set; }
}
[System.AttributeUsage(System.AttributeTargets.Method)]
public class QueryUriFormatAttribute : System.Attribute
Expand Down Expand Up @@ -428,7 +428,7 @@ namespace Refit
[System.Serializable]
public class ValidationApiException : Refit.ApiException
{
public Refit.ProblemDetails? Content { get; }
public new Refit.ProblemDetails? Content { get; }
public static Refit.ValidationApiException Create(Refit.ApiException exception) { }
}
}
2 changes: 1 addition & 1 deletion Refit.Tests/API/ApiApprovalTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

#if !NET462
#if !NET48
using System.Diagnostics.CodeAnalysis;

namespace Refit.Tests.API;
Expand Down
2 changes: 1 addition & 1 deletion Refit.Tests/API/ApiExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

#if !NET462
#if !NET48
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Runtime.CompilerServices;
Expand Down
14 changes: 10 additions & 4 deletions Refit.Tests/InterfaceStubGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;

using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Testing;

using Refit.Generator;

using Xunit;

using Task = System.Threading.Tasks.Task;
using VerifyCS = Refit.Tests.CSharpSourceGeneratorVerifier<Refit.Generator.InterfaceStubGenerator>;
using VerifyCSV2 = Refit.Tests.CSharpIncrementalSourceGeneratorVerifier<Refit.Generator.InterfaceStubGeneratorV2>;
Expand All @@ -33,13 +37,15 @@ static InterfaceStubGeneratorTests()
ReferenceAssemblies = ReferenceAssemblies.Net.Net60;
#elif NET8_0
ReferenceAssemblies = ReferenceAssemblies.Net.Net80;
#elif NET9_0
ReferenceAssemblies = ReferenceAssemblies.Net.Net90;
#else
ReferenceAssemblies = ReferenceAssemblies.Default.AddPackages(
ImmutableArray.Create(new PackageIdentity("System.Text.Json", "7.0.2"))
);
#endif

#if NET461
#if NET48
ReferenceAssemblies = ReferenceAssemblies
.AddAssemblies(ImmutableArray.Create("System.Web"))
.AddPackages(ImmutableArray.Create(new PackageIdentity("System.Net.Http", "4.3.4")));
Expand Down Expand Up @@ -108,7 +114,7 @@ static CSharpCompilation CreateCompilation(params string[] sourceFiles)
[Fact]
public async Task NoRefitInterfacesSmokeTest()
{
#if NET462
#if NET48
var input = File.ReadAllText(IntegrationTestHelper.GetPath("IInterfaceWithoutRefit.cs"));
#else
var input = await File.ReadAllTextAsync(
Expand All @@ -132,7 +138,7 @@ public async Task NoRefitInterfacesSmokeTest()
[Fact]
public async Task FindInterfacesSmokeTest()
{
#if NET462
#if NET48
var input = File.ReadAllText(IntegrationTestHelper.GetPath("GitHubApi.cs"));
#else
var input = await File.ReadAllTextAsync(IntegrationTestHelper.GetPath("GitHubApi.cs"));
Expand Down Expand Up @@ -794,7 +800,7 @@ public RefitTestsTestNestedINestedGitHubApi(global::System.Net.Http.HttpClient c
[Fact]
public async Task GenerateInterfaceStubsWithoutNamespaceSmokeTest()
{
#if NET462
#if NET48
var input = File.ReadAllText(IntegrationTestHelper.GetPath("IServiceWithoutNamespace.cs"));
#else
var input = await File.ReadAllTextAsync(
Expand Down
Loading
Loading