diff --git a/AutomaticInterface/AutomaticInterface.sln.DotSettings b/AutomaticInterface/AutomaticInterface.sln.DotSettings
index 7b81da3..9378311 100644
--- a/AutomaticInterface/AutomaticInterface.sln.DotSettings
+++ b/AutomaticInterface/AutomaticInterface.sln.DotSettings
@@ -1,4 +1,5 @@
+ True
True
True
True
\ No newline at end of file
diff --git a/AutomaticInterface/AutomaticInterface/Builder.cs b/AutomaticInterface/AutomaticInterface/Builder.cs
index 4eced99..6cef4ef 100644
--- a/AutomaticInterface/AutomaticInterface/Builder.cs
+++ b/AutomaticInterface/AutomaticInterface/Builder.cs
@@ -55,38 +55,40 @@ InterfaceBuilder codeGenerator
.ToList()
.ForEach(method =>
{
- var returnType = method.ReturnType;
- var name = method.Name;
-
- var hasNullableParameter = method.Parameters.Any(x =>
- x.NullableAnnotation == NullableAnnotation.Annotated
- );
- var hasNullableReturn =
- method.ReturnType.NullableAnnotation == NullableAnnotation.Annotated;
- if (hasNullableParameter || hasNullableReturn)
- {
- codeGenerator.HasNullable = true;
- }
-
- var paramResult = new HashSet();
- method
- .Parameters.Select(GetMethodSignature)
- .ToList()
- .ForEach(x => paramResult.Add(x));
-
- var typedArgs = method
- .TypeParameters.Select(arg => (arg.ToDisplayString(), arg.GetWhereStatement()))
- .ToList();
- codeGenerator.AddMethodToInterface(
- name,
- returnType.ToDisplayString(),
- InheritDoc,
- paramResult,
- typedArgs
- );
+ AddMethod(codeGenerator, method);
});
}
+ private static void AddMethod(InterfaceBuilder codeGenerator, IMethodSymbol method)
+ {
+ var returnType = method.ReturnType;
+ var name = method.Name;
+
+ var hasNullableParameter = method.Parameters.Any(x =>
+ x.NullableAnnotation == NullableAnnotation.Annotated
+ );
+ var hasNullableReturn =
+ method.ReturnType.NullableAnnotation == NullableAnnotation.Annotated;
+ if (hasNullableParameter || hasNullableReturn)
+ {
+ codeGenerator.HasNullable = true;
+ }
+
+ var paramResult = new HashSet();
+ method.Parameters.Select(GetMethodSignature).ToList().ForEach(x => paramResult.Add(x));
+
+ var typedArgs = method
+ .TypeParameters.Select(arg => (arg.ToDisplayString(), arg.GetWhereStatement()))
+ .ToList();
+ codeGenerator.AddMethodToInterface(
+ name,
+ returnType.ToDisplayString(),
+ InheritDoc,
+ paramResult,
+ typedArgs
+ );
+ }
+
private static void AddEventsToInterface(
ITypeSymbol classSymbol,
InterfaceBuilder codeGenerator
diff --git a/AutomaticInterface/Tests/GeneratorTests.cs b/AutomaticInterface/Tests/GeneratorTests.cs
index 286c93c..f55c696 100644
--- a/AutomaticInterface/Tests/GeneratorTests.cs
+++ b/AutomaticInterface/Tests/GeneratorTests.cs
@@ -6,1703 +6,1768 @@
using Microsoft.CodeAnalysis.CSharp;
using Xunit;
-namespace Tests
+namespace Tests;
+
+public class GeneratorTests
{
- public class GeneratorTests
+ private static string GenerateCode(string code)
{
- private static string GenerateCode(string code)
- {
- var syntaxTree = CSharpSyntaxTree.ParseText(code);
- var references = AppDomain
- .CurrentDomain.GetAssemblies()
- .Where(assembly => !assembly.IsDynamic)
- .Select(assembly => MetadataReference.CreateFromFile(assembly.Location))
- .Cast();
-
- var compilation = CSharpCompilation.Create(
- "SourceGeneratorTests",
- new[] { syntaxTree },
- references,
- new(OutputKind.DynamicallyLinkedLibrary)
+ var syntaxTree = CSharpSyntaxTree.ParseText(code);
+ var references = AppDomain
+ .CurrentDomain.GetAssemblies()
+ .Where(assembly => !assembly.IsDynamic)
+ .Select(assembly => MetadataReference.CreateFromFile(assembly.Location))
+ .Cast();
+
+ var compilation = CSharpCompilation.Create(
+ "SourceGeneratorTests",
+ new[] { syntaxTree },
+ references,
+ new(OutputKind.DynamicallyLinkedLibrary)
+ );
+
+ var generator = new AutomaticInterfaceGenerator();
+
+ CSharpGeneratorDriver
+ .Create(generator)
+ .RunGeneratorsAndUpdateCompilation(
+ compilation,
+ out var outputCompilation,
+ out var diagnostics
);
- var generator = new AutomaticInterfaceGenerator();
-
- CSharpGeneratorDriver
- .Create(generator)
- .RunGeneratorsAndUpdateCompilation(
- compilation,
- out var outputCompilation,
- out var diagnostics
- );
+ diagnostics.Where(d => d.Severity == DiagnosticSeverity.Error).Should().BeEmpty();
- diagnostics.Where(d => d.Severity == DiagnosticSeverity.Error).Should().BeEmpty();
-
- return outputCompilation.SyntaxTrees.Skip(1).LastOrDefault()?.ToString();
- }
+ return outputCompilation.SyntaxTrees.Skip(1).LastOrDefault()?.ToString();
+ }
- [Fact]
- public void WorksWithOptionalParameters()
- {
- const string code = """
+ [Fact]
+ public void WorksWithOptionalParameters()
+ {
+ const string code = """
- using AutomaticInterfaceAttribute;
+ using AutomaticInterfaceAttribute;
- namespace AutomaticInterfaceExample;
+ namespace AutomaticInterfaceExample;
- [GenerateAutomaticInterface]
- public class DemoClass
- {
- public bool TryStartTransaction(
- string file = "",
- string member = "",
- int line = 0)
- {
- return true;
- }
- }
+ [GenerateAutomaticInterface]
+ public class DemoClass
+ {
+ public bool TryStartTransaction(
+ string file = "",
+ string member = "",
+ int line = 0)
+ {
+ return true;
+ }
+ }
- """;
- const string expected = """
- //--------------------------------------------------------------------------------------------------
- //
- // This code was generated by a tool.
- //
- // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
- //
- //--------------------------------------------------------------------------------------------------
+ """;
+ const string expected = """
+ //--------------------------------------------------------------------------------------------------
+ //
+ // This code was generated by a tool.
+ //
+ // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
+ //
+ //--------------------------------------------------------------------------------------------------
- using System.CodeDom.Compiler;
- using AutomaticInterfaceAttribute;
+ using System.CodeDom.Compiler;
+ using AutomaticInterfaceAttribute;
- namespace AutomaticInterfaceExample
+ namespace AutomaticInterfaceExample
+ {
+ [GeneratedCode("AutomaticInterface", "")]
+ public partial interface IDemoClass
{
- [GeneratedCode("AutomaticInterface", "")]
- public partial interface IDemoClass
- {
- ///
- bool TryStartTransaction(string file = "", string member = "", int line = 0);
-
- }
+ ///
+ bool TryStartTransaction(string file = "", string member = "", int line = 0);
+
}
+ }
- """;
- GenerateCode(code).Should().Be(expected);
- }
+ """;
+ GenerateCode(code).Should().Be(expected);
+ }
- [Fact]
- public void WorksWithOptionalStructParameters()
- {
- const string code = """
+ [Fact]
+ public void WorksWithOptionalStructParameters()
+ {
+ const string code = """
- using AutomaticInterfaceAttribute;
+ using AutomaticInterfaceAttribute;
- namespace AutomaticInterfaceExample;
+ namespace AutomaticInterfaceExample;
- public struct MyStruct
- {
- private int Bar;
- }
+ public struct MyStruct
+ {
+ private int Bar;
+ }
- [GenerateAutomaticInterface]
- public class DemoClass
- {
- public bool TryStartTransaction(MyStruct data = default(MyStruct))
- {
- return true;
- }
- }
+ [GenerateAutomaticInterface]
+ public class DemoClass
+ {
+ public bool TryStartTransaction(MyStruct data = default(MyStruct))
+ {
+ return true;
+ }
+ }
- """;
- const string expected = """
- //--------------------------------------------------------------------------------------------------
- //
- // This code was generated by a tool.
- //
- // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
- //
- //--------------------------------------------------------------------------------------------------
+ """;
+ const string expected = """
+ //--------------------------------------------------------------------------------------------------
+ //
+ // This code was generated by a tool.
+ //
+ // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
+ //
+ //--------------------------------------------------------------------------------------------------
- using System.CodeDom.Compiler;
- using AutomaticInterfaceAttribute;
+ using System.CodeDom.Compiler;
+ using AutomaticInterfaceAttribute;
- namespace AutomaticInterfaceExample
+ namespace AutomaticInterfaceExample
+ {
+ [GeneratedCode("AutomaticInterface", "")]
+ public partial interface IDemoClass
{
- [GeneratedCode("AutomaticInterface", "")]
- public partial interface IDemoClass
- {
- ///
- bool TryStartTransaction(AutomaticInterfaceExample.MyStruct data = default(AutomaticInterfaceExample.MyStruct));
-
- }
+ ///
+ bool TryStartTransaction(AutomaticInterfaceExample.MyStruct data = default(AutomaticInterfaceExample.MyStruct));
+
}
+ }
- """;
- GenerateCode(code).Should().Be(expected);
- }
+ """;
+ GenerateCode(code).Should().Be(expected);
+ }
- [Fact]
- public void WorksWithOptionalNullParameters()
- {
- const string code = """
+ [Fact]
+ public void WorksWithOptionalNullParameters()
+ {
+ const string code = """
- using AutomaticInterfaceAttribute;
+ using AutomaticInterfaceAttribute;
- namespace AutomaticInterfaceExample;
+ namespace AutomaticInterfaceExample;
- [GenerateAutomaticInterface]
- public class DemoClass
- {
- public bool TryStartTransaction(string data = null)
- {
- return true;
- }
- }
+ [GenerateAutomaticInterface]
+ public class DemoClass
+ {
+ public bool TryStartTransaction(string data = null)
+ {
+ return true;
+ }
+ }
- """;
- const string expected = """
- //--------------------------------------------------------------------------------------------------
- //
- // This code was generated by a tool.
- //
- // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
- //
- //--------------------------------------------------------------------------------------------------
+ """;
+ const string expected = """
+ //--------------------------------------------------------------------------------------------------
+ //
+ // This code was generated by a tool.
+ //
+ // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
+ //
+ //--------------------------------------------------------------------------------------------------
- using System.CodeDom.Compiler;
- using AutomaticInterfaceAttribute;
+ using System.CodeDom.Compiler;
+ using AutomaticInterfaceAttribute;
- namespace AutomaticInterfaceExample
+ namespace AutomaticInterfaceExample
+ {
+ [GeneratedCode("AutomaticInterface", "")]
+ public partial interface IDemoClass
{
- [GeneratedCode("AutomaticInterface", "")]
- public partial interface IDemoClass
- {
- ///
- bool TryStartTransaction(string data = null);
-
- }
+ ///
+ bool TryStartTransaction(string data = null);
+
}
+ }
- """;
- GenerateCode(code).Should().Be(expected);
- }
+ """;
+ GenerateCode(code).Should().Be(expected);
+ }
- [Fact]
- public void GeneratesEmptyInterface()
- {
- var code = """
+ [Fact]
+ public void GeneratesEmptyInterface()
+ {
+ const string code = """
- using AutomaticInterfaceAttribute;
+ using AutomaticInterfaceAttribute;
- namespace AutomaticInterfaceExample
+ namespace AutomaticInterfaceExample
+ {
+ [GenerateAutomaticInterface]
+ class DemoClass
{
- [GenerateAutomaticInterface]
- class DemoClass
- {
- }
- }
+ }
+ }
- """;
+ """;
- const string expected = """
- //--------------------------------------------------------------------------------------------------
- //
- // This code was generated by a tool.
- //
- // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
- //
- //--------------------------------------------------------------------------------------------------
+ const string expected = """
+ //--------------------------------------------------------------------------------------------------
+ //
+ // This code was generated by a tool.
+ //
+ // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
+ //
+ //--------------------------------------------------------------------------------------------------
- using System.CodeDom.Compiler;
- using AutomaticInterfaceAttribute;
+ using System.CodeDom.Compiler;
+ using AutomaticInterfaceAttribute;
- namespace AutomaticInterfaceExample
+ namespace AutomaticInterfaceExample
+ {
+ [GeneratedCode("AutomaticInterface", "")]
+ public partial interface IDemoClass
{
- [GeneratedCode("AutomaticInterface", "")]
- public partial interface IDemoClass
- {
- }
}
+ }
- """;
+ """;
- GenerateCode(code).Should().Be(expected);
- }
+ GenerateCode(code).Should().Be(expected);
+ }
- [Fact]
- public void GeneratesStringPropertyInterface()
- {
- var code = """
+ [Fact]
+ public void GeneratesStringPropertyInterface()
+ {
+ const string code = """
- using AutomaticInterfaceAttribute;
+ using AutomaticInterfaceAttribute;
- namespace AutomaticInterfaceExample
- {
+ namespace AutomaticInterfaceExample
+ {
- [GenerateAutomaticInterface]
- class DemoClass
- {
- public string Hello { get; set; }
- }
+ [GenerateAutomaticInterface]
+ class DemoClass
+ {
+ public string Hello { get; set; }
}
+ }
- """;
+ """;
- var expected = """
- //--------------------------------------------------------------------------------------------------
- //
- // This code was generated by a tool.
- //
- // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
- //
- //--------------------------------------------------------------------------------------------------
+ const string expected = """
+ //--------------------------------------------------------------------------------------------------
+ //
+ // This code was generated by a tool.
+ //
+ // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
+ //
+ //--------------------------------------------------------------------------------------------------
- using System.CodeDom.Compiler;
- using AutomaticInterfaceAttribute;
+ using System.CodeDom.Compiler;
+ using AutomaticInterfaceAttribute;
- namespace AutomaticInterfaceExample
+ namespace AutomaticInterfaceExample
+ {
+ [GeneratedCode("AutomaticInterface", "")]
+ public partial interface IDemoClass
{
- [GeneratedCode("AutomaticInterface", "")]
- public partial interface IDemoClass
- {
- ///
- string Hello { get; set; }
-
- }
+ ///
+ string Hello { get; set; }
+
}
+ }
- """;
- GenerateCode(code).Should().Be(expected);
- }
+ """;
+ GenerateCode(code).Should().Be(expected);
+ }
- [Fact]
- public void GeneratesStringPropertySetOnlyInterface()
- {
- var code = """
+ [Fact]
+ public void GeneratesStringPropertySetOnlyInterface()
+ {
+ const string code = """
- using AutomaticInterfaceAttribute;
+ using AutomaticInterfaceAttribute;
- namespace AutomaticInterfaceExample
- {
+ namespace AutomaticInterfaceExample
+ {
- [GenerateAutomaticInterface]
- class DemoClass
- {
- private string x;
- public string Hello { set => x = value; }
- }
+ [GenerateAutomaticInterface]
+ class DemoClass
+ {
+ private string x;
+ public string Hello { set => x = value; }
}
+ }
- """;
+ """;
- var expected = """
- //--------------------------------------------------------------------------------------------------
- //
- // This code was generated by a tool.
- //
- // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
- //
- //--------------------------------------------------------------------------------------------------
+ const string expected = """
+ //--------------------------------------------------------------------------------------------------
+ //
+ // This code was generated by a tool.
+ //
+ // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
+ //
+ //--------------------------------------------------------------------------------------------------
- using System.CodeDom.Compiler;
- using AutomaticInterfaceAttribute;
+ using System.CodeDom.Compiler;
+ using AutomaticInterfaceAttribute;
- namespace AutomaticInterfaceExample
+ namespace AutomaticInterfaceExample
+ {
+ [GeneratedCode("AutomaticInterface", "")]
+ public partial interface IDemoClass
{
- [GeneratedCode("AutomaticInterface", "")]
- public partial interface IDemoClass
- {
- ///
- string Hello { set; }
-
- }
+ ///
+ string Hello { set; }
+
}
+ }
- """;
- GenerateCode(code).Should().Be(expected);
- }
+ """;
+ GenerateCode(code).Should().Be(expected);
+ }
- [Fact]
- public void GeneratesStringPropertyGetOnlyInterface()
- {
- var code = """
+ [Fact]
+ public void GeneratesStringPropertyGetOnlyInterface()
+ {
+ const string code = """
- using AutomaticInterfaceAttribute;
+ using AutomaticInterfaceAttribute;
- namespace AutomaticInterfaceExample
- {
+ namespace AutomaticInterfaceExample
+ {
- [GenerateAutomaticInterface]
- class DemoClass
- {
- private string x;
- public string Hello { get; }
- }
+ [GenerateAutomaticInterface]
+ class DemoClass
+ {
+ private string x;
+ public string Hello { get; }
}
+ }
- """;
+ """;
- var expected = """
- //--------------------------------------------------------------------------------------------------
- //
- // This code was generated by a tool.
- //
- // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
- //
- //--------------------------------------------------------------------------------------------------
+ const string expected = """
+ //--------------------------------------------------------------------------------------------------
+ //
+ // This code was generated by a tool.
+ //
+ // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
+ //
+ //--------------------------------------------------------------------------------------------------
- using System.CodeDom.Compiler;
- using AutomaticInterfaceAttribute;
+ using System.CodeDom.Compiler;
+ using AutomaticInterfaceAttribute;
- namespace AutomaticInterfaceExample
+ namespace AutomaticInterfaceExample
+ {
+ [GeneratedCode("AutomaticInterface", "")]
+ public partial interface IDemoClass
{
- [GeneratedCode("AutomaticInterface", "")]
- public partial interface IDemoClass
- {
- ///
- string Hello { get; }
-
- }
+ ///
+ string Hello { get; }
+
}
+ }
- """;
- GenerateCode(code).Should().Be(expected);
- }
+ """;
+ GenerateCode(code).Should().Be(expected);
+ }
- [Fact]
- public void AddsUsingsToInterface()
- {
- var code = """
+ [Fact]
+ public void AddsUsingsToInterface()
+ {
+ const string code = """
- using AutomaticInterfaceAttribute;
- using System.IO;
+ using AutomaticInterfaceAttribute;
+ using System.IO;
- namespace AutomaticInterfaceExample
- {
+ namespace AutomaticInterfaceExample
+ {
- [GenerateAutomaticInterface]
- class DemoClass
- {
- public DirectoryInfo Hello { get; set; }
- }
- }
+ [GenerateAutomaticInterface]
+ class DemoClass
+ {
+ public DirectoryInfo Hello { get; set; }
+ }
+ }
- """;
+ """;
- var expected = """
- //--------------------------------------------------------------------------------------------------
- //
- // This code was generated by a tool.
- //
- // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
- //
- //--------------------------------------------------------------------------------------------------
+ const string expected = """
+ //--------------------------------------------------------------------------------------------------
+ //
+ // This code was generated by a tool.
+ //
+ // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
+ //
+ //--------------------------------------------------------------------------------------------------
- using System.CodeDom.Compiler;
- using AutomaticInterfaceAttribute;
- using System.IO;
+ using System.CodeDom.Compiler;
+ using AutomaticInterfaceAttribute;
+ using System.IO;
- namespace AutomaticInterfaceExample
+ namespace AutomaticInterfaceExample
+ {
+ [GeneratedCode("AutomaticInterface", "")]
+ public partial interface IDemoClass
{
- [GeneratedCode("AutomaticInterface", "")]
- public partial interface IDemoClass
- {
- ///
- System.IO.DirectoryInfo Hello { get; set; }
-
- }
+ ///
+ System.IO.DirectoryInfo Hello { get; set; }
+
}
+ }
+
+ """;
+ GenerateCode(code).Should().Be(expected);
+ }
- """;
- GenerateCode(code).Should().Be(expected);
- }
+ [Fact]
+ public void AddsPublicMethodToInterface()
+ {
+ const string code = """
- [Fact]
- public void AddsPublicMethodToInterface()
- {
- var code = """
+ using AutomaticInterfaceAttribute;
+ using System.IO;
- using AutomaticInterfaceAttribute;
- using System.IO;
+ namespace AutomaticInterfaceExample
+ {
- namespace AutomaticInterfaceExample
+ [GenerateAutomaticInterface]
+ class DemoClass
{
-
- [GenerateAutomaticInterface]
- class DemoClass
- {
-
- public string Hello(){return "";}
- }
+
+ public string Hello(){return "";}
}
+ }
- """;
+ """;
- var expected = """
- //--------------------------------------------------------------------------------------------------
- //
- // This code was generated by a tool.
- //
- // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
- //
- //--------------------------------------------------------------------------------------------------
+ const string expected = """
+ //--------------------------------------------------------------------------------------------------
+ //
+ // This code was generated by a tool.
+ //
+ // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
+ //
+ //--------------------------------------------------------------------------------------------------
- using System.CodeDom.Compiler;
- using AutomaticInterfaceAttribute;
- using System.IO;
+ using System.CodeDom.Compiler;
+ using AutomaticInterfaceAttribute;
+ using System.IO;
- namespace AutomaticInterfaceExample
+ namespace AutomaticInterfaceExample
+ {
+ [GeneratedCode("AutomaticInterface", "")]
+ public partial interface IDemoClass
{
- [GeneratedCode("AutomaticInterface", "")]
- public partial interface IDemoClass
- {
- ///
- string Hello();
-
- }
+ ///
+ string Hello();
+
}
+ }
- """;
- GenerateCode(code).Should().Be(expected);
- }
+ """;
+ GenerateCode(code).Should().Be(expected);
+ }
- [Fact]
- public void AddsPublicTaskMethodToInterface()
- {
- var code = """
+ [Fact]
+ public void AddsPublicTaskMethodToInterface()
+ {
+ const string code = """
- using AutomaticInterfaceAttribute;
- using System.IO;
- using System.Threading.Tasks;
+ using AutomaticInterfaceAttribute;
+ using System.IO;
+ using System.Threading.Tasks;
- namespace AutomaticInterfaceExample
- {
+ namespace AutomaticInterfaceExample
+ {
- [GenerateAutomaticInterface]
- class DemoClass
- {
- public async Task Hello(){return "";}
- }
+ [GenerateAutomaticInterface]
+ class DemoClass
+ {
+ public async Task Hello(){return "";}
}
+ }
- """;
+ """;
- var expected = """
- //--------------------------------------------------------------------------------------------------
- //
- // This code was generated by a tool.
- //
- // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
- //
- //--------------------------------------------------------------------------------------------------
+ const string expected = """
+ //--------------------------------------------------------------------------------------------------
+ //
+ // This code was generated by a tool.
+ //
+ // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
+ //
+ //--------------------------------------------------------------------------------------------------
- using System.CodeDom.Compiler;
- using AutomaticInterfaceAttribute;
- using System.IO;
- using System.Threading.Tasks;
+ using System.CodeDom.Compiler;
+ using AutomaticInterfaceAttribute;
+ using System.IO;
+ using System.Threading.Tasks;
- namespace AutomaticInterfaceExample
+ namespace AutomaticInterfaceExample
+ {
+ [GeneratedCode("AutomaticInterface", "")]
+ public partial interface IDemoClass
{
- [GeneratedCode("AutomaticInterface", "")]
- public partial interface IDemoClass
- {
- ///
- System.Threading.Tasks.Task Hello();
-
- }
+ ///
+ System.Threading.Tasks.Task Hello();
+
}
+ }
- """;
- GenerateCode(code).Should().Be(expected);
- }
+ """;
+ GenerateCode(code).Should().Be(expected);
+ }
- [Fact]
- public void AddsPublicWithParamsMethodToInterface()
- {
- var code = """
+ [Fact]
+ public void AddsPublicWithParamsMethodToInterface()
+ {
+ const string code = """
- using AutomaticInterfaceAttribute;
- using System.IO;
+ using AutomaticInterfaceAttribute;
+ using System.IO;
- namespace AutomaticInterfaceExample
- {
+ namespace AutomaticInterfaceExample
+ {
- [GenerateAutomaticInterface]
- class DemoClass
- {
-
- public string Hello(string x){return x;}
- }
+ [GenerateAutomaticInterface]
+ class DemoClass
+ {
+
+ public string Hello(string x){return x;}
}
+ }
- """;
+ """;
- var expected = """
- //--------------------------------------------------------------------------------------------------
- //
- // This code was generated by a tool.
- //
- // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
- //
- //--------------------------------------------------------------------------------------------------
+ const string expected = """
+ //--------------------------------------------------------------------------------------------------
+ //
+ // This code was generated by a tool.
+ //
+ // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
+ //
+ //--------------------------------------------------------------------------------------------------
- using System.CodeDom.Compiler;
- using AutomaticInterfaceAttribute;
- using System.IO;
+ using System.CodeDom.Compiler;
+ using AutomaticInterfaceAttribute;
+ using System.IO;
- namespace AutomaticInterfaceExample
+ namespace AutomaticInterfaceExample
+ {
+ [GeneratedCode("AutomaticInterface", "")]
+ public partial interface IDemoClass
{
- [GeneratedCode("AutomaticInterface", "")]
- public partial interface IDemoClass
- {
- ///
- string Hello(string x);
-
- }
+ ///
+ string Hello(string x);
+
}
+ }
- """;
- GenerateCode(code).Should().Be(expected);
- }
+ """;
+ GenerateCode(code).Should().Be(expected);
+ }
- [Fact]
- public void AddsPublicWithParamsGenericMethodToInterface()
- {
- var code = """
+ [Fact]
+ public void AddsPublicWithParamsGenericMethodToInterface()
+ {
+ const string code = """
- using AutomaticInterfaceAttribute;
- using System.IO;
- using System.Threading.Tasks;
+ using AutomaticInterfaceAttribute;
+ using System.IO;
+ using System.Threading.Tasks;
- namespace AutomaticInterfaceExample
- {
+ namespace AutomaticInterfaceExample
+ {
- [GenerateAutomaticInterface]
- class DemoClass
- {
- public string Hello(Task x){return "";}
- }
+ [GenerateAutomaticInterface]
+ class DemoClass
+ {
+ public string Hello(Task x){return "";}
}
+ }
- """;
+ """;
- var expected = """
- //--------------------------------------------------------------------------------------------------
- //
- // This code was generated by a tool.
- //
- // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
- //
- //--------------------------------------------------------------------------------------------------
+ const string expected = """
+ //--------------------------------------------------------------------------------------------------
+ //
+ // This code was generated by a tool.
+ //
+ // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
+ //
+ //--------------------------------------------------------------------------------------------------
- using System.CodeDom.Compiler;
- using AutomaticInterfaceAttribute;
- using System.IO;
- using System.Threading.Tasks;
+ using System.CodeDom.Compiler;
+ using AutomaticInterfaceAttribute;
+ using System.IO;
+ using System.Threading.Tasks;
- namespace AutomaticInterfaceExample
+ namespace AutomaticInterfaceExample
+ {
+ [GeneratedCode("AutomaticInterface", "")]
+ public partial interface IDemoClass
{
- [GeneratedCode("AutomaticInterface", "")]
- public partial interface IDemoClass
- {
- ///
- string Hello(System.Threading.Tasks.Task x);
-
- }
+ ///
+ string Hello(System.Threading.Tasks.Task x);
+
}
+ }
- """;
- GenerateCode(code).Should().Be(expected);
- }
+ """;
+ GenerateCode(code).Should().Be(expected);
+ }
- [Fact]
- public void AddsPublicWithMultipleParamsMethodToInterface()
- {
- var code = """
+ [Fact]
+ public void AddsPublicWithMultipleParamsMethodToInterface()
+ {
+ const string code = """
- using AutomaticInterfaceAttribute;
- using System.IO;
+ using AutomaticInterfaceAttribute;
+ using System.IO;
- namespace AutomaticInterfaceExample
- {
+ namespace AutomaticInterfaceExample
+ {
- [GenerateAutomaticInterface]
- class DemoClass
- {
- public string Hello(string x, int y, double z){return x;}
- }
+ [GenerateAutomaticInterface]
+ class DemoClass
+ {
+ public string Hello(string x, int y, double z){return x;}
}
+ }
- """;
+ """;
- var expected = """
- //--------------------------------------------------------------------------------------------------
- //
- // This code was generated by a tool.
- //
- // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
- //
- //--------------------------------------------------------------------------------------------------
+ const string expected = """
+ //--------------------------------------------------------------------------------------------------
+ //
+ // This code was generated by a tool.
+ //
+ // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
+ //
+ //--------------------------------------------------------------------------------------------------
- using System.CodeDom.Compiler;
- using AutomaticInterfaceAttribute;
- using System.IO;
+ using System.CodeDom.Compiler;
+ using AutomaticInterfaceAttribute;
+ using System.IO;
- namespace AutomaticInterfaceExample
+ namespace AutomaticInterfaceExample
+ {
+ [GeneratedCode("AutomaticInterface", "")]
+ public partial interface IDemoClass
{
- [GeneratedCode("AutomaticInterface", "")]
- public partial interface IDemoClass
- {
- ///
- string Hello(string x, int y, double z);
-
- }
+ ///
+ string Hello(string x, int y, double z);
+
}
+ }
- """;
- GenerateCode(code).Should().Be(expected);
- }
+ """;
+ GenerateCode(code).Should().Be(expected);
+ }
- [Fact]
- public void IgnoresNotPublicMethodToInterface()
- {
- var code = """
+ [Fact]
+ public void IgnoresNotPublicMethodToInterface()
+ {
+ const string code = """
- using AutomaticInterfaceAttribute;
- using System.IO;
+ using AutomaticInterfaceAttribute;
+ using System.IO;
- namespace AutomaticInterfaceExample
- {
+ namespace AutomaticInterfaceExample
+ {
- [GenerateAutomaticInterface]
- class DemoClass
- {
- private string Hello(string x, int y, double z){return x;}
- internal string Hello2(string x, int y, double z){return x;}
- }
+ [GenerateAutomaticInterface]
+ class DemoClass
+ {
+ private string Hello(string x, int y, double z){return x;}
+ internal string Hello2(string x, int y, double z){return x;}
}
+ }
- """;
+ """;
- var expected = """
- //--------------------------------------------------------------------------------------------------
- //
- // This code was generated by a tool.
- //
- // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
- //
- //--------------------------------------------------------------------------------------------------
+ const string expected = """
+ //--------------------------------------------------------------------------------------------------
+ //
+ // This code was generated by a tool.
+ //
+ // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
+ //
+ //--------------------------------------------------------------------------------------------------
- using System.CodeDom.Compiler;
- using AutomaticInterfaceAttribute;
- using System.IO;
+ using System.CodeDom.Compiler;
+ using AutomaticInterfaceAttribute;
+ using System.IO;
- namespace AutomaticInterfaceExample
+ namespace AutomaticInterfaceExample
+ {
+ [GeneratedCode("AutomaticInterface", "")]
+ public partial interface IDemoClass
{
- [GeneratedCode("AutomaticInterface", "")]
- public partial interface IDemoClass
- {
- }
}
+ }
+
+ """;
+ GenerateCode(code).Should().Be(expected);
+ }
- """;
- GenerateCode(code).Should().Be(expected);
- }
+ [Fact]
+ public void AddsDescriptionFromMethodToInterface()
+ {
+ const string code = """
- [Fact]
- public void AddsDescriptionFromMethodToInterface()
- {
- var code = """
+ using AutomaticInterfaceAttribute;
+ using System.IO;
- using AutomaticInterfaceAttribute;
- using System.IO;
+ namespace AutomaticInterfaceExample
+ {
- namespace AutomaticInterfaceExample
+ [GenerateAutomaticInterface]
+ class DemoClass
{
- [GenerateAutomaticInterface]
- class DemoClass
- {
-
- ///
- /// TEST
- ///
- ///
- public string Hello(string x){return x;}
- }
+ ///
+ /// TEST
+ ///
+ ///
+ public string Hello(string x){return x;}
}
+ }
- """;
+ """;
- var expected = """
- //--------------------------------------------------------------------------------------------------
- //
- // This code was generated by a tool.
- //
- // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
- //
- //--------------------------------------------------------------------------------------------------
+ const string expected = """
+ //--------------------------------------------------------------------------------------------------
+ //
+ // This code was generated by a tool.
+ //
+ // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
+ //
+ //--------------------------------------------------------------------------------------------------
- using System.CodeDom.Compiler;
- using AutomaticInterfaceAttribute;
- using System.IO;
+ using System.CodeDom.Compiler;
+ using AutomaticInterfaceAttribute;
+ using System.IO;
- namespace AutomaticInterfaceExample
+ namespace AutomaticInterfaceExample
+ {
+ [GeneratedCode("AutomaticInterface", "")]
+ public partial interface IDemoClass
{
- [GeneratedCode("AutomaticInterface", "")]
- public partial interface IDemoClass
- {
- ///
- string Hello(string x);
-
- }
+ ///
+ string Hello(string x);
+
}
+ }
+
+ """;
+ GenerateCode(code).Should().Be(expected);
+ }
- """;
- GenerateCode(code).Should().Be(expected);
- }
+ [Fact]
+ public void AddsMultiLineDescriptionFromMethodToInterface()
+ {
+ const string code = """
- [Fact]
- public void AddsMultiLineDescriptionFromMethodToInterface()
- {
- var code = """
+ using AutomaticInterfaceAttribute;
+ using System.IO;
- using AutomaticInterfaceAttribute;
- using System.IO;
+ namespace AutomaticInterfaceExample
+ {
- namespace AutomaticInterfaceExample
+ [GenerateAutomaticInterface]
+ class DemoClass
{
- [GenerateAutomaticInterface]
- class DemoClass
- {
-
- /**
- * Hello World!
- */
- public string Hello(string x){return x;}
- }
+ /**
+ * Hello World!
+ */
+ public string Hello(string x){return x;}
}
+ }
- """;
+ """;
- var expected = """
- //--------------------------------------------------------------------------------------------------
- //
- // This code was generated by a tool.
- //
- // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
- //
- //--------------------------------------------------------------------------------------------------
+ const string expected = """
+ //--------------------------------------------------------------------------------------------------
+ //
+ // This code was generated by a tool.
+ //
+ // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
+ //
+ //--------------------------------------------------------------------------------------------------
- using System.CodeDom.Compiler;
- using AutomaticInterfaceAttribute;
- using System.IO;
+ using System.CodeDom.Compiler;
+ using AutomaticInterfaceAttribute;
+ using System.IO;
- namespace AutomaticInterfaceExample
+ namespace AutomaticInterfaceExample
+ {
+ [GeneratedCode("AutomaticInterface", "")]
+ public partial interface IDemoClass
{
- [GeneratedCode("AutomaticInterface", "")]
- public partial interface IDemoClass
- {
- ///
- string Hello(string x);
-
- }
+ ///
+ string Hello(string x);
+
}
+ }
- """;
- GenerateCode(code).Should().Be(expected);
- }
+ """;
+ GenerateCode(code).Should().Be(expected);
+ }
- [Fact]
- public void OmitsPrivateSetPropertyInterface()
- {
- var code = """
+ [Fact]
+ public void OmitsPrivateSetPropertyInterface()
+ {
+ const string code = """
- using AutomaticInterfaceAttribute;
+ using AutomaticInterfaceAttribute;
- namespace AutomaticInterfaceExample
- {
+ namespace AutomaticInterfaceExample
+ {
- [GenerateAutomaticInterface]
- class DemoClass
- {
- ///
- public string Hello { get; private set; }
- }
+ [GenerateAutomaticInterface]
+ class DemoClass
+ {
+ ///
+ public string Hello { get; private set; }
}
+ }
- """;
+ """;
- var expected = """
- //--------------------------------------------------------------------------------------------------
- //
- // This code was generated by a tool.
- //
- // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
- //
- //--------------------------------------------------------------------------------------------------
+ const string expected = """
+ //--------------------------------------------------------------------------------------------------
+ //
+ // This code was generated by a tool.
+ //
+ // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
+ //
+ //--------------------------------------------------------------------------------------------------
- using System.CodeDom.Compiler;
- using AutomaticInterfaceAttribute;
+ using System.CodeDom.Compiler;
+ using AutomaticInterfaceAttribute;
- namespace AutomaticInterfaceExample
+ namespace AutomaticInterfaceExample
+ {
+ [GeneratedCode("AutomaticInterface", "")]
+ public partial interface IDemoClass
{
- [GeneratedCode("AutomaticInterface", "")]
- public partial interface IDemoClass
- {
- ///
- string Hello { get; }
-
- }
+ ///
+ string Hello { get; }
+
}
+ }
+
+ """;
+ GenerateCode(code).Should().Be(expected);
+ }
- """;
- GenerateCode(code).Should().Be(expected);
- }
+ [Fact]
+ public void CopiesDocumentationOfPropertyToInterface()
+ {
+ const string code = """
- [Fact]
- public void CopiesDocumentationOfPropertyToInterface()
- {
- var code = """
+ using AutomaticInterfaceAttribute;
- using AutomaticInterfaceAttribute;
+ namespace AutomaticInterfaceExample
+ {
- namespace AutomaticInterfaceExample
+ [GenerateAutomaticInterface]
+ class DemoClass
{
+ ///
+ /// Bla bla
+ ///
+ public string Hello { get; private set; }
+ }
+ }
- [GenerateAutomaticInterface]
- class DemoClass
- {
- ///
- /// Bla bla
- ///
- public string Hello { get; private set; }
- }
+ """;
+
+ const string expected = """
+ //--------------------------------------------------------------------------------------------------
+ //
+ // This code was generated by a tool.
+ //
+ // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
+ //
+ //--------------------------------------------------------------------------------------------------
+
+ using System.CodeDom.Compiler;
+ using AutomaticInterfaceAttribute;
+
+ namespace AutomaticInterfaceExample
+ {
+ [GeneratedCode("AutomaticInterface", "")]
+ public partial interface IDemoClass
+ {
+ ///
+ string Hello { get; }
+
}
+ }
- """;
+ """;
+ GenerateCode(code).Should().Be(expected);
+ }
- var expected = """
- //--------------------------------------------------------------------------------------------------
- //
- // This code was generated by a tool.
- //
- // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
- //
- //--------------------------------------------------------------------------------------------------
+ [Fact]
+ public void CopiesDocumentationOfClassToInterface()
+ {
+ const string code = """
- using System.CodeDom.Compiler;
- using AutomaticInterfaceAttribute;
+ using AutomaticInterfaceAttribute;
- namespace AutomaticInterfaceExample
+ namespace AutomaticInterfaceExample
+ {
+ ///
+ /// Bla bla
+ ///
+ [GenerateAutomaticInterface]
+ class DemoClass
{
- [GeneratedCode("AutomaticInterface", "")]
- public partial interface IDemoClass
- {
- ///
- string Hello { get; }
-
- }
+ public string Hello { get; private set; }
}
+ }
- """;
- GenerateCode(code).Should().Be(expected);
- }
+ """;
- [Fact]
- public void CopiesDocumentationOfClassToInterface()
- {
- var code = """
+ const string expected = """
+ //--------------------------------------------------------------------------------------------------
+ //
+ // This code was generated by a tool.
+ //
+ // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
+ //
+ //--------------------------------------------------------------------------------------------------
- using AutomaticInterfaceAttribute;
+ using System.CodeDom.Compiler;
+ using AutomaticInterfaceAttribute;
- namespace AutomaticInterfaceExample
+ namespace AutomaticInterfaceExample
+ {
+ ///
+ /// Bla bla
+ ///
+ [GeneratedCode("AutomaticInterface", "")]
+ public partial interface IDemoClass
{
- ///
- /// Bla bla
- ///
- [GenerateAutomaticInterface]
- class DemoClass
- {
- public string Hello { get; private set; }
- }
+ ///
+ string Hello { get; }
+
}
+ }
- """;
+ """;
+ GenerateCode(code).Should().Be(expected);
+ }
- var expected = """
- //--------------------------------------------------------------------------------------------------
- //
- // This code was generated by a tool.
- //
- // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
- //
- //--------------------------------------------------------------------------------------------------
+ [Fact]
+ public void DoesNotCopyCtorToToInterface()
+ {
+ const string code = """
- using System.CodeDom.Compiler;
- using AutomaticInterfaceAttribute;
+ using AutomaticInterfaceAttribute;
- namespace AutomaticInterfaceExample
- {
+ namespace AutomaticInterfaceExample
+ {
///
/// Bla bla
///
- [GeneratedCode("AutomaticInterface", "")]
- public partial interface IDemoClass
+ [GenerateAutomaticInterface]
+ class DemoClass
+ {
+ DemoClass(string x)
{
- ///
- string Hello { get; }
-
+
}
+
+ public string Hello { get; private set; }
}
+ }
- """;
- GenerateCode(code).Should().Be(expected);
- }
+ """;
- [Fact]
- public void DoesNotCopyCtorToToInterface()
- {
- var code = """
+ const string expected = """
+ //--------------------------------------------------------------------------------------------------
+ //
+ // This code was generated by a tool.
+ //
+ // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
+ //
+ //--------------------------------------------------------------------------------------------------
- using AutomaticInterfaceAttribute;
+ using System.CodeDom.Compiler;
+ using AutomaticInterfaceAttribute;
- namespace AutomaticInterfaceExample
+ namespace AutomaticInterfaceExample
+ {
+ ///
+ /// Bla bla
+ ///
+ [GeneratedCode("AutomaticInterface", "")]
+ public partial interface IDemoClass
{
- ///
- /// Bla bla
- ///
- [GenerateAutomaticInterface]
- class DemoClass
- {
- DemoClass(string x)
- {
-
- }
-
- public string Hello { get; private set; }
- }
+ ///
+ string Hello { get; }
+
}
+ }
- """;
+ """;
+ GenerateCode(code).Should().Be(expected);
+ }
- var expected = """
- //--------------------------------------------------------------------------------------------------
- //
- // This code was generated by a tool.
- //
- // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
- //
- //--------------------------------------------------------------------------------------------------
+ [Fact]
+ public void DoesNotCopyStaticMethodsToInterface()
+ {
+ const string code = """
- using System.CodeDom.Compiler;
- using AutomaticInterfaceAttribute;
+ using AutomaticInterfaceAttribute;
- namespace AutomaticInterfaceExample
- {
+ namespace AutomaticInterfaceExample
+ {
///
/// Bla bla
///
- [GeneratedCode("AutomaticInterface", "")]
- public partial interface IDemoClass
+ [GenerateAutomaticInterface]
+ class DemoClass
+ {
+ public static string Hello => "abc"; // property
+
+ public static string StaticMethod() // method
{
- ///
- string Hello { get; }
-
- }
+ return "static";
+ }
}
+ }
- """;
- GenerateCode(code).Should().Be(expected);
- }
+ """;
- [Fact]
- public void DoesNotCopyStaticMethodsToInterface()
- {
- var code = """
+ const string expected = """
+ //--------------------------------------------------------------------------------------------------
+ //
+ // This code was generated by a tool.
+ //
+ // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
+ //
+ //--------------------------------------------------------------------------------------------------
- using AutomaticInterfaceAttribute;
+ using System.CodeDom.Compiler;
+ using AutomaticInterfaceAttribute;
- namespace AutomaticInterfaceExample
+ namespace AutomaticInterfaceExample
+ {
+ ///
+ /// Bla bla
+ ///
+ [GeneratedCode("AutomaticInterface", "")]
+ public partial interface IDemoClass
{
- ///
- /// Bla bla
- ///
- [GenerateAutomaticInterface]
- class DemoClass
- {
- public static string Hello => "abc"; // property
-
- public static string StaticMethod() // method
- {
- return "static";
- }
- }
}
+ }
- """;
+ """;
+ GenerateCode(code).Should().Be(expected);
+ }
- var expected = """
- //--------------------------------------------------------------------------------------------------
- //
- // This code was generated by a tool.
- //
- // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
- //
- //--------------------------------------------------------------------------------------------------
+ [Fact]
+ public void MakesGenericInterface()
+ {
+ const string code = """
- using System.CodeDom.Compiler;
- using AutomaticInterfaceAttribute;
+ using AutomaticInterfaceAttribute;
- namespace AutomaticInterfaceExample
- {
+ namespace AutomaticInterfaceExample
+ {
///
/// Bla bla
///
- [GeneratedCode("AutomaticInterface", "")]
- public partial interface IDemoClass
- {
- }
+ [GenerateAutomaticInterface]
+ class DemoClass where T:class
+ {
}
+ }
- """;
- GenerateCode(code).Should().Be(expected);
- }
+ """;
- [Fact]
- public void MakesGenericInterface()
- {
- var code = """
+ const string expected = """
+ //--------------------------------------------------------------------------------------------------
+ //
+ // This code was generated by a tool.
+ //
+ // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
+ //
+ //--------------------------------------------------------------------------------------------------
- using AutomaticInterfaceAttribute;
+ using System.CodeDom.Compiler;
+ using AutomaticInterfaceAttribute;
- namespace AutomaticInterfaceExample
+ namespace AutomaticInterfaceExample
+ {
+ ///
+ /// Bla bla
+ ///
+ [GeneratedCode("AutomaticInterface", "")]
+ public partial interface IDemoClass where T:class
{
- ///
- /// Bla bla
- ///
- [GenerateAutomaticInterface]
- class DemoClass where T:class
- {
- }
}
+ }
- """;
+ """;
+ GenerateCode(code).Should().Be(expected);
+ }
- var expected = """
- //--------------------------------------------------------------------------------------------------
- //
- // This code was generated by a tool.
- //
- // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
- //
- //--------------------------------------------------------------------------------------------------
+ [Fact]
+ public void CopiesEventsToInterface()
+ {
+ const string code = """
- using System.CodeDom.Compiler;
- using AutomaticInterfaceAttribute;
+ using AutomaticInterfaceAttribute;
+ using System;
- namespace AutomaticInterfaceExample
+ namespace AutomaticInterfaceExample
+ {
+ ///
+ /// Bla bla
+ ///
+ [GenerateAutomaticInterface]
+ class DemoClass
{
+
///
/// Bla bla
///
- [GeneratedCode("AutomaticInterface", "")]
- public partial interface IDemoClass where T:class
- {
- }
+ public event EventHandler ShapeChanged; // included
+
+ private event EventHandler ShapeChanged2; // ignored because not public
}
+ }
- """;
- GenerateCode(code).Should().Be(expected);
- }
+ """;
- [Fact]
- public void CopiesEventsToInterface()
- {
- var code = """
+ const string expected = """
+ //--------------------------------------------------------------------------------------------------
+ //
+ // This code was generated by a tool.
+ //
+ // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
+ //
+ //--------------------------------------------------------------------------------------------------
- using AutomaticInterfaceAttribute;
- using System;
+ using System.CodeDom.Compiler;
+ using AutomaticInterfaceAttribute;
+ using System;
- namespace AutomaticInterfaceExample
+ namespace AutomaticInterfaceExample
+ {
+ ///
+ /// Bla bla
+ ///
+ [GeneratedCode("AutomaticInterface", "")]
+ public partial interface IDemoClass
{
- ///
- /// Bla bla
- ///
- [GenerateAutomaticInterface]
- class DemoClass
- {
-
- ///
- /// Bla bla
- ///
- public event EventHandler ShapeChanged; // included
-
- private event EventHandler ShapeChanged2; // ignored because not public
- }
+ ///
+ event System.EventHandler ShapeChanged;
+
}
+ }
- """;
+ """;
+ GenerateCode(code).Should().Be(expected);
+ }
- var expected = """
- //--------------------------------------------------------------------------------------------------
- //
- // This code was generated by a tool.
- //
- // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
- //
- //--------------------------------------------------------------------------------------------------
+ [Fact]
+ public void DoesNotCopyIndexerToInterface()
+ {
+ const string code = """
- using System.CodeDom.Compiler;
- using AutomaticInterfaceAttribute;
- using System;
+ using AutomaticInterfaceAttribute;
+ using System;
- namespace AutomaticInterfaceExample
+ namespace AutomaticInterfaceExample
+ {
+ ///
+ /// Bla bla
+ ///
+ [GenerateAutomaticInterface]
+ class DemoClass
{
+
+ private int[] arr = new int[100];
+
///
/// Bla bla
///
- [GeneratedCode("AutomaticInterface", "")]
- public partial interface IDemoClass
+ public int this[int index] // currently ignored
{
- ///
- event System.EventHandler ShapeChanged;
-
+ get => arr[index];
+ set => arr[index] = value;
}
}
+ }
- """;
- GenerateCode(code).Should().Be(expected);
- }
+ """;
- [Fact]
- public void DoesNotCopyIndexerToInterface()
- {
- var code = """
+ const string expected = """
+ //--------------------------------------------------------------------------------------------------
+ //
+ // This code was generated by a tool.
+ //
+ // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
+ //
+ //--------------------------------------------------------------------------------------------------
- using AutomaticInterfaceAttribute;
- using System;
+ using System.CodeDom.Compiler;
+ using AutomaticInterfaceAttribute;
+ using System;
- namespace AutomaticInterfaceExample
+ namespace AutomaticInterfaceExample
+ {
+ ///
+ /// Bla bla
+ ///
+ [GeneratedCode("AutomaticInterface", "")]
+ public partial interface IDemoClass
{
- ///
- /// Bla bla
- ///
- [GenerateAutomaticInterface]
- class DemoClass
- {
-
- private int[] arr = new int[100];
-
- ///
- /// Bla bla
- ///
- public int this[int index] // currently ignored
- {
- get => arr[index];
- set => arr[index] = value;
- }
- }
}
+ }
- """;
+ """;
+ GenerateCode(code).Should().Be(expected);
+ }
- var expected = """
- //--------------------------------------------------------------------------------------------------
- //
- // This code was generated by a tool.
- //
- // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
- //
- //--------------------------------------------------------------------------------------------------
+ [Fact]
+ public void FullExample()
+ {
+ const string code = """
- using System.CodeDom.Compiler;
- using AutomaticInterfaceAttribute;
- using System;
+ using AutomaticInterfaceAttribute;
+ using System;
- namespace AutomaticInterfaceExample
- {
+ namespace AutomaticInterfaceExample
+ {
///
/// Bla bla
///
- [GeneratedCode("AutomaticInterface", "")]
- public partial interface IDemoClass
- {
- }
- }
-
- """;
- GenerateCode(code).Should().Be(expected);
- }
-
- [Fact]
- public void FullExample()
- {
- var code = """
+ [GenerateAutomaticInterface]
+ class DemoClass
+ {
+ ///
+ /// Property Documentation will be copied
+ ///
+ public string Hello { get; set; } // included, get and set are copied to the interface when public
- using AutomaticInterfaceAttribute;
- using System;
+ public string OnlyGet { get; } // included, get and set are copied to the interface when public
- namespace AutomaticInterfaceExample
- {
- ///
- /// Bla bla
- ///
- [GenerateAutomaticInterface]
- class DemoClass
+ ///
+ /// Method Documentation will be copied
+ ///
+ public string AMethod(string x, string y) // included
{
- ///
- /// Property Documentation will be copied
- ///
- public string Hello { get; set; } // included, get and set are copied to the interface when public
+ return BMethod(x,y);
+ }
- public string OnlyGet { get; } // included, get and set are copied to the interface when public
+ private string BMethod(string x, string y) // ignored because not public
+ {
+ return x + y;
+ }
- ///
- /// Method Documentation will be copied
- ///
- public string AMethod(string x, string y) // included
- {
- return BMethod(x,y);
- }
+ public static string StaticProperty => "abc"; // static property, ignored
- private string BMethod(string x, string y) // ignored because not public
+ public static string StaticMethod() // static method, ignored
{
- return x + y;
+ return "static" + DateTime.Now;
}
- public static string StaticProperty => "abc"; // static property, ignored
-
- public static string StaticMethod() // static method, ignored
- {
- return "static" + DateTime.Now;
- }
-
- ///
- /// event Documentation will be copied
- ///
+ ///
+ /// event Documentation will be copied
+ ///
- public event EventHandler ShapeChanged; // included
+ public event EventHandler ShapeChanged; // included
- private event EventHandler ShapeChanged2; // ignored because not public
+ private event EventHandler ShapeChanged2; // ignored because not public
- private readonly int[] arr = new int[100];
+ private readonly int[] arr = new int[100];
- public int this[int index] // currently ignored
- {
- get => arr[index];
- set => arr[index] = value;
- }
+ public int this[int index] // currently ignored
+ {
+ get => arr[index];
+ set => arr[index] = value;
}
}
+ }
- """;
+ """;
- var expected = """
- //--------------------------------------------------------------------------------------------------
- //
- // This code was generated by a tool.
- //
- // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
- //
- //--------------------------------------------------------------------------------------------------
+ const string expected = """
+ //--------------------------------------------------------------------------------------------------
+ //
+ // This code was generated by a tool.
+ //
+ // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
+ //
+ //--------------------------------------------------------------------------------------------------
- using System.CodeDom.Compiler;
- using AutomaticInterfaceAttribute;
- using System;
+ using System.CodeDom.Compiler;
+ using AutomaticInterfaceAttribute;
+ using System;
- namespace AutomaticInterfaceExample
+ namespace AutomaticInterfaceExample
+ {
+ ///
+ /// Bla bla
+ ///
+ [GeneratedCode("AutomaticInterface", "")]
+ public partial interface IDemoClass
{
- ///
- /// Bla bla
- ///
- [GeneratedCode("AutomaticInterface", "")]
- public partial interface IDemoClass
- {
- ///
- string Hello { get; set; }
-
- ///
- string OnlyGet { get; }
-
- ///
- string AMethod(string x, string y);
-
- ///
- event System.EventHandler ShapeChanged;
-
- }
+ ///
+ string Hello { get; set; }
+
+ ///
+ string OnlyGet { get; }
+
+ ///
+ string AMethod(string x, string y);
+
+ ///
+ event System.EventHandler ShapeChanged;
+
}
+ }
- """;
- GenerateCode(code).Should().Be(expected);
- }
+ """;
+ GenerateCode(code).Should().Be(expected);
+ }
- [Fact]
- public void WorksWithFileScopedNamespace()
- {
- var code = """
+ [Fact]
+ public void WorksWithFileScopedNamespace()
+ {
+ const string code = """
- using AutomaticInterfaceAttribute;
+ using AutomaticInterfaceAttribute;
- namespace AutomaticInterfaceExample;
+ namespace AutomaticInterfaceExample;
- [GenerateAutomaticInterface]
- class DemoClass
- {
- public string Hello { get; set; }
- }
+ [GenerateAutomaticInterface]
+ class DemoClass
+ {
+ public string Hello { get; set; }
+ }
- """;
+ """;
- var expected = """
- //--------------------------------------------------------------------------------------------------
- //
- // This code was generated by a tool.
- //
- // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
- //
- //--------------------------------------------------------------------------------------------------
+ const string expected = """
+ //--------------------------------------------------------------------------------------------------
+ //
+ // This code was generated by a tool.
+ //
+ // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
+ //
+ //--------------------------------------------------------------------------------------------------
- using System.CodeDom.Compiler;
- using AutomaticInterfaceAttribute;
+ using System.CodeDom.Compiler;
+ using AutomaticInterfaceAttribute;
- namespace AutomaticInterfaceExample
+ namespace AutomaticInterfaceExample
+ {
+ [GeneratedCode("AutomaticInterface", "")]
+ public partial interface IDemoClass
{
- [GeneratedCode("AutomaticInterface", "")]
- public partial interface IDemoClass
- {
- ///
- string Hello { get; set; }
-
- }
+ ///
+ string Hello { get; set; }
+
}
+ }
- """;
- GenerateCode(code).Should().Be(expected);
- }
+ """;
+ GenerateCode(code).Should().Be(expected);
+ }
- [Fact]
- public void WorksWithGenericMethods()
- {
- var code = """
+ [Fact]
+ public void WorksWithGenericMethods()
+ {
+ const string code = """
- using AutomaticInterfaceAttribute;
+ using AutomaticInterfaceAttribute;
- namespace AutomaticInterfaceExample;
+ namespace AutomaticInterfaceExample;
- [GenerateAutomaticInterface]
- public class DemoClass
+ [GenerateAutomaticInterface]
+ public class DemoClass
+ {
+ ///
+ public string CMethod(string x, string y)
+ where T : class
+ where T1 : struct
+ where T3 : DemoClass
+ where T4 : IDemoClass
{
- ///
- public string CMethod(string x, string y)
- where T : class
- where T1 : struct
- where T3 : DemoClass
- where T4 : IDemoClass
- {
- return "Ok";
- }
+ return "Ok";
}
+ }
- """;
+ """;
- var expected = """
- //--------------------------------------------------------------------------------------------------
- //
- // This code was generated by a tool.
- //
- // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
- //
- //--------------------------------------------------------------------------------------------------
+ const string expected = """
+ //--------------------------------------------------------------------------------------------------
+ //
+ // This code was generated by a tool.
+ //
+ // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
+ //
+ //--------------------------------------------------------------------------------------------------
- using System.CodeDom.Compiler;
- using AutomaticInterfaceAttribute;
+ using System.CodeDom.Compiler;
+ using AutomaticInterfaceAttribute;
- namespace AutomaticInterfaceExample
+ namespace AutomaticInterfaceExample
+ {
+ [GeneratedCode("AutomaticInterface", "")]
+ public partial interface IDemoClass
{
- [GeneratedCode("AutomaticInterface", "")]
- public partial interface IDemoClass
- {
- ///
- string CMethod(string x, string y) where T : class where T1 : struct where T3 : DemoClass where T4 : IDemoClass;
-
- }
+ ///
+ string CMethod(string x, string y) where T : class where T1 : struct where T3 : DemoClass where T4 : IDemoClass;
+
}
+ }
- """;
- GenerateCode(code).Should().Be(expected);
- }
+ """;
+ GenerateCode(code).Should().Be(expected);
+ }
- [Fact]
- public void GeneratesOverloadedMethodInterface()
- {
- var code = """
+ [Fact]
+ public void GeneratesOverloadedMethodInterface()
+ {
+ const string code = """
- using AutomaticInterfaceAttribute;
+ using AutomaticInterfaceAttribute;
- namespace AutomaticInterfaceExample
- {
+ namespace AutomaticInterfaceExample
+ {
- [GenerateAutomaticInterface]
- class DemoClass
+ [GenerateAutomaticInterface]
+ class DemoClass
+ {
+ public string AMethod(string x, string y)
{
- public string AMethod(string x, string y)
- {
- return string.Empty;
- }
+ return string.Empty;
+ }
- public string AMethod(string x, string y, string crash)
- {
- return string.Empty;
- }
+ public string AMethod(string x, string y, string crash)
+ {
+ return string.Empty;
}
}
+ }
- """;
+ """;
- var expected = """
- //--------------------------------------------------------------------------------------------------
- //
- // This code was generated by a tool.
- //
- // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
- //
- //--------------------------------------------------------------------------------------------------
+ const string expected = """
+ //--------------------------------------------------------------------------------------------------
+ //
+ // This code was generated by a tool.
+ //
+ // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
+ //
+ //--------------------------------------------------------------------------------------------------
- using System.CodeDom.Compiler;
- using AutomaticInterfaceAttribute;
+ using System.CodeDom.Compiler;
+ using AutomaticInterfaceAttribute;
- namespace AutomaticInterfaceExample
+ namespace AutomaticInterfaceExample
+ {
+ [GeneratedCode("AutomaticInterface", "")]
+ public partial interface IDemoClass
{
- [GeneratedCode("AutomaticInterface", "")]
- public partial interface IDemoClass
- {
- ///
- string AMethod(string x, string y);
-
- ///
- string AMethod(string x, string y, string crash);
-
- }
+ ///
+ string AMethod(string x, string y);
+
+ ///
+ string AMethod(string x, string y, string crash);
+
}
+ }
- """;
- GenerateCode(code).Should().Be(expected);
- }
+ """;
+ GenerateCode(code).Should().Be(expected);
+ }
- [Fact]
- public void WorksWithNullableContext()
- {
- var code = """
+ [Fact]
+ public void WorksWithNullableContext()
+ {
+ const string code = """
- using AutomaticInterfaceAttribute;
- namespace AutomaticInterfaceExample;
- [GenerateAutomaticInterface]
- public class DemoClass
+ using AutomaticInterfaceAttribute;
+ namespace AutomaticInterfaceExample;
+ [GenerateAutomaticInterface]
+ public class DemoClass
+ {
+ public string AMethod(DemoClass? x, string y)
{
- public string AMethod(DemoClass? x, string y)
- {
- return "Ok";
- }
+ return "Ok";
}
+ }
- """;
+ """;
- var expected = """
- //--------------------------------------------------------------------------------------------------
- //
- // This code was generated by a tool.
- //
- // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
- //
- //--------------------------------------------------------------------------------------------------
+ const string expected = """
+ //--------------------------------------------------------------------------------------------------
+ //
+ // This code was generated by a tool.
+ //
+ // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
+ //
+ //--------------------------------------------------------------------------------------------------
- #nullable enable
- using System.CodeDom.Compiler;
- using AutomaticInterfaceAttribute;
+ #nullable enable
+ using System.CodeDom.Compiler;
+ using AutomaticInterfaceAttribute;
- namespace AutomaticInterfaceExample
+ namespace AutomaticInterfaceExample
+ {
+ [GeneratedCode("AutomaticInterface", "")]
+ public partial interface IDemoClass
{
- [GeneratedCode("AutomaticInterface", "")]
- public partial interface IDemoClass
- {
- ///
- string AMethod(AutomaticInterfaceExample.DemoClass? x, string y);
-
- }
+ ///
+ string AMethod(AutomaticInterfaceExample.DemoClass? x, string y);
+
}
- #nullable restore
+ }
+ #nullable restore
- """;
- GenerateCode(code).Should().Be(expected);
- }
+ """;
+ GenerateCode(code).Should().Be(expected);
+ }
- [Fact]
- public void WorksWithNullableReturn()
- {
- var code = """
+ [Fact]
+ public void WorksWithNullableReturn()
+ {
+ const string code = """
- using AutomaticInterfaceAttribute;
- namespace AutomaticInterfaceExample;
- [GenerateAutomaticInterface]
- public class DemoClass
+ using AutomaticInterfaceAttribute;
+ namespace AutomaticInterfaceExample;
+ [GenerateAutomaticInterface]
+ public class DemoClass
+ {
+ public string? AMethod(DemoClass x, string y)
{
- public string? AMethod(DemoClass x, string y)
- {
- return "Ok";
- }
+ return "Ok";
}
+ }
- """;
+ """;
- var expected = """
- //--------------------------------------------------------------------------------------------------
- //
- // This code was generated by a tool.
- //
- // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
- //
- //--------------------------------------------------------------------------------------------------
+ const string expected = """
+ //--------------------------------------------------------------------------------------------------
+ //
+ // This code was generated by a tool.
+ //
+ // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
+ //
+ //--------------------------------------------------------------------------------------------------
- #nullable enable
- using System.CodeDom.Compiler;
- using AutomaticInterfaceAttribute;
+ #nullable enable
+ using System.CodeDom.Compiler;
+ using AutomaticInterfaceAttribute;
- namespace AutomaticInterfaceExample
+ namespace AutomaticInterfaceExample
+ {
+ [GeneratedCode("AutomaticInterface", "")]
+ public partial interface IDemoClass
{
- [GeneratedCode("AutomaticInterface", "")]
- public partial interface IDemoClass
- {
- ///
- string? AMethod(AutomaticInterfaceExample.DemoClass x, string y);
-
- }
+ ///
+ string? AMethod(AutomaticInterfaceExample.DemoClass x, string y);
+
}
- #nullable restore
+ }
+ #nullable restore
- """;
- GenerateCode(code).Should().Be(expected);
- }
+ """;
+ GenerateCode(code).Should().Be(expected);
+ }
- [Fact]
- public void NullableEvent()
- {
- var code = """
+ [Fact]
+ public void NullableEvent()
+ {
+ const string code = """
- using AutomaticInterfaceAttribute;
- using System;
+ using AutomaticInterfaceAttribute;
+ using System;
- namespace AutomaticInterfaceExample
+ namespace AutomaticInterfaceExample
+ {
+ ///
+ /// Bla bla
+ ///
+ [GenerateAutomaticInterface]
+ class DemoClass
{
- ///
- /// Bla bla
- ///
- [GenerateAutomaticInterface]
- class DemoClass
- {
- ///
- /// Bla bla
- ///
- public event EventHandler? ShapeChangedNullable;
- }
+ ///
+ /// Bla bla
+ ///
+ public event EventHandler? ShapeChangedNullable;
+ }
+ }
+
+ """;
+
+ const string expected = """
+ //--------------------------------------------------------------------------------------------------
+ //
+ // This code was generated by a tool.
+ //
+ // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
+ //
+ //--------------------------------------------------------------------------------------------------
+
+ using System.CodeDom.Compiler;
+ using AutomaticInterfaceAttribute;
+ using System;
+
+ namespace AutomaticInterfaceExample
+ {
+ ///
+ /// Bla bla
+ ///
+ [GeneratedCode("AutomaticInterface", "")]
+ public partial interface IDemoClass
+ {
+ ///
+ event System.EventHandler? ShapeChangedNullable;
+
}
+ }
- """;
+ """;
+ GenerateCode(code).Should().Be(expected);
+ }
- var expected = """
- //--------------------------------------------------------------------------------------------------
- //
- // This code was generated by a tool.
- //
- // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
- //
- //--------------------------------------------------------------------------------------------------
+ [Fact]
+ public void NullableProperty()
+ {
+ const string code = """
- using System.CodeDom.Compiler;
- using AutomaticInterfaceAttribute;
- using System;
+ using AutomaticInterfaceAttribute;
+ using System;
- namespace AutomaticInterfaceExample
+ namespace AutomaticInterfaceExample
+ {
+ ///
+ /// Bla bla
+ ///
+ [GenerateAutomaticInterface]
+ class DemoClass
{
+
///
/// Bla bla
///
- [GeneratedCode("AutomaticInterface", "")]
- public partial interface IDemoClass
- {
- ///
- event System.EventHandler? ShapeChangedNullable;
-
- }
+ public string? NullableProperty { get; set; }
}
+ }
- """;
- GenerateCode(code).Should().Be(expected);
- }
+ """;
- [Fact]
- public void NullableProperty()
- {
- const string code = """
+ const string expected = """
+ //--------------------------------------------------------------------------------------------------
+ //
+ // This code was generated by a tool.
+ //
+ // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
+ //
+ //--------------------------------------------------------------------------------------------------
- using AutomaticInterfaceAttribute;
- using System;
+ using System.CodeDom.Compiler;
+ using AutomaticInterfaceAttribute;
+ using System;
- namespace AutomaticInterfaceExample
+ namespace AutomaticInterfaceExample
+ {
+ ///
+ /// Bla bla
+ ///
+ [GeneratedCode("AutomaticInterface", "")]
+ public partial interface IDemoClass
{
- ///
- /// Bla bla
- ///
- [GenerateAutomaticInterface]
- class DemoClass
- {
-
- ///
- /// Bla bla
- ///
- public string? NullableProperty { get; set; }
- }
+ ///
+ string? NullableProperty { get; set; }
+
}
+ }
- """;
+ """;
+ GenerateCode(code).Should().Be(expected);
+ }
- var expected = """
- //--------------------------------------------------------------------------------------------------
- //
- // This code was generated by a tool.
- //
- // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
- //
- //--------------------------------------------------------------------------------------------------
+ [Fact]
+ public void BooleanWithNonNull()
+ {
+ const string code = """
- using System.CodeDom.Compiler;
- using AutomaticInterfaceAttribute;
- using System;
+ using AutomaticInterfaceAttribute;
+ using System;
- namespace AutomaticInterfaceExample
- {
+ namespace AutomaticInterfaceExample
+ {
///
/// Bla bla
///
- [GeneratedCode("AutomaticInterface", "")]
- public partial interface IDemoClass
- {
- ///
- string? NullableProperty { get; set; }
-
- }
- }
+ [GenerateAutomaticInterface]
+ class DemoClass
+ {
- """;
- GenerateCode(code).Should().Be(expected);
- }
+ public async Task GetFinalDocumentsByIDFails(
+ string agreementID,
+ string docType,
+ bool amt = false ,
+ bool? attachSupportingDocuments = true,
+ CancellationToken cancellationToken = default)
+ {
+ await Task.Delay(100);
+ return default(Stream?);
+
+ }
+ }
+ }
+
+ """;
+
+ const string expected = """
+ //--------------------------------------------------------------------------------------------------
+ //
+ // This code was generated by a tool.
+ //
+ // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
+ //
+ //--------------------------------------------------------------------------------------------------
+
+ #nullable enable
+ using System.CodeDom.Compiler;
+ using AutomaticInterfaceAttribute;
+ using System;
+
+ namespace AutomaticInterfaceExample
+ {
+ ///
+ /// Bla bla
+ ///
+ [GeneratedCode("AutomaticInterface", "")]
+ public partial interface IDemoClass
+ {
+ ///
+ Task GetFinalDocumentsByIDFails(string agreementID, string docType, bool amt = False, bool? attachSupportingDocuments = True, CancellationToken cancellationToken = null);
+
+ }
+ }
+ #nullable restore
+
+ """;
+ GenerateCode(code).Should().Be(expected);
}
}