diff --git a/src/ProxyInterfaceSourceGenerator/Extensions/PropertySymbolExtensions.cs b/src/ProxyInterfaceSourceGenerator/Extensions/PropertySymbolExtensions.cs index c8fcdfd..c7a8ce2 100644 --- a/src/ProxyInterfaceSourceGenerator/Extensions/PropertySymbolExtensions.cs +++ b/src/ProxyInterfaceSourceGenerator/Extensions/PropertySymbolExtensions.cs @@ -24,7 +24,7 @@ public static (string PropertyType, string? PropertyName, string GetSet)? ToProp var set = setIsPublic ? "set; " : string.Empty; var type = !string.IsNullOrEmpty(overrideType) ? overrideType - : BaseGenerator.FixType(property.Type.ToFullyQualifiedDisplayString(), property.NullableAnnotation); + : BaseGenerator.FixTypeForNullable(property.Type.ToFullyQualifiedDisplayString(), property.NullableAnnotation); return (type!, property.GetSanitizedName(), $"{{ {get}{set}}}"); } diff --git a/src/ProxyInterfaceSourceGenerator/FileGenerators/BaseGenerator.cs b/src/ProxyInterfaceSourceGenerator/FileGenerators/BaseGenerator.cs index 8303792..681b699 100644 --- a/src/ProxyInterfaceSourceGenerator/FileGenerators/BaseGenerator.cs +++ b/src/ProxyInterfaceSourceGenerator/FileGenerators/BaseGenerator.cs @@ -139,13 +139,10 @@ protected string GetReplacedTypeAsString(ITypeSymbol typeSymbol, out bool isRepl if (TryFindProxyDataByTypeName(typeSymbolAsString, out var existing)) { - if (!Context.ReplacedTypes.ContainsKey(typeSymbolAsString)) - { - Context.ReplacedTypes.Add(typeSymbolAsString, existing.FullInterfaceName); - } + TryAddDirect(typeSymbolAsString, existing); isReplaced = true; - return FixType(existing.FullInterfaceName, typeSymbol.NullableAnnotation); + return FixTypeForNullable(existing.FullInterfaceName, typeSymbol.NullableAnnotation); } ITypeSymbol[] typeArguments; @@ -155,32 +152,47 @@ protected string GetReplacedTypeAsString(ITypeSymbol typeSymbol, out bool isRepl } else if (typeSymbol is IArrayTypeSymbol arrayTypeSymbol) { - typeArguments = new[] { arrayTypeSymbol.ElementType }; + typeArguments = [arrayTypeSymbol.ElementType]; } else { - return FixType(typeSymbolAsString, typeSymbol.NullableAnnotation); + return FixTypeForNullable(typeSymbolAsString, typeSymbol.NullableAnnotation); } - var propertyTypeAsStringToBeModified = nullableTypeSymbolAsString; + var elementTypeAsStringToBeModified = nullableTypeSymbolAsString; foreach (var typeArgument in typeArguments) { var typeArgumentAsString = typeArgument.ToFullyQualifiedDisplayString(); if (TryFindProxyDataByTypeName(typeArgumentAsString, out var existingTypeArgument)) { - isReplaced = true; + var original = elementTypeAsStringToBeModified; - if (!Context.ReplacedTypes.ContainsKey(typeArgumentAsString)) + elementTypeAsStringToBeModified = elementTypeAsStringToBeModified.Replace(typeArgumentAsString, existingTypeArgument.FullInterfaceName); + + var foundIndirect = Context.ReplacedTypes.FirstOrDefault(r => !r.Direct && r.ClassType == original); + if (foundIndirect == null) { - Context.ReplacedTypes.Add(typeArgumentAsString, existingTypeArgument.FullInterfaceName); + Context.ReplacedTypes.Add(new(original, elementTypeAsStringToBeModified, typeArgumentAsString, existingTypeArgument.FullInterfaceName, string.Empty, false)); + + TryAddDirect(typeArgumentAsString, existingTypeArgument); } - propertyTypeAsStringToBeModified = propertyTypeAsStringToBeModified.Replace(typeArgumentAsString, existingTypeArgument.FullInterfaceName); + isReplaced = true; } } - return FixType(propertyTypeAsStringToBeModified, typeSymbol.NullableAnnotation); + return FixTypeForNullable(elementTypeAsStringToBeModified, typeSymbol.NullableAnnotation); + } + + private void TryAddDirect(string typeSymbolAsString, ProxyData existing) + { + var found = Context.ReplacedTypes.FirstOrDefault(r => r.Direct && r.ClassType == typeSymbolAsString); + if (found == null) + { + var proxy = $"global::{existing.NamespaceDot}{existing.ShortMetadataName}Proxy"; // global::ProxyInterfaceSourceGeneratorTests.Source.TimeProviderProxy + Context.ReplacedTypes.Add(new(typeSymbolAsString, existing.FullInterfaceName, string.Empty, string.Empty, proxy, true)); + } } protected bool TryGetNamedTypeSymbolByFullName(TypeKind kind, string name, IEnumerable usings, [NotNullWhen(true)] out ClassSymbol? classSymbol) @@ -228,7 +240,7 @@ protected IReadOnlyList GetMethodParameters(ImmutableArray GetExtendsProxyData(ProxyData proxyData, Clas return extendsProxyClasses; } - internal static string FixType(string type, NullableAnnotation nullableAnnotation) + internal static string FixTypeForNullable(string type, NullableAnnotation nullableAnnotation) { if (nullableAnnotation == NullableAnnotation.Annotated && !type.EndsWith("?", StringComparison.Ordinal)) { diff --git a/src/ProxyInterfaceSourceGenerator/FileGenerators/ProxyClassesGenerator.Mapster.cs b/src/ProxyInterfaceSourceGenerator/FileGenerators/ProxyClassesGenerator.Mapster.cs index ca0ff8a..9515405 100644 --- a/src/ProxyInterfaceSourceGenerator/FileGenerators/ProxyClassesGenerator.Mapster.cs +++ b/src/ProxyInterfaceSourceGenerator/FileGenerators/ProxyClassesGenerator.Mapster.cs @@ -1,39 +1,73 @@ -using System.Text; -using ProxyInterfaceSourceGenerator.Extensions; - -namespace ProxyInterfaceSourceGenerator.FileGenerators; - -internal partial class ProxyClassesGenerator -{ - private string GenerateMapperConfigurationForMapster(string className) - { - if (Context.ReplacedTypes.Count == 0) - { - return string.Empty; - } - - var str = new StringBuilder(); - - str.AppendLine($" static {className}()"); - str.AppendLine(@" {"); - - foreach (var replacedType in Context.ReplacedTypes) - { - TryFindProxyDataByTypeName(replacedType.Key, out var fullTypeName); - - var classNameProxy = $"global::{fullTypeName!.NamespaceDot}{fullTypeName!.ShortMetadataName}Proxy"; - - var instance = $"instance{(replacedType.Key + replacedType.Value).GetDeterministicHashCodeAsString()}"; - var proxy = $"proxy{(replacedType.Value + replacedType.Key).GetDeterministicHashCodeAsString()}"; - - str.AppendLine($" Mapster.TypeAdapterConfig<{replacedType.Key}, {replacedType.Value}>.NewConfig().ConstructUsing({instance} => new {classNameProxy}({instance}));"); - str.AppendLine($" Mapster.TypeAdapterConfig<{replacedType.Value}, {replacedType.Key}>.NewConfig().MapWith({proxy} => (({classNameProxy}) {proxy})._Instance);"); - str.AppendLine(); - } - - str.AppendLine(@" }"); - - - return str.ToString(); - } +using System.Text; +using ProxyInterfaceSourceGenerator.Extensions; + +namespace ProxyInterfaceSourceGenerator.FileGenerators; + +internal partial class ProxyClassesGenerator +{ + private string GenerateMapperConfigurationForMapster(string className) + { + if (Context.ReplacedTypes.Count == 0) + { + return string.Empty; + } + + var str = new StringBuilder(); + + var indirectReplacedTypes = Context.ReplacedTypes.Where(r => !r.Direct).ToArray(); + var directReplacedTypes = Context.ReplacedTypes.Where(r => r.Direct).ToArray(); + + if (indirectReplacedTypes.Length > 0) + { + str.AppendLine($" static {className}()"); + str.AppendLine(@" {"); + + foreach (var direct in directReplacedTypes) + { + var hash = (direct.ClassType + direct.InterfaceType).GetDeterministicHashCodeAsString(); + var instance = $"instance{hash}"; + var proxy = $"proxy{hash}"; + + str.AppendLine($" Mapster.TypeAdapterConfig<{direct.ClassType}, {direct.InterfaceType}>.NewConfig().ConstructUsing({instance} => new {direct.Proxy}({instance}));"); + str.AppendLine($" Mapster.TypeAdapterConfig<{direct.InterfaceType}, {direct.ClassType}>.NewConfig().MapWith({proxy} => {proxy}._Instance);"); + str.AppendLine(); + } + + str.AppendLine(@" }"); + } + + str.AppendLine(); + + foreach (var indirect in indirectReplacedTypes) + { + str.AppendLine($" private static {indirect.InterfaceType} MapToInterface({indirect.ClassType} value)"); + str.AppendLine(@" {"); + str.AppendLine($" return Mapster.TypeAdapter.Adapt<{indirect.InterfaceType}>(value);"); + str.AppendLine(@" }"); + str.AppendLine(); + + str.AppendLine($" private static {indirect.ClassType} MapToInstance({indirect.InterfaceType} value)"); + str.AppendLine(@" {"); + str.AppendLine($" return Mapster.TypeAdapter.Adapt<{indirect.ClassType}>(value);"); + str.AppendLine(@" }"); + str.AppendLine(); + } + + foreach (var direct in directReplacedTypes) + { + str.AppendLine($" private static {direct.InterfaceType} MapToInterface({direct.ClassType} value)"); + str.AppendLine(@" {"); + str.AppendLine($" return new {direct.Proxy}(value);"); + str.AppendLine(@" }"); + str.AppendLine(); + + str.AppendLine($" private static {direct.ClassType} MapToInstance({direct.InterfaceType} value)"); + str.AppendLine(@" {"); + str.AppendLine($" return value._Instance;"); + str.AppendLine(@" }"); + str.AppendLine(); + } + + return str.ToString(); + } } \ No newline at end of file diff --git a/src/ProxyInterfaceSourceGenerator/FileGenerators/ProxyClassesGenerator.cs b/src/ProxyInterfaceSourceGenerator/FileGenerators/ProxyClassesGenerator.cs index c4419b4..ed01fe1 100644 --- a/src/ProxyInterfaceSourceGenerator/FileGenerators/ProxyClassesGenerator.cs +++ b/src/ProxyInterfaceSourceGenerator/FileGenerators/ProxyClassesGenerator.cs @@ -81,11 +81,7 @@ private string CreateProxyClassCode( var events = GenerateEvents(targetClassSymbol, proxyData); var operators = GenerateOperators(targetClassSymbol, proxyData); - var configurationForMapster = string.Empty; - if (Context.ReplacedTypes.Count > 0) - { - configurationForMapster = GenerateMapperConfigurationForMapster(className); - } + var configurationForMapster = GenerateMapperConfigurationForMapster(className); var (namespaceStart, namespaceEnd) = NamespaceBuilder.Build(proxyData.Namespace); @@ -173,18 +169,18 @@ private string GeneratePublicProperties(ClassSymbol targetClassSymbol, ProxyData { if (getIsPublic) { - var mapster = $"Mapster.TypeAdapter.Adapt<{type}>({instancePropertyName})"; + var mapMethod = $"MapToInterface({instancePropertyName})"; get = propertyIsNullable ? - $"get => {instancePropertyName} != null ? {mapster} : null; " : - $"get => {mapster}; "; + $"get => {instancePropertyName} != null ? {mapMethod} : null; " : + $"get => {mapMethod}; "; } if (setIsPublic) { - var mapster = $"Mapster.TypeAdapter.Adapt<{property.Type}>(value)"; + var mapMethod = "MapToInstance(value)"; set = propertyIsNullable ? - $"set => {instancePropertyName} = value != null ? {mapster} : null; " : - $"set => {instancePropertyName} = {mapster}; "; + $"set => {instancePropertyName} = value != null ? {mapMethod} : null; " : + $"set => {instancePropertyName} = {mapMethod}; "; } } else @@ -261,7 +257,7 @@ private string GeneratePublicMethods(ClassSymbol targetClassSymbol, ProxyData pr foreach (var ps in method.Parameters.Where(p => !p.IsRef())) { - var type = FixType(ps.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat), ps.Type.NullableAnnotation); + var type = FixTypeForNullable(ps.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat), ps.Type.NullableAnnotation); var name = ps.GetSanitizedName(); var normalOrMap = $" = {name}"; if (ps.RefKind == RefKind.Out) @@ -270,13 +266,13 @@ private string GeneratePublicMethods(ClassSymbol targetClassSymbol, ProxyData pr } else { - _ = GetParameterType(ps, out var isReplaced); // TODO : response is not used? + _ = GetParameterType(ps, out var isReplaced); if (isReplaced) { - var mapster = $"Mapster.TypeAdapter.Adapt<{type}>({name})"; + var mapMethod = $"MapToInstance({name})"; normalOrMap = ps.IsNullable() ? - $" = {name} != null ? {mapster} : null" : - $" = {mapster}"; + $" = {name} != null ? {mapMethod} : null" : + $" = {mapMethod}"; } } @@ -303,13 +299,13 @@ private string GeneratePublicMethods(ClassSymbol targetClassSymbol, ProxyData pr var normalOrMap = $" = {name}_"; if (ps.GetTypeEnum() == TypeEnum.Complex) { - var type = GetParameterType(ps, out var isReplaced); + _ = GetParameterType(ps, out var isReplaced); if (isReplaced) { - var mapster = $"Mapster.TypeAdapter.Adapt<{type}>({name}_)"; + var mapMethod = $"MapToInstance({name}_)"; normalOrMap = ps.IsNullable() ? - $" = {name}_ != null ? {mapster} : null" : - $" = {mapster}"; + $" = {name}_ != null ? {mapMethod} : null" : + $" = {mapMethod}"; } } @@ -320,10 +316,10 @@ private string GeneratePublicMethods(ClassSymbol targetClassSymbol, ProxyData pr { if (returnIsReplaced) { - var mapster = $"Mapster.TypeAdapter.Adapt<{returnTypeAsString}>({alternateReturnVariableName})"; + var mapMethod = $"MapToInterface({alternateReturnVariableName})"; str.AppendLine(method.ReturnType.IsNullable() ? - $" return {alternateReturnVariableName} != null ? {mapster} : null;" : - $" return {mapster};"); + $" return {alternateReturnVariableName} != null ? {mapMethod} : null;" : + $" return {mapMethod};"); } else { @@ -358,6 +354,7 @@ private string GenerateEvents(ClassSymbol targetClassSymbol, ProxyData proxyData { str.Append($" add {{ _Instance.{name} += value; }}"); } + if (@event.Any(e => e.MethodKind == MethodKind.EventRemove)) { str.Append($" remove {{ _Instance.{name} -= value; }}"); diff --git a/src/ProxyInterfaceSourceGenerator/Models/Context.cs b/src/ProxyInterfaceSourceGenerator/Models/Context.cs index f08797c..9720fbf 100644 --- a/src/ProxyInterfaceSourceGenerator/Models/Context.cs +++ b/src/ProxyInterfaceSourceGenerator/Models/Context.cs @@ -1,13 +1,13 @@ -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp.Syntax; - -namespace ProxyInterfaceSourceGenerator.Models; - -internal record Context -{ - public GeneratorExecutionContext GeneratorExecutionContext { get; init; } - - public IDictionary Candidates { get; init; } = default!; - - public Dictionary ReplacedTypes { get; } = new(); +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp.Syntax; + +namespace ProxyInterfaceSourceGenerator.Models; + +internal record Context +{ + public GeneratorExecutionContext GeneratorExecutionContext { get; init; } + + public IDictionary Candidates { get; init; } = default!; + + public List ReplacedTypes { get; } = new(); } \ No newline at end of file diff --git a/src/ProxyInterfaceSourceGenerator/Models/ReplacedTypeInfo.cs b/src/ProxyInterfaceSourceGenerator/Models/ReplacedTypeInfo.cs new file mode 100644 index 0000000..e0397d1 --- /dev/null +++ b/src/ProxyInterfaceSourceGenerator/Models/ReplacedTypeInfo.cs @@ -0,0 +1,11 @@ +namespace ProxyInterfaceSourceGenerator.Models; + +internal record ReplacedTypeInfo +( + string ClassType, + string InterfaceType, + string ElementType, + string ElementInterfaceType, + string Proxy, + bool Direct +); \ No newline at end of file diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Destination/Microsoft.SharePoint.Client.ClientContextProxy.g.cs b/tests/ProxyInterfaceSourceGeneratorTests/Destination/Microsoft.SharePoint.Client.ClientContextProxy.g.cs index 242d3cb..5aaec74 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Destination/Microsoft.SharePoint.Client.ClientContextProxy.g.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Destination/Microsoft.SharePoint.Client.ClientContextProxy.g.cs @@ -14,29 +14,62 @@ namespace ProxyInterfaceSourceGeneratorTests.Source.PnP { public partial class ClientContextProxy : global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientRuntimeContextProxy, global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientContext { - static ClientContextProxy() + + private static global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientRuntimeContext MapToInterface(global::Microsoft.SharePoint.Client.ClientRuntimeContext value) + { + return new global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientRuntimeContextProxy(value); + } + + private static global::Microsoft.SharePoint.Client.ClientRuntimeContext MapToInstance(global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientRuntimeContext value) + { + return value._Instance; + } + + private static global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientObject MapToInterface(global::Microsoft.SharePoint.Client.ClientObject value) + { + return new global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientObjectProxy(value); + } + + private static global::Microsoft.SharePoint.Client.ClientObject MapToInstance(global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientObject value) + { + return value._Instance; + } + + private static global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ISecurableObject MapToInterface(global::Microsoft.SharePoint.Client.SecurableObject value) { - Mapster.TypeAdapterConfig.NewConfig().ConstructUsing(instance_572349648 => new global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientRuntimeContextProxy(instance_572349648)); - Mapster.TypeAdapterConfig.NewConfig().MapWith(proxy214349770 => ((global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientRuntimeContextProxy) proxy214349770)._Instance); + return new global::ProxyInterfaceSourceGeneratorTests.Source.PnP.SecurableObjectProxy(value); + } - Mapster.TypeAdapterConfig.NewConfig().ConstructUsing(instance_205438316 => new global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientObjectProxy(instance_205438316)); - Mapster.TypeAdapterConfig.NewConfig().MapWith(proxy_437526006 => ((global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientObjectProxy) proxy_437526006)._Instance); + private static global::Microsoft.SharePoint.Client.SecurableObject MapToInstance(global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ISecurableObject value) + { + return value._Instance; + } - Mapster.TypeAdapterConfig.NewConfig().ConstructUsing(instance_247129254 => new global::ProxyInterfaceSourceGeneratorTests.Source.PnP.SecurableObjectProxy(instance_247129254)); - Mapster.TypeAdapterConfig.NewConfig().MapWith(proxy_117192422 => ((global::ProxyInterfaceSourceGeneratorTests.Source.PnP.SecurableObjectProxy) proxy_117192422)._Instance); + private static global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientContext MapToInterface(global::Microsoft.SharePoint.Client.ClientContext value) + { + return new global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientContextProxy(value); + } - Mapster.TypeAdapterConfig.NewConfig().ConstructUsing(instance_1483513702 => new global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientContextProxy(instance_1483513702)); - Mapster.TypeAdapterConfig.NewConfig().MapWith(proxy343311664 => ((global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientContextProxy) proxy343311664)._Instance); + private static global::Microsoft.SharePoint.Client.ClientContext MapToInstance(global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientContext value) + { + return value._Instance; + } - Mapster.TypeAdapterConfig.NewConfig().ConstructUsing(instance290679610 => new global::ProxyInterfaceSourceGeneratorTests.Source.PnP.WebProxy(instance290679610)); - Mapster.TypeAdapterConfig.NewConfig().MapWith(proxy_1534869484 => ((global::ProxyInterfaceSourceGeneratorTests.Source.PnP.WebProxy) proxy_1534869484)._Instance); + private static global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IWeb MapToInterface(global::Microsoft.SharePoint.Client.Web value) + { + return new global::ProxyInterfaceSourceGeneratorTests.Source.PnP.WebProxy(value); + } + private static global::Microsoft.SharePoint.Client.Web MapToInstance(global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IWeb value) + { + return value._Instance; } + public new global::Microsoft.SharePoint.Client.ClientContext _Instance { get; } public global::Microsoft.SharePoint.Client.ClientRuntimeContext _InstanceClientRuntimeContext { get; } - public global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IWeb Web { get => Mapster.TypeAdapter.Adapt(_Instance.Web); } + public global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IWeb Web { get => MapToInterface(_Instance.Web); } public global::Microsoft.SharePoint.Client.Site Site { get => _Instance.Site; } diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Destination/Microsoft.SharePoint.Client.ClientObjectProxy.g.cs b/tests/ProxyInterfaceSourceGeneratorTests/Destination/Microsoft.SharePoint.Client.ClientObjectProxy.g.cs index 9b83fb2..9863dd8 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Destination/Microsoft.SharePoint.Client.ClientObjectProxy.g.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Destination/Microsoft.SharePoint.Client.ClientObjectProxy.g.cs @@ -14,20 +14,32 @@ namespace ProxyInterfaceSourceGeneratorTests.Source.PnP { public partial class ClientObjectProxy : global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientObject { - static ClientObjectProxy() + + private static global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientRuntimeContext MapToInterface(global::Microsoft.SharePoint.Client.ClientRuntimeContext value) { - Mapster.TypeAdapterConfig.NewConfig().ConstructUsing(instance_572349648 => new global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientRuntimeContextProxy(instance_572349648)); - Mapster.TypeAdapterConfig.NewConfig().MapWith(proxy214349770 => ((global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientRuntimeContextProxy) proxy214349770)._Instance); + return new global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientRuntimeContextProxy(value); + } - Mapster.TypeAdapterConfig.NewConfig().ConstructUsing(instance_205438316 => new global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientObjectProxy(instance_205438316)); - Mapster.TypeAdapterConfig.NewConfig().MapWith(proxy_437526006 => ((global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientObjectProxy) proxy_437526006)._Instance); + private static global::Microsoft.SharePoint.Client.ClientRuntimeContext MapToInstance(global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientRuntimeContext value) + { + return value._Instance; + } + private static global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientObject MapToInterface(global::Microsoft.SharePoint.Client.ClientObject value) + { + return new global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientObjectProxy(value); } + private static global::Microsoft.SharePoint.Client.ClientObject MapToInstance(global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientObject value) + { + return value._Instance; + } + + public global::Microsoft.SharePoint.Client.ClientObject _Instance { get; } - public global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientRuntimeContext Context { get => Mapster.TypeAdapter.Adapt(_Instance.Context); } + public global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientRuntimeContext Context { get => MapToInterface(_Instance.Context); } public object Tag { get => _Instance.Tag; set => _Instance.Tag = value; } @@ -40,7 +52,7 @@ static ClientObjectProxy() [Microsoft.SharePoint.Client.PseudoRemoteAttribute] public bool? ServerObjectIsNull { get => _Instance.ServerObjectIsNull; } - public global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientObject TypedObject { get => Mapster.TypeAdapter.Adapt(_Instance.TypedObject); } + public global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientObject TypedObject { get => MapToInterface(_Instance.TypedObject); } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public virtual void FromJson(global::Microsoft.SharePoint.Client.JsonReader reader) diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Destination/Microsoft.SharePoint.Client.ClientRuntimeContextProxy.g.cs b/tests/ProxyInterfaceSourceGeneratorTests/Destination/Microsoft.SharePoint.Client.ClientRuntimeContextProxy.g.cs index 7db1acf..31dd1b1 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Destination/Microsoft.SharePoint.Client.ClientRuntimeContextProxy.g.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Destination/Microsoft.SharePoint.Client.ClientRuntimeContextProxy.g.cs @@ -14,22 +14,48 @@ namespace ProxyInterfaceSourceGeneratorTests.Source.PnP { public partial class ClientRuntimeContextProxy : global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientRuntimeContext { - static ClientRuntimeContextProxy() + + private static global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientRuntimeContext MapToInterface(global::Microsoft.SharePoint.Client.ClientRuntimeContext value) { - Mapster.TypeAdapterConfig.NewConfig().ConstructUsing(instance_572349648 => new global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientRuntimeContextProxy(instance_572349648)); - Mapster.TypeAdapterConfig.NewConfig().MapWith(proxy214349770 => ((global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientRuntimeContextProxy) proxy214349770)._Instance); + return new global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientRuntimeContextProxy(value); + } - Mapster.TypeAdapterConfig.NewConfig().ConstructUsing(instance_205438316 => new global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientObjectProxy(instance_205438316)); - Mapster.TypeAdapterConfig.NewConfig().MapWith(proxy_437526006 => ((global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientObjectProxy) proxy_437526006)._Instance); + private static global::Microsoft.SharePoint.Client.ClientRuntimeContext MapToInstance(global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientRuntimeContext value) + { + return value._Instance; + } - Mapster.TypeAdapterConfig.NewConfig().ConstructUsing(instance_247129254 => new global::ProxyInterfaceSourceGeneratorTests.Source.PnP.SecurableObjectProxy(instance_247129254)); - Mapster.TypeAdapterConfig.NewConfig().MapWith(proxy_117192422 => ((global::ProxyInterfaceSourceGeneratorTests.Source.PnP.SecurableObjectProxy) proxy_117192422)._Instance); + private static global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientObject MapToInterface(global::Microsoft.SharePoint.Client.ClientObject value) + { + return new global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientObjectProxy(value); + } - Mapster.TypeAdapterConfig.NewConfig().ConstructUsing(instance_1483513702 => new global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientContextProxy(instance_1483513702)); - Mapster.TypeAdapterConfig.NewConfig().MapWith(proxy343311664 => ((global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientContextProxy) proxy343311664)._Instance); + private static global::Microsoft.SharePoint.Client.ClientObject MapToInstance(global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientObject value) + { + return value._Instance; + } + private static global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ISecurableObject MapToInterface(global::Microsoft.SharePoint.Client.SecurableObject value) + { + return new global::ProxyInterfaceSourceGeneratorTests.Source.PnP.SecurableObjectProxy(value); } + private static global::Microsoft.SharePoint.Client.SecurableObject MapToInstance(global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ISecurableObject value) + { + return value._Instance; + } + + private static global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientContext MapToInterface(global::Microsoft.SharePoint.Client.ClientContext value) + { + return new global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientContextProxy(value); + } + + private static global::Microsoft.SharePoint.Client.ClientContext MapToInstance(global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientContext value) + { + return value._Instance; + } + + public global::Microsoft.SharePoint.Client.ClientRuntimeContext _Instance { get; } @@ -94,7 +120,7 @@ public virtual void RetryQuery(global::Microsoft.SharePoint.Client.ClientRequest public T CastTo(global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientObject obj) where T : Microsoft.SharePoint.Client.ClientObject { - global::Microsoft.SharePoint.Client.ClientObject obj_ = Mapster.TypeAdapter.Adapt(obj); + global::Microsoft.SharePoint.Client.ClientObject obj_ = MapToInstance(obj); var result_366781530 = _Instance.CastTo(obj_); return result_366781530; } diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Destination/Microsoft.SharePoint.Client.SecurableObjectProxy.g.cs b/tests/ProxyInterfaceSourceGeneratorTests/Destination/Microsoft.SharePoint.Client.SecurableObjectProxy.g.cs index ade2afb..feb1889 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Destination/Microsoft.SharePoint.Client.SecurableObjectProxy.g.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Destination/Microsoft.SharePoint.Client.SecurableObjectProxy.g.cs @@ -14,24 +14,43 @@ namespace ProxyInterfaceSourceGeneratorTests.Source.PnP { public partial class SecurableObjectProxy : global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientObjectProxy, global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ISecurableObject { - static SecurableObjectProxy() + + private static global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientRuntimeContext MapToInterface(global::Microsoft.SharePoint.Client.ClientRuntimeContext value) + { + return new global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientRuntimeContextProxy(value); + } + + private static global::Microsoft.SharePoint.Client.ClientRuntimeContext MapToInstance(global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientRuntimeContext value) + { + return value._Instance; + } + + private static global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientObject MapToInterface(global::Microsoft.SharePoint.Client.ClientObject value) { - Mapster.TypeAdapterConfig.NewConfig().ConstructUsing(instance_572349648 => new global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientRuntimeContextProxy(instance_572349648)); - Mapster.TypeAdapterConfig.NewConfig().MapWith(proxy214349770 => ((global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientRuntimeContextProxy) proxy214349770)._Instance); + return new global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientObjectProxy(value); + } - Mapster.TypeAdapterConfig.NewConfig().ConstructUsing(instance_205438316 => new global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientObjectProxy(instance_205438316)); - Mapster.TypeAdapterConfig.NewConfig().MapWith(proxy_437526006 => ((global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientObjectProxy) proxy_437526006)._Instance); + private static global::Microsoft.SharePoint.Client.ClientObject MapToInstance(global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientObject value) + { + return value._Instance; + } - Mapster.TypeAdapterConfig.NewConfig().ConstructUsing(instance_247129254 => new global::ProxyInterfaceSourceGeneratorTests.Source.PnP.SecurableObjectProxy(instance_247129254)); - Mapster.TypeAdapterConfig.NewConfig().MapWith(proxy_117192422 => ((global::ProxyInterfaceSourceGeneratorTests.Source.PnP.SecurableObjectProxy) proxy_117192422)._Instance); + private static global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ISecurableObject MapToInterface(global::Microsoft.SharePoint.Client.SecurableObject value) + { + return new global::ProxyInterfaceSourceGeneratorTests.Source.PnP.SecurableObjectProxy(value); + } + private static global::Microsoft.SharePoint.Client.SecurableObject MapToInstance(global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ISecurableObject value) + { + return value._Instance; } + public new global::Microsoft.SharePoint.Client.SecurableObject _Instance { get; } public global::Microsoft.SharePoint.Client.ClientObject _InstanceClientObject { get; } [Microsoft.SharePoint.Client.RemoteAttribute] - public global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ISecurableObject FirstUniqueAncestorSecurableObject { get => Mapster.TypeAdapter.Adapt(_Instance.FirstUniqueAncestorSecurableObject); } + public global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ISecurableObject FirstUniqueAncestorSecurableObject { get => MapToInterface(_Instance.FirstUniqueAncestorSecurableObject); } [Microsoft.SharePoint.Client.RemoteAttribute] public bool HasUniqueRoleAssignments { get => _Instance.HasUniqueRoleAssignments; } diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Destination/Microsoft.SharePoint.Client.WebProxy.g.cs b/tests/ProxyInterfaceSourceGeneratorTests/Destination/Microsoft.SharePoint.Client.WebProxy.g.cs index 2f99dd1..e879a0d 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Destination/Microsoft.SharePoint.Client.WebProxy.g.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Destination/Microsoft.SharePoint.Client.WebProxy.g.cs @@ -14,22 +14,48 @@ namespace ProxyInterfaceSourceGeneratorTests.Source.PnP { public partial class WebProxy : global::ProxyInterfaceSourceGeneratorTests.Source.PnP.SecurableObjectProxy, global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IWeb { - static WebProxy() + + private static global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientRuntimeContext MapToInterface(global::Microsoft.SharePoint.Client.ClientRuntimeContext value) { - Mapster.TypeAdapterConfig.NewConfig().ConstructUsing(instance_572349648 => new global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientRuntimeContextProxy(instance_572349648)); - Mapster.TypeAdapterConfig.NewConfig().MapWith(proxy214349770 => ((global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientRuntimeContextProxy) proxy214349770)._Instance); + return new global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientRuntimeContextProxy(value); + } - Mapster.TypeAdapterConfig.NewConfig().ConstructUsing(instance_205438316 => new global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientObjectProxy(instance_205438316)); - Mapster.TypeAdapterConfig.NewConfig().MapWith(proxy_437526006 => ((global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientObjectProxy) proxy_437526006)._Instance); + private static global::Microsoft.SharePoint.Client.ClientRuntimeContext MapToInstance(global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientRuntimeContext value) + { + return value._Instance; + } - Mapster.TypeAdapterConfig.NewConfig().ConstructUsing(instance_247129254 => new global::ProxyInterfaceSourceGeneratorTests.Source.PnP.SecurableObjectProxy(instance_247129254)); - Mapster.TypeAdapterConfig.NewConfig().MapWith(proxy_117192422 => ((global::ProxyInterfaceSourceGeneratorTests.Source.PnP.SecurableObjectProxy) proxy_117192422)._Instance); + private static global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientObject MapToInterface(global::Microsoft.SharePoint.Client.ClientObject value) + { + return new global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientObjectProxy(value); + } - Mapster.TypeAdapterConfig.NewConfig().ConstructUsing(instance_1483513702 => new global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientContextProxy(instance_1483513702)); - Mapster.TypeAdapterConfig.NewConfig().MapWith(proxy343311664 => ((global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientContextProxy) proxy343311664)._Instance); + private static global::Microsoft.SharePoint.Client.ClientObject MapToInstance(global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientObject value) + { + return value._Instance; + } + private static global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ISecurableObject MapToInterface(global::Microsoft.SharePoint.Client.SecurableObject value) + { + return new global::ProxyInterfaceSourceGeneratorTests.Source.PnP.SecurableObjectProxy(value); } + private static global::Microsoft.SharePoint.Client.SecurableObject MapToInstance(global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ISecurableObject value) + { + return value._Instance; + } + + private static global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientContext MapToInterface(global::Microsoft.SharePoint.Client.ClientContext value) + { + return new global::ProxyInterfaceSourceGeneratorTests.Source.PnP.ClientContextProxy(value); + } + + private static global::Microsoft.SharePoint.Client.ClientContext MapToInstance(global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientContext value) + { + return value._Instance; + } + + public new global::Microsoft.SharePoint.Client.Web _Instance { get; } public global::Microsoft.SharePoint.Client.SecurableObject _InstanceSecurableObject { get; } @@ -440,7 +466,7 @@ static WebProxy() public global::System.Uri WebUrlFromPageUrlDirect(global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientContext context, global::System.Uri pageFullUrl) { - global::Microsoft.SharePoint.Client.ClientContext context_ = Mapster.TypeAdapter.Adapt(context); + global::Microsoft.SharePoint.Client.ClientContext context_ = MapToInstance(context); global::System.Uri pageFullUrl_ = pageFullUrl; var result__258107370 = global::Microsoft.SharePoint.Client.Web.WebUrlFromPageUrlDirect(context_, pageFullUrl_); return result__258107370; @@ -448,7 +474,7 @@ static WebProxy() public global::System.Uri WebUrlFromFolderUrlDirect(global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientContext context, global::System.Uri folderFullUrl) { - global::Microsoft.SharePoint.Client.ClientContext context_ = Mapster.TypeAdapter.Adapt(context); + global::Microsoft.SharePoint.Client.ClientContext context_ = MapToInstance(context); global::System.Uri folderFullUrl_ = folderFullUrl; var result_21992317 = global::Microsoft.SharePoint.Client.Web.WebUrlFromFolderUrlDirect(context_, folderFullUrl_); return result_21992317; @@ -482,7 +508,7 @@ public void CreateDefaultAssociatedGroups(string userLogin, string userLogin2, s [Microsoft.SharePoint.Client.RemoteAttribute] public global::Microsoft.SharePoint.Client.ClientResult CreateOrganizationSharingLink(global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientRuntimeContext context, string url, bool isEditLink) { - global::Microsoft.SharePoint.Client.ClientRuntimeContext context_ = Mapster.TypeAdapter.Adapt(context); + global::Microsoft.SharePoint.Client.ClientRuntimeContext context_ = MapToInstance(context); string url_ = url; bool isEditLink_ = isEditLink; var result_2070260011 = global::Microsoft.SharePoint.Client.Web.CreateOrganizationSharingLink(context_, url_, isEditLink_); @@ -492,7 +518,7 @@ public void CreateDefaultAssociatedGroups(string userLogin, string userLogin2, s [Microsoft.SharePoint.Client.RemoteAttribute] public void DestroyOrganizationSharingLink(global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientRuntimeContext context, string url, bool isEditLink, bool removeAssociatedSharingLinkGroup) { - global::Microsoft.SharePoint.Client.ClientRuntimeContext context_ = Mapster.TypeAdapter.Adapt(context); + global::Microsoft.SharePoint.Client.ClientRuntimeContext context_ = MapToInstance(context); string url_ = url; bool isEditLink_ = isEditLink; bool removeAssociatedSharingLinkGroup_ = removeAssociatedSharingLinkGroup; @@ -502,7 +528,7 @@ public void DestroyOrganizationSharingLink(global::ProxyInterfaceSourceGenerator [Microsoft.SharePoint.Client.RemoteAttribute] public global::Microsoft.SharePoint.Client.ClientResult GetSharingLinkKind(global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientRuntimeContext context, string fileUrl) { - global::Microsoft.SharePoint.Client.ClientRuntimeContext context_ = Mapster.TypeAdapter.Adapt(context); + global::Microsoft.SharePoint.Client.ClientRuntimeContext context_ = MapToInstance(context); string fileUrl_ = fileUrl; var result_654626020 = global::Microsoft.SharePoint.Client.Web.GetSharingLinkKind(context_, fileUrl_); return result_654626020; @@ -529,7 +555,7 @@ public void DestroyOrganizationSharingLink(global::ProxyInterfaceSourceGenerator [Microsoft.SharePoint.Client.RemoteAttribute] public global::Microsoft.SharePoint.Client.ClientResult GetWebUrlFromPageUrl(global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientRuntimeContext context, string pageFullUrl) { - global::Microsoft.SharePoint.Client.ClientRuntimeContext context_ = Mapster.TypeAdapter.Adapt(context); + global::Microsoft.SharePoint.Client.ClientRuntimeContext context_ = MapToInstance(context); string pageFullUrl_ = pageFullUrl; var result__907059837 = global::Microsoft.SharePoint.Client.Web.GetWebUrlFromPageUrl(context_, pageFullUrl_); return result__907059837; @@ -635,7 +661,7 @@ public void RemoveStorageEntity(string key) [Microsoft.SharePoint.Client.RemoteAttribute] public global::Microsoft.SharePoint.Client.SharingResult ShareObject(global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientRuntimeContext context, string url, string peoplePickerInput, string roleValue, int groupId, bool propagateAcl, bool sendEmail, bool includeAnonymousLinkInEmail, string emailSubject, string emailBody, bool useSimplifiedRoles) { - global::Microsoft.SharePoint.Client.ClientRuntimeContext context_ = Mapster.TypeAdapter.Adapt(context); + global::Microsoft.SharePoint.Client.ClientRuntimeContext context_ = MapToInstance(context); string url_ = url; string peoplePickerInput_ = peoplePickerInput; string roleValue_ = roleValue; @@ -653,7 +679,7 @@ public void RemoveStorageEntity(string key) [Microsoft.SharePoint.Client.RemoteAttribute] public global::Microsoft.SharePoint.Client.SharingResult ForwardObjectLink(global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientRuntimeContext context, string url, string peoplePickerInput, string emailSubject, string emailBody) { - global::Microsoft.SharePoint.Client.ClientRuntimeContext context_ = Mapster.TypeAdapter.Adapt(context); + global::Microsoft.SharePoint.Client.ClientRuntimeContext context_ = MapToInstance(context); string url_ = url; string peoplePickerInput_ = peoplePickerInput; string emailSubject_ = emailSubject; @@ -665,7 +691,7 @@ public void RemoveStorageEntity(string key) [Microsoft.SharePoint.Client.RemoteAttribute] public global::Microsoft.SharePoint.Client.SharingResult UnshareObject(global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientRuntimeContext context, string url) { - global::Microsoft.SharePoint.Client.ClientRuntimeContext context_ = Mapster.TypeAdapter.Adapt(context); + global::Microsoft.SharePoint.Client.ClientRuntimeContext context_ = MapToInstance(context); string url_ = url; var result__823224569 = global::Microsoft.SharePoint.Client.Web.UnshareObject(context_, url_); return result__823224569; @@ -674,7 +700,7 @@ public void RemoveStorageEntity(string key) [Microsoft.SharePoint.Client.RemoteAttribute] public global::Microsoft.SharePoint.Client.ObjectSharingSettings GetObjectSharingSettings(global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientRuntimeContext context, string objectUrl, int groupId, bool useSimplifiedRoles) { - global::Microsoft.SharePoint.Client.ClientRuntimeContext context_ = Mapster.TypeAdapter.Adapt(context); + global::Microsoft.SharePoint.Client.ClientRuntimeContext context_ = MapToInstance(context); string objectUrl_ = objectUrl; int groupId_ = groupId; bool useSimplifiedRoles_ = useSimplifiedRoles; @@ -685,7 +711,7 @@ public void RemoveStorageEntity(string key) [Microsoft.SharePoint.Client.RemoteAttribute] public global::Microsoft.SharePoint.Client.ClientResult CreateAnonymousLink(global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientRuntimeContext context, string url, bool isEditLink) { - global::Microsoft.SharePoint.Client.ClientRuntimeContext context_ = Mapster.TypeAdapter.Adapt(context); + global::Microsoft.SharePoint.Client.ClientRuntimeContext context_ = MapToInstance(context); string url_ = url; bool isEditLink_ = isEditLink; var result__820192309 = global::Microsoft.SharePoint.Client.Web.CreateAnonymousLink(context_, url_, isEditLink_); @@ -695,7 +721,7 @@ public void RemoveStorageEntity(string key) [Microsoft.SharePoint.Client.RemoteAttribute] public global::Microsoft.SharePoint.Client.ClientResult CreateAnonymousLinkWithExpiration(global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientRuntimeContext context, string url, bool isEditLink, string expirationString) { - global::Microsoft.SharePoint.Client.ClientRuntimeContext context_ = Mapster.TypeAdapter.Adapt(context); + global::Microsoft.SharePoint.Client.ClientRuntimeContext context_ = MapToInstance(context); string url_ = url; bool isEditLink_ = isEditLink; string expirationString_ = expirationString; @@ -706,7 +732,7 @@ public void RemoveStorageEntity(string key) [Microsoft.SharePoint.Client.RemoteAttribute] public void DeleteAllAnonymousLinksForObject(global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientRuntimeContext context, string url) { - global::Microsoft.SharePoint.Client.ClientRuntimeContext context_ = Mapster.TypeAdapter.Adapt(context); + global::Microsoft.SharePoint.Client.ClientRuntimeContext context_ = MapToInstance(context); string url_ = url; global::Microsoft.SharePoint.Client.Web.DeleteAllAnonymousLinksForObject(context_, url_); } @@ -714,7 +740,7 @@ public void DeleteAllAnonymousLinksForObject(global::ProxyInterfaceSourceGenerat [Microsoft.SharePoint.Client.RemoteAttribute] public void DeleteAnonymousLinkForObject(global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientRuntimeContext context, string url, bool isEditLink, bool removeAssociatedSharingLinkGroup) { - global::Microsoft.SharePoint.Client.ClientRuntimeContext context_ = Mapster.TypeAdapter.Adapt(context); + global::Microsoft.SharePoint.Client.ClientRuntimeContext context_ = MapToInstance(context); string url_ = url; bool isEditLink_ = isEditLink; bool removeAssociatedSharingLinkGroup_ = removeAssociatedSharingLinkGroup; @@ -894,7 +920,7 @@ public void Update() [Microsoft.SharePoint.Client.RemoteAttribute] public global::System.Collections.Generic.IList GetDocumentLibraries(global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientRuntimeContext context, string webFullUrl) { - global::Microsoft.SharePoint.Client.ClientRuntimeContext context_ = Mapster.TypeAdapter.Adapt(context); + global::Microsoft.SharePoint.Client.ClientRuntimeContext context_ = MapToInstance(context); string webFullUrl_ = webFullUrl; var result_2078170246 = global::Microsoft.SharePoint.Client.Web.GetDocumentLibraries(context_, webFullUrl_); return result_2078170246; @@ -903,7 +929,7 @@ public void Update() [Microsoft.SharePoint.Client.RemoteAttribute] public global::System.Collections.Generic.IList GetDocumentAndMediaLibraries(global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientRuntimeContext context, string webFullUrl, bool includePageLibraries) { - global::Microsoft.SharePoint.Client.ClientRuntimeContext context_ = Mapster.TypeAdapter.Adapt(context); + global::Microsoft.SharePoint.Client.ClientRuntimeContext context_ = MapToInstance(context); string webFullUrl_ = webFullUrl; bool includePageLibraries_ = includePageLibraries; var result__431075153 = global::Microsoft.SharePoint.Client.Web.GetDocumentAndMediaLibraries(context_, webFullUrl_, includePageLibraries_); @@ -913,7 +939,7 @@ public void Update() [Microsoft.SharePoint.Client.RemoteAttribute] public global::Microsoft.SharePoint.Client.ClientResult DefaultDocumentLibraryUrl(global::ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientRuntimeContext context, string webUrl) { - global::Microsoft.SharePoint.Client.ClientRuntimeContext context_ = Mapster.TypeAdapter.Adapt(context); + global::Microsoft.SharePoint.Client.ClientRuntimeContext context_ = MapToInstance(context); string webUrl_ = webUrl; var result_1125717726 = global::Microsoft.SharePoint.Client.Web.DefaultDocumentLibraryUrl(context_, webUrl_); return result_1125717726; diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.ClassDirectAndIndirectProxy.g.cs b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.ClassDirectAndIndirectProxy.g.cs new file mode 100644 index 0000000..38164c3 --- /dev/null +++ b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.ClassDirectAndIndirectProxy.g.cs @@ -0,0 +1,84 @@ +//---------------------------------------------------------------------------------------- +// +// 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 ClassDirectAndIndirectProxy : global::ProxyInterfaceSourceGeneratorTests.Source.IClassDirectAndIndirect + { + static ClassDirectAndIndirectProxy() + { + Mapster.TypeAdapterConfig.NewConfig().ConstructUsing(instance2067235185 => new global::ProxyInterfaceSourceGeneratorTests.Source.ClassDirectAndIndirectProxy(instance2067235185)); + Mapster.TypeAdapterConfig.NewConfig().MapWith(proxy2067235185 => proxy2067235185._Instance); + + } + + private static global::ProxyInterfaceSourceGeneratorTests.Source.IClassDirectAndIndirect[] MapToInterface(global::ProxyInterfaceSourceGeneratorTests.Source.ClassDirectAndIndirect[] value) + { + return Mapster.TypeAdapter.Adapt(value); + } + + private static global::ProxyInterfaceSourceGeneratorTests.Source.ClassDirectAndIndirect[] MapToInstance(global::ProxyInterfaceSourceGeneratorTests.Source.IClassDirectAndIndirect[] value) + { + return Mapster.TypeAdapter.Adapt(value); + } + + private static global::System.Collections.Generic.List MapToInterface(global::System.Collections.Generic.List value) + { + return Mapster.TypeAdapter.Adapt>(value); + } + + private static global::System.Collections.Generic.List MapToInstance(global::System.Collections.Generic.List value) + { + return Mapster.TypeAdapter.Adapt>(value); + } + + private static global::ProxyInterfaceSourceGeneratorTests.Source.IClassDirectAndIndirect MapToInterface(global::ProxyInterfaceSourceGeneratorTests.Source.ClassDirectAndIndirect value) + { + return new global::ProxyInterfaceSourceGeneratorTests.Source.ClassDirectAndIndirectProxy(value); + } + + private static global::ProxyInterfaceSourceGeneratorTests.Source.ClassDirectAndIndirect MapToInstance(global::ProxyInterfaceSourceGeneratorTests.Source.IClassDirectAndIndirect value) + { + return value._Instance; + } + + + + public global::ProxyInterfaceSourceGeneratorTests.Source.ClassDirectAndIndirect _Instance { get; } + + public string Id { get => _Instance.Id; set => _Instance.Id = value; } + + public global::ProxyInterfaceSourceGeneratorTests.Source.IClassDirectAndIndirect? Value { get => _Instance.Value != null ? MapToInterface(_Instance.Value) : null; set => _Instance.Value = value != null ? MapToInstance(value) : null; } + + public global::ProxyInterfaceSourceGeneratorTests.Source.IClassDirectAndIndirect[] Array { get => MapToInterface(_Instance.Array); set => _Instance.Array = MapToInstance(value); } + + public global::System.Collections.Generic.List List { get => MapToInterface(_Instance.List); set => _Instance.List = MapToInstance(value); } + + public int Test(global::ProxyInterfaceSourceGeneratorTests.Source.IClassDirectAndIndirect[] array, global::System.Collections.Generic.List list, global::ProxyInterfaceSourceGeneratorTests.Source.IClassDirectAndIndirect value, global::ProxyInterfaceSourceGeneratorTests.Source.IClassDirectAndIndirect? valueNullable) + { + global::ProxyInterfaceSourceGeneratorTests.Source.ClassDirectAndIndirect[] array_ = MapToInstance(array); + global::System.Collections.Generic.List list_ = MapToInstance(list); + global::ProxyInterfaceSourceGeneratorTests.Source.ClassDirectAndIndirect value_ = MapToInstance(value); + global::ProxyInterfaceSourceGeneratorTests.Source.ClassDirectAndIndirect? valueNullable_ = valueNullable != null ? MapToInstance(valueNullable) : null; + var result__1701808026 = _Instance.Test(array_, list_, value_, valueNullable_); + return result__1701808026; + } + + + public ClassDirectAndIndirectProxy(global::ProxyInterfaceSourceGeneratorTests.Source.ClassDirectAndIndirect instance) + { + _Instance = instance; + + } + } +} +#nullable restore \ No newline at end of file diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.ClassDirectProxy.g.cs b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.ClassDirectProxy.g.cs new file mode 100644 index 0000000..26cd7c5 --- /dev/null +++ b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.ClassDirectProxy.g.cs @@ -0,0 +1,47 @@ +//---------------------------------------------------------------------------------------- +// +// 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 ClassDirectProxy : global::ProxyInterfaceSourceGeneratorTests.Source.IClassDirect + { + + private static global::ProxyInterfaceSourceGeneratorTests.Source.IClassDirect MapToInterface(global::ProxyInterfaceSourceGeneratorTests.Source.ClassDirect value) + { + return new global::ProxyInterfaceSourceGeneratorTests.Source.ClassDirectProxy(value); + } + + private static global::ProxyInterfaceSourceGeneratorTests.Source.ClassDirect MapToInstance(global::ProxyInterfaceSourceGeneratorTests.Source.IClassDirect value) + { + return value._Instance; + } + + + + public global::ProxyInterfaceSourceGeneratorTests.Source.ClassDirect _Instance { get; } + + public global::ProxyInterfaceSourceGeneratorTests.Source.IClassDirect Test(global::ProxyInterfaceSourceGeneratorTests.Source.IClassDirect x) + { + global::ProxyInterfaceSourceGeneratorTests.Source.ClassDirect x_ = MapToInstance(x); + var result__1701808026 = _Instance.Test(x_); + return MapToInterface(result__1701808026); + } + + + public ClassDirectProxy(global::ProxyInterfaceSourceGeneratorTests.Source.ClassDirect instance) + { + _Instance = instance; + + } + } +} +#nullable restore \ No newline at end of file diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.IClassDirect.g.cs b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.IClassDirect.g.cs new file mode 100644 index 0000000..e84e214 --- /dev/null +++ b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.IClassDirect.g.cs @@ -0,0 +1,22 @@ +//---------------------------------------------------------------------------------------- +// +// 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 IClassDirect + { + global::ProxyInterfaceSourceGeneratorTests.Source.ClassDirect _Instance { get; } + + global::ProxyInterfaceSourceGeneratorTests.Source.IClassDirect Test(global::ProxyInterfaceSourceGeneratorTests.Source.IClassDirect x); + } +} +#nullable restore \ No newline at end of file diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.IClassDirectAndIndirect.g.cs b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.IClassDirectAndIndirect.g.cs new file mode 100644 index 0000000..a585728 --- /dev/null +++ b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.IClassDirectAndIndirect.g.cs @@ -0,0 +1,30 @@ +//---------------------------------------------------------------------------------------- +// +// 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 IClassDirectAndIndirect + { + global::ProxyInterfaceSourceGeneratorTests.Source.ClassDirectAndIndirect _Instance { get; } + + string Id { get; set; } + + global::ProxyInterfaceSourceGeneratorTests.Source.IClassDirectAndIndirect? Value { get; set; } + + global::ProxyInterfaceSourceGeneratorTests.Source.IClassDirectAndIndirect[] Array { get; set; } + + global::System.Collections.Generic.List List { get; set; } + + int Test(global::ProxyInterfaceSourceGeneratorTests.Source.IClassDirectAndIndirect[] array, global::System.Collections.Generic.List list, global::ProxyInterfaceSourceGeneratorTests.Source.IClassDirectAndIndirect value, global::ProxyInterfaceSourceGeneratorTests.Source.IClassDirectAndIndirect? valueNullable); + } +} +#nullable restore \ No newline at end of file diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.OperatorTestProxy.g.cs b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.OperatorTestProxy.g.cs index 6484fda..9d7ca58 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.OperatorTestProxy.g.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.OperatorTestProxy.g.cs @@ -20,7 +20,7 @@ public partial class OperatorTestProxy : global::ProxyInterfaceSourceGeneratorTe public string Name { get => _Instance.Name; set => _Instance.Name = value; } - public int? Id { get => _Instance.Id; set => _Instance.Id = value; } + public int? Id { get => _Instance.Id; set => _Instance.Id = value!; } public static implicit operator OperatorTestProxy(string name) { diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.PersonProxy.g.cs b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.PersonProxy.g.cs index 3ba6b0f..493104d 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.PersonProxy.g.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.PersonProxy.g.cs @@ -17,16 +17,47 @@ public partial class PersonProxy : global::ProxyInterfaceSourceGeneratorTests.So static PersonProxy() { Mapster.TypeAdapterConfig.NewConfig().ConstructUsing(instance2145588841 => new global::ProxyInterfaceSourceGeneratorTests.Source.HumanProxy(instance2145588841)); - Mapster.TypeAdapterConfig.NewConfig().MapWith(proxy1567394325 => ((global::ProxyInterfaceSourceGeneratorTests.Source.HumanProxy) proxy1567394325)._Instance); + Mapster.TypeAdapterConfig.NewConfig().MapWith(proxy2145588841 => proxy2145588841._Instance); } + private static global::System.Collections.Generic.List MapToInterface(global::System.Collections.Generic.List value) + { + return Mapster.TypeAdapter.Adapt>(value); + } + + private static global::System.Collections.Generic.List MapToInstance(global::System.Collections.Generic.List value) + { + return Mapster.TypeAdapter.Adapt>(value); + } + + private static global::System.Collections.Generic.IList MapToInterface(global::System.Collections.Generic.IList value) + { + return Mapster.TypeAdapter.Adapt>(value); + } + + private static global::System.Collections.Generic.IList MapToInstance(global::System.Collections.Generic.IList value) + { + return Mapster.TypeAdapter.Adapt>(value); + } + + private static global::ProxyInterfaceSourceGeneratorTests.Source.IHuman MapToInterface(global::ProxyInterfaceSourceGeneratorTests.Source.Human value) + { + return new global::ProxyInterfaceSourceGeneratorTests.Source.HumanProxy(value); + } + + private static global::ProxyInterfaceSourceGeneratorTests.Source.Human MapToInstance(global::ProxyInterfaceSourceGeneratorTests.Source.IHuman value) + { + return value._Instance; + } + + public new global::ProxyInterfaceSourceGeneratorTests.Source.Person _Instance { get; } public global::ProxyInterfaceSourceGeneratorTests.Source.Human _InstanceHuman { get; } - public global::ProxyInterfaceSourceGeneratorTests.Source.IHuman? Human { get => _Instance.Human != null ? Mapster.TypeAdapter.Adapt(_Instance.Human) : null; set => _Instance.Human = value != null ? Mapster.TypeAdapter.Adapt(value) : null; } + public global::ProxyInterfaceSourceGeneratorTests.Source.IHuman? Human { get => _Instance.Human != null ? MapToInterface(_Instance.Human) : null; set => _Instance.Human = value != null ? MapToInstance(value) : null; } - public global::System.Collections.Generic.List Humans { get => Mapster.TypeAdapter.Adapt>(_Instance.Humans); set => _Instance.Humans = Mapster.TypeAdapter.Adapt>(value); } + public global::System.Collections.Generic.List Humans { get => MapToInterface(_Instance.Humans); set => _Instance.Humans = MapToInstance(value); } [System.ComponentModel.DataAnnotations.DisplayAttribute(Prompt = "MyStruct Indexer")] public global::ProxyInterfaceSourceGeneratorTests.Source.MyStruct this[int i] { get => _Instance[i]; set => _Instance[i] = value; } @@ -44,18 +75,18 @@ static PersonProxy() public global::ProxyInterfaceSourceGeneratorTests.Source.IHuman? GetHuman(global::ProxyInterfaceSourceGeneratorTests.Source.IHuman? h1, global::ProxyInterfaceSourceGeneratorTests.Source.IHuman? h2, global::ProxyInterfaceSourceGeneratorTests.Source.IHuman h3) { - global::ProxyInterfaceSourceGeneratorTests.Source.Human? h1_ = h1 != null ? Mapster.TypeAdapter.Adapt(h1) : null; - global::ProxyInterfaceSourceGeneratorTests.Source.Human? h2_ = h2 != null ? Mapster.TypeAdapter.Adapt(h2) : null; - global::ProxyInterfaceSourceGeneratorTests.Source.Human h3_ = Mapster.TypeAdapter.Adapt(h3); + global::ProxyInterfaceSourceGeneratorTests.Source.Human? h1_ = h1 != null ? MapToInstance(h1) : null; + global::ProxyInterfaceSourceGeneratorTests.Source.Human? h2_ = h2 != null ? MapToInstance(h2) : null; + global::ProxyInterfaceSourceGeneratorTests.Source.Human h3_ = MapToInstance(h3); var result_121857625 = _Instance.GetHuman(h1_, h2_, h3_); - return result_121857625 != null ? Mapster.TypeAdapter.Adapt(result_121857625) : null; + return result_121857625 != null ? MapToInterface(result_121857625) : null; } public global::System.Collections.Generic.IList AddHuman(global::ProxyInterfaceSourceGeneratorTests.Source.IHuman h) { - global::ProxyInterfaceSourceGeneratorTests.Source.Human h_ = Mapster.TypeAdapter.Adapt(h); + global::ProxyInterfaceSourceGeneratorTests.Source.Human h_ = MapToInstance(h); var result_907493286 = _Instance.AddHuman(h_); - return Mapster.TypeAdapter.Adapt>(result_907493286); + return MapToInterface(result_907493286); } public void Void() diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Destination/System.TimeProviderProxy.g.cs b/tests/ProxyInterfaceSourceGeneratorTests/Destination/System.TimeProviderProxy.g.cs index 87471f2..d1b13b0 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Destination/System.TimeProviderProxy.g.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Destination/System.TimeProviderProxy.g.cs @@ -14,17 +14,22 @@ namespace ProxyInterfaceSourceGeneratorTests.Source { public partial class TimeProviderProxy : global::ProxyInterfaceSourceGeneratorTests.Source.ITimeProvider { - static TimeProviderProxy() + + private static global::ProxyInterfaceSourceGeneratorTests.Source.ITimeProvider MapToInterface(global::System.TimeProvider value) { - Mapster.TypeAdapterConfig.NewConfig().ConstructUsing(instance98737229 => new global::ProxyInterfaceSourceGeneratorTests.Source.TimeProviderProxy(instance98737229)); - Mapster.TypeAdapterConfig.NewConfig().MapWith(proxy_979750559 => ((global::ProxyInterfaceSourceGeneratorTests.Source.TimeProviderProxy) proxy_979750559)._Instance); + return new global::ProxyInterfaceSourceGeneratorTests.Source.TimeProviderProxy(value); + } + private static global::System.TimeProvider MapToInstance(global::ProxyInterfaceSourceGeneratorTests.Source.ITimeProvider value) + { + return value._Instance; } + public global::System.TimeProvider _Instance { get; } - public global::ProxyInterfaceSourceGeneratorTests.Source.ITimeProvider System { get => Mapster.TypeAdapter.Adapt(global::System.TimeProvider.System); } + public global::ProxyInterfaceSourceGeneratorTests.Source.ITimeProvider System { get => MapToInterface(global::System.TimeProvider.System); } public virtual global::System.TimeZoneInfo LocalTimeZone { get => _Instance.LocalTimeZone; } diff --git a/tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTest.GenerateFiles_ForClassWithArray_Should_GenerateCorrectFiles.verified.txt b/tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTest.GenerateFiles_ForClassWithArray_Should_GenerateCorrectFiles.verified.txt index f1e043e..e807e92 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTest.GenerateFiles_ForClassWithArray_Should_GenerateCorrectFiles.verified.txt +++ b/tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTest.GenerateFiles_ForClassWithArray_Should_GenerateCorrectFiles.verified.txt @@ -160,19 +160,40 @@ namespace ProxyInterfaceSourceGeneratorTests.Source static FooProxy() { Mapster.TypeAdapterConfig.NewConfig().ConstructUsing(instance2058774601 => new global::ProxyInterfaceSourceGeneratorTests.Source.FooProxy(instance2058774601)); - Mapster.TypeAdapterConfig.NewConfig().MapWith(proxy1662609081 => ((global::ProxyInterfaceSourceGeneratorTests.Source.FooProxy) proxy1662609081)._Instance); + Mapster.TypeAdapterConfig.NewConfig().MapWith(proxy2058774601 => proxy2058774601._Instance); } + private static global::ProxyInterfaceSourceGeneratorTests.Source.IFoo[] MapToInterface(global::ProxyInterfaceSourceGeneratorTests.Source.Foo[] value) + { + return Mapster.TypeAdapter.Adapt(value); + } + + private static global::ProxyInterfaceSourceGeneratorTests.Source.Foo[] MapToInstance(global::ProxyInterfaceSourceGeneratorTests.Source.IFoo[] value) + { + return Mapster.TypeAdapter.Adapt(value); + } + + private static global::ProxyInterfaceSourceGeneratorTests.Source.IFoo MapToInterface(global::ProxyInterfaceSourceGeneratorTests.Source.Foo value) + { + return new global::ProxyInterfaceSourceGeneratorTests.Source.FooProxy(value); + } + + private static global::ProxyInterfaceSourceGeneratorTests.Source.Foo MapToInstance(global::ProxyInterfaceSourceGeneratorTests.Source.IFoo value) + { + return value._Instance; + } + + public global::ProxyInterfaceSourceGeneratorTests.Source.Foo _Instance { get; } - public global::ProxyInterfaceSourceGeneratorTests.Source.IFoo[] Foos { get => Mapster.TypeAdapter.Adapt(_Instance.Foos); set => _Instance.Foos = Mapster.TypeAdapter.Adapt(value); } + public global::ProxyInterfaceSourceGeneratorTests.Source.IFoo[] Foos { get => MapToInterface(_Instance.Foos); set => _Instance.Foos = MapToInstance(value); } public global::ProxyInterfaceSourceGeneratorTests.Source.IFoo[] DoSomethingAndGetAnArrayOfFoos() { var result_1603865878 = _Instance.DoSomethingAndGetAnArrayOfFoos(); - return Mapster.TypeAdapter.Adapt(result_1603865878); + return MapToInterface(result_1603865878); } diff --git a/tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTest.GenerateFiles_ForClassWithIgnores.verified.txt b/tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTest.GenerateFiles_ForClassWithIgnores.verified.txt index a452d2c..5d6cfbd 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTest.GenerateFiles_ForClassWithIgnores.verified.txt +++ b/tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTest.GenerateFiles_ForClassWithIgnores.verified.txt @@ -162,19 +162,40 @@ namespace ProxyInterfaceSourceGeneratorTests.Source static Foo2Proxy() { Mapster.TypeAdapterConfig.NewConfig().ConstructUsing(instance1325374861 => new global::ProxyInterfaceSourceGeneratorTests.Source.Foo2Proxy(instance1325374861)); - Mapster.TypeAdapterConfig.NewConfig().MapWith(proxy1047178445 => ((global::ProxyInterfaceSourceGeneratorTests.Source.Foo2Proxy) proxy1047178445)._Instance); + Mapster.TypeAdapterConfig.NewConfig().MapWith(proxy1325374861 => proxy1325374861._Instance); } + private static global::ProxyInterfaceSourceGeneratorTests.Source.IFoo2[] MapToInterface(global::ProxyInterfaceSourceGeneratorTests.Source.Foo2[] value) + { + return Mapster.TypeAdapter.Adapt(value); + } + + private static global::ProxyInterfaceSourceGeneratorTests.Source.Foo2[] MapToInstance(global::ProxyInterfaceSourceGeneratorTests.Source.IFoo2[] value) + { + return Mapster.TypeAdapter.Adapt(value); + } + + private static global::ProxyInterfaceSourceGeneratorTests.Source.IFoo2 MapToInterface(global::ProxyInterfaceSourceGeneratorTests.Source.Foo2 value) + { + return new global::ProxyInterfaceSourceGeneratorTests.Source.Foo2Proxy(value); + } + + private static global::ProxyInterfaceSourceGeneratorTests.Source.Foo2 MapToInstance(global::ProxyInterfaceSourceGeneratorTests.Source.IFoo2 value) + { + return value._Instance; + } + + public global::ProxyInterfaceSourceGeneratorTests.Source.Foo2 _Instance { get; } - public global::ProxyInterfaceSourceGeneratorTests.Source.IFoo2[] Foos { get => Mapster.TypeAdapter.Adapt(_Instance.Foos); set => _Instance.Foos = Mapster.TypeAdapter.Adapt(value); } + public global::ProxyInterfaceSourceGeneratorTests.Source.IFoo2[] Foos { get => MapToInterface(_Instance.Foos); set => _Instance.Foos = MapToInstance(value); } public global::ProxyInterfaceSourceGeneratorTests.Source.IFoo2[] DoSomethingAndGetAnArrayOfFoos() { var result_1603865878 = _Instance.DoSomethingAndGetAnArrayOfFoos(); - return Mapster.TypeAdapter.Adapt(result_1603865878); + return MapToInterface(result_1603865878); } public int Weird2() diff --git a/tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTest.GenerateFiles_ForClassWithIgnores_Regex.verified.txt b/tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTest.GenerateFiles_ForClassWithIgnores_Regex.verified.txt index fb2a170..01572d0 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTest.GenerateFiles_ForClassWithIgnores_Regex.verified.txt +++ b/tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTest.GenerateFiles_ForClassWithIgnores_Regex.verified.txt @@ -160,19 +160,40 @@ namespace ProxyInterfaceSourceGeneratorTests.Source static Foo2Proxy() { Mapster.TypeAdapterConfig.NewConfig().ConstructUsing(instance1325374861 => new global::ProxyInterfaceSourceGeneratorTests.Source.Foo2Proxy(instance1325374861)); - Mapster.TypeAdapterConfig.NewConfig().MapWith(proxy1047178445 => ((global::ProxyInterfaceSourceGeneratorTests.Source.Foo2Proxy) proxy1047178445)._Instance); + Mapster.TypeAdapterConfig.NewConfig().MapWith(proxy1325374861 => proxy1325374861._Instance); } + private static global::ProxyInterfaceSourceGeneratorTests.Source.IFoo2[] MapToInterface(global::ProxyInterfaceSourceGeneratorTests.Source.Foo2[] value) + { + return Mapster.TypeAdapter.Adapt(value); + } + + private static global::ProxyInterfaceSourceGeneratorTests.Source.Foo2[] MapToInstance(global::ProxyInterfaceSourceGeneratorTests.Source.IFoo2[] value) + { + return Mapster.TypeAdapter.Adapt(value); + } + + private static global::ProxyInterfaceSourceGeneratorTests.Source.IFoo2 MapToInterface(global::ProxyInterfaceSourceGeneratorTests.Source.Foo2 value) + { + return new global::ProxyInterfaceSourceGeneratorTests.Source.Foo2Proxy(value); + } + + private static global::ProxyInterfaceSourceGeneratorTests.Source.Foo2 MapToInstance(global::ProxyInterfaceSourceGeneratorTests.Source.IFoo2 value) + { + return value._Instance; + } + + public global::ProxyInterfaceSourceGeneratorTests.Source.Foo2 _Instance { get; } - public global::ProxyInterfaceSourceGeneratorTests.Source.IFoo2[] Foos { get => Mapster.TypeAdapter.Adapt(_Instance.Foos); set => _Instance.Foos = Mapster.TypeAdapter.Adapt(value); } + public global::ProxyInterfaceSourceGeneratorTests.Source.IFoo2[] Foos { get => MapToInterface(_Instance.Foos); set => _Instance.Foos = MapToInstance(value); } public global::ProxyInterfaceSourceGeneratorTests.Source.IFoo2[] DoSomethingAndGetAnArrayOfFoos() { var result_1603865878 = _Instance.DoSomethingAndGetAnArrayOfFoos(); - return Mapster.TypeAdapter.Adapt(result_1603865878); + return MapToInterface(result_1603865878); } diff --git a/tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTest.cs b/tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTest.cs index 803f477..f1f7119 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTest.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTest.cs @@ -1,816 +1,862 @@ -using System.Runtime.CompilerServices; -using CSharp.SourceGenerators.Extensions; -using CSharp.SourceGenerators.Extensions.Models; -using FluentAssertions; -using ProxyInterfaceSourceGenerator; -using ProxyInterfaceSourceGeneratorTests.Helpers; -using ProxyInterfaceSourceGeneratorTests.Source; - -namespace ProxyInterfaceSourceGeneratorTests; - -[UsesVerify] -public class ProxyInterfaceSourceGeneratorTest -{ - [ModuleInitializer] - public static void ModuleInitializer() => VerifySourceGenerators.Enable(); - - private const bool Write = true; - - private readonly ProxyInterfaceCodeGenerator _sut; - private readonly string _basePath; - - public ProxyInterfaceSourceGeneratorTest() - { - _sut = new ProxyInterfaceCodeGenerator(); - _basePath = TestHelper.TestProjectRoot.Value; - } - - [Fact] - public void GenerateFiles_ForStruct_Should_Not_GenerateProxyCode() - { - // Arrange - var path = Path.Combine(_basePath, "Source/IMyStruct.cs"); - var sourceFile = new SourceFile - { - Path = path, - Text = File.ReadAllText(path), - AttributeToAddToInterface = new ExtraAttribute - { - Name = "ProxyInterfaceGenerator.Proxy", - ArgumentList = "typeof(ProxyInterfaceSourceGeneratorTests.Source.MyStruct)" - } - }; - - // Act - var result = _sut.Execute([sourceFile]); - - // Assert - result.Valid.Should().BeTrue(); - result.Files.Should().HaveCount(1); - } - - [Fact] - public Task GenerateFiles_ForClassWithArray_Should_GenerateCorrectFiles() - { - // Arrange - var fileNames = new[] - { - "ProxyInterfaceSourceGeneratorTests.Source.IFoo.g.cs", - "ProxyInterfaceSourceGeneratorTests.Source.FooProxy.g.cs" - }; - - var path = Path.Combine(_basePath, "Source/IFoo.cs"); - var sourceFile = new SourceFile - { - Path = path, - Text = File.ReadAllText(path), - AttributeToAddToInterface = new ExtraAttribute - { - Name = "ProxyInterfaceGenerator.Proxy", - ArgumentList = "typeof(ProxyInterfaceSourceGeneratorTests.Source.Foo)" - } - }; - - // Act - var result = _sut.Execute([ - sourceFile - ]); - - // Assert - result.Valid.Should().BeTrue(); - result.Files.Should().HaveCount(fileNames.Length + 1); - - // Verify - var results = result.GeneratorDriver.GetRunResult().Results.First().GeneratedSources; - return Verify(results); - } - - [Fact] - public void GenerateFiles_ForGenericType_Should_GenerateCorrectFiles() - { - // Arrange - var fileNames = new[] - { - "ProxyInterfaceSourceGeneratorTests.Source.IGeneric.g.cs", - "ProxyInterfaceSourceGeneratorTests.Source.Generic`1Proxy.g.cs" - }; - - var path = Path.Combine(_basePath, "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([ - 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); - - var destinationFilename = Path.Combine(_basePath, $"Destination/{fileName.fileName}"); - if (Write) File.WriteAllText(destinationFilename, builder.Text); - builder.Text.Should().Be(File.ReadAllText(destinationFilename)); - } - } - - [Fact] - public void GenerateFiles_ForÜberGenericType_Should_GenerateCorrectFiles() - { - // Arrange - var fileNames = new[] - { - "ProxyInterfaceSourceGeneratorTests.Source.IÜberGeneric.g.cs", - "ProxyInterfaceSourceGeneratorTests.Source.ÜberGeneric`3Proxy.g.cs" - }; - - var path = Path.Combine(_basePath, "Source/IÜberGeneric.cs"); - var sourceFile = new SourceFile - { - Path = path, - Text = File.ReadAllText(path), - AttributeToAddToInterface = new ExtraAttribute - { - Name = "ProxyInterfaceGenerator.Proxy", - ArgumentList = "typeof(ProxyInterfaceSourceGeneratorTests.Source.ÜberGeneric<>)" - } - }; - - // Act - var result = _sut.Execute([ - 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); - - var destinationFilename = Path.Combine(_basePath, $"Destination/{fileName.fileName}"); - if (Write) File.WriteAllText(destinationFilename, builder.Text); - builder.Text.Should().Be(File.ReadAllText(destinationFilename)); - } - } - - [Fact] - public void GenerateFiles_ForClassWithOperator_Should_GenerateCorrectFiles() - { - // Arrange - var fileNames = new[] - { - "ProxyInterfaceSourceGeneratorTests.Source.IOperatorTest.g.cs", - "ProxyInterfaceSourceGeneratorTests.Source.OperatorTestProxy.g.cs" - }; - - var path = Path.Combine(_basePath, "Source/IOperatorTest.cs"); - var sourceFile = new SourceFile - { - Path = path, - Text = File.ReadAllText(path), - AttributeToAddToInterface = new ExtraAttribute - { - Name = "ProxyInterfaceGenerator.Proxy", - ArgumentList = "typeof(ProxyInterfaceSourceGeneratorTests.Source.OperatorTest)" - } - }; - - // Act - var result = _sut.Execute([ - 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); - - var destinationFilename = Path.Combine(_basePath, $"Destination/{fileName.fileName}"); - if (Write) File.WriteAllText(destinationFilename, builder.Text); - builder.Text.Should().Be(File.ReadAllText(destinationFilename)); - } - - var name = "stef"; - var operatorTest = new OperatorTest - { - Name = name - }; - string name1 = (string)operatorTest; - name1.Should().Be(name); - - var p = new OperatorTestProxy(operatorTest); - string name2 = (string)p; - name2.Should().Be(name); - - var p2 = (OperatorTestProxy)name; - p2.Should().BeEquivalentTo(new OperatorTestProxy(operatorTest)); - } - - [Fact] - public void GenerateFiles_When_NoNamespace_Should_GenerateCorrectFiles() - { - // Arrange - var fileNames = new[] - { - "INoNamespace.g.cs", - "NoNamespaceProxy.g.cs" - }; - - var path = Path.Combine(_basePath, "Source/INoNamespace.cs"); - var sourceFile = new SourceFile - { - Path = path, - Text = File.ReadAllText(path), - AttributeToAddToInterface = new ExtraAttribute - { - Name = "ProxyInterfaceGenerator.Proxy", - ArgumentList = "typeof(ProxyInterfaceSourceGeneratorTests.Source.NoNamespace)" - } - }; - - // Act - var result = _sut.Execute([ - 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); - - var destinationFilename = Path.Combine(_basePath, $"Destination/{fileName.fileName}"); - if (Write) File.WriteAllText(destinationFilename, builder.Text); - builder.Text.Should().Be(File.ReadAllText(destinationFilename)); - } - } - - [Fact] - public void GenerateFiles_When_MixedVisibility_Should_GenerateCorrectFiles() - { - // Arrange - var fileNames = new[] - { - "ProxyInterfaceSourceGeneratorTests.Source.IMixedVisibility.g.cs", - "ProxyInterfaceSourceGeneratorTests.Source.MixedVisibilityProxy.g.cs" - }; - - var path = Path.Combine(_basePath, "Source/IMixedVisibility.cs"); - var sourceFile = new SourceFile - { - Path = path, - Text = File.ReadAllText(path), - AttributeToAddToInterface = new ExtraAttribute - { - Name = "ProxyInterfaceGenerator.Proxy", - ArgumentList = "typeof(ProxyInterfaceSourceGeneratorTests.Source.MixedVisibility)" - } - }; - - // Act - var result = _sut.Execute([ - 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); - - var destinationFilename = Path.Combine(_basePath, $"Destination/{fileName.fileName}"); - if (Write) File.WriteAllText(destinationFilename, builder.Text); - builder.Text.Should().Be(File.ReadAllText(destinationFilename)); - } - } - - [Fact] - public void GenerateFiles_ForSingleClass_Should_GenerateCorrectFiles() - { - // Arrange - var fileNames = new[] - { - "ProxyInterfaceGenerator.Extra.g.cs", - "ProxyInterfaceSourceGeneratorTests.Source.IPersonExtends.g.cs", - "ProxyInterfaceSourceGeneratorTests.Source.PersonExtendsProxy.g.cs", - }; - - var path = Path.Combine(_basePath, "Source", "IPersonExtends.cs"); - var sourceFile = new SourceFile - { - Path = path, - Text = File.ReadAllText(path), - AttributeToAddToInterface = new ExtraAttribute - { - Name = "ProxyInterfaceGenerator.Proxy", - ArgumentList = new[] { "typeof(ProxyInterfaceSourceGeneratorTests.Source.PersonExtends)", "true" } - } - }; - - // Act - var result = _sut.Execute([sourceFile]); - - // Assert - Assert(result, fileNames, false); - } - - [Fact] - public void GenerateFiles_ForSingleClass_AsInternal_Should_GenerateCorrectFiles() - { - // Arrange - var interfaceFilename = "ProxyInterfaceSourceGeneratorTests.Source.ITestClassInternal.g.cs"; - var proxyClassFilename = "ProxyInterfaceSourceGeneratorTests.Source.TestClassInternalProxy.g.cs"; - - var path = Path.Combine(_basePath, "Source", "ITestClassInternal.cs"); - var sourceFile = new SourceFile - { - Path = path, - Text = File.ReadAllText(path), - AttributeToAddToInterface = new ExtraAttribute - { - Name = "ProxyInterfaceGenerator.Proxy", - ArgumentList = new[] { "typeof(ProxyInterfaceSourceGeneratorTests.Source.TestClassInternal)", "ProxyClassAccessibility.Internal" } - } - }; - - // Act - var result = _sut.Execute([sourceFile]); - - // Assert - result.Valid.Should().BeTrue(); - result.Files.Should().HaveCount(3); - - // Assert interface - var @interface = result.Files[1].SyntaxTree; - @interface.FilePath.Should().EndWith(interfaceFilename); - - var interfaceCode = @interface.ToString(); - var interfaceCodeFilename = Path.Combine(_basePath, "Destination", interfaceFilename); - if (Write) File.WriteAllText(interfaceCodeFilename, interfaceCode); - interfaceCode.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText(interfaceCodeFilename)); - - // Assert Proxy - var proxyClass = result.Files[2].SyntaxTree; - proxyClass.FilePath.Should().EndWith(proxyClassFilename); - - var proxyCode = proxyClass.ToString(); - var proxyCodeFilename = Path.Combine(_basePath, "Destination", proxyClassFilename); - if (Write) File.WriteAllText(proxyCodeFilename, proxyCode); - proxyCode.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText(proxyCodeFilename)); - } - - [Fact] - public void GenerateFiles_ForTwoClasses_Should_GenerateCorrectFiles() - { - // Arrange - var attributeFilename = "ProxyInterfaceGenerator.Extra.g.cs"; - var interfaceHumanFilename = "ProxyInterfaceSourceGeneratorTests.Source.IHuman.g.cs"; - var proxyClassHumanFilename = "ProxyInterfaceSourceGeneratorTests.Source.HumanProxy.g.cs"; - var interfacePersonFilename = "ProxyInterfaceSourceGeneratorTests.Source.IPerson.g.cs"; - var proxyClassPersonFilename = "ProxyInterfaceSourceGeneratorTests.Source.PersonProxy.g.cs"; - - var pathHuman = Path.Combine(_basePath, "Source", "IHuman.cs"); - var sourceFileHuman = new SourceFile - { - Path = pathHuman, - Text = File.ReadAllText(pathHuman), - AttributeToAddToInterface = "ProxyInterfaceGenerator.Proxy" - }; - - var pathPerson = Path.Combine(_basePath, "Source", "IPerson.cs"); - var sourceFilePerson = new SourceFile - { - Path = pathPerson, - Text = File.ReadAllText(pathPerson), - AttributeToAddToInterface = new ExtraAttribute - { - Name = "ProxyInterfaceGenerator.Proxy", - ArgumentList = "typeof(ProxyInterfaceSourceGeneratorTests.Source.Person)" - } - }; - - // Act - var result = _sut.Execute([sourceFileHuman, sourceFilePerson]); - - // Assert - result.Valid.Should().BeTrue(); - result.WarningMessages.Should().BeEmpty(); - result.Files.Should().HaveCount(5); - - // Assert attribute - var attribute = result.Files[0].SyntaxTree; - attribute.FilePath.Should().EndWith(attributeFilename); - - - // Assert interface Human - var interfaceHuman = result.Files[1].SyntaxTree; - interfaceHuman.FilePath.Should().EndWith(interfaceHumanFilename); - - var interfaceCodeHuman = interfaceHuman.ToString(); - var interfaceCodeHumanFilename = Path.Combine(_basePath, "Destination", interfaceHumanFilename); - if (Write) File.WriteAllText(interfaceCodeHumanFilename, interfaceCodeHuman); - interfaceCodeHuman.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText(interfaceCodeHumanFilename)); - - - // Assert interface Person - var interfacePerson = result.Files[2].SyntaxTree; - interfacePerson.FilePath.Should().EndWith(interfacePersonFilename); - - var interfaceCodePerson = interfacePerson.ToString(); - var interfaceCodePersonFilename = Path.Combine(_basePath, "Destination", interfacePersonFilename); - if (Write) File.WriteAllText(interfaceCodePersonFilename, interfaceCodePerson); - interfaceCodePerson.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText(interfaceCodePersonFilename)); - - - // Assert Proxy Human - var proxyClassHuman = result.Files[3].SyntaxTree; - proxyClassHuman.FilePath.Should().EndWith(proxyClassHumanFilename); - - var proxyCodeHuman = proxyClassHuman.ToString(); - var proxyCodeHumanFilename = Path.Combine(_basePath, "Destination", proxyClassHumanFilename); - if (Write) File.WriteAllText(proxyCodeHumanFilename, proxyCodeHuman); - proxyCodeHuman.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText(proxyCodeHumanFilename)); - - - // Assert Proxy Person - var proxyClassPerson = result.Files[4].SyntaxTree; - proxyClassPerson.FilePath.Should().EndWith(proxyClassPersonFilename); - - var proxyCode = proxyClassPerson.ToString(); - var proxyCodeFilename = Path.Combine(_basePath, "Destination", proxyClassPersonFilename); - if (Write) File.WriteAllText(proxyCodeFilename, proxyCode); - proxyCode.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText(proxyCodeFilename)); - - var personProxy = new PersonProxy(new Person()); - - int c = 100; - personProxy.In_Out_Ref1(1, out _, ref c); - - c.Should().Be(101); - } - - [Fact] - public void GenerateFiles_ForTwoClassesSameName_Should_GenerateCorrectFiles() - { - // Arrange - var attributeFilename = "ProxyInterfaceGenerator.Extra.g.cs"; - - var sourceFiles = new List(); - - var list = new[] - { - (IF: "", INS: "ProxyInterfaceDemo", I: "IGroup", CF: "", CNS: "ProxyInterfaceDemo", C: "Group"), - (IF: "", INS: "ProxyInterfaceDemo", I: "IDisplayable", CF: "", CNS: "ProxyInterfaceDemo", C: "Displayable"), - (IF: "", INS: "ProxyInterfaceDemo", I: "IDestroyable", CF: "", CNS: "ProxyInterfaceDemo", C: "Destroyable"), - (IF: "Depth/", INS: "ProxyInterfaceDemo.Depth", I: "IGroupDepth", CF: "Depth/", CNS: "ProxyInterfaceDemo.Depth", C: "Group") - }; - - foreach (var x in list) - { - var pathInterface = Path.Combine(_basePath, "Source", $"{x.IF}{x.I}.cs"); - var sourceFile = new SourceFile - { - Path = pathInterface, - Text = File.ReadAllText(pathInterface), - AttributeToAddToInterface = new ExtraAttribute - { - Name = "ProxyInterfaceGenerator.Proxy", - ArgumentList = $"typeof({x.CNS}.{x.C})" - } - }; - sourceFiles.Add(sourceFile); - } - - // Act - var result = _sut.Execute(sourceFiles); - - // Assert - result.Valid.Should().BeTrue(); - result.Files.Should().HaveCount(1 + list.Length * 2); - - // Assert attribute - var attribute = result.Files[0].SyntaxTree; - attribute.FilePath.Should().EndWith(attributeFilename); - - var fileIndex = 1; - - // Interfaces - foreach (var x in list) - { - var filenameInterface = $"{x.INS}.{x.I}.g.cs"; - var syntaxTreeInterface = result.Files[fileIndex].SyntaxTree; - syntaxTreeInterface.FilePath.Should().EndWith(filenameInterface); - - var codeInterface = syntaxTreeInterface.ToString(); - var path = Path.Combine(_basePath, "Destination", $"{x.IF}{filenameInterface}"); - if (Write) File.WriteAllText(path, codeInterface); - codeInterface.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText(path)); - - fileIndex += 1; - } - - // Proxies - foreach (var x in list) - { - var filenameProxy = $"{x.CNS}.{x.C}Proxy.g.cs"; - var syntaxTreeProxy = result.Files[fileIndex].SyntaxTree; - syntaxTreeProxy.FilePath.Should().EndWith(filenameProxy); - - var codeProxy = syntaxTreeProxy.ToString(); - var path = Path.Combine(_basePath, "Destination", $"{x.CF}{filenameProxy}"); - if (Write) File.WriteAllText(path, codeProxy); - codeProxy.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText(path)); - - fileIndex += 1; - } - } - - [Fact] - public void GenerateFiles_HttpClient() - { - // Arrange - var attributeFilename = "ProxyInterfaceGenerator.Extra.g.cs"; - var interfaceIHttpClientFilename = "ProxyInterfaceSourceGeneratorTests.Source.IHttpClient.g.cs"; - var proxyClassIHttpClientFilename = "System.Net.Http.HttpClientProxy.g.cs"; - var interfaceIHttpMessageInvokerFilename = "ProxyInterfaceSourceGeneratorTests.Source.IHttpMessageInvoker.g.cs"; - var proxyClassIHttpMessageInvokerFilename = "System.Net.Http.HttpMessageInvokerProxy.g.cs"; - - var pathIHttpClient = Path.Combine(_basePath, "Source", "IHttpClient.cs"); - var sourceFileIHttpClient = new SourceFile - { - Path = pathIHttpClient, - Text = File.ReadAllText(pathIHttpClient), - AttributeToAddToInterface = new ExtraAttribute - { - Name = "ProxyInterfaceGenerator.Proxy", - ArgumentList = "typeof(System.Net.Http.HttpClient)" - } - }; - - var pathIHttpMessageInvoker = Path.Combine(_basePath, "Source", "IHttpMessageInvoker.cs"); - var sourceFileIHttpMessageInvoker = new SourceFile - { - Path = pathIHttpMessageInvoker, - Text = File.ReadAllText(pathIHttpMessageInvoker), - AttributeToAddToInterface = new ExtraAttribute - { - Name = "ProxyInterfaceGenerator.Proxy", - ArgumentList = "typeof(System.Net.Http.HttpMessageInvoker)" - } - }; - - // Act - var result = _sut.Execute([sourceFileIHttpClient, sourceFileIHttpMessageInvoker]); - - // Assert - result.Valid.Should().BeTrue(); - result.Files.Should().HaveCount(5); - - // Assert attribute - var attribute = result.Files[0].SyntaxTree; - attribute.FilePath.Should().EndWith(attributeFilename); - - - // Assert interface IHttpClient - var interfaceIHttpClient = result.Files[1].SyntaxTree; - interfaceIHttpClient.FilePath.Should().EndWith(interfaceIHttpClientFilename); - - var interfaceCodeIHttpClient = interfaceIHttpClient.ToString(); - var interfaceCodeIHttpClientFilename = Path.Combine(_basePath, "Destination", interfaceIHttpClientFilename); - if (Write) File.WriteAllText(interfaceCodeIHttpClientFilename, interfaceCodeIHttpClient); - interfaceCodeIHttpClient.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText(interfaceCodeIHttpClientFilename)); - - - // Assert interface IHttpMessageInvoker - var interfaceIMessageInvoker = result.Files[2].SyntaxTree; - interfaceIMessageInvoker.FilePath.Should().EndWith(interfaceIHttpMessageInvokerFilename); - - var interfaceCodeIMessageInvoker = interfaceIMessageInvoker.ToString(); - var interfaceCodeIMessageInvokerFilename = Path.Combine(_basePath, "Destination", interfaceIHttpMessageInvokerFilename); - if (Write) File.WriteAllText(interfaceCodeIMessageInvokerFilename, interfaceCodeIMessageInvoker); - interfaceCodeIMessageInvoker.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText(interfaceCodeIMessageInvokerFilename)); - - - // Assert Proxy IHttpClient - var proxyClassIHttpClient = result.Files[3].SyntaxTree; - proxyClassIHttpClient.FilePath.Should().EndWith(proxyClassIHttpClientFilename); - - var proxyCodeIHttpClient = proxyClassIHttpClient.ToString(); - var proxyCodeIHttpClientFilename = Path.Combine(_basePath, "Destination", proxyClassIHttpClientFilename); - if (Write) File.WriteAllText(proxyCodeIHttpClientFilename, proxyCodeIHttpClient); - proxyCodeIHttpClient.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText(proxyCodeIHttpClientFilename)); - - - // Assert Proxy IHttpMessageInvoker - var proxyClassIMessageInvoker = result.Files[4].SyntaxTree; - proxyClassIMessageInvoker.FilePath.Should().EndWith(proxyClassIHttpMessageInvokerFilename); - - var proxyIMessageInvoker = proxyClassIMessageInvoker.ToString(); - var proxyIMessageInvokerFilename = Path.Combine(_basePath, "Destination", proxyClassIHttpMessageInvokerFilename); - if (Write) File.WriteAllText(proxyIMessageInvokerFilename, proxyIMessageInvoker); - proxyIMessageInvoker.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText(proxyIMessageInvokerFilename)); - } - - [Fact] - public void GenerateFiles_ForClassWithSameName_But_DifferentNamespace_Should_GenerateCorrectFiles() - { - // Arrange - const string @class = "ClassInNamespace"; - foreach (var x in new[] { 1, 2 }) - { - var attributeFilename = "ProxyInterfaceGenerator.Extra.g.cs"; - var interfaceFilename = $"ProxyInterfaceSourceGeneratorTests.Namespace{x}.I{@class}.g.cs"; - var proxyClassFilename = $"ProxyInterfaceSourceGeneratorTests.Namespace{x}.{@class}Proxy.g.cs"; - - var path = Path.Combine(_basePath, "Source", $"I{@class}{x}.cs"); - var sourceFile = new SourceFile - { - Path = path, - Text = File.ReadAllText(path), - AttributeToAddToInterface = new ExtraAttribute - { - Name = "ProxyInterfaceGenerator.Proxy", - ArgumentList = new[] { $"typeof(ProxyInterfaceSourceGeneratorTests.Namespace{x}.{@class})", "true" } - } - }; - - // Act - var result = _sut.Execute([sourceFile]); - - // Assert - result.Valid.Should().BeTrue(); - result.Files.Should().HaveCount(3); - - // Assert attribute - var attribute = result.Files[0].SyntaxTree; - attribute.FilePath.Should().EndWith(attributeFilename); - - // Assert interface - var @interface = result.Files[1].SyntaxTree; - @interface.FilePath.Should().EndWith(interfaceFilename); - - var interfaceCode = @interface.ToString(); - var interfaceCodeFilename = Path.Combine(_basePath, "Destination", interfaceFilename); - if (Write) File.WriteAllText(interfaceCodeFilename, interfaceCode); - interfaceCode.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText(interfaceCodeFilename)); - - // Assert Proxy - var proxyClass = result.Files[2].SyntaxTree; - proxyClass.FilePath.Should().EndWith(proxyClassFilename); - - var proxyCode = proxyClass.ToString(); - var proxyCodeFilename = Path.Combine(_basePath, "Destination", proxyClassFilename); - if (Write) File.WriteAllText(proxyCodeFilename, proxyCode); - proxyCode.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText(proxyCodeFilename)); - } - } - - [Fact] - public Task GenerateFiles_ForClassWithIgnores() - { - // Arrange - var fileNames = new[] - { - "ProxyInterfaceSourceGeneratorTests.Source.IFoo2.g.cs", - "ProxyInterfaceSourceGeneratorTests.Source.Foo2Proxy.g.cs" - }; - - var path = Path.Combine(_basePath, "Source/IFoo2.cs"); - var sourceFile = new SourceFile - { - Path = path, - Text = File.ReadAllText(path), - AttributeToAddToInterface = new ExtraAttribute - { - Name = "ProxyInterfaceGenerator.Proxy", - ArgumentList = new[] - { - "typeof(ProxyInterfaceSourceGeneratorTests.Source.Foo2)", "false", "ProxyClassAccessibility.Public", - "new [] { \"Weird\", \"NotHere\" }" - } - } - }; - - // Act - var result = _sut.Execute([sourceFile]); - - // Assert - result.Valid.Should().BeTrue(); - result.Files.Should().HaveCount(fileNames.Length + 1); - - // Verify - var results = result.GeneratorDriver.GetRunResult().Results.First().GeneratedSources; - return Verify(results); - } - - [Fact] - public Task GenerateFiles_ForClassWithIgnores_Regex() - { - // Arrange - var fileNames = new[] - { - "ProxyInterfaceSourceGeneratorTests.Source.IFoo2.g.cs", - "ProxyInterfaceSourceGeneratorTests.Source.Foo2Proxy.g.cs" - }; - - var path = Path.Combine(_basePath, "Source/IFoo2.cs"); - var sourceFile = new SourceFile - { - Path = path, - Text = File.ReadAllText(path), - AttributeToAddToInterface = new ExtraAttribute - { - Name = "ProxyInterfaceGenerator.Proxy", - ArgumentList = new[] - { - "typeof(ProxyInterfaceSourceGeneratorTests.Source.Foo2)", "false", "ProxyClassAccessibility.Public", - "new [] { \"Weird*\" }" - } - } - }; - - // Act - var result = _sut.Execute([sourceFile]); - - // Assert - result.Valid.Should().BeTrue(); - result.Files.Should().HaveCount(fileNames.Length + 1); - - // Verify - var results = result.GeneratorDriver.GetRunResult().Results.First().GeneratedSources; - return Verify(results); - } - - [Fact] - public void GenerateFiles_ForTimeProvider_Should_GenerateCorrectFiles() - { - // Arrange - var fileNames = new[] - { - "ProxyInterfaceSourceGeneratorTests.Source.ITimeProvider.g.cs", - "System.TimeProviderProxy.g.cs" - }; - - var path = Path.Combine(_basePath, "Source/ITimeProvider.cs"); - var sourceFile = new SourceFile - { - Path = path, - Text = File.ReadAllText(path), - AttributeToAddToInterface = new ExtraAttribute - { - Name = "ProxyInterfaceGenerator.Proxy", - ArgumentList = "typeof(System.TimeProvider)" - } - }; - - // Act - var result = _sut.Execute([sourceFile]); - - // Assert - Assert(result, fileNames); - } - - private void Assert(ExecuteResult result, string[] fileNames, bool skipExtra = true) - { - var skip = skipExtra ? 1 : 0; - - result.Valid.Should().BeTrue(); - result.Files.Should().HaveCount(fileNames.Length + skip); - - foreach (var fileName in fileNames.Select((fileName, index) => new { fileName, index })) - { - var builder = result.Files[fileName.index + skip]; // +1 means skip the attribute - builder.Path.Should().EndWith(fileName.fileName); - - var destinationFilename = Path.Combine(_basePath, $"Destination/{fileName.fileName}"); - if (Write) File.WriteAllText(destinationFilename, builder.Text); - builder.Text.Should().Be(File.ReadAllText(destinationFilename)); - } - } +using System.Runtime.CompilerServices; +using CSharp.SourceGenerators.Extensions; +using CSharp.SourceGenerators.Extensions.Models; +using FluentAssertions; +using ProxyInterfaceSourceGenerator; +using ProxyInterfaceSourceGeneratorTests.Helpers; +using ProxyInterfaceSourceGeneratorTests.Source; + +namespace ProxyInterfaceSourceGeneratorTests; + +[UsesVerify] +public class ProxyInterfaceSourceGeneratorTest +{ + [ModuleInitializer] + public static void ModuleInitializer() => VerifySourceGenerators.Enable(); + + private const bool Write = true; + + private readonly ProxyInterfaceCodeGenerator _sut; + private readonly string _basePath; + + public ProxyInterfaceSourceGeneratorTest() + { + _sut = new ProxyInterfaceCodeGenerator(); + _basePath = TestHelper.TestProjectRoot.Value; + } + + [Fact] + public void GenerateFiles_ForStruct_Should_Not_GenerateProxyCode() + { + // Arrange + var path = Path.Combine(_basePath, "Source/IMyStruct.cs"); + var sourceFile = new SourceFile + { + Path = path, + Text = File.ReadAllText(path), + AttributeToAddToInterface = new ExtraAttribute + { + Name = "ProxyInterfaceGenerator.Proxy", + ArgumentList = "typeof(ProxyInterfaceSourceGeneratorTests.Source.MyStruct)" + } + }; + + // Act + var result = _sut.Execute([sourceFile]); + + // Assert + result.Valid.Should().BeTrue(); + result.Files.Should().HaveCount(1); + } + + [Fact] + public Task GenerateFiles_ForClassWithArray_Should_GenerateCorrectFiles() + { + // Arrange + var fileNames = new[] + { + "ProxyInterfaceSourceGeneratorTests.Source.IFoo.g.cs", + "ProxyInterfaceSourceGeneratorTests.Source.FooProxy.g.cs" + }; + + var path = Path.Combine(_basePath, "Source/IFoo.cs"); + var sourceFile = new SourceFile + { + Path = path, + Text = File.ReadAllText(path), + AttributeToAddToInterface = new ExtraAttribute + { + Name = "ProxyInterfaceGenerator.Proxy", + ArgumentList = "typeof(ProxyInterfaceSourceGeneratorTests.Source.Foo)" + } + }; + + // Act + var result = _sut.Execute([ + sourceFile + ]); + + // Assert + result.Valid.Should().BeTrue(); + result.Files.Should().HaveCount(fileNames.Length + 1); + + // Verify + var results = result.GeneratorDriver.GetRunResult().Results.First().GeneratedSources; + return Verify(results); + } + + [Fact] + public void GenerateFiles_ForGenericType_Should_GenerateCorrectFiles() + { + // Arrange + var fileNames = new[] + { + "ProxyInterfaceSourceGeneratorTests.Source.IGeneric.g.cs", + "ProxyInterfaceSourceGeneratorTests.Source.Generic`1Proxy.g.cs" + }; + + var path = Path.Combine(_basePath, "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([ + 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); + + var destinationFilename = Path.Combine(_basePath, $"Destination/{fileName.fileName}"); + if (Write) File.WriteAllText(destinationFilename, builder.Text); + builder.Text.Should().Be(File.ReadAllText(destinationFilename)); + } + } + + [Fact] + public void GenerateFiles_ForÜberGenericType_Should_GenerateCorrectFiles() + { + // Arrange + var fileNames = new[] + { + "ProxyInterfaceSourceGeneratorTests.Source.IÜberGeneric.g.cs", + "ProxyInterfaceSourceGeneratorTests.Source.ÜberGeneric`3Proxy.g.cs" + }; + + var path = Path.Combine(_basePath, "Source/IÜberGeneric.cs"); + var sourceFile = new SourceFile + { + Path = path, + Text = File.ReadAllText(path), + AttributeToAddToInterface = new ExtraAttribute + { + Name = "ProxyInterfaceGenerator.Proxy", + ArgumentList = "typeof(ProxyInterfaceSourceGeneratorTests.Source.ÜberGeneric<>)" + } + }; + + // Act + var result = _sut.Execute([ + 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); + + var destinationFilename = Path.Combine(_basePath, $"Destination/{fileName.fileName}"); + if (Write) File.WriteAllText(destinationFilename, builder.Text); + builder.Text.Should().Be(File.ReadAllText(destinationFilename)); + } + } + + [Fact] + public void GenerateFiles_ForClassWithOperator_Should_GenerateCorrectFiles() + { + // Arrange + var fileNames = new[] + { + "ProxyInterfaceSourceGeneratorTests.Source.IOperatorTest.g.cs", + "ProxyInterfaceSourceGeneratorTests.Source.OperatorTestProxy.g.cs" + }; + + var path = Path.Combine(_basePath, "Source/IOperatorTest.cs"); + var sourceFile = new SourceFile + { + Path = path, + Text = File.ReadAllText(path), + AttributeToAddToInterface = new ExtraAttribute + { + Name = "ProxyInterfaceGenerator.Proxy", + ArgumentList = "typeof(ProxyInterfaceSourceGeneratorTests.Source.OperatorTest)" + } + }; + + // Act + var result = _sut.Execute([ + 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); + + var destinationFilename = Path.Combine(_basePath, $"Destination/{fileName.fileName}"); + if (Write) File.WriteAllText(destinationFilename, builder.Text); + builder.Text.Should().Be(File.ReadAllText(destinationFilename)); + } + + var name = "stef"; + var operatorTest = new OperatorTest + { + Name = name + }; + string name1 = (string)operatorTest; + name1.Should().Be(name); + + var p = new OperatorTestProxy(operatorTest); + string name2 = (string)p; + name2.Should().Be(name); + + var p2 = (OperatorTestProxy)name; + p2.Should().BeEquivalentTo(new OperatorTestProxy(operatorTest)); + } + + [Fact] + public void GenerateFiles_When_NoNamespace_Should_GenerateCorrectFiles() + { + // Arrange + var fileNames = new[] + { + "INoNamespace.g.cs", + "NoNamespaceProxy.g.cs" + }; + + var path = Path.Combine(_basePath, "Source/INoNamespace.cs"); + var sourceFile = new SourceFile + { + Path = path, + Text = File.ReadAllText(path), + AttributeToAddToInterface = new ExtraAttribute + { + Name = "ProxyInterfaceGenerator.Proxy", + ArgumentList = "typeof(ProxyInterfaceSourceGeneratorTests.Source.NoNamespace)" + } + }; + + // Act + var result = _sut.Execute([ + 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); + + var destinationFilename = Path.Combine(_basePath, $"Destination/{fileName.fileName}"); + if (Write) File.WriteAllText(destinationFilename, builder.Text); + builder.Text.Should().Be(File.ReadAllText(destinationFilename)); + } + } + + [Fact] + public void GenerateFiles_When_MixedVisibility_Should_GenerateCorrectFiles() + { + // Arrange + var fileNames = new[] + { + "ProxyInterfaceSourceGeneratorTests.Source.IMixedVisibility.g.cs", + "ProxyInterfaceSourceGeneratorTests.Source.MixedVisibilityProxy.g.cs" + }; + + var path = Path.Combine(_basePath, "Source/IMixedVisibility.cs"); + var sourceFile = new SourceFile + { + Path = path, + Text = File.ReadAllText(path), + AttributeToAddToInterface = new ExtraAttribute + { + Name = "ProxyInterfaceGenerator.Proxy", + ArgumentList = "typeof(ProxyInterfaceSourceGeneratorTests.Source.MixedVisibility)" + } + }; + + // Act + var result = _sut.Execute([ + 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); + + var destinationFilename = Path.Combine(_basePath, $"Destination/{fileName.fileName}"); + if (Write) File.WriteAllText(destinationFilename, builder.Text); + builder.Text.Should().Be(File.ReadAllText(destinationFilename)); + } + } + + [Fact] + public void GenerateFiles_ForSingleClass_Should_GenerateCorrectFiles() + { + // Arrange + var fileNames = new[] + { + "ProxyInterfaceGenerator.Extra.g.cs", + "ProxyInterfaceSourceGeneratorTests.Source.IPersonExtends.g.cs", + "ProxyInterfaceSourceGeneratorTests.Source.PersonExtendsProxy.g.cs", + }; + + var path = Path.Combine(_basePath, "Source", "IPersonExtends.cs"); + var sourceFile = new SourceFile + { + Path = path, + Text = File.ReadAllText(path), + AttributeToAddToInterface = new ExtraAttribute + { + Name = "ProxyInterfaceGenerator.Proxy", + ArgumentList = new[] { "typeof(ProxyInterfaceSourceGeneratorTests.Source.PersonExtends)", "true" } + } + }; + + // Act + var result = _sut.Execute([sourceFile]); + + // Assert + Assert(result, fileNames, false); + } + + [Fact] + public void GenerateFiles_ForSingleClass_AsInternal_Should_GenerateCorrectFiles() + { + // Arrange + var interfaceFilename = "ProxyInterfaceSourceGeneratorTests.Source.ITestClassInternal.g.cs"; + var proxyClassFilename = "ProxyInterfaceSourceGeneratorTests.Source.TestClassInternalProxy.g.cs"; + + var path = Path.Combine(_basePath, "Source", "ITestClassInternal.cs"); + var sourceFile = new SourceFile + { + Path = path, + Text = File.ReadAllText(path), + AttributeToAddToInterface = new ExtraAttribute + { + Name = "ProxyInterfaceGenerator.Proxy", + ArgumentList = new[] { "typeof(ProxyInterfaceSourceGeneratorTests.Source.TestClassInternal)", "ProxyClassAccessibility.Internal" } + } + }; + + // Act + var result = _sut.Execute([sourceFile]); + + // Assert + result.Valid.Should().BeTrue(); + result.Files.Should().HaveCount(3); + + // Assert interface + var @interface = result.Files[1].SyntaxTree; + @interface.FilePath.Should().EndWith(interfaceFilename); + + var interfaceCode = @interface.ToString(); + var interfaceCodeFilename = Path.Combine(_basePath, "Destination", interfaceFilename); + if (Write) File.WriteAllText(interfaceCodeFilename, interfaceCode); + interfaceCode.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText(interfaceCodeFilename)); + + // Assert Proxy + var proxyClass = result.Files[2].SyntaxTree; + proxyClass.FilePath.Should().EndWith(proxyClassFilename); + + var proxyCode = proxyClass.ToString(); + var proxyCodeFilename = Path.Combine(_basePath, "Destination", proxyClassFilename); + if (Write) File.WriteAllText(proxyCodeFilename, proxyCode); + proxyCode.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText(proxyCodeFilename)); + } + + [Fact] + public void GenerateFiles_ForTwoClasses_Should_GenerateCorrectFiles() + { + // Arrange + var attributeFilename = "ProxyInterfaceGenerator.Extra.g.cs"; + var interfaceHumanFilename = "ProxyInterfaceSourceGeneratorTests.Source.IHuman.g.cs"; + var proxyClassHumanFilename = "ProxyInterfaceSourceGeneratorTests.Source.HumanProxy.g.cs"; + var interfacePersonFilename = "ProxyInterfaceSourceGeneratorTests.Source.IPerson.g.cs"; + var proxyClassPersonFilename = "ProxyInterfaceSourceGeneratorTests.Source.PersonProxy.g.cs"; + + var pathHuman = Path.Combine(_basePath, "Source", "IHuman.cs"); + var sourceFileHuman = new SourceFile + { + Path = pathHuman, + Text = File.ReadAllText(pathHuman), + AttributeToAddToInterface = "ProxyInterfaceGenerator.Proxy" + }; + + var pathPerson = Path.Combine(_basePath, "Source", "IPerson.cs"); + var sourceFilePerson = new SourceFile + { + Path = pathPerson, + Text = File.ReadAllText(pathPerson), + AttributeToAddToInterface = new ExtraAttribute + { + Name = "ProxyInterfaceGenerator.Proxy", + ArgumentList = "typeof(ProxyInterfaceSourceGeneratorTests.Source.Person)" + } + }; + + // Act + var result = _sut.Execute([sourceFileHuman, sourceFilePerson]); + + // Assert + result.Valid.Should().BeTrue(); + result.WarningMessages.Should().BeEmpty(); + result.Files.Should().HaveCount(5); + + // Assert attribute + var attribute = result.Files[0].SyntaxTree; + attribute.FilePath.Should().EndWith(attributeFilename); + + + // Assert interface Human + var interfaceHuman = result.Files[1].SyntaxTree; + interfaceHuman.FilePath.Should().EndWith(interfaceHumanFilename); + + var interfaceCodeHuman = interfaceHuman.ToString(); + var interfaceCodeHumanFilename = Path.Combine(_basePath, "Destination", interfaceHumanFilename); + if (Write) File.WriteAllText(interfaceCodeHumanFilename, interfaceCodeHuman); + interfaceCodeHuman.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText(interfaceCodeHumanFilename)); + + + // Assert interface Person + var interfacePerson = result.Files[2].SyntaxTree; + interfacePerson.FilePath.Should().EndWith(interfacePersonFilename); + + var interfaceCodePerson = interfacePerson.ToString(); + var interfaceCodePersonFilename = Path.Combine(_basePath, "Destination", interfacePersonFilename); + if (Write) File.WriteAllText(interfaceCodePersonFilename, interfaceCodePerson); + interfaceCodePerson.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText(interfaceCodePersonFilename)); + + + // Assert Proxy Human + var proxyClassHuman = result.Files[3].SyntaxTree; + proxyClassHuman.FilePath.Should().EndWith(proxyClassHumanFilename); + + var proxyCodeHuman = proxyClassHuman.ToString(); + var proxyCodeHumanFilename = Path.Combine(_basePath, "Destination", proxyClassHumanFilename); + if (Write) File.WriteAllText(proxyCodeHumanFilename, proxyCodeHuman); + proxyCodeHuman.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText(proxyCodeHumanFilename)); + + + // Assert Proxy Person + var proxyClassPerson = result.Files[4].SyntaxTree; + proxyClassPerson.FilePath.Should().EndWith(proxyClassPersonFilename); + + var proxyCode = proxyClassPerson.ToString(); + var proxyCodeFilename = Path.Combine(_basePath, "Destination", proxyClassPersonFilename); + if (Write) File.WriteAllText(proxyCodeFilename, proxyCode); + proxyCode.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText(proxyCodeFilename)); + + var personProxy = new PersonProxy(new Person()); + + int c = 100; + personProxy.In_Out_Ref1(1, out _, ref c); + + c.Should().Be(101); + } + + [Fact] + public void GenerateFiles_ForTwoClassesSameName_Should_GenerateCorrectFiles() + { + // Arrange + var attributeFilename = "ProxyInterfaceGenerator.Extra.g.cs"; + + var sourceFiles = new List(); + + var list = new[] + { + (IF: "", INS: "ProxyInterfaceDemo", I: "IGroup", CF: "", CNS: "ProxyInterfaceDemo", C: "Group"), + (IF: "", INS: "ProxyInterfaceDemo", I: "IDisplayable", CF: "", CNS: "ProxyInterfaceDemo", C: "Displayable"), + (IF: "", INS: "ProxyInterfaceDemo", I: "IDestroyable", CF: "", CNS: "ProxyInterfaceDemo", C: "Destroyable"), + (IF: "Depth/", INS: "ProxyInterfaceDemo.Depth", I: "IGroupDepth", CF: "Depth/", CNS: "ProxyInterfaceDemo.Depth", C: "Group") + }; + + foreach (var x in list) + { + var pathInterface = Path.Combine(_basePath, "Source", $"{x.IF}{x.I}.cs"); + var sourceFile = new SourceFile + { + Path = pathInterface, + Text = File.ReadAllText(pathInterface), + AttributeToAddToInterface = new ExtraAttribute + { + Name = "ProxyInterfaceGenerator.Proxy", + ArgumentList = $"typeof({x.CNS}.{x.C})" + } + }; + sourceFiles.Add(sourceFile); + } + + // Act + var result = _sut.Execute(sourceFiles); + + // Assert + result.Valid.Should().BeTrue(); + result.Files.Should().HaveCount(1 + list.Length * 2); + + // Assert attribute + var attribute = result.Files[0].SyntaxTree; + attribute.FilePath.Should().EndWith(attributeFilename); + + var fileIndex = 1; + + // Interfaces + foreach (var x in list) + { + var filenameInterface = $"{x.INS}.{x.I}.g.cs"; + var syntaxTreeInterface = result.Files[fileIndex].SyntaxTree; + syntaxTreeInterface.FilePath.Should().EndWith(filenameInterface); + + var codeInterface = syntaxTreeInterface.ToString(); + var path = Path.Combine(_basePath, "Destination", $"{x.IF}{filenameInterface}"); + if (Write) File.WriteAllText(path, codeInterface); + codeInterface.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText(path)); + + fileIndex += 1; + } + + // Proxies + foreach (var x in list) + { + var filenameProxy = $"{x.CNS}.{x.C}Proxy.g.cs"; + var syntaxTreeProxy = result.Files[fileIndex].SyntaxTree; + syntaxTreeProxy.FilePath.Should().EndWith(filenameProxy); + + var codeProxy = syntaxTreeProxy.ToString(); + var path = Path.Combine(_basePath, "Destination", $"{x.CF}{filenameProxy}"); + if (Write) File.WriteAllText(path, codeProxy); + codeProxy.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText(path)); + + fileIndex += 1; + } + } + + [Fact] + public void GenerateFiles_HttpClient() + { + // Arrange + var attributeFilename = "ProxyInterfaceGenerator.Extra.g.cs"; + var interfaceIHttpClientFilename = "ProxyInterfaceSourceGeneratorTests.Source.IHttpClient.g.cs"; + var proxyClassIHttpClientFilename = "System.Net.Http.HttpClientProxy.g.cs"; + var interfaceIHttpMessageInvokerFilename = "ProxyInterfaceSourceGeneratorTests.Source.IHttpMessageInvoker.g.cs"; + var proxyClassIHttpMessageInvokerFilename = "System.Net.Http.HttpMessageInvokerProxy.g.cs"; + + var pathIHttpClient = Path.Combine(_basePath, "Source", "IHttpClient.cs"); + var sourceFileIHttpClient = new SourceFile + { + Path = pathIHttpClient, + Text = File.ReadAllText(pathIHttpClient), + AttributeToAddToInterface = new ExtraAttribute + { + Name = "ProxyInterfaceGenerator.Proxy", + ArgumentList = "typeof(System.Net.Http.HttpClient)" + } + }; + + var pathIHttpMessageInvoker = Path.Combine(_basePath, "Source", "IHttpMessageInvoker.cs"); + var sourceFileIHttpMessageInvoker = new SourceFile + { + Path = pathIHttpMessageInvoker, + Text = File.ReadAllText(pathIHttpMessageInvoker), + AttributeToAddToInterface = new ExtraAttribute + { + Name = "ProxyInterfaceGenerator.Proxy", + ArgumentList = "typeof(System.Net.Http.HttpMessageInvoker)" + } + }; + + // Act + var result = _sut.Execute([sourceFileIHttpClient, sourceFileIHttpMessageInvoker]); + + // Assert + result.Valid.Should().BeTrue(); + result.Files.Should().HaveCount(5); + + // Assert attribute + var attribute = result.Files[0].SyntaxTree; + attribute.FilePath.Should().EndWith(attributeFilename); + + + // Assert interface IHttpClient + var interfaceIHttpClient = result.Files[1].SyntaxTree; + interfaceIHttpClient.FilePath.Should().EndWith(interfaceIHttpClientFilename); + + var interfaceCodeIHttpClient = interfaceIHttpClient.ToString(); + var interfaceCodeIHttpClientFilename = Path.Combine(_basePath, "Destination", interfaceIHttpClientFilename); + if (Write) File.WriteAllText(interfaceCodeIHttpClientFilename, interfaceCodeIHttpClient); + interfaceCodeIHttpClient.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText(interfaceCodeIHttpClientFilename)); + + + // Assert interface IHttpMessageInvoker + var interfaceIMessageInvoker = result.Files[2].SyntaxTree; + interfaceIMessageInvoker.FilePath.Should().EndWith(interfaceIHttpMessageInvokerFilename); + + var interfaceCodeIMessageInvoker = interfaceIMessageInvoker.ToString(); + var interfaceCodeIMessageInvokerFilename = Path.Combine(_basePath, "Destination", interfaceIHttpMessageInvokerFilename); + if (Write) File.WriteAllText(interfaceCodeIMessageInvokerFilename, interfaceCodeIMessageInvoker); + interfaceCodeIMessageInvoker.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText(interfaceCodeIMessageInvokerFilename)); + + + // Assert Proxy IHttpClient + var proxyClassIHttpClient = result.Files[3].SyntaxTree; + proxyClassIHttpClient.FilePath.Should().EndWith(proxyClassIHttpClientFilename); + + var proxyCodeIHttpClient = proxyClassIHttpClient.ToString(); + var proxyCodeIHttpClientFilename = Path.Combine(_basePath, "Destination", proxyClassIHttpClientFilename); + if (Write) File.WriteAllText(proxyCodeIHttpClientFilename, proxyCodeIHttpClient); + proxyCodeIHttpClient.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText(proxyCodeIHttpClientFilename)); + + + // Assert Proxy IHttpMessageInvoker + var proxyClassIMessageInvoker = result.Files[4].SyntaxTree; + proxyClassIMessageInvoker.FilePath.Should().EndWith(proxyClassIHttpMessageInvokerFilename); + + var proxyIMessageInvoker = proxyClassIMessageInvoker.ToString(); + var proxyIMessageInvokerFilename = Path.Combine(_basePath, "Destination", proxyClassIHttpMessageInvokerFilename); + if (Write) File.WriteAllText(proxyIMessageInvokerFilename, proxyIMessageInvoker); + proxyIMessageInvoker.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText(proxyIMessageInvokerFilename)); + } + + [Fact] + public void GenerateFiles_ForClassWithSameName_But_DifferentNamespace_Should_GenerateCorrectFiles() + { + // Arrange + const string @class = "ClassInNamespace"; + foreach (var x in new[] { 1, 2 }) + { + var attributeFilename = "ProxyInterfaceGenerator.Extra.g.cs"; + var interfaceFilename = $"ProxyInterfaceSourceGeneratorTests.Namespace{x}.I{@class}.g.cs"; + var proxyClassFilename = $"ProxyInterfaceSourceGeneratorTests.Namespace{x}.{@class}Proxy.g.cs"; + + var path = Path.Combine(_basePath, "Source", $"I{@class}{x}.cs"); + var sourceFile = new SourceFile + { + Path = path, + Text = File.ReadAllText(path), + AttributeToAddToInterface = new ExtraAttribute + { + Name = "ProxyInterfaceGenerator.Proxy", + ArgumentList = new[] { $"typeof(ProxyInterfaceSourceGeneratorTests.Namespace{x}.{@class})", "true" } + } + }; + + // Act + var result = _sut.Execute([sourceFile]); + + // Assert + result.Valid.Should().BeTrue(); + result.Files.Should().HaveCount(3); + + // Assert attribute + var attribute = result.Files[0].SyntaxTree; + attribute.FilePath.Should().EndWith(attributeFilename); + + // Assert interface + var @interface = result.Files[1].SyntaxTree; + @interface.FilePath.Should().EndWith(interfaceFilename); + + var interfaceCode = @interface.ToString(); + var interfaceCodeFilename = Path.Combine(_basePath, "Destination", interfaceFilename); + if (Write) File.WriteAllText(interfaceCodeFilename, interfaceCode); + interfaceCode.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText(interfaceCodeFilename)); + + // Assert Proxy + var proxyClass = result.Files[2].SyntaxTree; + proxyClass.FilePath.Should().EndWith(proxyClassFilename); + + var proxyCode = proxyClass.ToString(); + var proxyCodeFilename = Path.Combine(_basePath, "Destination", proxyClassFilename); + if (Write) File.WriteAllText(proxyCodeFilename, proxyCode); + proxyCode.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText(proxyCodeFilename)); + } + } + + [Fact] + public Task GenerateFiles_ForClassWithIgnores() + { + // Arrange + var fileNames = new[] + { + "ProxyInterfaceSourceGeneratorTests.Source.IFoo2.g.cs", + "ProxyInterfaceSourceGeneratorTests.Source.Foo2Proxy.g.cs" + }; + + var path = Path.Combine(_basePath, "Source/IFoo2.cs"); + var sourceFile = new SourceFile + { + Path = path, + Text = File.ReadAllText(path), + AttributeToAddToInterface = new ExtraAttribute + { + Name = "ProxyInterfaceGenerator.Proxy", + ArgumentList = new[] + { + "typeof(ProxyInterfaceSourceGeneratorTests.Source.Foo2)", "false", "ProxyClassAccessibility.Public", + "new [] { \"Weird\", \"NotHere\" }" + } + } + }; + + // Act + var result = _sut.Execute([sourceFile]); + + // Assert + result.Valid.Should().BeTrue(); + result.Files.Should().HaveCount(fileNames.Length + 1); + + // Verify + var results = result.GeneratorDriver.GetRunResult().Results.First().GeneratedSources; + return Verify(results); + } + + [Fact] + public Task GenerateFiles_ForClassWithIgnores_Regex() + { + // Arrange + var fileNames = new[] + { + "ProxyInterfaceSourceGeneratorTests.Source.IFoo2.g.cs", + "ProxyInterfaceSourceGeneratorTests.Source.Foo2Proxy.g.cs" + }; + + var path = Path.Combine(_basePath, "Source/IFoo2.cs"); + var sourceFile = new SourceFile + { + Path = path, + Text = File.ReadAllText(path), + AttributeToAddToInterface = new ExtraAttribute + { + Name = "ProxyInterfaceGenerator.Proxy", + ArgumentList = new[] + { + "typeof(ProxyInterfaceSourceGeneratorTests.Source.Foo2)", "false", "ProxyClassAccessibility.Public", + "new [] { \"Weird*\" }" + } + } + }; + + // Act + var result = _sut.Execute([sourceFile]); + + // Assert + result.Valid.Should().BeTrue(); + result.Files.Should().HaveCount(fileNames.Length + 1); + + // Verify + var results = result.GeneratorDriver.GetRunResult().Results.First().GeneratedSources; + return Verify(results); + } + + [Fact] + public void GenerateFiles_ForTimeProvider_Should_GenerateCorrectFiles() + { + // Arrange + var fileNames = new[] + { + "ProxyInterfaceSourceGeneratorTests.Source.ITimeProvider.g.cs", + "System.TimeProviderProxy.g.cs" + }; + + var path = Path.Combine(_basePath, "Source/ITimeProvider.cs"); + var sourceFile = new SourceFile + { + Path = path, + Text = File.ReadAllText(path), + AttributeToAddToInterface = new ExtraAttribute + { + Name = "ProxyInterfaceGenerator.Proxy", + ArgumentList = "typeof(System.TimeProvider)" + } + }; + + // Act + var result = _sut.Execute([sourceFile]); + + // Assert + Assert(result, fileNames); + } + + [Theory] + [InlineData("ClassDirect")] + [InlineData("ClassDirectAndIndirect")] + public void GenerateFiles_Map(string value) + { + // Arrange + var fileNames = new[] + { + $"ProxyInterfaceSourceGeneratorTests.Source.I{value}.g.cs", + $"ProxyInterfaceSourceGeneratorTests.Source.{value}Proxy.g.cs" + }; + + var path = Path.Combine(_basePath, $"Source/I{value}.cs"); + var sourceFile = new SourceFile + { + Path = path, + Text = File.ReadAllText(path), + AttributeToAddToInterface = new ExtraAttribute + { + Name = "ProxyInterfaceGenerator.Proxy", + ArgumentList = $"typeof(ProxyInterfaceSourceGeneratorTests.Source.{value})" + } + }; + + // Act + var result = _sut.Execute([sourceFile]); + + // Assert + Assert(result, fileNames); + + // Test + var instance = new ClassDirectAndIndirect + { + Id = "Instance", + Value = new ClassDirectAndIndirect { Id = "Value" }, + Array = [new ClassDirectAndIndirect { Id = "Array 1" }, new ClassDirectAndIndirect { Id = "Array 2" }], + List = [new ClassDirectAndIndirect { Id = "List 1" }, new ClassDirectAndIndirect { Id = "List 2" }, new ClassDirectAndIndirect { Id = "List 3" }] + }; + + var proxy = new ClassDirectAndIndirectProxy(instance); + proxy.Id.Should().Be("Instance"); + proxy.Value!.Id.Should().Be("Value"); + proxy.Array.Select(a => a.Id).Should().BeEquivalentTo("Array 1", "Array 2"); + proxy.List.Select(a => a.Id).Should().BeEquivalentTo("List 1", "List 2", "List 3"); + } + + private void Assert(ExecuteResult result, string[] fileNames, bool skipExtra = true) + { + var skip = skipExtra ? 1 : 0; + + result.Valid.Should().BeTrue(); + result.Files.Should().HaveCount(fileNames.Length + skip); + + foreach (var fileName in fileNames.Select((fileName, index) => new { fileName, index })) + { + var builder = result.Files[fileName.index + skip]; // +1 means skip the attribute + builder.Path.Should().EndWith(fileName.fileName); + + var destinationFilename = Path.Combine(_basePath, $"Destination/{fileName.fileName}"); + if (Write) File.WriteAllText(destinationFilename, builder.Text); + builder.Text.Should().Be(File.ReadAllText(destinationFilename)); + } + } } \ No newline at end of file diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/ClassDirect.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/ClassDirect.cs new file mode 100644 index 0000000..6742468 --- /dev/null +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/ClassDirect.cs @@ -0,0 +1,12 @@ +namespace ProxyInterfaceSourceGeneratorTests.Source +{ + public class ClassDirect + { + // public ClassDirect? Value { get; set; } + + public ClassDirect Test(ClassDirect x) + { + return x; + } + } +} \ No newline at end of file diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/ClassDirectAndIndirect.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/ClassDirectAndIndirect.cs new file mode 100644 index 0000000..5ecad47 --- /dev/null +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/ClassDirectAndIndirect.cs @@ -0,0 +1,18 @@ +namespace ProxyInterfaceSourceGeneratorTests.Source +{ + public class ClassDirectAndIndirect + { + public string Id { get; set; } = string.Empty; + + public ClassDirectAndIndirect? Value { get; set; } + + public ClassDirectAndIndirect[] Array { get; set; } = []; + + public List List { get; set; } = new List(); + + public int Test(ClassDirectAndIndirect[] array, List list, ClassDirectAndIndirect value, ClassDirectAndIndirect? valueNullable) + { + return 42; + } + } +} \ No newline at end of file diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/IClassDirect.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/IClassDirect.cs new file mode 100644 index 0000000..db996c4 --- /dev/null +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/IClassDirect.cs @@ -0,0 +1,6 @@ +namespace ProxyInterfaceSourceGeneratorTests.Source +{ + public partial interface IClassDirect + { + } +} \ No newline at end of file diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/IClassDirectAndIndirect.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/IClassDirectAndIndirect.cs new file mode 100644 index 0000000..b44be31 --- /dev/null +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/IClassDirectAndIndirect.cs @@ -0,0 +1,6 @@ +namespace ProxyInterfaceSourceGeneratorTests.Source +{ + public partial interface IClassDirectAndIndirect + { + } +} \ No newline at end of file