Exemplo n.º 1
0
        public void ShouldNotifyBeforeItemFinishing()
        {
            ILaunchReporter l = null;
            ITestReporter   t = null;
            BeforeLaunchFinishingEventArgs beforeLaunchFinishingEventArgs = null;
            BeforeTestFinishingEventArgs   beforeTestFinishingEventArgs   = null;

            var observer = new Mock <IReportEventsObserver>();

            observer.Setup(o => o.Initialize(It.IsAny <IReportEventsSource>())).Callback <IReportEventsSource>(s =>
            {
                s.OnBeforeLaunchFinishing += (a, b) => { l = a; beforeLaunchFinishingEventArgs = b; };
                s.OnBeforeTestFinishing   += (a, b) => { t = a; beforeTestFinishingEventArgs = b; };
            });

            var extManager = new Shared.Extensibility.ExtensionManager();

            extManager.ReportEventObservers.Add(observer.Object);

            var client = new MockServiceBuilder().Build().Object;
            var launch = new LaunchReporterBuilder(client).With(extManager).Build(1, 0, 0);

            launch.Sync();

            beforeLaunchFinishingEventArgs.ClientService.Should().BeSameAs(client);
            l.Should().BeSameAs(launch);
            beforeLaunchFinishingEventArgs.FinishLaunchRequest.Should().NotBeNull();

            beforeTestFinishingEventArgs.ClientService.Should().BeSameAs(client);
            t.Should().BeSameAs(launch.ChildTestReporters[0]);
            beforeTestFinishingEventArgs.FinishTestItemRequest.Should().NotBeNull();
        }
Exemplo n.º 2
0
        public void ShouldNotifyAfterItemStarted()
        {
            ILaunchReporter             l = null;
            ITestReporter               t = null;
            AfterLaunchStartedEventArgs afterLaunchStartedEventArgs = null;
            AfterTestStartedEventArgs   afterTestStartedEventArgs   = null;

            var observer = new Mock <IReportEventsObserver>();

            observer.Setup(o => o.Initialize(It.IsAny <IReportEventsSource>())).Callback <IReportEventsSource>(s =>
            {
                s.OnAfterLaunchStarted += (a, b) => { l = a; afterLaunchStartedEventArgs = b; };
                s.OnAfterTestStarted   += (a, b) => { t = a; afterTestStartedEventArgs = b; };
            });

            var extManager = new Shared.Extensibility.ExtensionManager();

            extManager.ReportEventObservers.Add(observer.Object);

            var client = new MockServiceBuilder().Build().Object;
            var launch = new LaunchReporterBuilder(client).With(extManager).Build(1, 0, 0);

            launch.Sync();

            afterLaunchStartedEventArgs.ClientService.Should().BeSameAs(client);
            l.Should().BeSameAs(launch);

            afterTestStartedEventArgs.ClientService.Should().BeSameAs(client);
            t.Should().BeSameAs(launch.ChildTestReporters[0]);
        }
Exemplo n.º 3
0
 public RunFinishedEventArgs(Service service, FinishLaunchRequest request, ILaunchReporter launchReporter, string report)
 {
     Service             = service;
     FinishLaunchRequest = request;
     LaunchReporter      = launchReporter;
     Report = report;
 }
Exemplo n.º 4
0
        private void Events_TestRunStart(object sender, TestRunStartEventArgs e)
        {
            var requestNewLaunch = new StartLaunchRequest
            {
                Name        = _config.GetValue(ConfigurationPath.LaunchName, "VsTest Launch"),
                Description = _config.GetValue(ConfigurationPath.LaunchDescription, ""),
                StartTime   = DateTime.UtcNow
            };

            if (_config.GetValue(ConfigurationPath.LaunchDebugMode, false))
            {
                requestNewLaunch.Mode = LaunchMode.Debug;
            }

            requestNewLaunch.Tags = _config.GetValues(ConfigurationPath.LaunchTags, new List <string>()).ToList();

            // see wether we need use external launch
            var launchId = _config.GetValue <string>("Launch:Id", "");

            if (string.IsNullOrEmpty(launchId))
            {
                _launchReporter = new LaunchReporter(Bridge.Service);
            }
            else
            {
                _launchReporter = new LaunchReporter(Bridge.Service, launchId);
            }

            _launchReporter.Start(requestNewLaunch);
        }
Exemplo n.º 5
0
        public TestReporter(Service service, ILaunchReporter launchReporter, ITestReporter parentTestReporter)
        {
            _service           = service;
            LaunchReporter     = launchReporter;
            ParentTestReporter = parentTestReporter;

            ThreadId = Thread.CurrentThread.ManagedThreadId;
        }
Exemplo n.º 6
0
 public TestReporter(IClientService service, IConfiguration configuration, ILaunchReporter launchReporter, ITestReporter parentTestReporter, IRequestExecuter requestExecuter, IExtensionManager extensionManager, ReportEventsSource reportEventNotifier)
 {
     _service            = service;
     _configuration      = configuration;
     _requestExecuter    = requestExecuter;
     _extensionManager   = extensionManager;
     _reportEventsSource = reportEventNotifier;
     LaunchReporter      = launchReporter;
     ParentTestReporter  = parentTestReporter;
 }
        public TestReporter(Service service, ILaunchReporter launchReporter, ITestReporter parentTestReporter, StartTestItemRequest startTestItemRequest)
        {
            _service           = service;
            LaunchReporter     = launchReporter;
            ParentTestReporter = parentTestReporter;

            if (StartTask != null)
            {
                throw new InsufficientExecutionStackException("The test item is already scheduled for starting.");
            }

            var parentStartTask = ParentTestReporter?.StartTask ?? LaunchReporter.StartTask;

            StartTask = parentStartTask.ContinueWith(async(pt) =>
            {
                if (pt.IsFaulted)
                {
                    throw pt.Exception;
                }

                startTestItemRequest.LaunchId = LaunchReporter.LaunchInfo.Id;
                if (ParentTestReporter == null)
                {
                    if (startTestItemRequest.StartTime < LaunchReporter.LaunchInfo.StartTime)
                    {
                        startTestItemRequest.StartTime = LaunchReporter.LaunchInfo.StartTime;
                    }

                    var id = (await _service.StartTestItemAsync(startTestItemRequest)).Id;

                    TestInfo = new TestItem
                    {
                        Id = id
                    };
                }
                else
                {
                    if (startTestItemRequest.StartTime < ParentTestReporter.TestInfo.StartTime)
                    {
                        startTestItemRequest.StartTime = ParentTestReporter.TestInfo.StartTime;
                    }

                    var id = (await _service.StartTestItemAsync(ParentTestReporter.TestInfo.Id, startTestItemRequest)).Id;

                    TestInfo = new TestItem
                    {
                        Id = id
                    };
                }

                TestInfo.StartTime = startTestItemRequest.StartTime;
            }).Unwrap();

            ThreadId = Thread.CurrentThread.ManagedThreadId;
        }
Exemplo n.º 8
0
        public static void BeforeTestRun()
        {
            try
            {
                var config = Initialize();

                var request = new StartLaunchRequest
                {
                    Name      = config.GetValue(ConfigurationPath.LaunchName, "SpecFlow Launch"),
                    StartTime = DateTime.UtcNow
                };

                if (config.GetValue(ConfigurationPath.LaunchDebugMode, false))
                {
                    request.Mode = LaunchMode.Debug;
                }

                request.Attributes = config.GetKeyValues("Launch:Attributes", new List <KeyValuePair <string, string> >()).Select(a => new ItemAttribute {
                    Key = a.Key, Value = a.Value
                }).ToList();
                request.Description = config.GetValue(ConfigurationPath.LaunchDescription, string.Empty);

                var eventArg = new RunStartedEventArgs(_service, request);
                ReportPortalAddin.OnBeforeRunStarted(null, eventArg);

                if (eventArg.LaunchReporter != null)
                {
                    _launchReporter = eventArg.LaunchReporter;
                }

                if (!eventArg.Canceled)
                {
                    Shared.Extensibility.Embedded.Analytics.AnalyticsReportEventsObserver.DefineConsumer("agent-dotnet-specflow");

                    _launchReporter = _launchReporter ?? new LaunchReporter(_service, config, null, Shared.Extensibility.ExtensionManager.Instance);

                    _launchReporter.Start(request);

                    ReportPortalAddin.OnAfterRunStarted(null, new RunStartedEventArgs(_service, request, _launchReporter));
                }
            }
            catch (Exception exp)
            {
                _traceLogger.Error(exp.ToString());
            }
        }
Exemplo n.º 9
0
        private void Events_TestRunStart(object sender, TestRunStartEventArgs e)
        {
            var requestNewLaunch = new StartLaunchRequest
            {
                Name        = _config.GetValue(ConfigurationPath.LaunchName, "VsTest Launch"),
                Description = _config.GetValue(ConfigurationPath.LaunchDescription, ""),
                StartTime   = DateTime.UtcNow
            };

            if (_config.GetValue(ConfigurationPath.LaunchDebugMode, false))
            {
                requestNewLaunch.Mode = LaunchMode.Debug;
            }

            requestNewLaunch.Tags = _config.GetValues(ConfigurationPath.LaunchTags, new List <string>()).ToList();

            _launchReporter = new LaunchReporter(Bridge.Service, _config, null);

            _launchReporter.Start(requestNewLaunch);
        }
Exemplo n.º 10
0
        private void Events_TestRunStart(object sender, TestRunStartEventArgs e)
        {
            try
            {
                var apiUri     = _config.GetValue <string>(ConfigurationPath.ServerUrl);
                var apiProject = _config.GetValue <string>(ConfigurationPath.ServerProject);
                var apiToken   = _config.GetValue <string>(ConfigurationPath.ServerAuthenticationUuid);
                var apiService = new Service(new Uri(apiUri), apiProject, apiToken);

                var requestNewLaunch = new StartLaunchRequest
                {
                    Name              = _config.GetValue(ConfigurationPath.LaunchName, "VsTest Launch"),
                    Description       = _config.GetValue(ConfigurationPath.LaunchDescription, ""),
                    StartTime         = DateTime.UtcNow,
                    RerunOfLaunchUuid = Environment.GetEnvironmentVariable("DTA.RerunIterationCount") != null ? this._config.Properties["RerunOfLaunchUuid"].ToString() : null,
                };
                if (_config.GetValue(ConfigurationPath.LaunchDebugMode, false))
                {
                    requestNewLaunch.Mode = LaunchMode.Debug;
                }

                requestNewLaunch.Attributes = _config.GetKeyValues("Launch:Attributes", new List <KeyValuePair <string, string> >()).Select(a => new ItemAttribute {
                    Key = a.Key, Value = a.Value
                }).ToList();

                _launchReporter = new LaunchReporter(apiService, _config, null);

                _launchReporter.Start(requestNewLaunch);
            }
            catch (Exception exp)
            {
                var error = $"Unexpected exception in {nameof(Events_TestRunStart)}: {exp}";
                TraceLogger.Error(error);
                Console.WriteLine(error);
                throw;
            }
        }
 public RunFinishedEventArgs(IClientService service, FinishLaunchRequest request, ILaunchReporter launchReporter)
 {
     Service             = service;
     FinishLaunchRequest = request;
     LaunchReporter      = launchReporter;
 }
 public RunStartedEventArgs(IClientService service, StartLaunchRequest request, ILaunchReporter launchReporter)
     : this(service, request)
 {
     LaunchReporter = launchReporter;
 }
Exemplo n.º 13
0
 public static void RaiseAfterLaunchFinished(ReportEventsSource source, ILaunchReporter launchReporter, AfterLaunchFinishedEventArgs args)
 {
     source.OnAfterLaunchFinished?.Invoke(launchReporter, args);
 }
Exemplo n.º 14
0
 public static void RaiseBeforeLaunchFinishing(ReportEventsSource source, ILaunchReporter launchReporter, BeforeLaunchFinishingEventArgs args)
 {
     source.OnBeforeLaunchFinishing?.Invoke(launchReporter, args);
 }
Exemplo n.º 15
0
 public RunStartedEventArgs(Service service, StartLaunchRequest request, ILaunchReporter launchReporter, string report) : this(service, request)
 {
     LaunchReporter = launchReporter;
     Report         = report;
 }
Exemplo n.º 16
0
 public LaunchLogRequestAmender(ILaunchReporter launchReporter)
 {
     _launchReporter = launchReporter;
 }