public void ShouldGetTagListFromSpecAndScenario()
        {
            var specInfo = new SpecInfo
            {
                Tags     = { "foo" },
                Name     = "",
                FileName = "",
                IsFailed = false
            };
            var scenarioInfo = new ScenarioInfo
            {
                Tags     = { "bar" },
                Name     = "",
                IsFailed = false
            };
            var currentScenario = new ExecutionInfo
            {
                CurrentSpec     = specInfo,
                CurrentScenario = scenarioInfo
            };
            var currentExecutionInfo = new ScenarioExecutionEndingRequest
            {
                CurrentExecutionInfo = currentScenario
            };
            var tags = AssertEx.ExecuteProtectedMethod <ScenarioExecutionEndingProcessor>("GetApplicableTags", currentScenario)
                       .ToList();

            Assert.IsNotEmpty(tags);
            Assert.AreEqual(2, tags.Count);
            Assert.Contains("foo", tags);
            Assert.Contains("bar", tags);
        }
예제 #2
0
        public void ShouldNotGetDuplicateTags()
        {
            var specInfo = SpecInfo.CreateBuilder()
                           .AddTags("foo")
                           .SetName("")
                           .SetFileName("")
                           .SetIsFailed(false)
                           .Build();
            var scenarioInfo = ScenarioInfo.CreateBuilder()
                               .AddTags("foo")
                               .SetName("")
                               .SetIsFailed(false)
                               .Build();
            var currentScenario = ExecutionInfo.CreateBuilder()
                                  .SetCurrentScenario(scenarioInfo)
                                  .SetCurrentSpec(specInfo)
                                  .Build();
            var currentExecutionInfo = ScenarioExecutionEndingRequest.CreateBuilder()
                                       .SetCurrentExecutionInfo(currentScenario)
                                       .Build();
            var message = Message.CreateBuilder()
                          .SetScenarioExecutionEndingRequest(currentExecutionInfo)
                          .SetMessageType(Message.Types.MessageType.ScenarioExecutionEnding)
                          .SetMessageId(0)
                          .Build();

            var tags = AssertEx.ExecuteProtectedMethod <ScenarioExecutionEndingProcessor>("GetApplicableTags", message).ToList();

            Assert.IsNotEmpty(tags);
            Assert.AreEqual(1, tags.Count);
            Assert.Contains("foo", tags);
        }
예제 #3
0
        public void ShouldExecutreBeforeScenarioHook()
        {
            var mockAssemblyLoader = new Mock <IAssemblyLoader>();
            var mockType           = new Mock <Type>().Object;

            mockAssemblyLoader.Setup(x => x.GetLibType(LibType.MessageCollector)).Returns(mockType);
            mockAssemblyLoader.Setup(x => x.GetLibType(LibType.ScreenshotCollector)).Returns(mockType);
            var scenarioExecutionEndingRequest = new ScenarioExecutionEndingRequest
            {
                CurrentExecutionInfo = new ExecutionInfo
                {
                    CurrentSpec     = new SpecInfo(),
                    CurrentScenario = new ScenarioInfo()
                }
            };
            var request = new Message
            {
                MessageId   = 20,
                MessageType = Message.Types.MessageType.SpecExecutionStarting,
                ScenarioExecutionEndingRequest = scenarioExecutionEndingRequest
            };

            var mockMethodExecutor   = new Mock <IExecutionOrchestrator>();
            var protoExecutionResult = new ProtoExecutionResult
            {
                ExecutionTime = 0,
                Failed        = false
            };
            IEnumerable <string> pendingMessages = new List <string> {
                "one", "two"
            };

            mockMethodExecutor.Setup(x =>
                                     x.ExecuteHooks("AfterScenario", It.IsAny <HooksStrategy>(), It.IsAny <IList <string> >(),
                                                    It.IsAny <ExecutionContext>()))
            .Returns(protoExecutionResult);
            var mockReflectionWrapper = new Mock <IReflectionWrapper>();

            mockReflectionWrapper.Setup(x =>
                                        x.InvokeMethod(mockType, null, "GetAllPendingMessages", It.IsAny <BindingFlags>()))
            .Returns(pendingMessages);
            var pendingScreenshots = new List <byte[]>()
            {
                Encoding.ASCII.GetBytes("screenshot")
            };

            mockReflectionWrapper.Setup(x =>
                                        x.InvokeMethod(mockType, null, "GetAllPendingScreenshots", It.IsAny <BindingFlags>()))
            .Returns(pendingScreenshots);

            var processor = new ScenarioExecutionEndingProcessor(mockMethodExecutor.Object,
                                                                 mockAssemblyLoader.Object, mockReflectionWrapper.Object);

            var result = processor.Process(request);

            Assert.False(result.ExecutionStatusResponse.ExecutionResult.Failed);
            Assert.AreEqual(result.ExecutionStatusResponse.ExecutionResult.Message.ToList(), pendingMessages);
            Assert.AreEqual(result.ExecutionStatusResponse.ExecutionResult.ScreenShot.ToList(), pendingScreenshots);
        }
예제 #4
0
        public ExecutionStatusResponse Process(ScenarioExecutionEndingRequest request)
        {
            _executionOrchestrator.CloseExecutionScope();
            var result = ExecuteHooks(request.CurrentExecutionInfo);

            ClearCacheForConfiguredLevel();
            return(result);
        }
        public void ShouldExecutreBeforeScenarioHook()
        {
            var scenarioExecutionStartingRequest = new ScenarioExecutionEndingRequest
            {
                CurrentExecutionInfo = new ExecutionInfo
                {
                    CurrentSpec     = new SpecInfo(),
                    CurrentScenario = new ScenarioInfo()
                }
            };
            var request = new Message
            {
                MessageId   = 20,
                MessageType = Message.Types.MessageType.SpecExecutionStarting,
                ScenarioExecutionEndingRequest = scenarioExecutionStartingRequest
            };

            var mockMethodExecutor   = new Mock <IExecutionOrchestrator>();
            var protoExecutionResult = new ProtoExecutionResult
            {
                ExecutionTime = 0,
                Failed        = false
            };
            var pendingMessages = new List <string> {
                "one", "two"
            };
            var pendingScreenshots = new List <byte[]> {
                Encoding.ASCII.GetBytes("screenshot")
            };

            mockMethodExecutor.Setup(x =>
                                     x.ExecuteHooks("AfterScenario", It.IsAny <HooksStrategy>(), It.IsAny <IList <string> >(),
                                                    It.IsAny <ExecutionContext>()))
            .Returns(protoExecutionResult);
            mockMethodExecutor.Setup(x =>
                                     x.GetAllPendingMessages()).Returns(pendingMessages);
            mockMethodExecutor.Setup(x =>
                                     x.GetAllPendingScreenshots()).Returns(pendingScreenshots);

            var processor = new ScenarioExecutionEndingProcessor(mockMethodExecutor.Object);

            var result = processor.Process(request);

            Assert.False(result.ExecutionStatusResponse.ExecutionResult.Failed);
            Assert.AreEqual(result.ExecutionStatusResponse.ExecutionResult.Message.ToList(), pendingMessages);
            Assert.AreEqual(result.ExecutionStatusResponse.ExecutionResult.Screenshots.ToList(), pendingScreenshots);
        }
예제 #6
0
        public override Task <Empty> NotifyScenarioExecutionEnding(ScenarioExecutionEndingRequest request, ServerCallContext context)
        {
            try
            {
                TraceLogger.Info($"{nameof(NotifyScenarioExecutionEnding)} received");
                TraceLogger.Verbose(System.Text.Json.JsonSerializer.Serialize(request));

                if (request.ScenarioResult != null)
                {
                    _sender.FinishScenario(request);
                }
            }
            catch (Exception exp)
            {
                TraceLogger.Error(exp.ToString());
            }

            return(Task.FromResult(new Empty()));
        }
예제 #7
0
        public void FinishScenario(ScenarioExecutionEndingRequest request)
        {
            var key = GetScenarioKey(request.CurrentExecutionInfo, request.CurrentExecutionInfo.CurrentSpec, request.CurrentExecutionInfo.CurrentScenario);

            var scenarioReporter = _scenarios[key];

            var scenarioResult = request.ScenarioResult;

            // post hook messages
            if (scenarioResult.ProtoItem.Scenario.PostHookMessages.Count != 0 || scenarioResult.ProtoItem.Scenario.PostHookFailure != null)
            {
                foreach (var postHookMessage in scenarioResult.ProtoItem.Scenario.PostHookMessages)
                {
                    scenarioReporter.Log(new CreateLogItemRequest
                    {
                        Level = LogLevel.Debug,
                        Text  = postHookMessage,
                        Time  = DateTime.UtcNow
                    });
                }

                if (scenarioResult.ProtoItem.Scenario.PostHookFailure != null)
                {
                    var postHookFailure = scenarioResult.ProtoItem.Scenario.PostHookFailure;

                    scenarioReporter.Log(new CreateLogItemRequest
                    {
                        Level = LogLevel.Error,
                        Text  = $"{postHookFailure.ErrorMessage}{Environment.NewLine}{postHookFailure.StackTrace}",
                        Time  = DateTime.UtcNow
                    });
                }
            }

            scenarioReporter.Finish(new FinishTestItemRequest
            {
                EndTime = DateTime.UtcNow,
                Status  = _statusMap[scenarioResult.ProtoItem.Scenario.ExecutionStatus]
            });

            _scenarios.TryRemove(key, out _);
        }
예제 #8
0
        public void ShouldExecutreBeforeScenarioHook()
        {
            var scenarioExecutionStartingRequest = new ScenarioExecutionEndingRequest
            {
                CurrentExecutionInfo = new ExecutionInfo
                {
                    CurrentSpec     = new SpecInfo(),
                    CurrentScenario = new ScenarioInfo()
                }
            };

            var mockMethodExecutor   = new Mock <IExecutionOrchestrator>();
            var protoExecutionResult = new ProtoExecutionResult
            {
                ExecutionTime = 0,
                Failed        = false
            };
            var pendingMessages = new List <string> {
                "one", "two"
            };
            var pendingScreenshotFiles = new List <string> {
                "screenshot.png"
            };

            mockMethodExecutor.Setup(x =>
                                     x.ExecuteHooks("AfterScenario", It.IsAny <HooksStrategy>(), It.IsAny <IList <string> >(),
                                                    It.IsAny <ExecutionInfo>()))
            .Returns(protoExecutionResult);
            mockMethodExecutor.Setup(x =>
                                     x.GetAllPendingMessages()).Returns(pendingMessages);
            mockMethodExecutor.Setup(x =>
                                     x.GetAllPendingScreenshotFiles()).Returns(pendingScreenshotFiles);

            var processor = new ScenarioExecutionEndingProcessor(mockMethodExecutor.Object);

            var result = processor.Process(scenarioExecutionStartingRequest);

            Assert.False(result.ExecutionResult.Failed);
            Assert.AreEqual(result.ExecutionResult.Message.ToList(), pendingMessages);
            Assert.AreEqual(result.ExecutionResult.ScreenshotFiles.ToList(), pendingScreenshotFiles);
        }
        public void ShouldNotGetDuplicateTags()
        {
            var specInfo = new SpecInfo
            {
                Tags     = { "foo" },
                Name     = "",
                FileName = "",
                IsFailed = false
            };
            var scenarioInfo = new ScenarioInfo
            {
                Tags     = { "foo" },
                Name     = "",
                IsFailed = false
            };
            var currentScenario = new ExecutionInfo
            {
                CurrentSpec     = specInfo,
                CurrentScenario = scenarioInfo
            };
            var currentExecutionInfo = new ScenarioExecutionEndingRequest
            {
                CurrentExecutionInfo = currentScenario
            };
            var message = new Message
            {
                ScenarioExecutionEndingRequest = currentExecutionInfo,
                MessageType = Message.Types.MessageType.ScenarioExecutionEnding,
                MessageId   = 0
            };

            var tags = AssertEx.ExecuteProtectedMethod <ScenarioExecutionEndingProcessor>("GetApplicableTags", message)
                       .ToList();

            Assert.IsNotEmpty(tags);
            Assert.AreEqual(1, tags.Count);
            Assert.Contains("foo", tags);
        }
예제 #10
0
 public override Task <ExecutionStatusResponse> FinishScenarioExecution(ScenarioExecutionEndingRequest request, ServerCallContext context)
 {
     return(_pool.Execute(getStream(request.Stream), () => this.scenarioExecutionEndingProcessor.Process(request)));
 }
예제 #11
0
 public override Task <ExecutionStatusResponse> FinishScenarioExecution(ScenarioExecutionEndingRequest request, ServerCallContext context)
 {
     return(Task.FromResult(this.scenarioExecutionEndingProcessor.Process(request)));
 }
 public ExecutionStatusResponse Process(ScenarioExecutionEndingRequest request)
 {
     _executionOrchestrator.CloseExecutionScope();
     return(ExecuteHooks(request.CurrentExecutionInfo));
 }
 public override Task <Empty> NotifyScenarioExecutionEnding(ScenarioExecutionEndingRequest request, ServerCallContext context)
 {
     return(Task.FromResult(new Empty()));
 }