public void SessionEndedShouldContinueDataCollectionIfExceptionIsThrownWhileSendingSessionEndEventToDataCollector()
        {
            var attachment = new AttachmentSet(new Uri("my://custom/datacollector"), "CustomDataCollector");

            attachment.Attachments.Add(new UriDataAttachment(new Uri("my://filename.txt"), "filename.txt"));

            this.mockDataCollectionAttachmentManager.Setup(x => x.GetAttachments(It.IsAny <DataCollectionContext>())).Returns(new List <AttachmentSet>()
            {
                attachment
            });

            this.SetupMockDataCollector((XmlElement a, DataCollectionEvents b, DataCollectionSink c, DataCollectionLogger d, DataCollectionEnvironmentContext e) =>
            {
                b.SessionEnd += (sender, ev) =>
                {
                    c.SendFileAsync(e.SessionDataCollectionContext, "filename.txt", true);
                    throw new Exception();
                };
            });

            this.dataCollectionManager.InitializeDataCollectors(this.dataCollectorSettings);
            var sessionStartEventArgs = new SessionStartEventArgs();

            this.dataCollectionManager.SessionStarted(sessionStartEventArgs);

            var result = this.dataCollectionManager.SessionEnded();

            Assert.AreEqual(1, result.Count);
        }
        public void SessionStartedShouldReturnFalseIfDataCollectorsAreNotInitialized()
        {
            var sessionStartEventArgs = new SessionStartEventArgs();
            var result = this.dataCollectionManager.SessionStarted(sessionStartEventArgs);

            Assert.IsFalse(result);
        }
Exemplo n.º 3
0
        /// <summary>
        /// SessionStart event handler
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="sessionStartEventArgs">Event args</param>
        private void OnSessionStart(object sender, SessionStartEventArgs sessionStartEventArgs)
        {
            _eqtTrace.Verbose("{0}: SessionStart received", CoverletConstants.DataCollectorName);

            try
            {
                // Get coverlet settings
                IEnumerable <string> testModules  = this.GetTestModules(sessionStartEventArgs);
                var coverletSettingsParser        = new CoverletSettingsParser(_eqtTrace);
                CoverletSettings coverletSettings = coverletSettingsParser.Parse(_configurationElement, testModules);

                // Build services container
                _serviceProvider = _serviceCollectionFactory(_eqtTrace, _logger, coverletSettings.TestModule).BuildServiceProvider();

                // Get coverage and attachment managers
                _coverageManager = new CoverageManager(coverletSettings, _eqtTrace, _logger, _coverageWrapper,
                                                       _serviceProvider.GetRequiredService <IInstrumentationHelper>(), _serviceProvider.GetRequiredService <IFileSystem>(),
                                                       _serviceProvider.GetRequiredService <ISourceRootTranslator>());

                // Instrument modules
                _coverageManager.InstrumentModules();
            }
            catch (Exception ex)
            {
                _logger.LogWarning(ex.ToString());
                this.Dispose(true);
            }
        }
        private IDictionary <string, object> GetSessionStartProperties(SessionStartEventArgs sessionStartEventArgs)
        {
            var properties = new Dictionary <string, object>();

            properties.Add(Constants.TestSourcesPropertyName, sessionStartEventArgs.GetPropertyValue <IEnumerable <string> >(Constants.TestSourcesPropertyName));
            return(properties);
        }
        /// <inheritdoc />
        public void RaiseSessionStart(SessionStartEventArgs e)
        {
            this.testCaseEndStatusMap.Clear();
            this.testResultDictionary.Clear();

            this.SessionStart.SafeInvoke(this, e, "DataCollectionTestCaseEventManager.RaiseSessionStart");
        }
Exemplo n.º 6
0
        private void OnSessionStart(object?sender, SessionStartEventArgs e)
        {
            _logger?.SetContext(e.Context);
            var testSources = e.GetPropertyValue("TestSources");

            if (testSources is string testSourceString)
            {
                // Process folder
                var outputFolder = Path.GetDirectoryName(testSourceString);
                if (outputFolder is not null)
                {
                    BackupFolder(outputFolder);
                    ProcessFolder(outputFolder, SearchOption.TopDirectoryOnly);
                }
            }
            else if (testSources is List <string> testSourcesList)
            {
                // Process folder
                foreach (var source in testSourcesList)
                {
                    var outputFolder = Path.GetDirectoryName(source);
                    if (outputFolder is not null)
                    {
                        BackupFolder(outputFolder);
                        ProcessFolder(outputFolder, SearchOption.TopDirectoryOnly);
                    }
                }
            }
            else
            {
                // Process folder
                BackupFolder(Environment.CurrentDirectory);
                ProcessFolder(Environment.CurrentDirectory, SearchOption.AllDirectories);
            }
        }
Exemplo n.º 7
0
        public void SessionStartShouldStartVanguard()
        {
            var sessionStartEventArgs = new SessionStartEventArgs();

            this.collectorImpl.SessionStart(null, sessionStartEventArgs);

            this.vanguardMock.Verify(v => v.Start(It.IsAny <string>(), It.IsAny <DataCollectionContext>()));
        }
Exemplo n.º 8
0
        private void SessionStarted_Handler(object sender, SessionStartEventArgs args)
        {
            var filename = Path.Combine(Path.GetTempPath(), "filename.txt");

            File.WriteAllText(filename, string.Empty);
            this.dataCollectionSink.SendFileAsync(context.SessionDataCollectionContext, filename, true);
            this.logger.LogWarning(this.context.SessionDataCollectionContext, "SessionEnded");
        }
Exemplo n.º 9
0
        public SessionEventsTests()
        {
            var properties = new Dictionary <string, object>();

            properties.Add("property1", 1);
            properties.Add("property2", 2);

            this.sessionStartEventArgs = new SessionStartEventArgs(properties);
        }
Exemplo n.º 10
0
 void SessionStarted_Handler(object sender, SessionStartEventArgs e)
 {
     clocks.AddOrUpdate($"{e.Context?.SessionId?.Id}", _ => Stopwatch.StartNew(), (_, s) => s);
     log.Value.Log(new
     {
         Name      = "TestSessionStarted",
         RequestId = BuildArn ?? $"{e.Context?.SessionId?.Id}",
     });
     log2.LogWarning(e.Context, "SessionStarted");
 }
Exemplo n.º 11
0
        public void SessionStartedShouldReturnFalseIfDataCollectionIsNotConfiguredInRunSettings()
        {
            var runSettings = string.Format(this.defaultRunSettings, string.Empty);

            this.dataCollectionManager.InitializeDataCollectors(runSettings);

            var sessionStartEventArgs = new SessionStartEventArgs();
            var result = this.dataCollectionManager.SessionStarted(sessionStartEventArgs);

            Assert.IsFalse(result);
        }
Exemplo n.º 12
0
        public void SessionEndedShouldCancelProcessingAttachmentRequestsIfSessionIsCancelled()
        {
            this.dataCollectionManager.InitializeDataCollectors(this.dataCollectorSettings);
            var sessionStartEventArgs = new SessionStartEventArgs();

            this.dataCollectionManager.SessionStarted(sessionStartEventArgs);

            var result = this.dataCollectionManager.SessionEnded(true);

            this.mockDataCollectionAttachmentManager.Verify(x => x.Cancel(), Times.Once);
        }
Exemplo n.º 13
0
        public void SessionStartedShouldHaveCorrectSessionContext()
        {
            this.dataCollectionManager.InitializeDataCollectors(this.dataCollectorSettings);

            var sessionStartEventArgs = new SessionStartEventArgs();

            Assert.AreEqual(sessionStartEventArgs.Context.SessionId, new SessionId(Guid.Empty));

            this.dataCollectionManager.SessionStarted(sessionStartEventArgs);

            Assert.AreNotEqual(sessionStartEventArgs.Context.SessionId, new SessionId(Guid.Empty));
        }
Exemplo n.º 14
0
        private void OnSessionStart(object sender, SessionStartEventArgs e)
        {
            ValidateArg.NotNull(e, "SessionStartEventArgs");
            ValidateArg.NotNull(e.Context, "SessionStartEventArgs.Context");

            if (EqtTrace.IsVerboseEnabled)
            {
                EqtTrace.Verbose("EventLogDataCollector: SessionStart received");
            }

            this.StartCollectionForContext(e.Context, true);
        }
        private void ServiceHost_SessionStartRequested(SessionStartEventArgs args)
        {
            if (!SessionIsRunning)
            {
                sessionContext.Configuration = args.Configuration;

                StartSession();
            }
            else
            {
                logger.Warn("Received session start request, even though a session is already running!");
            }
        }
        /// <summary>
        /// Gets test modules
        /// </summary>
        /// <param name="sessionStartEventArgs">Event args</param>
        /// <returns>Test modules list</returns>
        private IEnumerable <string> GetTestModules(SessionStartEventArgs sessionStartEventArgs)
        {
            var testModules = sessionStartEventArgs.GetPropertyValue <IEnumerable <string> >(CoverletConstants.TestSourcesPropertyName);

            if (_eqtTrace.IsInfoEnabled)
            {
                _eqtTrace.Info("{0}: TestModules: '{1}'",
                               CoverletConstants.DataCollectorName,
                               string.Join(",", testModules ?? Enumerable.Empty <string>()));
            }

            return(testModules);
        }
Exemplo n.º 17
0
        /// <inheritdoc/>
        public bool SessionStarted(SessionStartEventArgs sessionStartEventArgs)
        {
            // If datacollectors are not configured or datacollection is not enabled, return false.
            if (!this.isDataCollectionEnabled || this.RunDataCollectors.Count == 0)
            {
                return(false);
            }

            sessionStartEventArgs.Context = new DataCollectionContext(this.dataCollectionEnvironmentContext.SessionDataCollectionContext.SessionId);
            this.SendEvent(sessionStartEventArgs);

            return(this.events.AreTestCaseEventsSubscribed());
        }
        public void RaiseEventsShouldNotRaiseEventsIfEventIsNotRegisterd()
        {
            this.isEventRaised = false;
            var testCase = new TestCase();

            this.context = new DataCollectionContext(testCase);

            var eventArgs = new SessionStartEventArgs(this.context, new Dictionary <string, object>());

            this.events.RaiseEvent(eventArgs);

            Assert.IsFalse(this.isEventRaised);
        }
        public void RaiseEventsShouldRaiseEventsIfSessionStartEventArgsIsPassed()
        {
            this.isEventRaised = false;
            var testCase = new TestCase();

            this.context = new DataCollectionContext(testCase);

            this.events.SessionStart += this.SessionStartMessageHandler;
            var eventArgs = new SessionStartEventArgs(this.context, new Dictionary <string, object>());

            this.events.RaiseEvent(eventArgs);

            Assert.IsTrue(this.isEventRaised);
        }
Exemplo n.º 20
0
        public void SessionStaretedShouldContinueDataCollectionIfExceptionIsThrownWhileSendingEventsToDataCollector()
        {
            this.SetupMockDataCollector((XmlElement a, DataCollectionEvents b, DataCollectionSink c, DataCollectionLogger d, DataCollectionEnvironmentContext e) =>
            {
                b.SessionStart += (sender, eventArgs) => throw new Exception();
            });

            this.dataCollectionManager.InitializeDataCollectors(this.dataCollectorSettings);

            var sessionStartEventArgs = new SessionStartEventArgs();
            var result = this.dataCollectionManager.SessionStarted(sessionStartEventArgs);

            Assert.IsFalse(result);
        }
Exemplo n.º 21
0
        public void SessionStartedShouldReturnTrueIfTestCaseStartIsSubscribed()
        {
            this.SetupMockDataCollector((XmlElement a, DataCollectionEvents b, DataCollectionSink c, DataCollectionLogger d, DataCollectionEnvironmentContext e) =>
            {
                b.TestCaseStart += (sender, eventArgs) => { };
            });

            this.dataCollectionManager.InitializeDataCollectors(this.dataCollectorSettings);

            var sessionStartEventArgs       = new SessionStartEventArgs();
            var areTestCaseEventsSubscribed = this.dataCollectionManager.SessionStarted(sessionStartEventArgs);

            Assert.IsTrue(areTestCaseEventsSubscribed);
        }
        public void RaiseEventsShouldNotRaiseEventsIfEventIsUnRegisterd()
        {
            this.isEventRaised = false;
            var testCase = new TestCase();

            this.context = new DataCollectionContext(testCase);

            this.events.SessionStart += this.SessionStartMessageHandler;
            this.events.SessionStart -= this.SessionStartMessageHandler;
            var eventArgs = new SessionStartEventArgs(this.context);

            this.events.RaiseEvent(eventArgs);

            Assert.IsFalse(this.isEventRaised);
        }
Exemplo n.º 23
0
        public void SessionStartShouldCreateDirectoryForCoverageFile()
        {
            var sessionStartEventArgs = new SessionStartEventArgs();
            var coverageFilePath      = string.Empty;

            this.vanguardMock.Setup(v => v.Start(It.IsAny <string>(), It.IsAny <DataCollectionContext>()))
            .Callback <string, DataCollectionContext>((filePath, dcContext) =>
            {
                coverageFilePath = filePath;
            });
            this.collectorImpl.SessionStart(null, sessionStartEventArgs);

            StringAssert.StartsWith(Path.GetDirectoryName(coverageFilePath), this.atempDirectory);
            StringAssert.EndsWith(coverageFilePath, DynamicCoverageDataCollectorImplTests.DefaultCoverageFileName);
        }
Exemplo n.º 24
0
        public void Communication_MustNotFailIfNoValidSessionData()
        {
            var args = new SessionStartEventArgs {
                Configuration = null
            };

            bootstrapSequence.Setup(b => b.TryPerform()).Returns(OperationResult.Success);
            sessionSequence.Setup(b => b.TryPerform()).Returns(OperationResult.Success);

            sut.TryStart();
            serviceHost.Raise(h => h.SessionStartRequested += null, args);

            sessionSequence.Verify(s => s.TryPerform(), Times.Once);

            Assert.IsNull(sessionContext.Configuration);
        }
Exemplo n.º 25
0
        public void SessionStartShouldUseAutoGenrateCoverageFileNameIfNotSpecified()
        {
            var sessionStartEventArgs = new SessionStartEventArgs();
            var coverageFilePath      = string.Empty;

            this.collectorImpl.Initialize(null, this.dataCollectionSinkMock.Object, this.dataCollectionLoggerMock.Object);
            this.vanguardMock.Setup(v => v.Start(It.IsAny <string>(), It.IsAny <DataCollectionContext>()))
            .Callback <string, DataCollectionContext>((filePath, dcContext) =>
            {
                coverageFilePath = filePath;
            });
            this.collectorImpl.SessionStart(null, sessionStartEventArgs);

            StringAssert.StartsWith(Path.GetDirectoryName(coverageFilePath), this.atempDirectory);
            StringAssert.Contains(coverageFilePath, DynamicCoverageDataCollectorImplTests.GetAutoGenerageCodeCoverageFileNamePrefix());
        }
Exemplo n.º 26
0
        public void SessionStartedShouldSendEventToDataCollector()
        {
            var isStartInvoked = false;

            this.SetupMockDataCollector((XmlElement a, DataCollectionEvents b, DataCollectionSink c, DataCollectionLogger d, DataCollectionEnvironmentContext e) =>
            {
                b.SessionStart += (sender, eventArgs) => isStartInvoked = true;
            });

            this.dataCollectionManager.InitializeDataCollectors(this.dataCollectorSettings);

            var sessionStartEventArgs       = new SessionStartEventArgs();
            var areTestCaseEventsSubscribed = this.dataCollectionManager.SessionStarted(sessionStartEventArgs);

            Assert.IsTrue(isStartInvoked);
            Assert.IsFalse(areTestCaseEventsSubscribed);
        }
Exemplo n.º 27
0
 /// <summary>
 /// Gets test modules
 /// </summary>
 /// <param name="sessionStartEventArgs">Event args</param>
 /// <returns>Test modules list</returns>
 private IEnumerable <string> GetTestModules(SessionStartEventArgs sessionStartEventArgs)
 {
     try
     {
         IEnumerable <string> testModules = GetPropertyValueWrapper(sessionStartEventArgs);
         if (_eqtTrace.IsInfoEnabled)
         {
             _eqtTrace.Info("{0}: TestModules: '{1}'",
                            CoverletConstants.DataCollectorName,
                            string.Join(",", testModules ?? Enumerable.Empty <string>()));
         }
         return(testModules);
     }
     catch (MissingMethodException ex)
     {
         throw new MissingMethodException("Make sure to use .NET core SDK Version >= 2.2.300", ex);
     }
 }
Exemplo n.º 28
0
        public void Communication_MustStartNewSessionUponRequest()
        {
            var args = new SessionStartEventArgs {
                Configuration = new ServiceConfiguration {
                    SessionId = Guid.NewGuid()
                }
            };

            bootstrapSequence.Setup(b => b.TryPerform()).Returns(OperationResult.Success);
            sessionSequence.Setup(b => b.TryPerform()).Returns(OperationResult.Success);

            sut.TryStart();
            serviceHost.Raise(h => h.SessionStartRequested += null, args);

            sessionSequence.Verify(s => s.TryPerform(), Times.Once);

            Assert.IsNotNull(sessionContext.Configuration);
            Assert.AreEqual(args.Configuration.SessionId, sessionContext.Configuration.SessionId);
        }
Exemplo n.º 29
0
        public void SessionEndedShouldReturnAttachments()
        {
            var attachment = new AttachmentSet(new Uri("my://custom/datacollector"), "CustomDataCollector");

            attachment.Attachments.Add(new UriDataAttachment(new Uri("my://filename.txt"), "filename.txt"));

            this.mockDataCollectionAttachmentManager.Setup(x => x.GetAttachments(It.IsAny <DataCollectionContext>())).Returns(new List <AttachmentSet>()
            {
                attachment
            });

            this.dataCollectionManager.InitializeDataCollectors(this.dataCollectorSettings);
            var sessionStartEventArgs = new SessionStartEventArgs();

            this.dataCollectionManager.SessionStarted(sessionStartEventArgs);

            var result = this.dataCollectionManager.SessionEnded();

            Assert.IsTrue(result[0].Attachments[0].Uri.ToString().Contains("filename.txt"));
        }
Exemplo n.º 30
0
        public void SessionStartShouldLogErrorOnException()
        {
            var       sessionStartEventArgs = new SessionStartEventArgs();
            var       exceptionMessage      = "Vanguard not found";
            Exception expectedEx            = null;

            this.vanguardMock.Setup(d => d.Start(It.IsAny <string>(), It.IsAny <DataCollectionContext>()))
            .Throws(new VanguardException(exceptionMessage));
            this.dataCollectionLoggerMock
            .Setup(l => l.LogError(It.IsAny <DataCollectionContext>(), It.IsAny <Exception>()))
            .Callback <DataCollectionContext, Exception>((context, ex) =>
            {
                expectedEx = ex;
            });
            var actualEx = Assert.ThrowsException <VanguardException>(() => this.collectorImpl.SessionStart(null, sessionStartEventArgs));

            this.vanguardMock.Verify(v => v.Start(It.IsAny <string>(), It.IsAny <DataCollectionContext>()));
            Assert.AreEqual(expectedEx, actualEx);
            StringAssert.Contains(actualEx.Message, exceptionMessage);
        }
 private void OnSessionStart(object sender, SessionStartEventArgs e)
 {
     _nyanCat.Start();
 }