コード例 #1
0
        public async Task WhenNotCoveredByTestThenFindsNoCoverage()
        {
            var code = @"namespace MyCode
{
	public class MyClass
	{
		public string Get(int value)
		{
			return GetInternal(value);
		}

		private string GetInternal(int value)
		{
			return value.ToString();
		}
	}
}";

            var solution            = CreateSolution(code);
            var projectCompilations = (from project in solution.Projects
                                       let compilation = project.GetCompilationAsync()
                                                         select new
            {
                Documents = project.Documents.Select(
                    x => new
                {
                    Tree = x.GetSyntaxTreeAsync(),
                    Root = x.GetSyntaxRootAsync()
                }),
                Compilation = compilation
            })
                                      .AsArray();
            await Task.WhenAll(
                projectCompilations.SelectMany(x => x.Documents.SelectMany(y => new Task[] { y.Root, y.Tree })));

            var matches = (from x in projectCompilations
                           from doc in x.Documents
                           let model = x.Compilation.Result.GetSemanticModel(doc.Tree.Result)
                                       let root = doc.Root.Result
                                                  from method in root.DescendantNodes()
                                                  .OfType <MethodDeclarationSyntax>()
                                                  where !method.AttributeLists.Any(
                               a => a.Attributes.Any(
                                   b => b.Name.ToString()
                                   .IsKnownTestAttribute()))
                                                  select model.GetDeclaredSymbol(method))
                          .AsArray();

            var analyzer           = new CoverageAnalyzer(solution);
            var areReferencedTasks = matches.Select(analyzer.IsReferencedInTest).AsArray();
            var areReferenced      = await Task.WhenAll(areReferencedTasks);

            Assert.False(areReferenced.All(x => x));
        }
コード例 #2
0
        public async Task <bool> ExecuteTests()
        {
            try
            {
                var log      = _outputLogger.GetLogFromOutput(TestsExecutionOutput, string.Empty);
                var document = MutationDocumentManagerService.CreateDocument(nameof(CommandPromptOutputViewer), log);
                var test     = new TestExecutor(Settings, _source.TestClaz.ClassLibrary);
                document.Title = TestsExecutionOutput;
                if (!_silently)
                {
                    document.Show();
                }

                void OutputData(object sender, string args) => log.CommandPromptOutput += args.Encode().PrintWithPreTag();

                test.EnableCustomOptions = ChkEnableCodeCoverage.IsChecked;
                test.EnableLogging       = false;
                test.OutputDataReceived += OutputData;
                test.X64TargetPlatform   = _source.X64TargetPlatform;
                test.FullyQualifiedName  = _source.TestClaz.MethodDetails.Count > Convert.ToInt32(Settings.UseClassFilterTestsThreshold) ||
                                           ChkUseClassFilter.IsChecked || _source.TestClaz.BaseClass != null
                    ? _source.TestClaz.Claz.Syntax.FullName()
                    : string.Empty;

                if (_silently)
                {
                    test.FullyQualifiedName = _source.TestClaz.Claz.Syntax.FullName();
                }

                await test.ExecuteTests(_source.TestClaz.MethodDetails);

                var coverageAnalyzer = new CoverageAnalyzer();
                coverageAnalyzer.FindCoverage(_source, test.CodeCoverage);

                if (test.LastTestExecutionStatus == TestExecutionStatus.Success)
                {
                    if (!_silently)
                    {
                        document.Close();
                    }

                    return(true);
                }
            }
            catch (Exception exp)
            {
                Trace.TraceError("Tests Execution Failed [{0}]", exp);
                MessageBoxService.Show(exp.Message);
            }

            return(false);
        }
コード例 #3
0
		public async Task WhenNotCoveredByTestThenFindsNoCoverage()
		{
			var code = @"namespace MyCode
{
	public class MyClass
	{
		public string Get(int value)
		{
			return GetInternal(value);
		}

		private string GetInternal(int value)
		{
			return value.ToString();
		}
	}
}";

			var solution = CreateSolution(code);
			var projectCompilations = (from project in solution.Projects
									   let compilation = project.GetCompilationAsync()
									   select new
											  {
												  Documents = project.Documents.Select(
													  x => new
														   {
															   Tree = x.GetSyntaxTreeAsync(),
															   Root = x.GetSyntaxRootAsync()
														   }),
												  Compilation = compilation
											  })
				.AsArray();
			await Task.WhenAll(
				projectCompilations.SelectMany(x => x.Documents.SelectMany(y => new Task[] { y.Root, y.Tree })));

			var matches = (from x in projectCompilations
						   from doc in x.Documents
						   let model = x.Compilation.Result.GetSemanticModel(doc.Tree.Result)
						   let root = doc.Root.Result
						   from method in root.DescendantNodes()
							   .OfType<MethodDeclarationSyntax>()
						   where !method.AttributeLists.Any(
							   a => a.Attributes.Any(
								   b => b.Name.ToString()
											.IsKnownTestAttribute()))
						   select model.GetDeclaredSymbol(method))
				.AsArray();

			var analyzer = new CoverageAnalyzer(solution);
			var areReferencedTasks = matches.Select(analyzer.IsReferencedInTest).AsArray();
			var areReferenced = await Task.WhenAll(areReferencedTasks);

			Assert.False(areReferenced.All(x => x));
		}