Exemplo n.º 1
0
        public void ShouldExecuteMethodFromRequest()
        {
            const string parameterizedStepText = "Step that takes a table {}";
            const string stepText          = "Step that takes a table <table>";
            var          reflectionWrapper = new ReflectionWrapper();
            var          activatorWrapper  = new ActivatorWrapper();
            var          path                 = new AssemblyLocater(new DirectoryWrapper()).GetTestAssembly();
            var          assemblyLoader       = new AssemblyLoader(path, new GaugeLoadContext(path), reflectionWrapper, activatorWrapper, new StepRegistry());
            var          executionInfoMapper  = new ExecutionInfoMapper(assemblyLoader, activatorWrapper);
            var          classInstanceManager = assemblyLoader.GetClassInstanceManager();
            var          orchestrator         = new ExecutionOrchestrator(reflectionWrapper, assemblyLoader,
                                                                          classInstanceManager,
                                                                          new HookExecutor(assemblyLoader, reflectionWrapper, classInstanceManager, executionInfoMapper),
                                                                          new StepExecutor(assemblyLoader, reflectionWrapper, classInstanceManager));

            var executeStepProcessor = new ExecuteStepProcessor(assemblyLoader.GetStepRegistry(),
                                                                orchestrator, new TableFormatter(assemblyLoader, activatorWrapper));

            var protoTable = new ProtoTable
            {
                Headers = new ProtoTableRow
                {
                    Cells = { "foo", "bar" }
                },
                Rows =
                {
                    new ProtoTableRow
                    {
                        Cells ={ "foorow1",             "foorow2" }
                    }
                }
            };
            var message = new ExecuteStepRequest
            {
                ParsedStepText = parameterizedStepText,
                ActualStepText = stepText,
                Parameters     =
                {
                    new Parameter
                    {
                        Name          = "table",
                        ParameterType = Parameter.Types.ParameterType.Table,
                        Table         = protoTable
                    }
                }
            };
            var result = executeStepProcessor.Process(message);

            var protoExecutionResult = result.ExecutionResult;

            Assert.IsNotNull(protoExecutionResult);
            Assert.IsFalse(protoExecutionResult.Failed);
        }
        protected virtual ProtoExecutionResult ExecuteHooks(Message request)
        {
            var applicableTags   = GetApplicableTags(request);
            var mapper           = new ExecutionInfoMapper();
            var executionContext = mapper.ExecutionInfoFrom(GetExecutionInfo(request));
            var res = MethodExecutor.ExecuteHooks(HookType, Strategy, applicableTags, executionContext);
            var allPendingMessages    = MethodExecutor.GetAllPendingMessages().Where(m => m != null);
            var allPendingScreenshots = MethodExecutor.GetAllPendingScreenshots().Select(ByteString.CopyFrom);

            res.Message.AddRange(allPendingMessages);
            res.Screenshots.AddRange(allPendingScreenshots);
            return(res);
        }
Exemplo n.º 3
0
        protected virtual ExecutionStatusResponse ExecuteHooks(ExecutionInfo info)
        {
            var applicableTags       = GetApplicableTags(info);
            var mapper               = new ExecutionInfoMapper();
            var executionContext     = mapper.ExecutionInfoFrom(info);
            var protoExecutionResult =
                ExecutionOrchestrator.ExecuteHooks(HookType, Strategy, applicableTags, executionContext);
            var allPendingMessages        = ExecutionOrchestrator.GetAllPendingMessages().Where(m => m != null);
            var allPendingScreenShotFiles = ExecutionOrchestrator.GetAllPendingScreenshotFiles();

            protoExecutionResult.Message.AddRange(allPendingMessages);
            protoExecutionResult.ScreenshotFiles.AddRange(allPendingScreenShotFiles);
            return(new ExecutionStatusResponse {
                ExecutionResult = protoExecutionResult
            });
        }
Exemplo n.º 4
0
        public void ShouldExecuteMethodAndReturnResult()
        {
            var reflectionWrapper = new ReflectionWrapper();
            var activatorWrapper  = new ActivatorWrapper();
            var path                 = new AssemblyLocater(new DirectoryWrapper()).GetTestAssembly();
            var assemblyLoader       = new AssemblyLoader(path, new GaugeLoadContext(path), reflectionWrapper, activatorWrapper, new StepRegistry());
            var classInstanceManager = assemblyLoader.GetClassInstanceManager();
            var executionInfoMapper  = new ExecutionInfoMapper(assemblyLoader, activatorWrapper);
            var orchestrator         = new ExecutionOrchestrator(reflectionWrapper, assemblyLoader,
                                                                 classInstanceManager,
                                                                 new HookExecutor(assemblyLoader, reflectionWrapper, classInstanceManager, executionInfoMapper),
                                                                 new StepExecutor(assemblyLoader, reflectionWrapper, classInstanceManager));
            var gaugeMethod = assemblyLoader.GetStepRegistry()
                              .MethodFor("A context step which gets executed before every scenario");

            var executionResult = orchestrator.ExecuteStep(gaugeMethod);

            Assert.False(executionResult.Failed);
        }
Exemplo n.º 5
0
        public void RecoverableIsTrueOnExceptionThrownWhenContinueOnFailure()
        {
            var reflectionWrapper = new ReflectionWrapper();
            var activatorWrapper  = new ActivatorWrapper();
            var path                 = new AssemblyLocater(new DirectoryWrapper()).GetTestAssembly();
            var assemblyLoader       = new AssemblyLoader(path, new GaugeLoadContext(path), reflectionWrapper, activatorWrapper, new StepRegistry());
            var classInstanceManager = assemblyLoader.GetClassInstanceManager();
            var executionInfoMapper  = new ExecutionInfoMapper(assemblyLoader, activatorWrapper);
            var orchestrator         = new ExecutionOrchestrator(reflectionWrapper, assemblyLoader,
                                                                 classInstanceManager,
                                                                 new HookExecutor(assemblyLoader, reflectionWrapper, classInstanceManager, executionInfoMapper),
                                                                 new StepExecutor(assemblyLoader, reflectionWrapper, classInstanceManager));
            var gaugeMethod = assemblyLoader.GetStepRegistry()
                              .MethodFor("I throw a serializable exception and continue");
            var executionResult = orchestrator.ExecuteStep(gaugeMethod);

            Assert.IsTrue(executionResult.Failed);
            Assert.IsTrue(executionResult.RecoverableError);
        }
Exemplo n.º 6
0
        public void ShouldGetPendingMessages()
        {
            var reflectionWrapper = new ReflectionWrapper();
            var activatorWrapper  = new ActivatorWrapper();
            var path                  = new AssemblyLocater(new DirectoryWrapper()).GetTestAssembly();
            var assemblyLoader        = new AssemblyLoader(path, new GaugeLoadContext(path), reflectionWrapper, activatorWrapper, new StepRegistry());
            var classInstanceManager  = assemblyLoader.GetClassInstanceManager();
            var executionInfoMapper   = new ExecutionInfoMapper(assemblyLoader, activatorWrapper);
            var executionOrchestrator = new ExecutionOrchestrator(reflectionWrapper, assemblyLoader,
                                                                  classInstanceManager,
                                                                  new HookExecutor(assemblyLoader, reflectionWrapper, classInstanceManager, executionInfoMapper),
                                                                  new StepExecutor(assemblyLoader, reflectionWrapper, classInstanceManager));

            var gaugeMethod = assemblyLoader.GetStepRegistry().MethodFor("Say {} to {}");

            var executionResult = executionOrchestrator.ExecuteStep(gaugeMethod, "hello", "world");

            Assert.False(executionResult.Failed);
            Assert.Contains("hello, world!", executionResult.Message);
        }
Exemplo n.º 7
0
        public void ShouldGetStacktraceForAggregateException()
        {
            var reflectionWrapper = new ReflectionWrapper();
            var activatorWrapper  = new ActivatorWrapper();
            var path                  = new AssemblyLocater(new DirectoryWrapper()).GetTestAssembly();
            var assemblyLoader        = new AssemblyLoader(path, new GaugeLoadContext(path), reflectionWrapper, activatorWrapper, new StepRegistry());
            var classInstanceManager  = assemblyLoader.GetClassInstanceManager();
            var executionInfoMapper   = new ExecutionInfoMapper(assemblyLoader, activatorWrapper);
            var executionOrchestrator = new ExecutionOrchestrator(reflectionWrapper, assemblyLoader,
                                                                  classInstanceManager,
                                                                  new HookExecutor(assemblyLoader, reflectionWrapper, classInstanceManager, executionInfoMapper),
                                                                  new StepExecutor(assemblyLoader, reflectionWrapper, classInstanceManager));

            var gaugeMethod     = assemblyLoader.GetStepRegistry().MethodFor("I throw an AggregateException");
            var executionResult = executionOrchestrator.ExecuteStep(gaugeMethod);

            Assert.True(executionResult.Failed);
            Assert.True(executionResult.StackTrace.Contains("First Exception"));
            Assert.True(executionResult.StackTrace.Contains("Second Exception"));
        }
Exemplo n.º 8
0
        public void SuccessIsFalseOnUnserializableExceptionThrown()
        {
            const string expectedMessage   = "I am a custom exception";
            var          reflectionWrapper = new ReflectionWrapper();
            var          activatorWrapper  = new ActivatorWrapper();
            var          path                  = new AssemblyLocater(new DirectoryWrapper()).GetTestAssembly();
            var          assemblyLoader        = new AssemblyLoader(path, new GaugeLoadContext(path), reflectionWrapper, activatorWrapper, new StepRegistry());
            var          classInstanceManager  = assemblyLoader.GetClassInstanceManager();
            var          executionInfoMapper   = new ExecutionInfoMapper(assemblyLoader, activatorWrapper);
            var          executionOrchestrator = new ExecutionOrchestrator(reflectionWrapper, assemblyLoader,
                                                                           classInstanceManager,
                                                                           new HookExecutor(assemblyLoader, reflectionWrapper, classInstanceManager, executionInfoMapper),
                                                                           new StepExecutor(assemblyLoader, reflectionWrapper, classInstanceManager));

            var gaugeMethod     = assemblyLoader.GetStepRegistry().MethodFor("I throw an unserializable exception");
            var executionResult = executionOrchestrator.ExecuteStep(gaugeMethod);

            Assert.True(executionResult.Failed);
            Assert.AreEqual(expectedMessage, executionResult.ErrorMessage);
            StringAssert.Contains("IntegrationTestSample.StepImplementation.ThrowUnserializableException",
                                  executionResult.StackTrace);
        }