示例#1
0
        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);
        }
示例#2
0
        public void DeserializeTestResultsFile_WhenFailedTestsPresentAndNoTestResultsFilePassed()
        {
            var consoleArgumentsProvider = Mock.Create <IConsoleArgumentsProvider>();

            Mock.Arrange(() => consoleArgumentsProvider.TestResultPath).Returns("Exceptions.trx");
            var fileSystemProvider = new FileSystemProvider(consoleArgumentsProvider);
            var testRun            = fileSystemProvider.DeserializeTestRun();

            Assert.AreEqual <int>(2, testRun.Results.Count());
            Assert.AreEqual <string>("Failed", testRun.Results.First().outcome);
            Assert.IsNotNull(testRun.ResultSummary);
            Assert.AreEqual <int>(2, testRun.ResultSummary.Counters.total);
            Assert.AreEqual <int>(1, testRun.ResultSummary.Counters.passed);
            Assert.AreEqual <int>(1, testRun.ResultSummary.Counters.failed);
            Assert.AreEqual <string>("Failed", testRun.ResultSummary.outcome);
        }
        public void GetAllPassedTests_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 passedTests = microsoftTestTestRunProvider.GetAllPassesTests(testRun);

            Assert.AreEqual <int>(1, passedTests.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);
        }
示例#5
0
        public void SetCorrectPassedCounter_WhenFailedTestsPresent()
        {
            var log = Mock.Create <ILog>();

            Mock.Arrange(() => log.Info(Arg.AnyString));
            var consoleArgumentsProvider = Mock.Create <IConsoleArgumentsProvider>();
            var 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 <int>(1, failedTestsRun.ResultSummary.Counters.Passed);
        }
        public void DeserializeTestResultsFile_WhenNoFailedTestsPresent()
        {
            var consoleArgumentsProvider = Mock.Create <IConsoleArgumentsProvider>();
            var newFileName = Path.GetTempFileName();

            Mock.Arrange(() => consoleArgumentsProvider.NewTestResultPath).Returns(newFileName);
            var fileSystemProvider = new FileSystemProvider(consoleArgumentsProvider);
            var testRun            = fileSystemProvider.DeserializeTestRun("NoExceptions.trx");

            Assert.AreEqual <int>(2, testRun.Results.Count());
            Assert.AreEqual <string>("Passed", testRun.Results.First().Outcome);
            Assert.IsNotNull(testRun.ResultSummary);
            Assert.AreEqual <int>(2, testRun.ResultSummary.Counters.Total);
            Assert.AreEqual <int>(2, testRun.ResultSummary.Counters.Passed);
            Assert.AreEqual <int>(0, testRun.ResultSummary.Counters.Failed);
            Assert.AreEqual <string>("Passed", testRun.ResultSummary.Outcome);
        }
        public void AddTwoTestArgument_WhenTwoFailedTestsPresent()
        {
            var log = Mock.Create <ILog>();

            Mock.Arrange(() => log.Info(Arg.AnyString));
            var consoleArgumentsProvider = Mock.Create <IConsoleArgumentsProvider>();
            var 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);
            var additionalArguments          = microsoftTestTestRunProvider.GenerateAdditionalArgumentsForFailedTestsRun(testRun.Results.ToList(), newTestResultsPath);

            Assert.AreEqual <string>(string.Format(@"/resultsfile:""{0}"" /test:TestConsoleExtended /test:TestConsoleExtended_Second", newTestResultsPath), additionalArguments);
        }
        public void ExcludeTestListFromConsoleArguments_WhenTestListPresent()
        {
            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"" /test:testmask1 /test:testmask2 /retriesCount:3");
            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);

            // Check if "/test:testmask1 /test:testmask2" parameters are removed from command line arguments
            Assert.AreEqual <string>(string.Format(@"/resultsfile:""{0}""   /retriesCount:3 /test:TestConsoleExtended /test:TestConsoleExtended_Second", newTestResultsPath), additionalArguments);
        }
        public void SerializeTestResultsFile_WhenFailedTestsPresent()
        {
            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");

            fileSystemProvider.SerializeTestRun(testRun);

            string originalFileContent = File.ReadAllText("Exceptions.trx");
            string newFileContent      = File.ReadAllText(newFileName);
            var    originalDoc         = new XmlDocument();

            originalDoc.LoadXml(originalFileContent);
            var newDoc = new XmlDocument();

            newDoc.LoadXml(newFileContent);
            var originalXElement = XElement.Parse(originalFileContent);
            var newXElement      = XElement.Parse(newFileContent);

            XElement.DeepEquals(originalXElement, newXElement);
        }