public void TestSessionStartEventShouldCreateEventLogContainer()
        {
            var eventLogDataCollector = new EventLogDataCollector();

            Assert.AreEqual(eventLogDataCollector.ContextMap.Count, 0);
            eventLogDataCollector.Initialize(null, this.mockDataCollectionEvents.Object, this.mockDataCollectionSink, this.mockDataCollectionLogger.Object, this.dataCollectionEnvironmentContext);
            this.mockDataCollectionEvents.Raise(x => x.SessionStart += null, new SessionStartEventArgs());
            Assert.AreEqual(eventLogDataCollector.ContextMap.Count, 1);
        }
示例#2
0
        public void TestCaseStartEventShouldCreateEventLogContainer()
        {
            var eventLogDataCollector = new EventLogDataCollector();

            Assert.AreEqual(0, eventLogDataCollector.ContextMap.Count);

            eventLogDataCollector.Initialize(null, this.mockDataCollectionEvents.Object, this.mockDataCollectionSink, this.mockDataCollectionLogger.Object, this.dataCollectionEnvironmentContext);
            this.mockDataCollectionEvents.Raise(x => x.TestCaseStart += null, new TestCaseStartEventArgs(new DataCollectionContext(new SessionId(Guid.NewGuid()), new TestExecId(Guid.NewGuid())), new TestCase()));
            Assert.AreEqual(1, eventLogDataCollector.ContextMap.Count);
        }
        public void SessionEndEventShouldThrowIfSessionStartEventtIsNotInvoked()
        {
            var eventLogDataCollector = new EventLogDataCollector();

            eventLogDataCollector.Initialize(null, this.mockDataCollectionEvents.Object, this.mockDataCollectionSink, this.mockDataCollectionLogger.Object, this.dataCollectionEnvironmentContext);
            var tc = new TestCase();

            Assert.ThrowsException <EventLogCollectorException>(() =>
            {
                this.mockDataCollectionEvents.Raise(x => x.SessionEnd += null, new SessionEndEventArgs(this.dataCollectionEnvironmentContext.SessionDataCollectionContext));
            });
        }
        public void TestCaseEndEventShouldInvokeSendFileAsync()
        {
            var eventLogDataCollector = new EventLogDataCollector();

            eventLogDataCollector.Initialize(null, this.mockDataCollectionEvents.Object, this.mockDataCollectionSink, this.mockDataCollectionLogger.Object, this.dataCollectionEnvironmentContext);
            var tc      = new TestCase();
            var context = new DataCollectionContext(new SessionId(Guid.NewGuid()), new TestExecId(Guid.NewGuid()));

            this.mockDataCollectionEvents.Raise(x => x.TestCaseStart += null, new TestCaseStartEventArgs(context, tc));
            this.mockDataCollectionEvents.Raise(x => x.TestCaseEnd   += null, new TestCaseEndEventArgs(context, tc, TestOutcome.Passed));
            Assert.IsTrue(this.mockDataCollectionSink.IsSendFileAsyncInvoked);
        }
        public EventLogDataCollectorTests()
        {
            this.mockDataCollectionEvents = new Mock <DataCollectionEvents>();
            this.mockDataCollectionSink   = new TestableDataCollectionSink();
            this.mockFileHelper           = new Mock <IFileHelper>();
            TestCase tc = new TestCase();
            DataCollectionContext dataCollectionContext =
                new DataCollectionContext(new SessionId(Guid.NewGuid()));

            this.dataCollectionEnvironmentContext = new DataCollectionEnvironmentContext(dataCollectionContext);
            this.mockDataCollectionLogger         = new Mock <DataCollectionLogger>();
            this.eventLogDataCollector            = new EventLogDataCollector(this.mockFileHelper.Object);
        }
        public void TestCaseEndEventShouldThrowIfTestCaseStartIsNotInvoked()
        {
            var eventLogDataCollector = new EventLogDataCollector();

            eventLogDataCollector.Initialize(null, this.mockDataCollectionEvents.Object, this.mockDataCollectionSink, this.mockDataCollectionLogger.Object, this.dataCollectionEnvironmentContext);
            var tc      = new TestCase();
            var context = new DataCollectionContext(new SessionId(Guid.NewGuid()), new TestExecId(Guid.NewGuid()));

            Assert.ThrowsException <EventLogCollectorException>(() =>
            {
                this.mockDataCollectionEvents.Raise(x => x.TestCaseEnd += null, new TestCaseEndEventArgs(context, tc, TestOutcome.Passed));
            });
        }
        public void TestSessionEndEventShouldWriteEventLogEntriesAndSendFile()
        {
            var eventLogDataCollector = new EventLogDataCollector();

            eventLogDataCollector.Initialize(null, this.mockDataCollectionEvents.Object, this.mockDataCollectionSink, this.mockDataCollectionLogger.Object, this.dataCollectionEnvironmentContext);
            var testcase = new TestCase()
            {
                Id = Guid.NewGuid()
            };

            this.mockDataCollectionEvents.Raise(x => x.SessionStart += null, new SessionStartEventArgs(this.dataCollectionEnvironmentContext.SessionDataCollectionContext));
            this.mockDataCollectionEvents.Raise(x => x.SessionEnd   += null, new SessionEndEventArgs(this.dataCollectionEnvironmentContext.SessionDataCollectionContext));
            Assert.IsTrue(this.mockDataCollectionSink.IsSendFileAsyncInvoked);
        }
        public void EventLoggerLogsErrorForInvalidEventSources()
        {
            string configurationString =
                @"<Configuration><Setting name=""EventLogs"" value=""MyEventName"" /></Configuration>";
            XmlDocument expectedXmlDoc = new XmlDocument();

            expectedXmlDoc.LoadXml(configurationString);
            var mockCollector = new Mock <DataCollectionLogger>();

            mockCollector.Setup(m => m.LogError(It.IsAny <DataCollectionContext>(), It.Is <string>(s => s.Contains(@"The event log 'MyEventName' on computer '.' does not exist.")), It.IsAny <Exception>()));

            var eventLogDataCollector = new EventLogDataCollector();

            eventLogDataCollector.Initialize(expectedXmlDoc.DocumentElement, this.mockDataCollectionEvents.Object, this.mockDataCollectionSink, mockCollector.Object, this.dataCollectionEnvironmentContext);

            mockCollector.Verify(m => m.LogError(It.IsAny <DataCollectionContext>(), It.IsAny <string>(), It.IsAny <Exception>()), Times.Once);
        }