コード例 #1
0
        public ProtoExecutionResult Execute(GaugeMethod method, params string[] args)
        {
            var stopwatch = Stopwatch.StartNew();
            var builder   = new ProtoExecutionResult
            {
                Failed = false
            };
            var executionResult = _sandbox.ExecuteMethod(method, args);

            builder.ExecutionTime = stopwatch.ElapsedMilliseconds;
            if (!executionResult.Success)
            {
                var elapsedMilliseconds = stopwatch.ElapsedMilliseconds;
                builder.Failed = true;
                var isScreenShotEnabled = Utils.TryReadEnvValue("SCREENSHOT_ON_FAILURE");
                if (isScreenShotEnabled == null || isScreenShotEnabled.ToLower() != "false")
                {
                    var screenshot = TakeScreenshot();
                    builder.ScreenShot        = screenshot;
                    builder.FailureScreenshot = screenshot;
                }

                builder.ErrorMessage     = executionResult.ExceptionMessage;
                builder.StackTrace       = executionResult.StackTrace;
                builder.RecoverableError = executionResult.Recoverable;
                builder.ExecutionTime    = elapsedMilliseconds;
            }

            var allPendingMessages = GetAllPendingMessages().Where(m => m != null);

            builder.Message.AddRange(allPendingMessages);
            var allPendingScreenshots = GetAllPendingScreenshots().Select(ByteString.CopyFrom);

            builder.Screenshots.AddRange(allPendingScreenshots);

            return(builder);
        }
コード例 #2
0
        public void Setup()
        {
            var mockHookRegistry   = new Mock <IHookRegistry>();
            var mockAssemblyLoader = new Mock <IAssemblyLoader>();
            var mockMethod         = new MockMethodBuilder(mockAssemblyLoader)
                                     .WithName("Foo")
                                     .WithFilteredHook(LibType.BeforeSpec)
                                     .Build();

            var hooks = new HashSet <IHookMethod>
            {
                new HookMethod(LibType.BeforeSpec, mockMethod, mockAssemblyLoader.Object)
            };

            mockHookRegistry.Setup(x => x.BeforeSuiteHooks).Returns(hooks);
            var executionEndingRequest = new ExecutionStartingRequest();

            _request = new Message
            {
                MessageId   = 20,
                MessageType = Message.Types.MessageType.ExecutionEnding,
                ExecutionStartingRequest = executionEndingRequest
            };

            _mockMethodExecutor   = new Mock <IMethodExecutor>();
            _protoExecutionResult = new ProtoExecutionResult
            {
                ExecutionTime = 0,
                Failed        = false
            };
            _mockMethodExecutor.Setup(x => x.ExecuteHooks("BeforeSuite", It.IsAny <HooksStrategy>(), new List <string>()))
            .Returns(_protoExecutionResult);
            var mockReflectionWrapper = new Mock <IReflectionWrapper>();

            _executionStartingProcessor = new ExecutionStartingProcessor(_mockMethodExecutor.Object, mockAssemblyLoader.Object, mockReflectionWrapper.Object);
        }
コード例 #3
0
        public void Setup()
        {
            var mockHookRegistry = new Mock <IHookRegistry>();

            var hooks = new HashSet <HookMethod> {
                new HookMethod(GetType().GetMethod("Foo"), typeof(Step).Assembly)
            };
            var hooksToExecute = hooks.Select(method => method.Method);

            mockHookRegistry.Setup(x => x.BeforeSuiteHooks).Returns(hooks);
            var executionEndingRequest = ExecutionEndingRequest.DefaultInstance;

            _request = Message.CreateBuilder()
                       .SetMessageId(20)
                       .SetMessageType(Message.Types.MessageType.ExecutionEnding)
                       .SetExecutionEndingRequest(executionEndingRequest)
                       .Build();

            _mockMethodExecutor          = new Mock <IMethodExecutor>();
            _protoExecutionResultBuilder = ProtoExecutionResult.CreateBuilder().SetExecutionTime(0).SetFailed(false);
            _mockMethodExecutor.Setup(x => x.ExecuteHooks(hooksToExecute, executionEndingRequest.CurrentExecutionInfo))
            .Returns(_protoExecutionResultBuilder);
            _executionStartingProcessor = new ExecutionStartingProcessor(mockHookRegistry.Object, _mockMethodExecutor.Object);
        }
コード例 #4
0
        public void Setup()
        {
            var mockHookRegistry           = new Mock <IHookRegistry>();
            var mockAssemblyLoader         = new Mock <IAssemblyLoader>();
            var mockMessageCollectorType   = new Mock <Type>();
            var mockScreenshtCollectorType = new Mock <Type>();

            mockAssemblyLoader.Setup(x => x.GetLibType(LibType.MessageCollector))
            .Returns(mockMessageCollectorType.Object);
            mockAssemblyLoader.Setup(x => x.GetLibType(LibType.ScreenshotCollector))
            .Returns(mockScreenshtCollectorType.Object);
            var mockMethod = new MockMethodBuilder(mockAssemblyLoader)
                             .WithName("Foo")
                             .WithFilteredHook(LibType.BeforeSpec)
                             .Build();
            var hooks = new HashSet <IHookMethod>
            {
                new HookMethod(LibType.BeforeSpec, mockMethod, mockAssemblyLoader.Object)
            };

            mockHookRegistry.Setup(x => x.AfterStepHooks).Returns(hooks);
            var stepExecutionEndingRequest = new StepExecutionEndingRequest
            {
                CurrentExecutionInfo = new ExecutionInfo
                {
                    CurrentSpec     = new SpecInfo(),
                    CurrentScenario = new ScenarioInfo()
                }
            };

            _request = new Message
            {
                MessageType = Message.Types.MessageType.StepExecutionEnding,
                MessageId   = 20,
                StepExecutionEndingRequest = stepExecutionEndingRequest
            };

            _mockMethodExecutor   = new Mock <IExecutionOrchestrator>();
            _protoExecutionResult = new ProtoExecutionResult
            {
                ExecutionTime = 0,
                Failed        = false
            };
            _mockMethodExecutor.Setup(x =>
                                      x.ExecuteHooks("AfterStep", It.IsAny <TaggedHooksFirstStrategy>(), new List <string>(),
                                                     It.IsAny <ExecutionContext>()))
            .Returns(_protoExecutionResult);
            var mockReflectionWrapper = new Mock <IReflectionWrapper>();

            var pendindScreenshots = new List <byte[]>()
            {
                Encoding.ASCII.GetBytes("screenshot")
            };

            mockReflectionWrapper.Setup(x => x.InvokeMethod(mockMessageCollectorType.Object, null,
                                                            "GetAllPendingMessages",
                                                            BindingFlags.Static | BindingFlags.Public))
            .Returns(_pendingMessages).Verifiable();
            mockReflectionWrapper.Setup(x => x.InvokeMethod(mockScreenshtCollectorType.Object, null,
                                                            "GetAllPendingScreenshots",
                                                            BindingFlags.Static | BindingFlags.Public))
            .Returns(pendindScreenshots).Verifiable();
            _stepExecutionEndingProcessor = new StepExecutionEndingProcessor(_mockMethodExecutor.Object,
                                                                             mockAssemblyLoader.Object, mockReflectionWrapper.Object);
        }
コード例 #5
0
        public void ShouldClearExistingGaugeMessages()
        {
            var mockExectionHelper = new Mock <IExecutionOrchestrator>();

            var request = new Message
            {
                MessageId   = 20,
                MessageType = Message.Types.MessageType.ScenarioExecutionStarting,
                StepExecutionStartingRequest = new StepExecutionStartingRequest
                {
                    CurrentExecutionInfo = new ExecutionInfo
                    {
                        CurrentSpec     = new SpecInfo(),
                        CurrentScenario = new ScenarioInfo()
                    }
                }
            };

            var protoExecutionResult = new ProtoExecutionResult {
                ExecutionTime = 0, Failed = false
            };

            mockExectionHelper.Setup(executor =>
                                     executor.ExecuteHooks(It.IsAny <string>(), It.IsAny <HooksStrategy>(), It.IsAny <IList <string> >(),
                                                           It.IsAny <ExecutionContext>()))
            .Returns(protoExecutionResult);
            var hookRegistry = new Mock <IHookRegistry>();

            hookRegistry.Setup(registry => registry.BeforeStepHooks).Returns(new HashSet <IHookMethod>());
            var mockAssemblyLoader       = new Mock <IAssemblyLoader>();
            var mockMessageCollectorType = new Mock <Type>();

            var mockReflectionWrapper = new Mock <IReflectionWrapper>();
            var pendingMessages       = new List <string>()
            {
                "one", "two"
            };
            var pendindScreenshots = new List <byte[]>()
            {
                Encoding.ASCII.GetBytes("screenshot")
            };

            mockReflectionWrapper.Setup(x => x.InvokeMethod(mockMessageCollectorType.Object, null,
                                                            "GetAllPendingMessages",
                                                            BindingFlags.Static | BindingFlags.Public))
            .Returns(pendingMessages).Verifiable();
            mockReflectionWrapper.Setup(x => x.InvokeMethod(mockMessageCollectorType.Object, null,
                                                            "GetAllPendingScreenshots",
                                                            BindingFlags.Static | BindingFlags.Public))
            .Returns(pendindScreenshots).Verifiable();
            mockAssemblyLoader.Setup(x => x.GetLibType(LibType.MessageCollector))
            .Returns(mockMessageCollectorType.Object);
            mockAssemblyLoader.Setup(x => x.GetLibType(LibType.ScreenshotCollector))
            .Returns(mockMessageCollectorType.Object);

            var processor = new StepExecutionStartingProcessor(mockExectionHelper.Object, mockAssemblyLoader.Object,
                                                               mockReflectionWrapper.Object);
            var result = processor.Process(request);

            Assert.AreEqual(result.ExecutionStatusResponse.ExecutionResult.Message, pendingMessages);
            Assert.AreEqual(result.ExecutionStatusResponse.ExecutionResult.ScreenShot.ToList(), pendindScreenshots);


            mockReflectionWrapper.VerifyAll();
        }
コード例 #6
0
        public void ShouldProcessExecuteStepRequest()
        {
            const string parsedStepText = "Foo";
            var          request        = Message.CreateBuilder()
                                          .SetMessageType(Message.Types.MessageType.ExecuteStep)
                                          .SetExecuteStepRequest(
                ExecuteStepRequest.CreateBuilder()
                .SetActualStepText(parsedStepText)
                .SetParsedStepText(parsedStepText)
                .AddParameters(
                    Parameter.CreateBuilder()
                    .SetParameterType(Parameter.Types.ParameterType.Static)
                    .SetName("Foo")
                    .SetValue("Bar")
                    .Build())
                .Build())
                                          .SetMessageId(20)
                                          .Build();
            var mockStepRegistry = new Mock <IStepRegistry>();

            mockStepRegistry.Setup(x => x.ContainsStep(parsedStepText)).Returns(true);
            var fooMethodInfo = GetType().GetMethod("Foo");

            mockStepRegistry.Setup(x => x.MethodFor(parsedStepText)).Returns(fooMethodInfo);
            var mockMethodExecutor = new Mock <IMethodExecutor>();

            mockMethodExecutor.Setup(e => e.Execute(fooMethodInfo, It.IsAny <Object[]>())).Returns(() => ProtoExecutionResult.CreateBuilder().SetExecutionTime(1).SetFailed(false).Build());
            var mockSandbox = new Mock <ISandbox>();

            var response = new ExecuteStepProcessor(mockStepRegistry.Object, mockMethodExecutor.Object, mockSandbox.Object).Process(request);

            Assert.False(response.ExecutionStatusResponse.ExecutionResult.Failed);
        }