public void ReturnZeroPercent_WhenNoTestsPresent()
        {
            var log = Mock.Create<ILog>();
            Mock.Arrange(() => log.Info(Arg.AnyString));
            var consoleArgumentsProvider = Mock.Create<IConsoleArgumentsProvider>();
            
            var microsoftTestTestRunProvider = new MsTestTestRunProvider(consoleArgumentsProvider, log);
            List<TestRunUnitTestResult> failedTests = new List<TestRunUnitTestResult>();
            List<TestRunUnitTestResult> allTests = new List<TestRunUnitTestResult>();
            var failedTestsPercentage = microsoftTestTestRunProvider.CalculatedFailedTestsPercentage(failedTests, allTests);

            Assert.AreEqual<int>(0, failedTestsPercentage);
        }
 public void GetAllFailedTests_WhenNotAllArePassed()
 {
     var log = Mock.Create<ILog>();
     Mock.Arrange(() => log.Info(Arg.AnyString));
     var consoleArgumentsProvider = Mock.Create<IConsoleArgumentsProvider>();
     string newFileName = Path.GetTempFileName();
     Mock.Arrange(() => consoleArgumentsProvider.NewTestResultPath).Returns(newFileName);
     var fileSystemProvider = new FileSystemProvider(consoleArgumentsProvider);
     var testRun = fileSystemProvider.DeserializeTestRun("Exceptions.trx");
     
     var microsoftTestTestRunProvider = new MsTestTestRunProvider(consoleArgumentsProvider, log);
     var failedTests = microsoftTestTestRunProvider.GetAllNotPassedTests(testRun.Results.ToList());
     Assert.AreEqual<int>(1, failedTests.Count);
 }
        public void SetFailedSummaryOutcome_WhenOneFailedTestPresent()
        {
            var log = Mock.Create<ILog>();
            Mock.Arrange(() => log.Info(Arg.AnyString));
            var consoleArgumentsProvider = Mock.Create<IConsoleArgumentsProvider>();
            string newFileName = Path.GetTempFileName();
            Mock.Arrange(() => consoleArgumentsProvider.NewTestResultPath).Returns(newFileName);
            var fileSystemProvider = new FileSystemProvider(consoleArgumentsProvider);
            var failedTestsRun = fileSystemProvider.DeserializeTestRun("Exceptions.trx");
            var microsoftTestTestRunProvider = new MsTestTestRunProvider(consoleArgumentsProvider, log);

            microsoftTestTestRunProvider.UpdateResultsSummary(failedTestsRun);

            Assert.AreEqual<string>("Failed", failedTestsRun.ResultSummary.outcome);
        }
 public void AddTwoTestArgument_WhenTwoFailedTestsPresent()
 {
     var log = Mock.Create<ILog>();
     Mock.Arrange(() => log.Info(Arg.AnyString));
     var consoleArgumentsProvider = Mock.Create<IConsoleArgumentsProvider>();
     string newTestResultsPath = Path.GetTempFileName();
     Mock.Arrange(() => consoleArgumentsProvider.ConsoleArguments).Returns(@"/resultsfile:""C:\Results.trx""");
     Mock.Arrange(() => consoleArgumentsProvider.TestResultPath).Returns(@"C:\Results.trx");
     var fileSystemProvider = new FileSystemProvider(consoleArgumentsProvider);
     var testRun = fileSystemProvider.DeserializeTestRun("Exceptions.trx");
     
     var microsoftTestTestRunProvider = new MsTestTestRunProvider(consoleArgumentsProvider, log);
     string additionalArguments = microsoftTestTestRunProvider.GenerateAdditionalArgumentsForFailedTestsRun(testRun.Results.ToList(), newTestResultsPath);
     Assert.AreEqual<string>(string.Format(@"/resultsfile:""{0}"" /test:TestConsoleExtended /test:TestConsoleExtended_Second", newTestResultsPath), additionalArguments);
 }
        public void SetCorrectPassedCounter_WhenNoFailedTestsPresent()
        {
            var log = Mock.Create<ILog>();
            Mock.Arrange(() => log.Info(Arg.AnyString));
            var consoleArgumentsProvider = Mock.Create<IConsoleArgumentsProvider>();
            string newFileName = Path.GetTempFileName();
            Mock.Arrange(() => consoleArgumentsProvider.NewTestResultPath).Returns(newFileName);
            var fileSystemProvider = new FileSystemProvider(consoleArgumentsProvider);
            var failedTestsRun = fileSystemProvider.DeserializeTestRun("Exceptions.trx");
            var microsoftTestTestRunProvider = new MsTestTestRunProvider(consoleArgumentsProvider, log);

            var failedTests = microsoftTestTestRunProvider.GetAllNotPassedTests(failedTestsRun.Results.ToList());
            
            microsoftTestTestRunProvider.UpdatePassedTests(failedTests, failedTestsRun.Results.ToList());
            microsoftTestTestRunProvider.UpdateResultsSummary(failedTestsRun);

            Assert.AreEqual<int>(2, failedTestsRun.ResultSummary.Counters.passed);
        }
        public void UpdatePassedTests_WhenNoMatchingTestsExist()
        {
            var log = Mock.Create<ILog>();
            Mock.Arrange(() => log.Info(Arg.AnyString));
            var consoleArgumentsProvider = Mock.Create<IConsoleArgumentsProvider>();
            string newFileName = Path.GetTempFileName();
            Mock.Arrange(() => consoleArgumentsProvider.NewTestResultPath).Returns(newFileName);
            var fileSystemProvider = new FileSystemProvider(consoleArgumentsProvider);
            var failedTestsRun = fileSystemProvider.DeserializeTestRun("Exceptions.trx");
            var passedTestRun = fileSystemProvider.DeserializeTestRun("NoExceptions.trx");
            var microsoftTestTestRunProvider = new MsTestTestRunProvider(consoleArgumentsProvider, log);

            var passedTests = microsoftTestTestRunProvider.GetAllPassesTests(passedTestRun);
            var failedTests = microsoftTestTestRunProvider.GetAllNotPassedTests(failedTestsRun.Results.ToList());
            passedTests.ForEach(x => x.testId = Guid.NewGuid().ToString());

            microsoftTestTestRunProvider.UpdatePassedTests(passedTests, failedTestsRun.Results.ToList());

            var updatedFailedTests = microsoftTestTestRunProvider.GetAllNotPassedTests(failedTests);
            Assert.AreEqual<int>(1, updatedFailedTests.Count);
        }