Skip to content

Commit

Permalink
Add test for use of global type shadowed by local namespace
Browse files Browse the repository at this point in the history
Without `global::` types in interfaces, the generated interface will resolve to the locally-defined type instead of the global one
  • Loading branch information
simonmckenzie committed Aug 24, 2024
1 parent 296d31c commit 37e79a7
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions AutomaticInterface/Tests/GeneratorTests.TypeResolution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,52 @@ public partial interface IModelManager
GenerateCode(code).Should().Be(expected);
}

[Fact]
public void WorksWithShadowedGlobalNamespace()
{
const string code = """
using AutomaticInterface;
using Task = System.Threading.Tasks.Task;
namespace AutomaticInterfaceExample
{
namespace System.Threading.Tasks
{
public class Task;
}
[GenerateAutomaticInterface]
public class DemoClass
{
public Task GetTask() => null!;
}
}
""";

const string expected = """
//--------------------------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
// </auto-generated>
//--------------------------------------------------------------------------------------------------
namespace AutomaticInterfaceExample
{
[global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")]
public partial interface IDemoClass
{
/// <inheritdoc />
global::System.Threading.Tasks.Task GetTask();
}
}
""";
GenerateCode(code).Should().Be(expected);
}

[Fact]
public void WorksWithGlobalUsing()
{
Expand Down

0 comments on commit 37e79a7

Please sign in to comment.