예제 #1
0
        public void TestCoverageCatalog_Given_GenerateSingleTestCoverage_Executed_OnExistingReport_ExpectCoverageReport_On_FetchReport()
        {
            SetupMocks(_testCoverageModelTo, out Mock <IDirectory> mockDirectory, out Mock <IStreamWriterFactory> mockStreamWriterFactory, out Mock <IServiceTestCoverageModelToFactory> mockServiceTestCoverageModelToFactory, out Mock <IFilePath> mockFilePath, out Mock <ISerializer> mockSerialize);

            var test = GetFalseBranchTest();

            var sut = new TestCoverageCatalog(mockServiceTestCoverageModelToFactory.Object, mockFilePath.Object, new Mock <IFile>().Object, mockDirectory.Object, mockStreamWriterFactory.Object, new Mock <IStreamReaderFactory>().Object, mockSerialize.Object);

            sut.TestCoverageReports.GetOrAdd(_workflowId, new List <IServiceTestCoverageModelTo> {
                _testCoverageModelTo
            });

            var result = sut.GenerateSingleTestCoverage(_workflowId, test);

            var report = sut.FetchReport(_workflowId, "False branch test");

            Assert.AreEqual(.0, result.TotalCoverage);
            Assert.AreEqual("False branch test", report.ReportName);
            Assert.AreEqual(result.TotalCoverage, report.TotalCoverage);

            mockDirectory.Verify(o => o.CreateIfNotExists(_reportPath), Times.Once);
            mockStreamWriterFactory.Verify(o => o.New(_newReportPath, false), Times.Exactly(2));
            mockServiceTestCoverageModelToFactory.Verify(o => o.New(_workflowId, It.IsAny <ICoverageArgs>(), It.IsAny <List <IServiceTestModelTO> >()), Times.Once);
            mockFilePath.Verify(o => o.Combine(_testCoveragePath, _workflowId.ToString()), Times.Once);
            mockFilePath.Verify(o => o.Combine(_reportPath, "old_report_name.coverage"), Times.Once);
            mockFilePath.Verify(o => o.Combine(_reportPath, "False branch test.coverage"), Times.Once);
        }
예제 #2
0
        public void TestCoverageCatalog_GivenTestCoverage_When_ReloadAllReports_GetReportList_ExpectCoverageRemoved()
        {
            SetupMocks(_testCoverageModelTo, out Mock <IDirectory> mockDirectory, out Mock <IStreamWriterFactory> mockStreamWriterFactory, out Mock <IServiceTestCoverageModelToFactory> mockServiceTestCoverageModelToFactory, out Mock <IFilePath> mockFilePath, out Mock <ISerializer> mockSerialize);

            var derivedTestPath = _newReportPath.Replace(EnvironmentVariables.TestCoveragePath, EnvironmentVariables.TestPath).Replace(".coverage", ".test");
            var mockFile        = new Mock <IFile>();

            mockFile.Setup(o => o.Exists(derivedTestPath)).Returns(true);

            var mockStreamReaderFactory = new Mock <IStreamReaderFactory>();
            //Arrange
            var sut = new TestCoverageCatalog(mockServiceTestCoverageModelToFactory.Object, mockFilePath.Object, mockFile.Object, mockDirectory.Object, mockStreamWriterFactory.Object, mockStreamReaderFactory.Object, mockSerialize.Object);

            Assert.AreEqual(0, sut.TestCoverageReports.Count);

            _ = sut.GenerateSingleTestCoverage(_workflowId, _falseBranchTest);
            //Act
            sut.ReloadAllReports();

            //Assert
            var results = sut.TestCoverageReports;

            Assert.IsTrue(results.Count > 0);
            Assert.AreEqual(_workflowId, results.First().Key);

            mockStreamReaderFactory.Verify(o => o.New(_newReportPath), Times.Once);
            mockSerialize.Verify(o => o.Deserialize <ServiceTestCoverageModelTo>(It.IsAny <StreamReader>()), Times.Once);
        }
예제 #3
0
        public void TestCoverageCatalog_Given_GenerateAllTestsCoverage_Executed_When_DeleteAllCoverageReports_ExpectCoverageReportRemoved()
        {
            SetupMocks(_testCoverageModelTo, out Mock <IDirectory> mockDirectory, out Mock <IStreamWriterFactory> mockStreamWriterFactory, out Mock <IServiceTestCoverageModelToFactory> mockServiceTestCoverageModelToFactory, out Mock <IFilePath> mockFilePath, out Mock <ISerializer> mockSerialize);

            var mockFileWrapper = new Mock <IFile>();

            mockFileWrapper.Setup(o => o.Exists(_newReportPath)).Returns(true);

            //Arrange
            var tests = GetTests();

            var sut = new TestCoverageCatalog(mockServiceTestCoverageModelToFactory.Object, mockFilePath.Object, mockFileWrapper.Object, mockDirectory.Object, mockStreamWriterFactory.Object, new Mock <IStreamReaderFactory>().Object, mockSerialize.Object);

            var coverage = sut.GenerateAllTestsCoverage(_testCoverageModelTo.ReportName, _workflowId, tests);

            var report = sut.FetchReport(_workflowId, _testCoverageModelTo.ReportName);

            Assert.AreEqual(.0, coverage.TotalCoverage);

            Assert.AreEqual(_testCoverageModelTo.ReportName, report.ReportName);
            Assert.AreEqual(coverage.TotalCoverage, report.TotalCoverage);

            //Act
            sut.DeleteAllCoverageReports(_workflowId);

            //Assert
            var afterDeleteReport = sut.FetchReport(_workflowId, _falseBranchTest.TestName);

            Assert.IsNull(afterDeleteReport);

            mockDirectory.Verify(o => o.Delete(_reportPath, true), Times.Once);
        }
예제 #4
0
        public void TestCoverageCatalog_Given_GenerateAllTestsCoverage_Executed_ExpectCoverageReport_On_FetchReport_ToBeNewEverytime()
        {
            SetupMocks(_testCoverageModelTo, out Mock <IDirectory> mockDirectory, out Mock <IStreamWriterFactory> mockStreamWriterFactory, out Mock <IServiceTestCoverageModelToFactory> mockServiceTestCoverageModelToFactory, out Mock <IFilePath> mockFilePath, out Mock <ISerializer> mockSerialize);

            var tests = GetTests();

            var sut = new TestCoverageCatalog(mockServiceTestCoverageModelToFactory.Object, mockFilePath.Object, new Mock <IFile>().Object, mockDirectory.Object, mockStreamWriterFactory.Object, new Mock <IStreamReaderFactory>().Object, mockSerialize.Object);

            var coverageReportOne = sut.GenerateAllTestsCoverage("False branch test", _workflowId, tests);

            var reportOne = sut.FetchReport(_workflowId, "False branch test");

            Assert.AreEqual(.0, coverageReportOne.TotalCoverage);

            Assert.AreEqual("False branch test", reportOne.ReportName);
            Assert.AreEqual(coverageReportOne.TotalCoverage, reportOne.TotalCoverage);

            //====================

            var coverageReportTwo = sut.GenerateAllTestsCoverage("False branch test", _workflowId, tests);

            var reportTwo = sut.FetchReport(_workflowId, "False branch test");

            Assert.AreEqual(.0, coverageReportTwo.TotalCoverage);

            Assert.AreEqual("False branch test", reportTwo.ReportName);
            Assert.AreEqual(coverageReportTwo.TotalCoverage, reportTwo.TotalCoverage);
            Assert.AreEqual(reportOne.LastRunDate, reportTwo.LastRunDate, "these should be updated with every execution");

            mockStreamWriterFactory.Verify(o => o.New(_newReportPath, false), Times.Once);
            mockServiceTestCoverageModelToFactory.Verify(o => o.New(_workflowId, It.IsAny <ICoverageArgs>(), It.IsAny <List <IServiceTestModelTO> >()), Times.Exactly(2));
        }
예제 #5
0
        public StringBuilder Execute(Dictionary <string, StringBuilder> values, IWorkspace theWorkspace)
        {
            var serializer = new Dev2JsonSerializer();

            try
            {
                Dev2Logger.Info("Delete Test Service", GlobalConstants.WarewolfInfo);

                values.TryGetValue("resourceID", out StringBuilder resourceIdString);
                if (resourceIdString == null)
                {
                    throw new InvalidDataContractException("resourceID is missing");
                }
                if (!Guid.TryParse(resourceIdString.ToString(), out Guid resourceId))
                {
                    throw new InvalidDataContractException("resourceID is not a valid GUID.");
                }
                TestCoverageCatalog.DeleteAllCoverageReports(resourceId);

                var message = new CompressedExecuteMessage {
                    HasError = false
                };
                return(serializer.SerializeToBuilder(message));
            }
            catch (Exception err)
            {
                Dev2Logger.Error(err, GlobalConstants.WarewolfError);
                var res = new CompressedExecuteMessage {
                    HasError = true, Message = new StringBuilder(err.Message)
                };
                return(serializer.SerializeToBuilder(res));
            }
        }
예제 #6
0
        public void TestCoverageCatalog_GenerateSingleTestCoverage_With_MockNodes_ExpectPartialCoverage()
        {
            var mockResourceCatalog = GetMockResourceCatalog(GetMockWorkflowBuilder().Object);
            var tests = GetTrueBranchTest();

            var sut = new TestCoverageCatalog(mockResourceCatalog.Object);

            var coverage = sut.GenerateSingleTestCoverage(_workflowId, tests);

            Assert.AreEqual(.33, Math.Round(coverage.TotalCoverage, 2));
        }
예제 #7
0
        public void TestCoverageCatalog_GivenGenerateAllTestsCoverageExecuted_Using_FlowSwitch_HaveMockedNode_When_FetchReport_ExpectCoverageWitoutMockedNode()
        {
            var workflowMock = GetMockResourceCatalog(GetRealWorkflowBuilder());
            var tests        = GetRealWorkflowTests();

            var sut      = new TestCoverageCatalog(workflowMock.Object);
            var coverage = sut.GenerateAllTestsCoverage(_workflowName, _workflowId, tests);

            var report = sut.FetchReport(_workflowId, _workflowName);

            Assert.AreEqual(.12, report.TotalCoverage);

            Assert.AreEqual(_workflowName, report.ReportName);
            Assert.AreEqual(coverage.TotalCoverage, report.TotalCoverage);
        }
예제 #8
0
        public void TestCoverageCatalog_GivenGenerateAllTestsCoverageExecuted_When_FetchReport_ExpectFullCoverageReport()
        {
            var mockResourceCatalog = GetMockResourceCatalog(GetMockWorkflowBuilder().Object);
            var tests = GetTests();

            var sut      = new TestCoverageCatalog(mockResourceCatalog.Object);
            var coverage = sut.GenerateAllTestsCoverage(_workflowName, _workflowId, tests);

            var report = sut.FetchReport(_workflowId, _workflowName);

            Assert.AreEqual(.5, coverage.TotalCoverage);

            Assert.AreEqual(_workflowName, report.ReportName);
            Assert.AreEqual(coverage.TotalCoverage, report.TotalCoverage);
        }
예제 #9
0
        public void TestCoverageCatalog_GivenGenerateAllTestsCoverageExecuted_ExpectPartialCoverageReport()
        {
            var mockResourceCatalog = GetMockResourceCatalog(GetMockWorkflowBuilder().Object);
            var test = GetFalseBranchTest();

            var sut = new TestCoverageCatalog(mockResourceCatalog.Object);

            var coverage = sut.GenerateSingleTestCoverage(_workflowId, test);

            var report = sut.FetchReport(_workflowId, _falseBranchTest.TestName);

            Assert.AreEqual(.5, coverage.TotalCoverage);

            Assert.AreEqual(_falseBranchTest.TestName, report.ReportName);
            Assert.AreEqual(coverage.TotalCoverage, report.TotalCoverage);
        }
예제 #10
0
        public void TestCoverageCatalog_GivenTestCoverage_When_ReloadAllReports_ExpectFullCoverageRemoved()
        {
            var mockResourceCatalog = GetMockResourceCatalog(GetMockWorkflowBuilder().Object);

            //Arrange
            var sut = new TestCoverageCatalog(mockResourceCatalog.Object);

            Assert.AreEqual(0, sut.TestCoverageReports.Count);

            _ = sut.GenerateSingleTestCoverage(_workflowId, _falseBranchTest);
            //Act
            sut.ReloadAllReports();

            //Assert
            Assert.IsTrue(sut.TestCoverageReports.Count > 0);
        }
예제 #11
0
        public void TestCoverageCatalog_Given_GenerateSingleTestCoverage_Executed_When_Fetch_ExpectCoverageReport()
        {
            SetupMocks(_testCoverageModelTo, out Mock <IDirectory> mockDirectory, out Mock <IStreamWriterFactory> mockStreamWriterFactory, out Mock <IServiceTestCoverageModelToFactory> mockServiceTestCoverageModelToFactory, out Mock <IFilePath> mockFilePath, out Mock <ISerializer> mockSerialize);

            //Arrange
            var sut = new TestCoverageCatalog(mockServiceTestCoverageModelToFactory.Object, mockFilePath.Object, new Mock <IFile>().Object, mockDirectory.Object, mockStreamWriterFactory.Object, new Mock <IStreamReaderFactory>().Object, mockSerialize.Object);

            Assert.AreEqual(0, sut.TestCoverageReports.Count);

            _ = sut.GenerateSingleTestCoverage(_workflowId, _falseBranchTest);
            //Act
            var result = sut.Fetch(_workflowId);

            //Assert
            Assert.IsTrue(result.Count > 0);
        }
예제 #12
0
        public void TestCoverageCatalog_GivenGenerateAllTestsCoverageExecuted_When_DeleteCoverageReport_ExpectFullCoverageRemoved()
        {
            var mockResourceCatalog = GetMockResourceCatalog(GetMockWorkflowBuilder().Object);
            //Arrange
            var tests = GetTests();

            var sut      = new TestCoverageCatalog(mockResourceCatalog.Object);
            var coverage = sut.GenerateAllTestsCoverage(_workflowName, _workflowId, tests);

            var report = sut.FetchReport(_workflowId, _workflowName);

            Assert.AreEqual(.5, coverage.TotalCoverage);

            Assert.AreEqual(_workflowName, report.ReportName);
            Assert.AreEqual(coverage.TotalCoverage, report.TotalCoverage);

            //Act
            sut.DeleteCoverageReport(_workflowId, _falseBranchTest.TestName);

            //Assert
            var afterDeleteReport = sut.FetchReport(_workflowId, _falseBranchTest.TestName);

            Assert.IsNull(afterDeleteReport);
        }