public void Generate_ShouldEmitUsingOnlyOnce_IfIsDefault_AndAlreadyInSourceDocument( string usingToEmit, [Substitute] SyntaxTree syntaxTree ) { var defaultUsings = new[] { usingToEmit }; var usings = new[] { UsingDirective(ParseName(usingToEmit)) }; var generator = new UsingsGenerator(defaultUsings); var root = CompilationUnit().WithUsings(List(usings)); var context = new GenerationContext { SyntaxTree = syntaxTree }; syntaxTree.GetRoot().Returns(root); var result = generator.Generate(context); result.Should().ContainSingle(directive => directive.Name.ToFullString() == usingToEmit); }
public void Generate_ShouldEmitUsingOnlyOnce_IfIsDefault_AndAddedAtRuntime( string usingToEmit, [Substitute] SyntaxTree syntaxTree ) { var defaultUsings = new[] { usingToEmit }; var generator = new UsingsGenerator(defaultUsings); var root = CompilationUnit().WithUsings(List <UsingDirectiveSyntax>()); var context = new GenerationContext { SyntaxTree = syntaxTree }; syntaxTree.GetRoot().Returns(root); context.Usings.Add(usingToEmit); var result = generator.Generate(context); result.Should().ContainSingle(directive => directive.Name.ToFullString() == usingToEmit); }