Пример #1
0
 private static async Task AddSolutionAsync(SolutionSizeTracker.IncrementalAnalyzer analyzer, Solution solution)
 {
     foreach (var document in solution.Projects.SelectMany(p => p.Documents))
     {
         await analyzer.AnalyzeSyntaxAsync(document, InvocationReasons.Empty, CancellationToken.None);
     }
 }
Пример #2
0
        public async Task Test_SolutionSize_Update()
        {
            var expected = 12345;
            var solution = CreateSolution(expected);

            var analyzer = new SolutionSizeTracker.IncrementalAnalyzer();

            // initialize
            await analyzer.NewSolutionSnapshotAsync(solution, CancellationToken.None);

            await AddSolutionAsync(analyzer, solution);

            // update document
            var document = solution.Projects.First().Documents.First();
            var length   = (await document.GetSyntaxTreeAsync()).Length;

            var text        = SourceText.From(new string('2', 1000));
            var newDocument = document.WithText(text);

            await analyzer.AnalyzeSyntaxAsync(newDocument, InvocationReasons.DocumentChanged, CancellationToken.None);

            var size = analyzer.GetSolutionSize(solution.Id);

            Assert.Equal(expected - length + text.Length, size);
        }
Пример #3
0
 private static void AddSolution(SolutionSizeTracker.IncrementalAnalyzer analyzer, Solution solution)
 {
     foreach (var document in solution.Projects.SelectMany(p => p.Documents))
     {
         analyzer.AnalyzeSyntaxAsync(document, CancellationToken.None).Wait();
     }
 }
Пример #4
0
        public void Test_SolutionSize()
        {
            var expected = 12345;
            var solution = CreateSolution(expected);

            var analyzer = new SolutionSizeTracker.IncrementalAnalyzer();

            // initialize
            analyzer.NewSolutionSnapshotAsync(solution, CancellationToken.None).Wait();
            AddSolution(analyzer, solution);

            var size = analyzer.GetSolutionSize(solution.Id);

            Assert.Equal(expected, size);
        }
Пример #5
0
        public void Test_RemoveDocument()
        {
            var expected = 12345;
            var solution = CreateSolution(expected);

            var analyzer = new SolutionSizeTracker.IncrementalAnalyzer();

            // initialize
            analyzer.NewSolutionSnapshotAsync(solution, CancellationToken.None).Wait();
            AddSolution(analyzer, solution);

            // remove document
            var document = solution.Projects.First().Documents.First();

            analyzer.RemoveDocument(document.Id);

            var size = analyzer.GetSolutionSize(solution.Id);

            var length = document.GetSyntaxTreeAsync().Result.Length;

            Assert.Equal(expected - length, size);
        }