Add tests for interfaces with same name but different namespace (#70)
This commit is contained in:
+29
@@ -0,0 +1,29 @@
|
||||
//----------------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// 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.
|
||||
// </auto-generated>
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
#nullable enable
|
||||
using System;
|
||||
|
||||
namespace ProxyInterfaceSourceGeneratorTests.Namespace1
|
||||
{
|
||||
public partial class ClassInNamespaceProxy : global::ProxyInterfaceSourceGeneratorTests.Namespace1.IClassInNamespace
|
||||
{
|
||||
public global::ProxyInterfaceSourceGeneratorTests.Namespace1.ClassInNamespace _Instance { get; }
|
||||
|
||||
|
||||
public ClassInNamespaceProxy(global::ProxyInterfaceSourceGeneratorTests.Namespace1.ClassInNamespace instance)
|
||||
{
|
||||
_Instance = instance;
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
#nullable restore
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
//----------------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// 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.
|
||||
// </auto-generated>
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
#nullable enable
|
||||
using System;
|
||||
|
||||
namespace ProxyInterfaceSourceGeneratorTests.Namespace1
|
||||
{
|
||||
public partial interface IClassInNamespace
|
||||
{
|
||||
global::ProxyInterfaceSourceGeneratorTests.Namespace1.ClassInNamespace _Instance { get; }
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
#nullable restore
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
//----------------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// 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.
|
||||
// </auto-generated>
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
#nullable enable
|
||||
using System;
|
||||
|
||||
namespace ProxyInterfaceSourceGeneratorTests.Namespace2
|
||||
{
|
||||
public partial class ClassInNamespaceProxy : global::ProxyInterfaceSourceGeneratorTests.Namespace2.IClassInNamespace
|
||||
{
|
||||
public global::ProxyInterfaceSourceGeneratorTests.Namespace2.ClassInNamespace _Instance { get; }
|
||||
|
||||
|
||||
public ClassInNamespaceProxy(global::ProxyInterfaceSourceGeneratorTests.Namespace2.ClassInNamespace instance)
|
||||
{
|
||||
_Instance = instance;
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
#nullable restore
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
//----------------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// 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.
|
||||
// </auto-generated>
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
#nullable enable
|
||||
using System;
|
||||
|
||||
namespace ProxyInterfaceSourceGeneratorTests.Namespace2
|
||||
{
|
||||
public partial interface IClassInNamespace
|
||||
{
|
||||
global::ProxyInterfaceSourceGeneratorTests.Namespace2.ClassInNamespace _Instance { get; }
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
#nullable restore
|
||||
@@ -572,4 +572,58 @@ public class ProxyInterfaceSourceGeneratorTest
|
||||
if (Write) File.WriteAllText($"../../../Destination/{proxyClassIHttpMessageInvokerFilename}", proxyIMessageInvoker);
|
||||
proxyIMessageInvoker.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText($"../../../Destination/{proxyClassIHttpMessageInvokerFilename}"));
|
||||
}
|
||||
|
||||
[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 = $"./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(new[] { 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();
|
||||
if (Write) File.WriteAllText($"../../../Destination/{interfaceFilename}", interfaceCode);
|
||||
interfaceCode.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText($"../../../Destination/{interfaceFilename}"));
|
||||
|
||||
// Assert Proxy
|
||||
var proxyClass = result.Files[2].SyntaxTree;
|
||||
proxyClass.FilePath.Should().EndWith(proxyClassFilename);
|
||||
|
||||
var proxyCode = proxyClass.ToString();
|
||||
if (Write) File.WriteAllText($"../../../Destination/{proxyClassFilename}", proxyCode);
|
||||
proxyCode.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText($"../../../Destination/{proxyClassFilename}"));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<IsPackable>false</IsPackable>
|
||||
<LangVersion>12.0</LangVersion>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<Configurations>Debug;Release;DebugAttach</Configurations>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
// ReSharper disable once CheckNamespace
|
||||
namespace ProxyInterfaceSourceGeneratorTests.Namespace1
|
||||
{
|
||||
public class ClassInNamespace
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// ReSharper disable once CheckNamespace
|
||||
namespace ProxyInterfaceSourceGeneratorTests.Namespace2
|
||||
{
|
||||
public class ClassInNamespace
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// ReSharper disable once CheckNamespace
|
||||
namespace ProxyInterfaceSourceGeneratorTests.Namespace1
|
||||
{
|
||||
public partial interface IClassInNamespace
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// ReSharper disable once CheckNamespace
|
||||
namespace ProxyInterfaceSourceGeneratorTests.Namespace2
|
||||
{
|
||||
public partial interface IClassInNamespace
|
||||
{
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user