diff --git a/src/ProxyInterfaceSourceGenerator/Extensions/NamedTypeSymbolExtensions.cs b/src/ProxyInterfaceSourceGenerator/Extensions/NamedTypeSymbolExtensions.cs index f3bbecf..ad53355 100644 --- a/src/ProxyInterfaceSourceGenerator/Extensions/NamedTypeSymbolExtensions.cs +++ b/src/ProxyInterfaceSourceGenerator/Extensions/NamedTypeSymbolExtensions.cs @@ -28,7 +28,7 @@ internal static class NamedTypeSymbolExtensions var typeName = namedTypeSymbol.GetFullType(); return !(typeName.Contains('<') && typeName.Contains('>')) ? typeName : - $"{typeName.Replace('.', '_').Replace('<', '_').Replace('>', '_').Replace(", ", "-")}_{typeName.Count(c => c == ',') + 1}"; + $"{typeName.Replace('<', '_').Replace('>', '_').Replace(", ", "-")}_{typeName.Count(c => c == ',') + 1}"; } public static string GetFullType(this INamedTypeSymbol namedTypeSymbol) diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.Generic_T__1Proxy.g.cs b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.Generic_T__1Proxy.g.cs new file mode 100644 index 0000000..2c1df34 --- /dev/null +++ b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.Generic_T__1Proxy.g.cs @@ -0,0 +1,42 @@ +//---------------------------------------------------------------------------------------- +// +// This code was generated by https://github.com/StefH/ProxyInterfaceSourceGenerator. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//---------------------------------------------------------------------------------------- + +#nullable enable +using System; + +namespace ProxyInterfaceSourceGeneratorTests.Source +{ + public partial class GenericProxy : IGeneric + { + public ProxyInterfaceSourceGeneratorTests.Source.Generic _Instance { get; } + + + + + public T Test(T value) + { + T value_ = value; + var result__1701808026 = _Instance.Test(value_); + return result__1701808026; + } + + + + + + public GenericProxy(ProxyInterfaceSourceGeneratorTests.Source.Generic instance) + { + _Instance = instance; + + + + } + } +} +#nullable disable \ No newline at end of file diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.IGeneric.g.cs b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.IGeneric.g.cs new file mode 100644 index 0000000..6bab330 --- /dev/null +++ b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.IGeneric.g.cs @@ -0,0 +1,28 @@ +//---------------------------------------------------------------------------------------- +// +// This code was generated by https://github.com/StefH/ProxyInterfaceSourceGenerator. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//---------------------------------------------------------------------------------------- + +#nullable enable +using System; + +namespace ProxyInterfaceSourceGeneratorTests.Source +{ + public partial interface IGeneric + { + ProxyInterfaceSourceGeneratorTests.Source.Generic _Instance { get; } + + + + T Test(T value); + + + + + } +} +#nullable disable \ No newline at end of file diff --git a/tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTest.cs b/tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTest.cs index 2b70523..3fef764 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTest.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTest.cs @@ -1,5 +1,3 @@ -using System.IO; -using System.Linq; using CSharp.SourceGenerators.Extensions; using CSharp.SourceGenerators.Extensions.Models; using FluentAssertions; @@ -21,9 +19,7 @@ namespace ProxyInterfaceSourceGeneratorTests var pp = new PersonProxy(new Person()); - var h = pp.AddHuman(new HumanProxy(new Human())); - - int x = 0; + _ = pp.AddHuman(new HumanProxy(new Human())); } [Fact] @@ -50,6 +46,48 @@ namespace ProxyInterfaceSourceGeneratorTests result.Files.Should().HaveCount(1); } + [Fact] + public void GenerateFiles_ForGenericType_Should_GenerateCorrectFiles() + { + // Arrange + var fileNames = new[] + { + "ProxyInterfaceSourceGeneratorTests.Source.IGeneric.g.cs", + "ProxyInterfaceSourceGeneratorTests.Source.Generic_T__1Proxy.g.cs" + }; + + var path = "./Source/IGeneric.cs"; + var sourceFile = new SourceFile + { + Path = path, + Text = File.ReadAllText(path), + AttributeToAddToInterface = new ExtraAttribute + { + Name = "ProxyInterfaceGenerator.Proxy", + ArgumentList = "typeof(ProxyInterfaceSourceGeneratorTests.Source.Generic<>)" + } + }; + + // Act + var result = _sut.Execute(new[] + { + sourceFile + }); + + // Assert + result.Valid.Should().BeTrue(); + result.Files.Should().HaveCount(fileNames.Length + 1); + + foreach (var fileName in fileNames.Select((fileName, index) => new { fileName, index })) + { + var builder = result.Files[fileName.index + 1]; // +1 means skip the attribute + builder.Path.Should().EndWith(fileName.fileName); + + if (Write) File.WriteAllText($"../../../Destination/{fileName.fileName}", builder.Text); + builder.Text.Should().Be(File.ReadAllText($"../../../Destination/{fileName.fileName}")); + } + } + [Fact] public void GenerateFiles_When_NoNamespace_Should_GenerateCorrectFiles() { diff --git a/tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTests.csproj b/tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTests.csproj index 6981157..11e7eed 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTests.csproj +++ b/tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTests.csproj @@ -53,4 +53,13 @@ + + + PreserveNewest + + + PreserveNewest + + + \ No newline at end of file diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/Generic.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/Generic.cs new file mode 100644 index 0000000..76b28c4 --- /dev/null +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/Generic.cs @@ -0,0 +1,10 @@ +namespace ProxyInterfaceSourceGeneratorTests.Source +{ + public class Generic + { + public T Test(T value) + { + return value; + } + } +} \ No newline at end of file diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/IGeneric.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/IGeneric.cs new file mode 100644 index 0000000..4a80576 --- /dev/null +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/IGeneric.cs @@ -0,0 +1,6 @@ +namespace ProxyInterfaceSourceGeneratorTests.Source +{ + public partial interface IGeneric + { + } +} \ No newline at end of file