コード例 #1
0
        public async Task TestFilePublisher_DontPublishWhenFilesAreNotValid()
        {
            var publisher = new Agent.Plugins.Log.TestFilePublisher.TestFilePublisher(_vssConnection.Object, _pipelineConfig, _traceListener.Object, _logger.Object,
                                                                                      _telemetry.Object, _testFileFinder.Object, _testResultParser.Object, _testRunPublisher.Object);

            var testFiles = new List <string>
            {
                "/tmp/test-1.xml",
                "/tmp/test-2.xml",
                "/tmp/test-3.xml",
            };

            _testFileFinder.Setup(x => x.FindAsync(It.IsAny <IList <string> >())).ReturnsAsync(testFiles.AsEnumerable());
            _testResultParser.Setup(x => x.ParseTestResultFiles(It.IsAny <TestRunContext>(), It.IsAny <IList <string> >()))
            .Returns(new TestDataProvider(null));

            _testRunPublisher.Setup(x => x.PublishTestRunDataAsync(It.IsAny <TestRunContext>(), It.IsAny <string>(), It.IsAny <IList <TestRunData> >(),
                                                                   It.IsAny <PublishOptions>(), It.IsAny <CancellationToken>())).Throws <Exception>();

            await publisher.InitializeAsync();

            await publisher.PublishAsync();

            _testFileFinder.Verify(x => x.FindAsync(It.IsAny <IList <string> >()), Times.Once);

            _logger.Verify(x => x.Info(It.Is <string>(msg => msg.Contains("No valid Junit test result files are found which can be parsed"))), Times.Once);
        }
コード例 #2
0
        public async Task TestFilePublisher_PublishMultipleFiles()
        {
            var publisher = new Agent.Plugins.Log.TestFilePublisher.TestFilePublisher(_vssConnection.Object, _pipelineConfig, _traceListener.Object, _logger.Object,
                                                                                      _telemetry.Object, _testFileFinder.Object, _testResultParser.Object, _testRunPublisher.Object);

            var testFiles = new List <string>
            {
                "/tmp/test-1.xml",
                "/tmp/test-2.xml",
                "/tmp/test-3.xml",
            };
            var testRuns = new List <TestRun>
            {
                new TestRun()
            };

            _testFileFinder.Setup(x => x.FindAsync(It.IsAny <IList <string> >())).ReturnsAsync(testFiles.AsEnumerable());
            _testResultParser.Setup(x => x.ParseTestResultFiles(It.IsAny <TestRunContext>(), It.IsAny <IList <string> >()))
            .Returns(new TestDataProvider(new List <TestData>
            {
                new TestData
                {
                    TestRunData = new TestRunData(null)
                }, new TestData()
                {
                    TestRunData = new TestRunData(null)
                }
            }));
            _testRunPublisher.Setup(x => x.PublishTestRunDataAsync(It.IsAny <TestRunContext>(), It.IsAny <string>(), It.IsAny <IList <TestRunData> >(),
                                                                   It.IsAny <PublishOptions>(), It.IsAny <CancellationToken>())).ReturnsAsync(testRuns);

            await publisher.InitializeAsync();

            await publisher.PublishAsync();

            _testFileFinder.Verify(x => x.FindAsync(It.IsAny <IList <string> >()), Times.Once);
            _testResultParser.Verify(x => x.ParseTestResultFiles(It.IsAny <TestRunContext>(), It.IsAny <IList <string> >()), Times.Once);
            _testRunPublisher.Verify(x => x.PublishTestRunDataAsync(It.IsAny <TestRunContext>(), It.IsAny <string>(), It.IsAny <IList <TestRunData> >(),
                                                                    It.IsAny <PublishOptions>(), It.IsAny <CancellationToken>()), Times.Once);


            _logger.Verify(x => x.Info(It.Is <string>(msg => msg.Contains("Number of files found with matching pattern 3"))), Times.Once);
            _logger.Verify(x => x.Info(It.Is <string>(msg => msg.Contains("Successfully parsed 2 files"))), Times.Once);
            _logger.Verify(x => x.Info(It.Is <string>(msg => msg.Contains("Successfully published 1 runs"))), Times.Once);
        }
コード例 #3
0
        public async Task TestFilePublisher_DontPublishWhenFileExceptionsAreThrown()
        {
            var publisher = new Agent.Plugins.Log.TestFilePublisher.TestFilePublisher(_vssConnection.Object, _pipelineConfig, _traceListener.Object, _logger.Object,
                                                                                      _telemetry.Object, _testFileFinder.Object, _testResultParser.Object, _testRunPublisher.Object);

            _testFileFinder.Setup(x => x.FindAsync(It.IsAny <IList <string> >())).Throws <Exception>();
            _testResultParser.Setup(x => x.ParseTestResultFiles(It.IsAny <TestRunContext>(), It.IsAny <IList <string> >()))
            .Throws <Exception>();
            _testRunPublisher.Setup(x => x.PublishTestRunDataAsync(It.IsAny <TestRunContext>(), It.IsAny <string>(), It.IsAny <IList <TestRunData> >(),
                                                                   It.IsAny <PublishOptions>(), It.IsAny <CancellationToken>())).Throws <Exception>();

            await publisher.InitializeAsync();

            await publisher.PublishAsync();

            _testFileFinder.Verify(x => x.FindAsync(It.IsAny <IList <string> >()), Times.Once);

            _logger.Verify(x => x.Info(It.Is <string>(msg => msg.Contains("No test result files are found"))), Times.Once);
        }