public void GetBaseline_UsesBaselineFallbackVersion_WhenReportForCurrentVersionNotFound()
        {
            // Arrange
            var branchName = "refs/heads/master";
            var baselineProvider = new Mock<IBaselineProvider>();
            var gitInfoProvider = new Mock<IGitInfoProvider>();
            var baselineMutantHelperMock = new Mock<IBaselineMutantHelper>();

            var options = new StrykerOptions()
            {
                WithBaseline = true,
                DashboardApiKey = "Acces_Token",
                ProjectName = "github.com/JohnDoe/project",
                ProjectVersion = "version/human/readable",
                Reporters = new[] { Reporter.Dashboard },
                FallbackVersion = "fallback/version"
            };

            var inputComponent = new Mock<IReadOnlyProjectComponent>().Object;

            var jsonReport = JsonReport.Build(options, inputComponent);

            gitInfoProvider.Setup(x => x.GetCurrentBranchName()).Returns(branchName);

            baselineProvider.Setup(x => x.Load($"baseline/{branchName}")).Returns(Task.FromResult<JsonReport>(null));
            baselineProvider.Setup(x => x.Load($"baseline/{options.FallbackVersion}")).Returns(Task.FromResult(jsonReport));

            // Act
            var target = new BaselineMutantFilter(options, baselineProvider.Object, gitInfoProvider.Object);

            // Assert
            baselineProvider.Verify(x => x.Load($"baseline/{branchName}"), Times.Once);
            baselineProvider.Verify(x => x.Load($"baseline/{options.FallbackVersion}"), Times.Once);
            baselineProvider.VerifyNoOtherCalls();
        }
Exemplo n.º 2
0
        public void GetBaselineDoesNotCallFallbackWhenDashboardClientReturnsReport()
        {
            // Arrange
            var baselineProvider = new Mock <IBaselineProvider>();
            var diffProvider     = new Mock <IDiffProvider>(MockBehavior.Loose);
            var gitInfoProvider  = new Mock <IGitInfoProvider>();

            var reporters = new string[1];

            reporters[0] = "dashboard";

            var options = new StrykerOptions(
                compareToDashboard: true,
                dashboardApiKey: "Acces_Token",
                projectName: "github.com/JohnDoe/project",
                projectVersion: "version/human/readable",
                reporters: reporters,
                fallbackVersion: "fallback/version");

            var inputComponent = new Mock <IReadOnlyProjectComponent>().Object;

            var jsonReport = JsonReport.Build(options, inputComponent);

            gitInfoProvider.Setup(x => x.GetCurrentBranchName()).Returns("refs/heads/master");

            baselineProvider.Setup(x => x.Load("dashboard-compare/refs/heads/master")).Returns(Task.FromResult(jsonReport));

            // Act
            var target = new DiffMutantFilter(options, gitInfoProvider: gitInfoProvider.Object, baselineProvider: baselineProvider.Object, diffProvider: diffProvider.Object);

            // Assert
            baselineProvider.Verify(x => x.Load("dashboard-compare/refs/heads/master"), Times.Once);
            baselineProvider.Verify(x => x.Load("fallback/version"), Times.Never);
        }
Exemplo n.º 3
0
        public void OnAllMutantsTested(IReadOnlyProjectComponent reportComponent)
        {
            var mutationReport = JsonReport.Build(_options, reportComponent);
            var filename       = _options.ReportFileName + ".html";
            var reportPath     = Path.Combine(_options.OutputPath, "reports", filename);

            reportPath = FilePathUtils.NormalizePathSeparators(reportPath);

            WriteHtmlReport(reportPath, mutationReport.ToJsonHtmlSafe());

            // to make path clickable it should always start with: file:///
            var reportUri = reportPath.Replace("\\", "/");

            reportUri = reportUri.StartsWith("/") ? reportUri : "/" + reportUri;
            reportUri = "file://" + reportUri;

            if (_options.ReportTypeToOpen == Options.Inputs.ReportType.Html)
            {
                _processWrapper.Open(reportUri);
            }
            else
            {
                _consoleWriter.Write(Output.Cyan("Hint: by passing \"--open-report or -o\" the report will open automatically once Stryker is done."));
            }

            _consoleWriter.WriteLine(Output.Green($"\nYour html report has been generated at:\n" +
                                                  $"{reportUri}\n" +
                                                  $"You can open it in your browser of choice."));
        }
Exemplo n.º 4
0
        public void OnAllMutantsTested(IReadOnlyProjectComponent reportComponent)
        {
            var mutationReport = JsonReport.Build(_options, reportComponent);

            var reportUri = _dashboardClient.PublishReport(mutationReport, _options.ProjectVersion).Result;

            if (reportUri != null)
            {
                if (_options.ReportTypeToOpen == Options.Inputs.ReportType.Dashboard)
                {
                    _processWrapper.Open(reportUri);
                }
                else
                {
                    _consoleWriter.Write(Output.Cyan("Hint: by passing \"--open-report:dashboard or -o:dashboard\" the report will open automatically once Stryker is done."));
                }

                _logger.LogDebug("Your stryker report has been uploaded to: \n {0} \nYou can open it in your browser of choice.", reportUri);
                _consoleWriter.Write(Output.Green($"Your stryker report has been uploaded to: \n {reportUri} \nYou can open it in your browser of choice."));
            }
            else
            {
                _logger.LogError("Uploading to stryker dashboard failed...");
            }

            _consoleWriter.WriteLine();
            _consoleWriter.WriteLine();
        }
        public async Task DashboardClient_Get_With_Right_URL_with_module_name()
        {
            // Arrange
            var loggerMock  = new Mock <ILogger <DashboardClient> >(MockBehavior.Loose);
            var handlerMock = new Mock <HttpMessageHandler>(MockBehavior.Strict);

            var reporters = new[] { Reporter.Dashboard };

            var options = new StrykerOptions
            {
                DashboardUrl    = "http://www.example.com",
                DashboardApiKey = "Access_Token",
                ProjectName     = "github.com/JohnDoe/project",
                ProjectVersion  = "test/version",
                ModuleName      = "moduleName",
                Reporters       = reporters
            };

            var readonlyInputComponent = new Mock <IReadOnlyProjectComponent>(MockBehavior.Loose).Object;

            var jsonReport = JsonReport.Build(options, readonlyInputComponent);
            var json       = jsonReport.ToJson();

            handlerMock
            .Protected()
            .Setup <Task <HttpResponseMessage> >(
                "SendAsync",
                ItExpr.IsAny <HttpRequestMessage>(),
                ItExpr.IsAny <CancellationToken>())
            .ReturnsAsync(new HttpResponseMessage()
            {
                StatusCode = System.Net.HttpStatusCode.OK,
                Content    = new StringContent(json, Encoding.UTF8, "application/json")
            })
            .Verifiable();

            var httpClient = new HttpClient(handlerMock.Object);

            var target = new DashboardClient(options, httpClient, loggerMock.Object);

            // Act
            var result = await target.PullReport("version");

            // Assert
            var expectedUri = new Uri("http://www.example.com/api/reports/github.com/JohnDoe/project/version?module=moduleName");

            handlerMock.Protected().Verify(
                "SendAsync",
                Times.Exactly(1),
                ItExpr.Is <HttpRequestMessage>(req =>
                                               req.Method == HttpMethod.Get &&
                                               req.RequestUri == expectedUri
                                               ),
                ItExpr.IsAny <CancellationToken>()
                );

            result.ShouldNotBeNull();
            result.ToJson().ShouldBe(json);
        }
Exemplo n.º 6
0
        public void JsonReport_WithMutationScoreUnderThresholdLowHasDangerHealth()
        {
            var folderComponent = JsonReportTestHelper.CreateProjectWith();

            var report = JsonReport.Build(new StrykerOptions(thresholdHigh: 80, thresholdLow: 67), folderComponent);

            report.Files.First().Value.Health.ShouldBe(Health.Danger);
        }
Exemplo n.º 7
0
        public void JsonReport_WithMutationScoreBetweenThresholdHighInclusiveAndLowNonInclusiveHasWarningHealth()
        {
            var folderComponent = JsonReportTestHelper.CreateProjectWith();

            var report = JsonReport.Build(new StrykerOptions(thresholdHigh: 67, thresholdLow: 66), folderComponent);

            report.Files.First().Value.Health.ShouldBe(Health.Warning);
        }
Exemplo n.º 8
0
        public void JsonReport_ShouldContainAtLeastOneFile()
        {
            var folderComponent = JsonReportTestHelper.CreateProjectWith();

            var report = JsonReport.Build(new StrykerOptions(), folderComponent);

            report.Files.Count.ShouldBeGreaterThan(0);
        }
        public void OnAllMutantsTested(IReadOnlyProjectComponent reportComponent)
        {
            var mutationReport  = JsonReport.Build(_options, reportComponent);
            var projectVersion  = _gitInfoProvider.GetCurrentBranchName();
            var baselineVersion = $"dashboard-compare/{projectVersion}";

            _baselineProvider.Save(mutationReport, baselineVersion).Wait();
        }
Exemplo n.º 10
0
        public void JsonReport_WithMutationScoreOverThresholdHighHasGoodHealth()
        {
            var folderComponent = JsonReportTestHelper.CreateProjectWith();

            var report = JsonReport.Build(new StrykerOptions(thresholdHigh: 20, thresholdLow: 10), folderComponent);

            report.Files.First().Value.Health.ShouldBe(Health.Good);
        }
        public void JsonReport_ShouldContainTheProjectRoot()
        {
            var folderComponent = JsonReportTestHelper.CreateProjectWith();

            var report = JsonReport.Build(new StrykerOptions(), folderComponent);

            report.ProjectRoot.ShouldBe("/home/user/src/project/");
        }
Exemplo n.º 12
0
        public void JsonReport_BuildReportReturnsSingletonJsonReport()
        {
            var folderComponent = JsonReportTestHelper.CreateProjectWith();
            var options         = new StrykerOptions();

            var firstReport  = JsonReport.Build(options, folderComponent);
            var secondReport = JsonReport.Build(options, folderComponent);

            secondReport.ShouldBe(firstReport);
        }
Exemplo n.º 13
0
        public void JsonReport_ThresholdsAreSet()
        {
            var folderComponent = JsonReportTestHelper.CreateProjectWith();

            var report = JsonReport.Build(new StrykerOptions(), folderComponent);

            report.ShouldSatisfyAllConditions(
                () => report.Thresholds.ShouldContainKey("high"),
                () => report.Thresholds.ShouldContainKey("low"));
        }
Exemplo n.º 14
0
        public void FilterMutants_FiltersNoMutants_IfTestsChanged()
        {
            // Arrange
            var baselineProvider = new Mock <IBaselineProvider>();

            baselineProvider.Setup(x =>
                                   x.Load(It.IsAny <string>())
                                   ).Returns(
                Task.FromResult(
                    JsonReport.Build(new StrykerOptions(), JsonReportTestHelper.CreateProjectWith().ToReadOnlyInputComponent())
                    ));

            var diffProvider    = new Mock <IDiffProvider>(MockBehavior.Loose);
            var gitInfoProvider = new Mock <IGitInfoProvider>();

            var options = new StrykerOptions(compareToDashboard: false, projectVersion: "version");

            diffProvider.Setup(x => x.ScanDiff()).Returns(new DiffResult
            {
                ChangedSourceFiles = new List <string>(),
                ChangedTestFiles   = new List <string> {
                    "C:/testfile1.cs"
                }
            });

            var target = new DiffMutantFilter(options, diffProvider.Object, baselineProvider.Object, gitInfoProvider.Object);

            var testFile1 = new TestListDescription(new[] { new TestDescription(Guid.NewGuid().ToString(), "name1", "C:/testfile1.cs") });
            var testFile2 = new TestListDescription(new[] { new TestDescription(Guid.NewGuid().ToString(), "name2", "C:/testfile2.cs") });

            var expectedToStay1 = new Mutant
            {
                CoveringTests = testFile1
            };
            var expectedToStay2 = new Mutant
            {
                CoveringTests = testFile1
            };
            var mutants = new List <Mutant>
            {
                expectedToStay1,
                expectedToStay2,
                new Mutant
                {
                    CoveringTests = testFile2
                }
            };

            // Act
            var results = target.FilterMutants(mutants, new CsharpFileLeaf().ToReadOnly(), options);

            // Assert
            results.ShouldBe(new [] { expectedToStay1, expectedToStay2 });
        }
Exemplo n.º 15
0
        public void OnAllMutantsTested(IReadOnlyInputComponent mutationTree)
        {
            var mutationReport = JsonReport.Build(_options, mutationTree);

            var reportPath = Path.Combine(_options.OutputPath, "reports", "mutation-report.html");

            WriteHtmlReport(reportPath, mutationReport.ToJson());

            _chalk.Green($"\nYour html report has been generated at: \n " +
                         $"{reportPath} \n" +
                         $"You can open it in your browser of choice. \n");
        }
Exemplo n.º 16
0
        public void JsonReporter_OnAllMutantsTestedShouldContainJsonReport()
        {
            var mockFileSystem = new MockFileSystem();
            var options        = new StrykerOptions(thresholdBreak: 0, thresholdHigh: 80, thresholdLow: 60);
            var reporter       = new HtmlReporter(options, mockFileSystem);

            reporter.OnAllMutantsTested(JsonReportTestHelper.CreateProjectWith().ToReadOnlyInputComponent());
            var reportPath = Path.Combine(options.OutputPath, "reports", $"mutation-report.html");

            var fileContents = mockFileSystem.GetFile(reportPath).TextContents;

            JsonReport.Build(options, null).ToJson().ShouldBeSubsetOf(fileContents);
        }
Exemplo n.º 17
0
        public async Task Save_Calls_DashboardClient_With_version()
        {
            var strykerOptions = new StrykerOptions();

            var dashboardClient = new Mock <IDashboardClient>();

            dashboardClient.Setup(x => x.PublishReport(It.IsAny <string>(), It.IsAny <string>()));

            var target = new DashboardBaselineProvider(strykerOptions, dashboardClient.Object);

            await target.Save(JsonReport.Build(strykerOptions, JsonReportTestHelper.CreateProjectWith()), "version");

            dashboardClient.Verify(x => x.PublishReport(It.IsAny <string>(), It.Is <string>(x => x == "version")), Times.Once);
        }
Exemplo n.º 18
0
        public void OnAllMutantsTested(IReadOnlyInputComponent reportComponent)
        {
            var mutationReport = JsonReport.Build(_options, reportComponent);


            if (_options.CompareToDashboard)
            {
                Task.WaitAll(UploadHumanReadableReport(mutationReport), UploadBaseline(mutationReport));
            }
            else
            {
                Task.WaitAll(UploadHumanReadableReport(mutationReport));
            }
        }
        public async Task Load_Calls_Correct_URL()
        {
            // Arrange
            var options = new StrykerOptions()
            {
                AzureFileStorageUrl = "https://www.filestoragelocation.com",
                AzureFileStorageSas = "AZURE_SAS_KEY",
                BaselineProvider    = BaselineProvider.AzureFileStorage
            };

            var handlerMock = new Mock <HttpMessageHandler>(MockBehavior.Strict);

            var readonlyInputComponent = new Mock <IReadOnlyProjectComponent>(MockBehavior.Loose).Object;

            var jsonReport = JsonReport.Build(options, readonlyInputComponent);

            handlerMock
            .Protected()
            .Setup <Task <HttpResponseMessage> >(
                "SendAsync",
                ItExpr.IsAny <HttpRequestMessage>(),
                ItExpr.IsAny <CancellationToken>())
            .ReturnsAsync(new HttpResponseMessage()
            {
                StatusCode = System.Net.HttpStatusCode.OK,
                Content    = new StringContent(jsonReport.ToJson(), Encoding.UTF8, "application/json")
            })
            .Verifiable();

            var httpClient = new HttpClient(handlerMock.Object);

            var target = new AzureFileShareBaselineProvider(options, httpClient: httpClient);

            var result = await target.Load("baseline/project_version");

            var expectedUri = new Uri("https://www.filestoragelocation.com/StrykerOutput/baseline/project_version/stryker-report.json?sv=AZURE_SAS_KEY");

            handlerMock
            .Protected()
            .Verify(
                "SendAsync",
                Times.Exactly(1),
                ItExpr.Is <HttpRequestMessage>(req =>
                                               req.Method == HttpMethod.Get &&
                                               req.RequestUri == expectedUri
                                               ),
                ItExpr.IsAny <CancellationToken>()
                );
        }
Exemplo n.º 20
0
        public void OnAllMutantsTested(IReadOnlyProjectComponent mutationTree)
        {
            var mutationReport = JsonReport.Build(_options, mutationTree);

            var reportPath = Path.Combine(_options.OutputPath, "reports", "mutation-report.html");

            WriteHtmlReport(reportPath, mutationReport.ToJsonHtmlSafe());

            var clickablePath = reportPath.Replace("\\", "/");

            clickablePath = clickablePath.StartsWith("/") ? clickablePath : $"/{clickablePath}";

            _consoleWriter.Write(Output.Green($"\nYour html report has been generated at: \n " +
                                              $"file://{clickablePath} \n" +
                                              $"You can open it in your browser of choice. \n"));
        }
Exemplo n.º 21
0
        public void OnAllMutantsTested(IReadOnlyInputComponent reportComponent)
        {
            var mutationReport = JsonReport.Build(_options, reportComponent);

            var reportUrl = PublishReport(mutationReport.ToJson()).Result;

            if (reportUrl != null)
            {
                _chalk.Green($"\nYour stryker report has been uploaded to: \n {reportUrl} \nYou can open it in your browser of choice.");
            }
            else
            {
                _chalk.Red("Uploading to stryker dashboard failed...");
            }
            Console.WriteLine(Environment.NewLine);
        }
Exemplo n.º 22
0
        public void FilterMutants_FiltersNoMutants_IfTestsChanged()
        {
            // Arrange
            var baselineProvider = new Mock <IBaselineProvider>();

            baselineProvider.Setup(x =>
                                   x.Load(It.IsAny <string>())
                                   ).Returns(
                Task.FromResult(
                    JsonReport.Build(new StrykerOptions(), JsonReportTestHelper.CreateProjectWith())
                    ));

            var diffProvider    = new Mock <IDiffProvider>(MockBehavior.Loose);
            var gitInfoProvider = new Mock <IGitInfoProvider>();

            var options = new StrykerOptions(compareToDashboard: false, projectVersion: "version");

            diffProvider.Setup(x => x.ScanDiff()).Returns(new DiffResult
            {
                ChangedFiles     = new List <string>(),
                TestFilesChanged = new List <string> {
                    "C:/testfile.cs"
                }
            });

            var target = new DiffMutantFilter(options, diffProvider.Object, baselineProvider.Object, gitInfoProvider.Object);

            var testDescriptions = new List <TestDescription> {
                new TestDescription(Guid.NewGuid().ToString(), "name", "C:/testfile.cs")
            };
            var testListDescription = new TestListDescription(testDescriptions);

            var mutants = new List <Mutant>
            {
                new Mutant {
                    CoveringTests = testListDescription
                },
                new Mutant(),
                new Mutant()
            };

            // Act
            var results = target.FilterMutants(mutants, new FileLeaf(), options);

            // Assert
            results.Count().ShouldBe(1);
        }
Exemplo n.º 23
0
        public async Task ShouldWriteToDisk()
        {
            // Arrange
            var fileSystemMock = new MockFileSystem();
            var options        = new StrykerOptions(basePath: @"C:/Users/JohnDoe/Project/TestFolder", fileSystem: fileSystemMock);
            var sut            = new DiskBaselineProvider(options, fileSystemMock);

            // Act
            await sut.Save(JsonReport.Build(options, JsonReportTestHelper.CreateProjectWith()), "version");

            // Assert
            var path = FilePathUtils.NormalizePathSeparators(@"C:/Users/JohnDoe/Project/TestFolder/StrykerOutput/Baselines/version/stryker-report.json");

            MockFileData file = fileSystemMock.GetFile(path);

            file.ShouldNotBeNull();
        }
Exemplo n.º 24
0
        public void FilterMutantsForStatusNotRunReturnsAllMutantsWithStatusNotRun()
        {
            // Arrange
            var dashboardClient = new Mock <IDashboardClient>();

            dashboardClient.Setup(x =>
                                  x.PullReport(It.IsAny <string>())
                                  ).Returns(
                Task.FromResult(
                    JsonReport.Build(new StrykerOptions(), JsonReportTestHelper.CreateProjectWith())
                    ));

            var diffProvider   = new Mock <IDiffProvider>(MockBehavior.Loose);
            var branchProvider = new Mock <IGitInfoProvider>();

            var options = new StrykerOptions(compareToDashboard: true, projectVersion: "version");

            diffProvider.Setup(x => x.ScanDiff()).Returns(new DiffResult
            {
                TestsChanged = false,
                ChangedFiles = new List <string>()
            });

            var target = new DiffMutantFilter(options, diffProvider.Object, dashboardClient.Object, branchProvider.Object);

            var mutants = new List <Mutant>
            {
                new Mutant()
                {
                    ResultStatus = MutantStatus.NotRun
                },
                new Mutant()
                {
                    ResultStatus = MutantStatus.NotRun
                },
                new Mutant()
                {
                    ResultStatus = MutantStatus.Killed
                }
            };

            var results = target.FilterMutants(mutants, new FileLeaf(), options);

            results.Count().ShouldBe(2);
        }
Exemplo n.º 25
0
        public void OnAllMutantsTested(IReadOnlyInputComponent reportComponent)
        {
            var mutationReport = JsonReport.Build(_options, reportComponent);

            var reportUrl = _dashboardClient.PublishReport(mutationReport.ToJson(), _options.ProjectVersion).Result;

            if (reportUrl != null)
            {
                _logger.LogDebug("Your stryker report has been uploaded to: \n {0} \nYou can open it in your browser of choice.", reportUrl);
                _chalk.Green($"Your stryker report has been uploaded to: \n {reportUrl} \nYou can open it in your browser of choice.");
            }
            else
            {
                _logger.LogError("Uploading to stryker dashboard failed...");
            }

            Console.WriteLine(Environment.NewLine);
        }
Exemplo n.º 26
0
        public async Task ShouldLoadReportFromDisk()
        {
            // Arrange
            var fileSystemMock = new MockFileSystem();
            var options        = new StrykerOptions(basePath: @"C:/Users/JohnDoe/Project/TestFolder", fileSystem: fileSystemMock);

            var report = JsonReport.Build(options, JsonReportTestHelper.CreateProjectWith());

            fileSystemMock.AddFile("C:/Users/JohnDoe/Project/TestFolder/StrykerOutput/Baselines/version/stryker-report.json", report.ToJson());

            var target = new DiskBaselineProvider(options, fileSystemMock);

            // Act
            var result = await target.Load("version");

            // Assert
            result.ShouldNotBeNull();
            result.ToJson().ShouldBe(report.ToJson());
        }
Exemplo n.º 27
0
        public void OnAllMutantsTested(IReadOnlyProjectComponent reportComponent)
        {
            var mutationReport = JsonReport.Build(_options, reportComponent);

            var reportUri = _dashboardClient.PublishReport(mutationReport, _options.ProjectVersion).Result;

            if (reportUri != null)
            {
                if (_options.ReportTypeToOpen == Options.Inputs.ReportType.Dashboard)
                {
                    _processWrapper.Open(reportUri);
                }
                else
                {
                    _console.Write("[Cyan]Hint: by passing \"--open-report:dashboard or -o:dashboard\" the report will open automatically once Stryker is done.[/]");
                }

                _console.WriteLine();
                _console.MarkupLine("[Green]Your report has been uploaded at:[/]");

                if (_console.Profile.Capabilities.Links)
                {
                    // We must print the report path as the link text because on some terminals links might be supported but not actually clickable: https://github.com/spectreconsole/spectre.console/issues/764
                    _console.MarkupLine($"[Green][link={reportUri}]{reportUri}[/][/]");
                }
                else
                {
                    _console.MarkupLine($"[Green]{reportUri}[/]");
                }

                _console.MarkupLine("[Green]You can open it in your browser of choice.[/]");
            }
            else
            {
                _logger.LogError("Uploading to stryker dashboard failed...");
            }

            _console.WriteLine();
            _console.WriteLine();
        }
Exemplo n.º 28
0
        public void Should_ReturnAllMutants_When_NonSourceCodeFile_In_Tests_Has_Changed()
        {
            // Arrange
            var options = new StrykerOptions(compareToDashboard: true, projectVersion: "version");

            var diffProviderMock     = new Mock <IDiffProvider>();
            var baselineProviderMock = new Mock <IBaselineProvider>();
            var gitInfoProviderMock  = new Mock <IGitInfoProvider>(MockBehavior.Loose);

            var diffResult = new DiffResult()
            {
                ChangedTestFiles = new List <string> {
                    "config.json"
                }
            };

            diffProviderMock.Setup(x => x.ScanDiff()).Returns(diffResult);

            baselineProviderMock.Setup(x =>
                                       x.Load(It.IsAny <string>())
                                       ).Returns(
                Task.FromResult(
                    JsonReport.Build(new StrykerOptions(), JsonReportTestHelper.CreateProjectWith().ToReadOnlyInputComponent())
                    ));

            var target = new DiffMutantFilter(options, diffProviderMock.Object, baselineProviderMock.Object, gitInfoProviderMock.Object);

            var mutants = new List <Mutant> {
                new Mutant(), new Mutant(), new Mutant()
            };

            // Act
            var result = target.FilterMutants(mutants, new CsharpFileLeaf()
            {
                FullPath = "C:\\Foo\\Bar"
            }.ToReadOnly(), options);

            // Assert
            result.ShouldBe(mutants);
        }
Exemplo n.º 29
0
        public void Should_IgnoreMutants_WithoutCoveringTestsInfo_When_Tests_Have_Changed()
        {
            // Arrange
            var baselineProvider = new Mock <IBaselineProvider>();

            baselineProvider.Setup(x =>
                                   x.Load(It.IsAny <string>())
                                   ).Returns(
                Task.FromResult(
                    JsonReport.Build(new StrykerOptions(), JsonReportTestHelper.CreateProjectWith().ToReadOnlyInputComponent())
                    ));

            var diffProvider    = new Mock <IDiffProvider>(MockBehavior.Loose);
            var gitInfoProvider = new Mock <IGitInfoProvider>();

            var options = new StrykerOptions(compareToDashboard: false, projectVersion: "version");

            diffProvider.Setup(x => x.ScanDiff()).Returns(new DiffResult
            {
                ChangedSourceFiles = new List <string>(),
                ChangedTestFiles   = new List <string> {
                    "C:/testfile.cs"
                }
            });

            var target = new DiffMutantFilter(options, diffProvider.Object, baselineProvider.Object, gitInfoProvider.Object);

            var mutants = new List <Mutant>
            {
                new Mutant()
            };

            // Act
            var results = target.FilterMutants(mutants, new CsharpFileLeaf().ToReadOnly(), options);

            // Assert
            results.ShouldBeEmpty();
        }
Exemplo n.º 30
0
        public void FilterMutantsFiltersAll_WhenNoTestsChanged_CompareToDashboardDisabled_AndFileNotCahnged()
        {
            // Arrange
            var baselineProvider = new Mock <IBaselineProvider>();

            baselineProvider.Setup(x =>
                                   x.Load(It.IsAny <string>())
                                   ).Returns(
                Task.FromResult(
                    JsonReport.Build(new StrykerOptions(), JsonReportTestHelper.CreateProjectWith())
                    ));

            var diffProvider   = new Mock <IDiffProvider>(MockBehavior.Loose);
            var branchProvider = new Mock <IGitInfoProvider>();

            var options = new StrykerOptions(compareToDashboard: false, projectVersion: "version");

            diffProvider.Setup(x => x.ScanDiff()).Returns(new DiffResult
            {
                ChangedFiles = new List <string>(),
            });

            var target = new DiffMutantFilter(options, diffProvider.Object, baselineProvider.Object, branchProvider.Object);

            var mutants = new List <Mutant>
            {
                new Mutant(),
                new Mutant(),
                new Mutant()
            };

            // Act
            var results = target.FilterMutants(mutants, new FileLeaf(), options);

            // Assert
            results.Count().ShouldBe(0);
        }