コード例 #1
0
        public void ShouldCreateTableFromTargetType()
        {
            var reflectionWrapper = new ReflectionWrapper();
            var activatorWrapper  = new ActivatorWrapper();
            var assemblyLoader    = new AssemblyLoader(new AssemblyWrapper(),
                                                       new AssemblyLocater(new DirectoryWrapper(), new FileWrapper()).GetAllAssemblies(), reflectionWrapper, activatorWrapper, new StepRegistry());
            var classInstanceManager = assemblyLoader.GetClassInstanceManager();
            var orchestrator         = new ExecutionOrchestrator(reflectionWrapper, assemblyLoader, activatorWrapper,
                                                                 classInstanceManager,
                                                                 new HookExecutor(assemblyLoader, reflectionWrapper, classInstanceManager),
                                                                 new StepExecutor(assemblyLoader, reflectionWrapper, classInstanceManager));
            var gaugeMethod = assemblyLoader.GetStepRegistry().MethodFor("Step that takes a table {}");
            var table       = new Table(new List <string> {
                "foo", "bar"
            });

            table.AddRow(new List <string> {
                "foorow1", "barrow1"
            });
            table.AddRow(new List <string> {
                "foorow2", "barrow2"
            });

            var executionResult = orchestrator.ExecuteStep(gaugeMethod, SerializeTable(table));

            Assert.False(executionResult.Failed);
        }
コード例 #2
0
        public void ShouldExecuteMethod()
        {
            var gaugeMethod = new GaugeMethod {
                Name = "ShouldExecuteMethod", ParameterCount = 1
            };
            var args = new[] { "Bar", "String" };

            var mockClassInstanceManager = new Mock <object>().Object;
            var mockReflectionWrapper    = new Mock <IReflectionWrapper>();
            var mockAssemblyLoader       = new Mock <IAssemblyLoader>();
            var mockActivationWrapper    = new Mock <IActivatorWrapper>();
            var mockHookExecuter         = new Mock <IHookExecutor>();
            var mockStepExecutor         = new Mock <IStepExecutor>();

            mockStepExecutor.Setup(executor => executor.Execute(gaugeMethod, It.IsAny <string[]>()))
            .Returns(() => new ExecutionResult {
                Success = true
            })
            .Callback(() => Thread.Sleep(1));     // Simulate a delay in method execution

            var orchestrator = new ExecutionOrchestrator(mockReflectionWrapper.Object, mockAssemblyLoader.Object,
                                                         mockActivationWrapper.Object, mockClassInstanceManager,
                                                         mockHookExecuter.Object, mockStepExecutor.Object);
            var result = orchestrator.ExecuteStep(gaugeMethod, args);

            mockStepExecutor.VerifyAll();
            Assert.False(result.Failed);
            Assert.True(result.ExecutionTime > 0);
        }
コード例 #3
0
        public void ShouldNotTakeScreenShotWhenDisabled()
        {
            var pendingMessages = new List <string> {
                "Foo", "Bar"
            };
            var pendingScrennshots = new List <byte[]> {
                Encoding.ASCII.GetBytes("screenshot")
            };
            var gaugeMethod = new GaugeMethod {
                Name = "ShouldNotTakeScreenShotWhenDisabled", ParameterCount = 1
            };

            var executionResult = new ExecutionResult
            {
                Success          = false,
                ExceptionMessage = "Some Error",
                StackTrace       = "StackTrace"
            };
            var mockClassInstanceManager = new Mock <object>().Object;
            var mockReflectionWrapper    = new Mock <IReflectionWrapper>();
            var mockAssemblyLoader       = new Mock <IAssemblyLoader>();
            var mockActivationWrapper    = new Mock <IActivatorWrapper>();
            var mockHookExecuter         = new Mock <IHookExecutor>();
            var mockStepExecutor         = new Mock <IStepExecutor>();

            mockStepExecutor.Setup(executor => executor.Execute(gaugeMethod, It.IsAny <string[]>()))
            .Returns(executionResult);
            var mockType = new Mock <Type>().Object;

            mockAssemblyLoader.Setup(x => x.GetLibType(LibType.MessageCollector)).Returns(mockType);
            mockAssemblyLoader.Setup(x => x.GetLibType(LibType.ScreenshotCollector)).Returns(mockType);
            mockReflectionWrapper.Setup(x =>
                                        x.InvokeMethod(mockType, null, "GetAllPendingMessages", It.IsAny <BindingFlags>()))
            .Returns(pendingMessages);
            mockReflectionWrapper.Setup(x =>
                                        x.InvokeMethod(mockType, null, "GetAllPendingScreenshots", It.IsAny <BindingFlags>()))
            .Returns(pendingScrennshots);

            var orchestrator = new ExecutionOrchestrator(mockReflectionWrapper.Object, mockAssemblyLoader.Object,
                                                         mockActivationWrapper.Object, mockClassInstanceManager,
                                                         mockHookExecuter.Object, mockStepExecutor.Object);

            var screenshotEnabled = Utils.TryReadEnvValue("SCREENSHOT_ON_FAILURE");

            Environment.SetEnvironmentVariable("SCREENSHOT_ON_FAILURE", "false");

            var result = orchestrator.ExecuteStep(gaugeMethod, "Bar", "string");

            mockStepExecutor.VerifyAll();
            Assert.True(result.FailureScreenshot.IsNullOrEmpty());
            Environment.SetEnvironmentVariable("SCREENSHOT_ON_FAILURE", screenshotEnabled);
        }
コード例 #4
0
        public void ShouldTakeScreenShotOnFailedExecution()
        {
            var pendingMessages = new List <string> {
                "Foo", "Bar"
            };
            var expectedScreenshot = "Testscreenshot.png";
            var pendingScreenshots = new List <string> {
                expectedScreenshot
            };
            var gaugeMethod = new GaugeMethod {
                Name = "ShouldExecuteMethod", ParameterCount = 1
            };
            var executionResult = new ExecutionResult
            {
                Success          = false,
                ExceptionMessage = "error",
                StackTrace       = "stacktrace"
            };
            var mockInstance          = new Mock <object>().Object;
            var mockAssemblyLoader    = new Mock <IAssemblyLoader>();
            var mockActivationWrapper = new Mock <IActivatorWrapper>();
            var mockReflectionWrapper = new Mock <IReflectionWrapper>();
            var mockHookExecuter      = new Mock <IHookExecutor>();
            var mockStepExecutor      = new Mock <IStepExecutor>();

            mockStepExecutor.Setup(executor => executor.Execute(gaugeMethod, It.IsAny <string[]>()))
            .Returns(executionResult).Verifiable();
            var mockType = new Mock <Type>().Object;

            mockAssemblyLoader.Setup(x => x.GetLibType(LibType.MessageCollector)).Returns(mockType);
            mockAssemblyLoader.Setup(x => x.GetLibType(LibType.ScreenshotFilesCollector)).Returns(mockType);
            mockReflectionWrapper.Setup(x =>
                                        x.InvokeMethod(mockType, null, "GetAllPendingMessages", It.IsAny <BindingFlags>()))
            .Returns(pendingMessages);
            mockReflectionWrapper.Setup(x =>
                                        x.InvokeMethod(mockType, null, "GetAllPendingScreenshotFiles", It.IsAny <BindingFlags>()))
            .Returns(pendingScreenshots);

            var orchestrator = new ExecutionOrchestrator(mockReflectionWrapper.Object, mockAssemblyLoader.Object,
                                                         mockActivationWrapper.Object, mockInstance,
                                                         mockHookExecuter.Object, mockStepExecutor.Object);

            var result = orchestrator.ExecuteStep(gaugeMethod, "Bar", "String");

            mockStepExecutor.VerifyAll();


            Assert.True(result.Failed);
            Assert.AreEqual(expectedScreenshot, result.FailureScreenshotFile);
        }
コード例 #5
0
        public void ShouldExecuteMethod()
        {
            var pendingMessages = new List <string> {
                "Foo", "Bar"
            };
            var pendingScrennshots = new List <byte[]> {
                Encoding.ASCII.GetBytes("screenshot")
            };
            var gaugeMethod = new GaugeMethod {
                Name = "ShouldExecuteMethod", ParameterCount = 1
            };
            var args = new[] { "Bar", "String" };

            var mockClassInstanceManager = new Mock <object>().Object;
            var mockReflectionWrapper    = new Mock <IReflectionWrapper>();
            var mockAssemblyLoader       = new Mock <IAssemblyLoader>();
            var mockActivationWrapper    = new Mock <IActivatorWrapper>();
            var mockHookExecuter         = new Mock <IHookExecutor>();
            var mockStepExecutor         = new Mock <IStepExecutor>();

            mockStepExecutor.Setup(executor => executor.Execute(gaugeMethod, It.IsAny <string[]>()))
            .Returns(() => new ExecutionResult {
                Success = true
            })
            .Callback(() => Thread.Sleep(1));     // Simulate a delay in method execution

            var orchestrator = new ExecutionOrchestrator(mockReflectionWrapper.Object, mockAssemblyLoader.Object,
                                                         mockActivationWrapper.Object, mockClassInstanceManager,
                                                         mockHookExecuter.Object, mockStepExecutor.Object);

            var mockType = new Mock <Type>().Object;

            mockAssemblyLoader.Setup(x => x.GetLibType(LibType.MessageCollector)).Returns(mockType);
            mockAssemblyLoader.Setup(x => x.GetLibType(LibType.ScreenshotCollector)).Returns(mockType);
            mockReflectionWrapper.Setup(x =>
                                        x.InvokeMethod(mockType, null, "GetAllPendingMessages", It.IsAny <BindingFlags>()))
            .Returns(pendingMessages);
            mockReflectionWrapper.Setup(x =>
                                        x.InvokeMethod(mockType, null, "GetAllPendingScreenshots", It.IsAny <BindingFlags>()))
            .Returns(pendingScrennshots);
            var result = orchestrator.ExecuteStep(gaugeMethod, args);

            mockStepExecutor.VerifyAll();
            Assert.False(result.Failed);
            Assert.True(result.ExecutionTime > 0);
        }
コード例 #6
0
        public void ShouldTakeScreenShotOnFailedExecution()
        {
            var gaugeMethod = new GaugeMethod {
                Name = "ShouldExecuteMethod", ParameterCount = 1
            };
            var executionResult = new ExecutionResult
            {
                Success          = false,
                ExceptionMessage = "error",
                StackTrace       = "stacktrace"
            };
            var expectedScreenshot = Encoding.UTF8.GetBytes("TestScreenshot");

            var type               = new Mock <Type>().Object;
            var mockInstance       = new Mock <object>().Object;
            var mockAssemblyLoader = new Mock <IAssemblyLoader>();

            mockAssemblyLoader.Setup(x => x.ScreengrabberType).Returns(type);

            var mockActivationWrapper = new Mock <IActivatorWrapper>();

            mockActivationWrapper.Setup(x => x.CreateInstance(type)).Returns(mockInstance);

            var mockReflectionWrapper = new Mock <IReflectionWrapper>();

            mockReflectionWrapper
            .Setup(x => x.InvokeMethod(type, mockInstance, "TakeScreenShot"))
            .Returns(expectedScreenshot);

            var mockHookExecuter = new Mock <IHookExecutor>();
            var mockStepExecutor = new Mock <IStepExecutor>();

            mockStepExecutor.Setup(executor => executor.Execute(gaugeMethod, It.IsAny <string[]>()))
            .Returns(executionResult).Verifiable();

            var orchestrator = new ExecutionOrchestrator(mockReflectionWrapper.Object, mockAssemblyLoader.Object,
                                                         mockActivationWrapper.Object, mockInstance,
                                                         mockHookExecuter.Object, mockStepExecutor.Object);

            var result = orchestrator.ExecuteStep(gaugeMethod, "Bar", "String");

            mockStepExecutor.VerifyAll();

            Assert.True(result.Failed);
            Assert.AreEqual(expectedScreenshot, result.ScreenShot);
        }
コード例 #7
0
        public void ShouldExecuteMethodAndReturnResult()
        {
            var reflectionWrapper = new ReflectionWrapper();
            var activatorWrapper  = new ActivatorWrapper();
            var assemblyLoader    = new AssemblyLoader(new AssemblyWrapper(),
                                                       new AssemblyLocater(new DirectoryWrapper(), new FileWrapper()).GetAllAssemblies(), reflectionWrapper, activatorWrapper, new StepRegistry());
            var classInstanceManager = assemblyLoader.GetClassInstanceManager();
            var orchestrator         = new ExecutionOrchestrator(reflectionWrapper, assemblyLoader, activatorWrapper,
                                                                 classInstanceManager,
                                                                 new HookExecutor(assemblyLoader, reflectionWrapper, classInstanceManager),
                                                                 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);
        }
コード例 #8
0
        public void RecoverableIsTrueOnExceptionThrownWhenContinueOnFailure()
        {
            var reflectionWrapper = new ReflectionWrapper();
            var activatorWrapper  = new ActivatorWrapper();
            var assemblyLoader    = new AssemblyLoader(new AssemblyWrapper(),
                                                       new AssemblyLocater(new DirectoryWrapper(), new FileWrapper()).GetAllAssemblies(), reflectionWrapper, activatorWrapper, new StepRegistry());
            var classInstanceManager = assemblyLoader.GetClassInstanceManager();
            var orchestrator         = new ExecutionOrchestrator(reflectionWrapper, assemblyLoader, activatorWrapper,
                                                                 classInstanceManager,
                                                                 new HookExecutor(assemblyLoader, reflectionWrapper, classInstanceManager),
                                                                 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);
        }
コード例 #9
0
        public void ShouldGetPendingMessages()
        {
            var reflectionWrapper = new ReflectionWrapper();
            var activatorWrapper  = new ActivatorWrapper();
            var assemblyLoader    = new AssemblyLoader(new AssemblyWrapper(),
                                                       new AssemblyLocater(new DirectoryWrapper(), new FileWrapper()).GetAllAssemblies(), reflectionWrapper, activatorWrapper, new StepRegistry());
            var classInstanceManager  = assemblyLoader.GetClassInstanceManager();
            var executionOrchestrator = new ExecutionOrchestrator(reflectionWrapper, assemblyLoader, activatorWrapper,
                                                                  classInstanceManager,
                                                                  new HookExecutor(assemblyLoader, reflectionWrapper, classInstanceManager),
                                                                  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);
        }
コード例 #10
0
        public void ShouldGetStacktraceForAggregateException()
        {
            var reflectionWrapper = new ReflectionWrapper();
            var activatorWrapper  = new ActivatorWrapper();
            var assemblyLoader    = new AssemblyLoader(new AssemblyWrapper(),
                                                       new AssemblyLocater(new DirectoryWrapper(), new FileWrapper()).GetAllAssemblies(), reflectionWrapper, activatorWrapper, new StepRegistry());
            var classInstanceManager  = assemblyLoader.GetClassInstanceManager();
            var executionOrchestrator = new ExecutionOrchestrator(reflectionWrapper, assemblyLoader, activatorWrapper,
                                                                  classInstanceManager,
                                                                  new HookExecutor(assemblyLoader, reflectionWrapper, classInstanceManager),
                                                                  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"));
        }
コード例 #11
0
        public void SuccessIsFalseOnUnserializableExceptionThrown()
        {
            const string expectedMessage   = "I am a custom exception";
            var          reflectionWrapper = new ReflectionWrapper();
            var          activatorWrapper  = new ActivatorWrapper();
            var          assemblyLoader    = new AssemblyLoader(new AssemblyWrapper(),
                                                                new AssemblyLocater(new DirectoryWrapper(), new FileWrapper()).GetAllAssemblies(), reflectionWrapper, activatorWrapper, new StepRegistry());
            var classInstanceManager  = assemblyLoader.GetClassInstanceManager();
            var executionOrchestrator = new ExecutionOrchestrator(reflectionWrapper, assemblyLoader, activatorWrapper,
                                                                  classInstanceManager,
                                                                  new HookExecutor(assemblyLoader, reflectionWrapper, classInstanceManager),
                                                                  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);
        }
コード例 #12
0
        public void ShouldNotTakeScreenShotWhenDisabled()
        {
            var gaugeMethod = new GaugeMethod {
                Name = "ShouldNotTakeScreenShotWhenDisabled", ParameterCount = 1
            };

            var executionResult = new ExecutionResult
            {
                Success          = false,
                ExceptionMessage = "Some Error",
                StackTrace       = "StackTrace"
            };
            var mockClassInstanceManager = new Mock <object>().Object;
            var mockReflectionWrapper    = new Mock <IReflectionWrapper>();
            var mockAssemblyLoader       = new Mock <IAssemblyLoader>();
            var mockActivationWrapper    = new Mock <IActivatorWrapper>();
            var mockHookExecuter         = new Mock <IHookExecutor>();
            var mockStepExecutor         = new Mock <IStepExecutor>();

            mockStepExecutor.Setup(executor => executor.Execute(gaugeMethod, It.IsAny <string[]>()))
            .Returns(executionResult);

            var orchestrator = new ExecutionOrchestrator(mockReflectionWrapper.Object, mockAssemblyLoader.Object,
                                                         mockActivationWrapper.Object, mockClassInstanceManager,
                                                         mockHookExecuter.Object, mockStepExecutor.Object);

            var screenshotEnabled = Utils.TryReadEnvValue("SCREENSHOT_ON_FAILURE");

            Environment.SetEnvironmentVariable("SCREENSHOT_ON_FAILURE", "false");

            var result = orchestrator.ExecuteStep(gaugeMethod, "Bar", "string");

            mockStepExecutor.VerifyAll();
            Assert.True(result.ScreenShot.IsNullOrEmpty());
            Environment.SetEnvironmentVariable("SCREENSHOT_ON_FAILURE", screenshotEnabled);
        }