From 36840265ca7975eae39c56b76f8b65327e5a16cb Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Mon, 3 Jun 2024 14:41:30 +0100 Subject: [PATCH] Add test for new _Instance but removing if option is used --- README.md | 6 +-- .../FileGenerators/BaseGenerator.cs | 5 --- .../Speckle.ProxyGenerator.csproj | 2 +- ...eratorTests.Source.PnP.IClientContext.g.cs | 2 +- ...atorTests.Source.PnP.ISecurableObject.g.cs | 2 +- ...eSourceGeneratorTests.Source.PnP.IWeb.g.cs | 2 +- .../InheritedInterfaceTests.cs | 37 ++++++++++++++++++- .../ProxyInterfaceSourceGeneratorTests.csproj | 7 ++++ .../Disposable/IRevitLocationPointProxy.cs | 3 ++ .../Source/Disposable/IRevitLocationProxy.cs | 3 ++ .../RevitLocationPointProxyExtras.cs | 27 ++++++++++++++ 11 files changed, 82 insertions(+), 14 deletions(-) create mode 100644 tests/ProxyInterfaceSourceGeneratorTests/Source/Disposable/IRevitLocationPointProxy.cs create mode 100644 tests/ProxyInterfaceSourceGeneratorTests/Source/Disposable/IRevitLocationProxy.cs create mode 100644 tests/ProxyInterfaceSourceGeneratorTests/Source/Disposable/RevitLocationPointProxyExtras.cs diff --git a/README.md b/README.md index 7f50e36..f89877a 100644 --- a/README.md +++ b/README.md @@ -31,15 +31,15 @@ It supports: ## Install -[![NuGet Badge](https://buildstats.info/nuget/ProxyInterfaceGenerator)](https://www.nuget.org/packages/ProxyInterfaceGenerator) +[![NuGet Badge](https://buildstats.info/nuget/Speckle.ProxyGenerator)](https://www.nuget.org/packages/Speckle.ProxyGenerator) You can install from NuGet using the following command in the package manager window: -`Install-Package ProxyInterfaceGenerator` +`Install-Package Speckle.ProxyGenerator` Or via the Visual Studio NuGet package manager or if you use the `dotnet` command: -`dotnet add package ProxyInterfaceGenerator` +`dotnet add package Speckle.ProxyGenerator` ## Usage diff --git a/src/Speckle.ProxyGenerator/FileGenerators/BaseGenerator.cs b/src/Speckle.ProxyGenerator/FileGenerators/BaseGenerator.cs index dd585bb..d79f9f1 100644 --- a/src/Speckle.ProxyGenerator/FileGenerators/BaseGenerator.cs +++ b/src/Speckle.ProxyGenerator/FileGenerators/BaseGenerator.cs @@ -300,11 +300,6 @@ internal abstract class BaseGenerator if (useFullQualifiedMappedTypeName) { //is a candidate and overrides - if (candidate?.FullQualifiedMappedTypeName != null) - { - extendsProxyClasses.Add(candidate); - break; - } } else { diff --git a/src/Speckle.ProxyGenerator/Speckle.ProxyGenerator.csproj b/src/Speckle.ProxyGenerator/Speckle.ProxyGenerator.csproj index 8bd3432..b9d9147 100644 --- a/src/Speckle.ProxyGenerator/Speckle.ProxyGenerator.csproj +++ b/src/Speckle.ProxyGenerator/Speckle.ProxyGenerator.csproj @@ -1,7 +1,7 @@ - 0.1.5 + 0.1.6 netstandard2.0 Latest enable diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientContext.g.cs b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientContext.g.cs index c1b1bf5..ec8456d 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientContext.g.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientContext.g.cs @@ -14,7 +14,7 @@ namespace ProxyInterfaceSourceGeneratorTests.Source.PnP { public partial interface IClientContext { - new global::Microsoft.SharePoint.Client.ClientContext _Instance { get; } + global::Microsoft.SharePoint.Client.ClientContext _Instance { get; } global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IWeb Web { get; } diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.PnP.ISecurableObject.g.cs b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.PnP.ISecurableObject.g.cs index 11afdfb..e1e8de0 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.PnP.ISecurableObject.g.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.PnP.ISecurableObject.g.cs @@ -14,7 +14,7 @@ namespace ProxyInterfaceSourceGeneratorTests.Source.PnP { public partial interface ISecurableObject : global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientObject { - new global::Microsoft.SharePoint.Client.SecurableObject _Instance { get; } + global::Microsoft.SharePoint.Client.SecurableObject _Instance { get; } [Microsoft.SharePoint.Client.RemoteAttribute] global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ISecurableObject FirstUniqueAncestorSecurableObject { get; } diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.PnP.IWeb.g.cs b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.PnP.IWeb.g.cs index dc047c7..d38a558 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.PnP.IWeb.g.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.PnP.IWeb.g.cs @@ -14,7 +14,7 @@ namespace ProxyInterfaceSourceGeneratorTests.Source.PnP { public partial interface IWeb : global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ISecurableObject { - new global::Microsoft.SharePoint.Client.Web _Instance { get; } + global::Microsoft.SharePoint.Client.Web _Instance { get; } [Microsoft.SharePoint.Client.RemoteAttribute] string AccessRequestListUrl { get; } diff --git a/tests/ProxyInterfaceSourceGeneratorTests/InheritedInterfaceTests.cs b/tests/ProxyInterfaceSourceGeneratorTests/InheritedInterfaceTests.cs index 74864ed..b373659 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/InheritedInterfaceTests.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/InheritedInterfaceTests.cs @@ -106,6 +106,39 @@ public class InheritedInterfaceTests Assert.Equal(nameof(IUpdate), type2.Right.Identifier.Text); } + [Fact] + public void GenerateFiles_InheritedInterface_Should_InheritTheInterfaceAndNotNew() + { + var className1 = "LocationPoint"; + var interfaceName1 = "IRevitLocationPointProxy"; + var proxyName1 = $"{className1}Proxy"; + + // Arrange + var path1 = $"./Source/Disposable/{interfaceName1}.cs"; + + var sourceFile1 = CreateSourceFile(path1, className1, ImplementationOptions.ProxyForBaseInterface | ImplementationOptions.UseExtendedInterfaces); + var className2 = "Location"; + var interfaceName2 = "IRevitLocationProxy"; + var proxyName2 = $"{className2}Proxy"; + + // Arrange + var path2 = $"./Source/Disposable/{interfaceName2}.cs"; + var sourceFile2 = CreateSourceFile(path2, className2, ImplementationOptions.ProxyForBaseInterface | ImplementationOptions.UseExtendedInterfaces); + + // Act + var result = _sut.Execute([sourceFile1, sourceFile2]); + string[] fileNames = [$"{Namespace}.{interfaceName1}.g.cs", $"{Namespace}.{proxyName1}.g.cs", + $"{Namespace}.{interfaceName2}.g.cs", $"{Namespace}.{proxyName2}.g.cs"]; + + 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 + File.WriteAllText($"{OutputPath}{fileName.fileName}", builder.Text); + } + } [Fact] public void GenerateFiles_InheritedInterface_Should_Not_InheritExplicitImplementedInterfaces() { @@ -145,7 +178,7 @@ public class InheritedInterfaceTests var o = string.Empty; foreach (var val in Enum.GetValues()) { - if (!options.HasFlag(val)) + if (val == ImplementationOptions.None || !options.HasFlag(val)) { continue; } @@ -154,7 +187,7 @@ public class InheritedInterfaceTests o += " | "; } - o += "ImplementationOptions." + val.ToString(); + o += "ImplementationOptions." + val; } if (o.Length == 0) { diff --git a/tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTests.csproj b/tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTests.csproj index a1db8cf..3b45955 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTests.csproj +++ b/tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTests.csproj @@ -69,6 +69,13 @@ PreserveNewest + + PreserveNewest + + + + + diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/Disposable/IRevitLocationPointProxy.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/Disposable/IRevitLocationPointProxy.cs new file mode 100644 index 0000000..ad406cf --- /dev/null +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/Disposable/IRevitLocationPointProxy.cs @@ -0,0 +1,3 @@ +namespace ProxyInterfaceSourceGeneratorTests.Source.Disposable; + +public partial interface IRevitLocationPointProxy : IRevitLocationPoint { } diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/Disposable/IRevitLocationProxy.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/Disposable/IRevitLocationProxy.cs new file mode 100644 index 0000000..8cad283 --- /dev/null +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/Disposable/IRevitLocationProxy.cs @@ -0,0 +1,3 @@ +namespace ProxyInterfaceSourceGeneratorTests.Source.Disposable; + +public partial interface IRevitLocationProxy : IRevitLocation { } diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/Disposable/RevitLocationPointProxyExtras.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/Disposable/RevitLocationPointProxyExtras.cs new file mode 100644 index 0000000..2a8ddc6 --- /dev/null +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/Disposable/RevitLocationPointProxyExtras.cs @@ -0,0 +1,27 @@ +namespace ProxyInterfaceSourceGeneratorTests.Source.Disposable; + + + +public interface IRevitLocationPoint : IRevitLocation +{ +} + +public interface IRevitLocationCurve : IRevitLocation +{ + IRevitCurve Curve { get; } +} + +public class LocationPoint : Location +{ + public XYZ Point => throw new NotImplementedException(); +} +public class Location : APIObject { } +public class APIObject { } +public class XYZ { } +public interface IRevitLocation +{ +} +public interface IRevitCurve +{ + double Length { get; } +}