Skip to content
Closed
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 Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.14.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="4.14.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="10.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="10.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="10.0.0" />
Expand All @@ -28,5 +29,7 @@
<PackageVersion Include="Swashbuckle.AspNetCore" Version="8.1.1" />
<PackageVersion Include="MessagePack" Version="2.5.187" />
<PackageVersion Include="MessagePack.AspNetCoreMvcFormatter" Version="2.5.129" />
<PackageVersion Include="xunit" Version="2.9.2" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions TypedSignalR.Client.TypeScript.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
<Folder Name="/tests/">
<Project Path="tests/TypedSignalR.Client.TypeScript.Tests.Server/TypedSignalR.Client.TypeScript.Tests.Server.csproj" />
<Project Path="tests/TypedSignalR.Client.TypeScript.Tests.Shared/TypedSignalR.Client.TypeScript.Tests.Shared.csproj" />
<Project Path="tests/TypedSignalR.Client.TypeScript.Tests/TypedSignalR.Client.TypeScript.Tests.csproj" />
</Folder>
</Solution>
3 changes: 3 additions & 0 deletions src/TypedSignalR.Client.TypeScript/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("TypedSignalR.Client.TypeScript.Tests")]
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ public static IReadOnlyList<INamedTypeSymbol> GetNamedTypeSymbols(this Compilati
.DescendantNodes()
.Select(x => semanticModel.GetDeclaredSymbol(x))
.OfType<INamedTypeSymbol>();
}).ToArray();
})
.Distinct<INamedTypeSymbol>(SymbolEqualityComparer.Default)
.ToArray();

return NamedTypeSymbols;
}
Expand Down Expand Up @@ -68,6 +70,7 @@ public static IReadOnlyList<INamedTypeSymbol> GetAttributeAnnotatedTypes(this Co

return attributes.Any(a => SymbolEqualityComparer.Default.Equals(a.AttributeClass, attributeSymbol));
})
.Distinct<INamedTypeSymbol>(SymbolEqualityComparer.Default)
.ToArray();

return types;
Expand Down Expand Up @@ -100,6 +103,7 @@ public static IReadOnlyList<INamedTypeSymbol> GetAttributeAnnotatedTypes(

return false;
})
.Distinct<INamedTypeSymbol>(SymbolEqualityComparer.Default)
.ToArray();

return types;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using TypedSignalR.Client.TypeScript;
using Xunit;

namespace TypedSignalR.Client.TypeScript.Tests;

public class RoslynExtensionsTests
{
[Fact]
public void GetAttributeAnnotatedTypes_DeduplicatesPartialInterfaces()
{
const string source = """
using System.Threading.Tasks;
using TypedSignalR.Client;

namespace TypedSignalR.Client
{
public sealed class HubAttribute : Attribute { }
}

[Hub]
public partial interface IClientHub
{
Task Join(int clientId);
}

public partial interface IClientHub
{
Task Leave(int clientId);
}
""";

var compilation = CSharpCompilation.Create(
"TestAssembly",
new[] { CSharpSyntaxTree.ParseText(source) },
new[]
{
MetadataReference.CreateFromFile(typeof(object).Assembly.Location),
MetadataReference.CreateFromFile(typeof(Task).Assembly.Location),
MetadataReference.CreateFromFile(typeof(Attribute).Assembly.Location)
},
new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));

var hubAttributeSymbol = compilation.GetTypeByMetadataName("TypedSignalR.Client.HubAttribute");
Assert.NotNull(hubAttributeSymbol);

var annotatedTypes = compilation.GetAttributeAnnotatedTypes(hubAttributeSymbol!, includeReferencedAssemblies: false);

var clientHub = Assert.Single(annotatedTypes);
Assert.Equal("IClientHub", clientHub.Name);
Assert.Equal(2, clientHub.GetMembers().OfType<IMethodSymbol>().Count());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\TypedSignalR.Client.TypeScript\TypedSignalR.Client.TypeScript.csproj" />
</ItemGroup>

</Project>