Exemple #1
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");
        }
Exemple #2
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);
        }