Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions DecoratorGenerator.UnitTests/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using SampleLibrary.Deep.Nesteds;
using System.Reflection;
using System.Text;
using TestLibrary;
using VerifyCS = DecoratorGenerator.UnitTests.CSharpSourceGeneratorVerifier<DecoratorGenerator.Main>;

namespace DecoratorGenerator.UnitTests;
Expand Down Expand Up @@ -41,6 +42,29 @@
}.RunAsync();
}

[Test]
public async Task OneInterface_Internal() {
var source = await ReadCSharpFile<IInternalType>(true);
var generated = await ReadCSharpFile<InternalTypeDecorator>(true);

await new VerifyCS.Test
{
TestState = {
ReferenceAssemblies = ReferenceAssemblies.Net.Net90,
AdditionalReferences =
{
implementationAssembly,
GetAssembly("TestLibrary")
},
Sources = { source },
GeneratedSources =
{
(typeof(Main), "InternalTypeDecorator.generated.cs", SourceText.From(generated, Encoding.UTF8, SourceHashAlgorithm.Sha256)),
},
},
}.RunAsync();
}

[Test]
public async Task OneInterface_Properties() {
var source = await ReadCSharpFile<ILionProperties>(true);
Expand Down Expand Up @@ -152,7 +176,7 @@
{
implementationAssembly,
GetAssembly("TestLibrary"),
Assembly.GetAssembly(typeof(DynamoDBContext)),

Check warning on line 179 in DecoratorGenerator.UnitTests/Tests.cs

View workflow job for this annotation

GitHub Actions / Unit tests (10.0.x)

Possible null reference argument for parameter 'assembly' in 'void MetadataReferenceCollection.Add(Assembly assembly)'.
},
Sources = { wrapperList, source },
GeneratedSources =
Expand Down Expand Up @@ -182,19 +206,19 @@
private static async Task<string> ReadFile(bool isTestLibrary, string searchPattern) {
var currentDirectory = GetCurrentDirectory();

var targetDirectory = isTestLibrary ? GetTestLibraryDirectory(currentDirectory) : currentDirectory;

Check warning on line 209 in DecoratorGenerator.UnitTests/Tests.cs

View workflow job for this annotation

GitHub Actions / Unit tests (10.0.x)

Possible null reference argument for parameter 'currentDirectory' in 'DirectoryInfo Tests.GetTestLibraryDirectory(DirectoryInfo currentDirectory)'.

var file = targetDirectory.GetFiles(searchPattern).First();

Check warning on line 211 in DecoratorGenerator.UnitTests/Tests.cs

View workflow job for this annotation

GitHub Actions / Unit tests (10.0.x)

Dereference of a possibly null reference.

using var fileReader = new StreamReader(file.OpenRead());
return await fileReader.ReadToEndAsync();
}

private static DirectoryInfo? GetCurrentDirectory() {
return Directory.GetParent(Directory.GetParent(AppDomain.CurrentDomain.BaseDirectory).Parent.Parent.FullName);

Check warning on line 218 in DecoratorGenerator.UnitTests/Tests.cs

View workflow job for this annotation

GitHub Actions / Unit tests (10.0.x)

Dereference of a possibly null reference.

Check warning on line 218 in DecoratorGenerator.UnitTests/Tests.cs

View workflow job for this annotation

GitHub Actions / Unit tests (10.0.x)

Dereference of a possibly null reference.

Check warning on line 218 in DecoratorGenerator.UnitTests/Tests.cs

View workflow job for this annotation

GitHub Actions / Unit tests (10.0.x)

Dereference of a possibly null reference.
}

private static DirectoryInfo GetTestLibraryDirectory(DirectoryInfo currentDirectory) {
return currentDirectory.Parent.GetDirectories("TestLibrary").First();

Check warning on line 222 in DecoratorGenerator.UnitTests/Tests.cs

View workflow job for this annotation

GitHub Actions / Unit tests (10.0.x)

Dereference of a possibly null reference.
}
}
3 changes: 2 additions & 1 deletion DecoratorGenerator/OutputGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace DecoratorGenerator
internal static class OutputGenerator
{
public static (string source, string className) GenerateOutputs(INamedTypeSymbol @interface) {
var interfaceAccessModifier = @interface.DeclaredAccessibility.ToString().ToLower();
var className = $"{@interface.Name.Substring(1)}Decorator";
var formattedConstraintTypes = FormatInterfaceConstraintTypes(@interface);
var formattedConstraints = CreateFormattedConstraints(@interface.TypeParameters);
Expand All @@ -25,7 +26,7 @@ public static (string source, string className) GenerateOutputs(INamedTypeSymbol
#nullable restore
namespace {@interface.ContainingNamespace.ToDisplayString()};

public abstract class {className}{formattedConstraintTypes} : {@interface.Name}{formattedConstraintTypes}{(formattedConstraints != string.Empty ? $@" {formattedConstraints}" : string.Empty)}
{interfaceAccessModifier} abstract class {className}{formattedConstraintTypes} : {@interface.Name}{formattedConstraintTypes}{(formattedConstraints != string.Empty ? $@" {formattedConstraints}" : string.Empty)}
{{
private {@interface.Name}{formattedConstraintTypes} {targetFieldName};

Expand Down
9 changes: 9 additions & 0 deletions TestLibrary/IInternalType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using DecoratorGenerator;

namespace TestLibrary;

[Decorate]
internal interface IInternalType
{

}
16 changes: 16 additions & 0 deletions TestLibrary/InternalTypeDecorator.generated.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// <auto-generated/>
#nullable restore
namespace TestLibrary;

internal abstract class InternalTypeDecorator : IInternalType
{
private IInternalType internalType;

protected InternalTypeDecorator(IInternalType internalType) {
this.internalType = internalType;
}




}
Loading