Example #1
0
        public void TestResultHandlerShouldCreateOneTestResultCollectionForOneSource()
        {
            TestCase testCase1 = CreateTestCase("TestCase1");

            testCase1.Source = "abc.dll";

            TestCase testCase2 = CreateTestCase("TestCase2");

            testCase2.Source = "def.dll";

            ObjectModel.TestResult result1 = new ObjectModel.TestResult(testCase1)
            {
                Outcome = TestOutcome.Failed
            };
            ObjectModel.TestResult result2 = new ObjectModel.TestResult(testCase2)
            {
                Outcome = TestOutcome.Passed
            };

            this.htmlLogger.TestResultHandler(new object(), new Mock <TestResultEventArgs>(result1).Object);
            this.htmlLogger.TestResultHandler(new object(), new Mock <TestResultEventArgs>(result2).Object);

            Assert.AreEqual(2, this.htmlLogger.TestRunDetails.ResultCollectionList.Count);
            Assert.AreEqual("abc.dll", this.htmlLogger.TestRunDetails.ResultCollectionList.First().Source);
            Assert.AreEqual("def.dll", this.htmlLogger.TestRunDetails.ResultCollectionList.Last().Source);
        }
Example #2
0
        public void TestResultHandlerShouldCreateTestResultProperly()
        {
            var passTestCase = CreateTestCase("Pass1");

            passTestCase.DisplayName        = "abc";
            passTestCase.FullyQualifiedName = "fully";
            passTestCase.Source             = "abc/def.dll";
            TimeSpan ts1 = new TimeSpan(0, 0, 0, 1, 0);

            var passTestResultExpected = new ObjectModel.TestResult(passTestCase)
            {
                DisplayName     = "def",
                ErrorMessage    = "error message",
                ErrorStackTrace = "Error stack trace",
                Duration        = ts1
            };

            var eventArg = new Mock <TestResultEventArgs>(passTestResultExpected);

            // Act
            this.htmlLogger.TestResultHandler(new object(), eventArg.Object);

            var result = this.htmlLogger.TestRunDetails.ResultCollectionList.First().ResultList.First();

            Assert.AreEqual("def", result.DisplayName);
            Assert.AreEqual("error message", result.ErrorMessage);
            Assert.AreEqual("Error stack trace", result.ErrorStackTrace);
            Assert.AreEqual("fully", result.FullyQualifiedName);
            Assert.AreEqual("abc/def.dll", this.htmlLogger.TestRunDetails.ResultCollectionList.First().Source);
            Assert.AreEqual("1s", result.Duration);
        }
Example #3
0
        public void TestResultHandlerShouldKeepTrackOfTotalResult()
        {
            var passTestCase1 = CreateTestCase("Pass1");
            var passResult1   = new ObjectModel.TestResult(passTestCase1)
            {
                Outcome = TestOutcome.Passed
            };

            this.htmlLogger.TestResultHandler(new object(), new Mock <TestResultEventArgs>(passResult1).Object);

            Assert.AreEqual(this.htmlLogger.TotalTests, 1, "Total Tests");
        }
Example #4
0
        public void TestResultHandlerShouldKeepTrackOfSkippedResult()
        {
            var skipTestCase1 = CreateTestCase("Skip1");
            var skipResult1   = new ObjectModel.TestResult(skipTestCase1)
            {
                Outcome = TestOutcome.Skipped
            };

            this.htmlLogger.TestResultHandler(new object(), new Mock <TestResultEventArgs>(skipResult1).Object);

            Assert.AreEqual(1, this.htmlLogger.SkippedTests, "Skipped Tests");
        }
Example #5
0
        public void TestResultHandlerShouldKeepTrackOfPassedResult()
        {
            var passTestCase2 = CreateTestCase("Pass2");
            var passResult2   = new ObjectModel.TestResult(passTestCase2)
            {
                Outcome = TestOutcome.Passed
            };

            this.htmlLogger.TestResultHandler(new object(), new Mock <TestResultEventArgs>(passResult2).Object);

            Assert.AreEqual(1, this.htmlLogger.PassedTests, "Passed Tests");
        }
Example #6
0
        public void TestResultHandlerShouldKeepTrackOfFailedResult()
        {
            var failTestCase1 = CreateTestCase("Fail1");

            var failResult1 = new ObjectModel.TestResult(failTestCase1)
            {
                Outcome = TestOutcome.Failed
            };

            this.htmlLogger.TestResultHandler(new object(), new Mock <TestResultEventArgs>(failResult1).Object);

            Assert.AreEqual(1, this.htmlLogger.FailedTests, "Failed Tests");
        }
Example #7
0
        public void TestResultHandlerShouldAddFailedResultToFailedResultListInTestResultCollection()
        {
            TestCase testCase1 = CreateTestCase("TestCase1");

            ObjectModel.TestResult result1 = new ObjectModel.TestResult(testCase1)
            {
                Outcome = TestOutcome.Failed
            };

            this.htmlLogger.TestResultHandler(new object(), new Mock <TestResultEventArgs>(result1).Object);

            Assert.AreEqual(1, this.htmlLogger.TestRunDetails.ResultCollectionList.First().FailedResultList.Count);
        }
Example #8
0
        public void TestResultHandlerShouldSetDisplayNameIfDisplayNameIsNotNull()
        {
            //this assert is for checking result display name not equals to null
            var passTestCase1          = CreateTestCase("Pass1");
            var passTestResultExpected = new ObjectModel.TestResult(passTestCase1)
            {
                DisplayName = "def",
                TestCase    = { FullyQualifiedName = "abc" }
            };

            this.htmlLogger.TestResultHandler(new object(), new Mock <TestResultEventArgs>(passTestResultExpected).Object);

            Assert.AreEqual("def", this.htmlLogger.TestRunDetails.ResultCollectionList.First().ResultList.Last().DisplayName);
        }
        public void CloneShouldCloneTestResultsObject()
        {
            var testCase = JsonDataSerializerTests.GetSampleTestCase(out var expectedTrait);

            var testResult = new TestResult(testCase);

            var startTime = DateTimeOffset.UtcNow;

            testResult.StartTime = startTime;

            var clonedTestResult = this.jsonDataSerializer.Clone <TestResult>(testResult);

            Assert.IsFalse(ReferenceEquals(testResult, clonedTestResult));

            Assert.AreEqual(testResult.StartTime, clonedTestResult.StartTime);

            VerifyTestCaseClone(testResult.TestCase, clonedTestResult.TestCase, expectedTrait);
        }
Example #10
0
        public void TestCompleteHandlerShouldCallHtmlTransformerCorrectly()
        {
            var testCase1 = CreateTestCase("TestCase1");
            var result1   = new ObjectModel.TestResult(testCase1)
            {
                Outcome = TestOutcome.Failed
            };
            var resultEventArg1 = new Mock <TestResultEventArgs>(result1);

            this.mockFileHelper.Setup(x => x.GetStream(It.IsAny <string>(), FileMode.Create, FileAccess.ReadWrite)).Callback <string, FileMode, FileAccess>((x, y, z) =>
            {
            }).Returns(new Mock <Stream>().Object);

            this.htmlLogger.TestResultHandler(new object(), resultEventArg1.Object);
            this.htmlLogger.TestRunCompleteHandler(new object(), new TestRunCompleteEventArgs(null, false, true, null, null, TimeSpan.Zero));

            this.mockHtmlTransformer.Verify(x => x.Transform(It.IsAny <string>(), It.IsAny <string>()), Times.Once);
        }
Example #11
0
        public void TestCompleteHandlerShouldDeleteFileCorrectly()
        {
            var testCase1 = CreateTestCase("TestCase1");
            var result1   = new ObjectModel.TestResult(testCase1)
            {
                Outcome = TestOutcome.Failed
            };
            var resultEventArg1 = new Mock <TestResultEventArgs>(result1);

            this.mockFileHelper.Setup(x => x.Delete(It.IsAny <string>())).Callback <string>((x) =>
            {
            });

            this.htmlLogger.TestResultHandler(new object(), resultEventArg1.Object);
            this.htmlLogger.TestRunCompleteHandler(new object(), new TestRunCompleteEventArgs(null, false, true, null, null, TimeSpan.Zero));

            this.mockFileHelper.Verify(x => x.Delete(It.IsAny <string>()), Times.Once);
        }
Example #12
0
        public void TestCompleteHandlerShouldThrowExceptionWithLogPrefixIfTargetFrameworkKeyIsNotPresent()
        {
            var parameters = new Dictionary <string, string>();

            parameters[HtmlLoggerConstants.LogFilePrefixKey]         = "sample.html";
            parameters[DefaultLoggerParameterNames.TestRunDirectory] = "dsa";
            var testCase1 = CreateTestCase("TestCase1");
            var result1   = new ObjectModel.TestResult(testCase1)
            {
                Outcome = TestOutcome.Failed
            };
            var resultEventArg1 = new Mock <TestResultEventArgs>(result1);

            this.htmlLogger.TestResultHandler(new object(), resultEventArg1.Object);

            this.htmlLogger.Initialize(new Mock <TestLoggerEvents>().Object, parameters);

            Assert.ThrowsException <KeyNotFoundException>(() => this.htmlLogger.TestRunCompleteHandler(new object(), new TestRunCompleteEventArgs(null, false, true, null, null, TimeSpan.Zero)));
        }
Example #13
0
        public void TestCompleteHandlerShouldWriteToXmlSerializerCorrectly()
        {
            var testCase1 = CreateTestCase("TestCase1") ?? throw new ArgumentNullException($"CreateTestCase(\"TestCase1\")");
            var result1   = new ObjectModel.TestResult(testCase1)
            {
                Outcome = TestOutcome.Failed
            };
            var resultEventArg1 = new Mock <TestResultEventArgs>(result1);

            this.mockFileHelper.Setup(x => x.GetStream(It.IsAny <string>(), FileMode.Create, FileAccess.ReadWrite)).Callback <string, FileMode, FileAccess>((x, y, z) =>
            {
            }).Returns(new Mock <Stream>().Object);

            this.htmlLogger.TestResultHandler(new object(), resultEventArg1.Object);
            this.htmlLogger.TestRunCompleteHandler(new object(), new TestRunCompleteEventArgs(null, false, true, null, null, TimeSpan.Zero));

            this.mockXmlSerializer.Verify(x => x.WriteObject(It.IsAny <Stream>(), It.IsAny <TestRunDetails>()), Times.Once);
            Assert.IsTrue(htmlLogger.XmlFilePath.Contains(".xml"));
            Assert.IsTrue(htmlLogger.HtmlFilePath.Contains(".html"));
        }
Example #14
0
        public void TestCompleteHandlerShouldCreateCustumHtmlFileNamewithLogFileNameKey()
        {
            var parameters = new Dictionary <string, string>();

            parameters[HtmlLoggerConstants.LogFileNameKey]           = null;
            parameters[DefaultLoggerParameterNames.TestRunDirectory] = "dsa";

            var testCase1 = CreateTestCase("TestCase1");
            var result1   = new ObjectModel.TestResult(testCase1)
            {
                Outcome = TestOutcome.Failed
            };
            var resultEventArg1 = new Mock <TestResultEventArgs>(result1);

            this.htmlLogger.TestResultHandler(new object(), resultEventArg1.Object);

            this.htmlLogger.Initialize(new Mock <TestLoggerEvents>().Object, parameters);
            this.htmlLogger.TestRunCompleteHandler(new object(), new TestRunCompleteEventArgs(null, false, true, null, null, TimeSpan.Zero));
            Assert.IsTrue(this.htmlLogger.HtmlFilePath.Contains("TestResult"));
        }
Example #15
0
        public void TestCompleteHandlerShouldKeepTackOfSummary()
        {
            TestCase passTestCase1 = CreateTestCase("Pass1");
            TestCase passTestCase2 = CreateTestCase("Pass2");
            TestCase failTestCase1 = CreateTestCase("Fail1");
            TestCase skipTestCase1 = CreateTestCase("Skip1");
            var      passResult1   = new ObjectModel.TestResult(passTestCase1)
            {
                Outcome = TestOutcome.Passed
            };
            var passResult2 = new ObjectModel.TestResult(passTestCase2)
            {
                Outcome = TestOutcome.Passed
            };
            var failResult1 = new ObjectModel.TestResult(failTestCase1)
            {
                Outcome = TestOutcome.Failed
            };
            var skipResult1 = new ObjectModel.TestResult(skipTestCase1)
            {
                Outcome = TestOutcome.Skipped
            };

            this.htmlLogger.TestResultHandler(new object(), new Mock <TestResultEventArgs>(passResult1).Object);
            this.htmlLogger.TestResultHandler(new object(), new Mock <TestResultEventArgs>(passResult2).Object);
            this.htmlLogger.TestResultHandler(new object(), new Mock <TestResultEventArgs>(failResult1).Object);
            this.htmlLogger.TestResultHandler(new object(), new Mock <TestResultEventArgs>(skipResult1).Object);

            this.mockFileHelper.Setup(x => x.GetStream(It.IsAny <string>(), FileMode.Create, FileAccess.ReadWrite)).Callback <string, FileMode, FileAccess>((x, y, z) =>
            {
            }).Returns(new Mock <Stream>().Object);

            this.htmlLogger.TestRunCompleteHandler(new object(), new TestRunCompleteEventArgs(null, false, true, null, null, TimeSpan.Zero));

            Assert.AreEqual(4, this.htmlLogger.TestRunDetails.Summary.TotalTests, "summary should keep track of total tests");
            Assert.AreEqual(1, this.htmlLogger.TestRunDetails.Summary.FailedTests, "summary should keep track of failed tests");
            Assert.AreEqual(2, this.htmlLogger.TestRunDetails.Summary.PassedTests, "summary should keep track of passed tests");
            Assert.AreEqual(1, this.htmlLogger.TestRunDetails.Summary.SkippedTests, "summary should keep track of passed tests");
            Assert.AreEqual(50, this.htmlLogger.TestRunDetails.Summary.PassPercentage, "summary should keep track of passed tests");
            Assert.IsNull(this.htmlLogger.TestRunDetails.Summary.TotalRunTime, "summary should keep track of passed tests");
        }
Example #16
0
        public void TestResultHandlerShouldCreateOneTestEntryForEachTestCase()
        {
            TestCase testCase1 = CreateTestCase("TestCase1");
            TestCase testCase2 = CreateTestCase("TestCase2");

            ObjectModel.TestResult result1 = new ObjectModel.TestResult(testCase1)
            {
                Outcome = TestOutcome.Failed
            };
            ObjectModel.TestResult result2 = new ObjectModel.TestResult(testCase2)
            {
                Outcome = TestOutcome.Passed
            };
            Mock <TestResultEventArgs> resultEventArg1 = new Mock <TestResultEventArgs>(result1);
            Mock <TestResultEventArgs> resultEventArg2 = new Mock <TestResultEventArgs>(result2);

            // Act
            this.htmlLogger.TestResultHandler(new object(), resultEventArg1.Object);
            this.htmlLogger.TestResultHandler(new object(), resultEventArg2.Object);

            Assert.AreEqual(2, this.htmlLogger.TestRunDetails.ResultCollectionList.First().ResultList.Count, "TestResultHandler is not creating test result entry for each test case");
        }
Example #17
0
        public void TestCompleteHandlerShouldCreateCustumHtmlFileNameWithLogPrefixNull()
        {
            var parameters = new Dictionary <string, string>();

            parameters[HtmlLoggerConstants.LogFilePrefixKey]         = null;
            parameters[DefaultLoggerParameterNames.TestRunDirectory] = "dsa";
            parameters[DefaultLoggerParameterNames.TargetFramework]  = ".NETFramework,Version=4.5.1";

            var testCase1 = CreateTestCase("TestCase1");
            var result1   = new ObjectModel.TestResult(testCase1)
            {
                Outcome = TestOutcome.Failed
            };
            var resultEventArg1 = new Mock <TestResultEventArgs>(result1);

            this.mockFileHelper.Setup(x => x.GetStream(It.IsAny <string>(), FileMode.Create, FileAccess.ReadWrite)).Callback <string, FileMode, FileAccess>((x, y, z) =>
            {
            }).Returns(new Mock <Stream>().Object);

            this.htmlLogger.TestResultHandler(new object(), resultEventArg1.Object);
            this.htmlLogger.TestRunCompleteHandler(new object(), new TestRunCompleteEventArgs(null, false, true, null, null, TimeSpan.Zero));

            this.mockFileHelper.Verify(x => x.GetStream(It.IsAny <string>(), FileMode.Create, FileAccess.ReadWrite), Times.Once);
        }
Example #18
0
        public void TestResultHandlerShouldAddHierarchicalResultsForOrderedTest()
        {
            TestCase testCase1 = CreateTestCase("TestCase1");
            TestCase testCase2 = CreateTestCase("TestCase2");
            TestCase testCase3 = CreateTestCase("TestCase3");

            Guid parentExecutionId = Guid.NewGuid();

            ObjectModel.TestResult result1 = new ObjectModel.TestResult(testCase1);
            result1.SetPropertyValue(HtmlLoggerConstants.ExecutionIdProperty, parentExecutionId);
            result1.SetPropertyValue(HtmlLoggerConstants.TestTypeProperty, HtmlLoggerConstants.OrderedTestTypeGuid);

            this.htmlLogger.TestResultHandler(new object(), new Mock <TestResultEventArgs>(result1).Object);

            Assert.AreEqual(1, this.htmlLogger.TestRunDetails.ResultCollectionList.First().ResultList.Count, "test handler is adding parent result correctly");
            Assert.IsNull(this.htmlLogger.TestRunDetails.ResultCollectionList.First().ResultList.First().InnerTestResults, "test handler is adding child result correctly");

            var result2 = new ObjectModel.TestResult(testCase2);

            result2.SetPropertyValue(HtmlLoggerConstants.ExecutionIdProperty, Guid.NewGuid());
            result2.SetPropertyValue(HtmlLoggerConstants.ParentExecIdProperty, parentExecutionId);

            var result3 = new ObjectModel.TestResult(testCase3)
            {
                Outcome = TestOutcome.Failed
            };

            result3.SetPropertyValue(HtmlLoggerConstants.ExecutionIdProperty, Guid.NewGuid());
            result3.SetPropertyValue(HtmlLoggerConstants.ParentExecIdProperty, parentExecutionId);

            this.htmlLogger.TestResultHandler(new object(), new Mock <TestResultEventArgs>(result2).Object);
            this.htmlLogger.TestResultHandler(new object(), new Mock <TestResultEventArgs>(result3).Object);

            Assert.AreEqual(1, this.htmlLogger.TestRunDetails.ResultCollectionList.First().ResultList.Count, "test handler is adding parent result correctly");
            Assert.AreEqual(2, this.htmlLogger.TestRunDetails.ResultCollectionList.First().ResultList.First().InnerTestResults.Count, "test handler is adding child result correctly");
        }