public void ErrorForAllMissingDependencies1() { string userSource = @" using StrongInject; [Register(typeof(A))] [Register(typeof(B))] public class Container { } public class A { public A(B b, C c){} } public class B { public B(C c, D d){} } public class C {} public class D { } "; Compilation comp = CreateCompilation(userSource, MetadataReference.CreateFromFile(typeof(IAsyncContainer <>).Assembly.Location)); Assert.Empty(comp.GetDiagnostics()); var diagnostics = new List <Diagnostic>(); Assert.True(WellKnownTypes.TryCreate(comp, x => Assert.False(true, x.ToString()), out var wellKnownTypes)); var registrations = new RegistrationCalculator(comp, wellKnownTypes, x => Assert.False(true, x.ToString()), default).GetModuleRegistrations(comp.AssertGetTypeByMetadataName("Container")); var hasErrors = DependencyCheckerVisitor.HasCircularOrMissingDependencies( comp.AssertGetTypeByMetadataName("A"), isAsync: true, new( registrations, new GenericRegistrationsResolver.Builder().Build(comp), ImmutableDictionary <ITypeSymbol, ImmutableArray <DecoratorSource> > .Empty, new(comp, ImmutableArray <DecoratorFactoryMethod> .Empty), wellKnownTypes), x => diagnostics.Add(x), ((ClassDeclarationSyntax)comp.AssertGetTypeByMetadataName("Container").DeclaringSyntaxReferences.First().GetSyntax()).Identifier.GetLocation()); Assert.True(hasErrors); diagnostics.Verify( // (6,14): Error SI0102: Error while resolving dependencies for 'A': We have no source for instance of type 'C' // Container new DiagnosticResult("SI0102", @"Container", DiagnosticSeverity.Error).WithLocation(6, 14), // (6,14): Error SI0102: Error while resolving dependencies for 'A': We have no source for instance of type 'D' // Container new DiagnosticResult("SI0102", @"Container", DiagnosticSeverity.Error).WithLocation(6, 14), // (6,14): Error SI0102: Error while resolving dependencies for 'A': We have no source for instance of type 'C' // Container new DiagnosticResult("SI0102", @"Container", DiagnosticSeverity.Error).WithLocation(6, 14)); }
public void IgnoresErrorsInUnusedDependencies() { string userSource = @" using StrongInject; [Register(typeof(A))] [Register(typeof(B))] [Register(typeof(C))] [Register(typeof(D))] public class Container { } public class A { public A(B b, C c, E e){} } public class B { public B(C c, D d){} } public class C {} public class D { public D(C c){} } public class E {} "; Compilation comp = CreateCompilation(userSource, MetadataReference.CreateFromFile(typeof(IAsyncContainer <>).Assembly.Location)); Assert.Empty(comp.GetDiagnostics()); Assert.True(WellKnownTypes.TryCreate(comp, x => Assert.False(true, x.ToString()), out var wellKnownTypes)); var registrations = new RegistrationCalculator(comp, wellKnownTypes, x => Assert.False(true, x.ToString()), default).GetModuleRegistrations(comp.AssertGetTypeByMetadataName("Container")); var hasErrors = DependencyCheckerVisitor.HasCircularOrMissingDependencies( comp.AssertGetTypeByMetadataName("B"), isAsync: true, new( registrations, new GenericRegistrationsResolver.Builder().Build(comp), ImmutableDictionary <ITypeSymbol, ImmutableArray <DecoratorSource> > .Empty, new(comp, ImmutableArray <DecoratorFactoryMethod> .Empty), wellKnownTypes), x => Assert.True(false, x.ToString()), ((ClassDeclarationSyntax)comp.AssertGetTypeByMetadataName("Container").DeclaringSyntaxReferences.First().GetSyntax()).Identifier.GetLocation()); Assert.False(hasErrors); }