Skip to content

Commit

Permalink
Merge pull request #10 from VeyronSakai/feature/use-entrypoints
Browse files Browse the repository at this point in the history
Added test
  • Loading branch information
VeyronSakai authored Apr 7, 2024
2 parents d38844d + 327b2e9 commit 07f4662
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
29 changes: 24 additions & 5 deletions VContainerAnalyzer.Test/PreserveAttributeAnalyzerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public async ValueTask AnalyzeRegisterEntryPointMethod_ConstructorDoesNotExist_R
.Where(x => x.Id != "CS8019") // Ignore "Unnecessary using directive"
.ToArray();

Assert.That(actual.Length, Is.EqualTo(0));
Assert.That(actual, Is.Empty);
}

[Test]
Expand Down Expand Up @@ -173,7 +173,7 @@ public async ValueTask AnalyzeRegisterMethod_ConstructorDoesNotExist_ReportNoDia
.Where(x => x.Id != "CS8019") // Ignore "Unnecessary using directive"
.ToArray();

Assert.That(actual.Length, Is.EqualTo(0));
Assert.That(actual, Is.Empty);
}

[Test]
Expand All @@ -191,7 +191,7 @@ public async ValueTask AnalyzeRegisterMethod_OnlyDefaultConstructorExists_Report
.Where(x => x.Id != "CS8019") // Ignore "Unnecessary using directive"
.ToArray();

Assert.That(actual.Length, Is.EqualTo(0));
Assert.That(actual, Is.Empty);
}

[Test]
Expand All @@ -210,7 +210,7 @@ public async ValueTask AnalyzeRegisterEntryPointMethod_ConstructorHasInjectAttri
.Where(x => x.Id != "CS8019") // Ignore "Unnecessary using directive"
.ToArray();

Assert.That(actual.Length, Is.EqualTo(0));
Assert.That(actual, Is.Empty);
}

[Test]
Expand All @@ -229,7 +229,7 @@ public async ValueTask AnalyzeRegisterMethod_ConstructorHasInjectAttribute_Repor
.Where(x => x.Id != "CS8019") // Ignore "Unnecessary using directive"
.ToArray();

Assert.That(actual.Length, Is.EqualTo(0));
Assert.That(actual, Is.Empty);
}

[Test]
Expand Down Expand Up @@ -269,4 +269,23 @@ public async ValueTask AnalyzeAddMethod_ConstructorDoesNotHaveInjectAttribute_Re
);
}
}

[Test]
public async ValueTask AnalyzeAddMethod_ConstructorHasInjectAttribute_ReportNoDiagnostics()
{
var source = ReadCodes("ConstructorWithInjectAttributeClass.cs",
"EmptyClassStub.cs",
"Interfaces.cs",
"AddConstructorWithInjectAttributeClassLifetimeScope.cs");

var analyzer = new PreserveAttributeAnalyzer();
var diagnostics = await DiagnosticAnalyzerRunner.Run(analyzer, source);

var actual = diagnostics
.Where(x => x.Id != "CS1591") // Ignore "Missing XML comment for publicly visible type or member"
.Where(x => x.Id != "CS8019") // Ignore "Unnecessary using directive"
.ToArray();

Assert.That(actual, Is.Empty);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) 2020-2024 VeyronSakai.
// This software is released under the MIT License.

using VContainer;
using VContainer.Unity;

namespace VContainerAnalyzer.Test.TestData
{
public class AddConstructorWithInjectAttributeClassLifetimeScope
{
// ReSharper disable once UnusedMember.Global
public void Configure(IContainerBuilder builder)
{
builder.UseEntryPoints(Lifetime.Singleton, entryPoints =>
{
entryPoints.Add<ConstructorWithInjectAttributeClass>();
});
}
}
}

0 comments on commit 07f4662

Please sign in to comment.