コード例 #1
0
ファイル: Fixture.cs プロジェクト: p3NTech/AsyncGenerator
        public Task TestEnumerableWarningAfterAnalyzation()
        {
            var enumerable = GetMethodName <EnumerableWarning>(o => o.Enumerable);
            var enumerableQueryExpression       = GetMethodName <EnumerableWarning>(o => o.EnumerableQueryExpression);
            var enumerableQueryExpressionNested = GetMethodName <EnumerableWarning>(o => o.EnumerableQueryExpressionNested);

            return(ReadonlyTest(nameof(EnumerableWarning), p => p
                                .ConfigureAnalyzation(a => a
                                                      .MethodConversion(symbol => MethodConversion.Smart)
                                                      .AfterAnalyzation(result =>
            {
                var methods = result.Documents.First().AllTypes.First().Methods.ToDictionary(o => o.Symbol.Name);
                FunctionData method = (MethodData)methods[enumerable];
                Assert.AreEqual(DiagnosticSeverity.Warning, method.IgnoredReason.DiagnosticSeverity);
                Assert.AreEqual(0, method.GetDiagnostics().Count());
                Assert.AreEqual(2, method.ChildFunctions.Count);

                foreach (var functionData in method.ChildFunctions.Values)
                {
                    Assert.AreEqual(DiagnosticSeverity.Warning, functionData.IgnoredReason.DiagnosticSeverity);
                    Assert.AreEqual(0, functionData.GetDiagnostics().Count());
                    Assert.AreEqual(1, functionData.BodyFunctionReferences.Count());
                    var bodyReference = functionData.BodyFunctionReferences.First();
                    Assert.AreEqual(DiagnosticSeverity.Warning, bodyReference.IgnoredReason.DiagnosticSeverity);
                    Assert.AreEqual(1, bodyReference.GetDiagnostics().Count());
                    Assert.AreEqual(DiagnosticSeverity.Warning, bodyReference.GetDiagnostics().First().DiagnosticSeverity);
                }


                method = (MethodData)methods[enumerableQueryExpression];
                Assert.AreEqual(DiagnosticSeverity.Warning, method.IgnoredReason.DiagnosticSeverity);
                Assert.AreEqual(0, method.GetDiagnostics().Count());

                Assert.AreEqual(2, method.BodyFunctionReferences.Count());
                foreach (var bodyReference in method.BodyFunctionReferences)
                {
                    Assert.AreEqual(DiagnosticSeverity.Warning, bodyReference.IgnoredReason.DiagnosticSeverity);
                    Assert.AreEqual(1, bodyReference.GetDiagnostics().Count());
                    Assert.AreEqual(DiagnosticSeverity.Warning, bodyReference.GetDiagnostics().First().DiagnosticSeverity);
                }

                method = (MethodData)methods[enumerableQueryExpressionNested];
                Assert.AreEqual(DiagnosticSeverity.Warning, method.IgnoredReason.DiagnosticSeverity);
                Assert.AreEqual(0, method.GetDiagnostics().Count());
                Assert.AreEqual(1, method.ChildFunctions.Count);

                method = method.ChildFunctions.First().Value;
                Assert.AreEqual(DiagnosticSeverity.Warning, method.IgnoredReason.DiagnosticSeverity);
                Assert.AreEqual(0, method.GetDiagnostics().Count());

                Assert.AreEqual(2, method.BodyFunctionReferences.Count());
                foreach (var bodyReference in method.BodyFunctionReferences)
                {
                    Assert.AreEqual(DiagnosticSeverity.Warning, bodyReference.IgnoredReason.DiagnosticSeverity);
                    Assert.AreEqual(1, bodyReference.GetDiagnostics().Count());
                    Assert.AreEqual(DiagnosticSeverity.Warning, bodyReference.GetDiagnostics().First().DiagnosticSeverity);
                }
            })
                                                      )
                                .ConfigureTransformation(t => t.Disable())
                                ));
        }