Exemplo n.º 1
0
        public StepExecutorTests(ITestOutputHelper output)
        {
            Middleware = new List <IWorkflowStepMiddleware>();
            Body       = A.Fake <IStepBody>();
            Context    = A.Fake <IStepExecutionContext>();
            Out        = output;
            Runner     = new StepExecutor(Middleware);

            A
            .CallTo(() => Body.RunAsync(A <IStepExecutionContext> ._))
            .Invokes(() => Out.WriteLine("Called step body"))
            .Returns(DummyResult);
        }
Exemplo n.º 2
0
        public void ShoudExecuteStepAndGetRecoverableError()
        {
            var mockInstance = new Mock <object>().Object;
            var mockClassInstanceManagerType = new Mock <Type>().Object;
            var mockClassInstanceManager     = new ThreadLocal <object>(() => new Mock <object>().Object);

            var mockAssemblyLoader = new Mock <IAssemblyLoader>();
            var methodInfo         = new MockMethodBuilder(mockAssemblyLoader)
                                     .WithName("StepImplementation")
                                     .WithContinueOnFailure()
                                     .WithDeclaringTypeName("my.foo.type")
                                     .Build();

            var gaugeMethod = new GaugeMethod
            {
                Name              = "StepImplementation",
                MethodInfo        = methodInfo,
                ContinueOnFailure = true
            };

            mockAssemblyLoader.Setup(x => x.ClassInstanceManagerType).Returns(mockClassInstanceManagerType);

            var mockReflectionWrapper = new Mock <IReflectionWrapper>();

            mockReflectionWrapper
            .Setup(x => x.InvokeMethod(mockClassInstanceManagerType, mockClassInstanceManager, "Get",
                                       methodInfo.DeclaringType))
            .Returns(mockInstance);

            var executor = new StepExecutor(mockAssemblyLoader.Object, mockReflectionWrapper.Object,
                                            mockClassInstanceManager);

            mockReflectionWrapper.Setup(x => x.Invoke(methodInfo, mockInstance))
            .Throws(new Exception("step execution failure"));

            var result = executor.Execute(gaugeMethod);

            Assert.False(result.Success);
            Assert.True(result.Recoverable);
            Assert.AreEqual(result.ExceptionMessage, "step execution failure");
        }
Exemplo n.º 3
0
        public void ShoudExecuteStep()
        {
            var mockInstance = new Mock <object>().Object;
            var mockClassInstanceManagerType = new Mock <Type>().Object;
            var mockClassInstanceManager     = new ThreadLocal <object>(() => new Mock <object>().Object);

            var mockAssemblyLoader = new Mock <IAssemblyLoader>();
            var methodInfo         = new MockMethodBuilder(mockAssemblyLoader)
                                     .WithName("StepImplementation")
                                     .WithDeclaringTypeName("my.foo.type")
                                     .Build();
            var gaugeMethod = new GaugeMethod
            {
                Name       = "StepImplementation",
                MethodInfo = methodInfo
            };

            mockAssemblyLoader.Setup(x => x.ClassInstanceManagerType).Returns(mockClassInstanceManagerType);

            var mockReflectionWrapper = new Mock <IReflectionWrapper>();

            mockReflectionWrapper
            .Setup(x => x.InvokeMethod(mockClassInstanceManagerType, mockClassInstanceManager, "Get",
                                       methodInfo.DeclaringType))
            .Returns(mockInstance);

            var executor = new StepExecutor(mockAssemblyLoader.Object, mockReflectionWrapper.Object,
                                            mockClassInstanceManager);

            mockReflectionWrapper.Setup(x => x.Invoke(methodInfo, mockInstance))
            .Returns(null);


            var result = executor.Execute(gaugeMethod);

            Assert.True(result.Success);
        }
Exemplo n.º 4
0
 protected Step()
 {
     AsyncExecuter = ExecuteAsync;
 }