Ejemplo n.º 1
0
        public ProtoExecutionResult ExecuteHooks(string hookType, HooksStrategy strategy, IList <string> applicableTags,
                                                 ExecutionContext context)
        {
            var stopwatch = Stopwatch.StartNew();
            var result    = new ProtoExecutionResult
            {
                Failed = false
            };

            var executionResult = _hookExecutor.Execute(hookType, strategy, applicableTags, context);

            result.ExecutionTime = stopwatch.ElapsedMilliseconds;
            if (executionResult.Success)
            {
                return(result);
            }
            var elapsedMilliseconds = stopwatch.ElapsedMilliseconds;

            result.Failed = true;
            var isScreenShotEnabled = Utils.TryReadEnvValue("SCREENSHOT_ON_FAILURE");

            if (isScreenShotEnabled == null || isScreenShotEnabled.ToLower() != "false")
            {
                result.ScreenShot = TakeScreenshot();
            }
            result.ErrorMessage     = executionResult.ExceptionMessage;
            result.StackTrace       = executionResult.StackTrace;
            result.RecoverableError = executionResult.Recoverable;
            result.ExecutionTime    = elapsedMilliseconds;

            return(result);
        }
Ejemplo n.º 2
0
        public void ShouldExecuteHooksAndNotTakeScreenshotOnFailureWhenDisabled()
        {
            var mockSandBox   = new Mock <ISandbox>();
            var hooksStrategy = new HooksStrategy();
            var result        = new ExecutionResult
            {
                Success          = false,
                ExceptionMessage = "Some Error",
                StackTrace       = "StackTrace"
            };

            mockSandBox.Setup(sandbox =>
                              sandbox.ExecuteHooks("hooks", hooksStrategy, new List <string>(), It.IsAny <Gauge.CSharp.Lib.ExecutionContext>())
                              ).Returns(result).Verifiable();

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

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

            var protoExecutionResult =
                new MethodExecutor(mockSandBox.Object).ExecuteHooks("hooks", hooksStrategy, new List <string>(), new Gauge.CSharp.Lib.ExecutionContext());

            mockSandBox.VerifyAll();
            Assert.False(protoExecutionResult.ScreenShot == null);
            Environment.SetEnvironmentVariable("SCREENSHOT_ON_FAILURE", screenshotEnabled);
        }
Ejemplo n.º 3
0
        public ProtoExecutionResult ExecuteHooks(string hookType, HooksStrategy strategy, IList <string> applicableTags)
        {
            var stopwatch = Stopwatch.StartNew();
            var builder   = new ProtoExecutionResult()
            {
                Failed = false
            };
            var executionResult = _sandbox.ExecuteHooks(hookType, strategy, applicableTags);

            builder.ExecutionTime = stopwatch.ElapsedMilliseconds;
            if (!executionResult.Success)
            {
                var elapsedMilliseconds = stopwatch.ElapsedMilliseconds;
                builder.Failed = true;
                var isScreenShotEnabled = Utils.TryReadEnvValue("SCREENSHOT_ENABLED");
                if (isScreenShotEnabled == null || isScreenShotEnabled.ToLower() != "false")
                {
                    builder.ScreenShot = TakeScreenshot();
                }
                builder.ErrorMessage     = executionResult.ExceptionMessage;
                builder.StackTrace       = executionResult.StackTrace;
                builder.RecoverableError = executionResult.Recoverable;
                builder.ExecutionTime    = elapsedMilliseconds;
            }
            return(builder);
        }
 protected HookExecutionProcessor(IMethodExecutor methodExecutor, IAssemblyLoader assemblyLoader, IReflectionWrapper reflectionWrapper)
 {
     _messageCollectorType = assemblyLoader.GetLibType(LibType.MessageCollector);
     MethodExecutor        = methodExecutor;
     _reflectionWrapper    = reflectionWrapper;
     Strategy = new HooksStrategy();
 }
Ejemplo n.º 5
0
        public void ShouldExecuteHooks()
        {
            var executionResult = new ExecutionResult {
                Success = true
            };
            var mockReflectionWrapper    = new Mock <IReflectionWrapper>();
            var mockAssemblyLoader       = new Mock <IAssemblyLoader>();
            var mockActivationWrapper    = new Mock <IActivatorWrapper>();
            var mockClassInstanceManager = new Mock <object>().Object;
            var hooksStrategy            = new HooksStrategy();
            var mockHookExecuter         = new Mock <IHookExecutor>();

            mockHookExecuter.Setup(m =>
                                   m.Execute("hooks", hooksStrategy, new List <string>(), It.IsAny <ExecutionContext>())
                                   ).Returns(executionResult).Verifiable();
            var mockStepExecuter      = new Mock <IStepExecutor>();
            var reflectionWrapper     = mockReflectionWrapper.Object;
            var assemblyLoader        = mockAssemblyLoader.Object;
            var executionOrchestrator = new ExecutionOrchestrator(reflectionWrapper, assemblyLoader, mockActivationWrapper.Object,
                                                                  mockClassInstanceManager, mockHookExecuter.Object, mockStepExecuter.Object);


            var result = executionOrchestrator.ExecuteHooks("hooks", hooksStrategy, new List <string>(),
                                                            It.IsAny <ExecutionContext>());

            mockHookExecuter.VerifyAll();
            Assert.False(result.Failed);
        }
        public void ShouldFetchAllHooksWhenNoTagsSpecified()
        {
            var applicableHooks = new HooksStrategy().GetApplicableHooks(new List <string>(), _hookMethods);

            Assert.IsNotNull(applicableHooks);
            Assert.AreEqual(1, applicableHooks.Count());
        }
Ejemplo n.º 7
0
        public ProtoExecutionResult ExecuteHooks(string hookType, HooksStrategy strategy, IList <string> applicableTags,
                                                 ExecutionContext context)
        {
            var stopwatch       = Stopwatch.StartNew();
            var executionResult = _hookExecutor.Execute(hookType, strategy, applicableTags, context);

            return(BuildResult(stopwatch, executionResult));
        }
Ejemplo n.º 8
0
 protected HookExecutionProcessor(IExecutionOrchestrator executionOrchestrator, IAssemblyLoader assemblyLoader,
                                  IReflectionWrapper reflectionWrapper)
 {
     _assemblyLoader       = assemblyLoader;
     ExecutionOrchestrator = executionOrchestrator;
     _reflectionWrapper    = reflectionWrapper;
     Strategy = new HooksStrategy();
 }
        public void ShouldFetchAllHooksWithSpecifiedTagsWhenDoingAnd()
        {
            var applicableHooks = new HooksStrategy().GetTaggedHooks(new List <string> {
                "Bar"
            }, _hookMethods);

            Assert.IsNotNull(applicableHooks);
            Assert.IsEmpty(applicableHooks);
        }
        public void ShouldNotFetchAnyTaggedHooksWhenTagsAreASuperSet()
        {
            var applicableHooks = new HooksStrategy().GetTaggedHooks(new List <string> {
                "Bar", "Blah"
            }, _hookMethods);

            Assert.IsNotNull(applicableHooks);
            Assert.IsEmpty(applicableHooks);
        }
Ejemplo n.º 11
0
        public void ShouldFetchAllHooksWithSpecifiedTags()
        {
            var applicableHooks = new HooksStrategy().GetTaggedHooks(new List <string> {
                "Foo"
            }, _hookMethods).ToList();

            Assert.IsNotNull(applicableHooks);
            Assert.AreEqual(2, applicableHooks.Count);
            AssertEx.ContainsMethods(applicableHooks, "Baz", "Foo");
        }
        public void ShouldFetchAnyHooksWithSpecifiedTagsWhenDoingOr()
        {
            var applicableHooks = new HooksStrategy().GetTaggedHooks(new List <string> {
                "Baz"
            }, _hookMethods).ToList();

            Assert.IsNotNull(applicableHooks);
            Assert.AreEqual(1, applicableHooks.Count);
            Assert.Contains(mockBazMethod.FullyQuallifiedName(), applicableHooks);
        }
        public void ShouldExecuteHooksAndNotTakeScreenshotOnFailureWhenDisabled()
        {
            var pendingMessages = new List <string> {
                "Foo", "Bar"
            };
            var pendingScrennshots = new List <byte[]> {
                Encoding.ASCII.GetBytes("screenshot")
            };
            var hooksStrategy   = new HooksStrategy();
            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 mockStepExecuter         = new Mock <IStepExecutor>();
            var reflectionWrapper        = mockReflectionWrapper.Object;
            var assemblyLoader           = mockAssemblyLoader.Object;
            var orchestrator             = new ExecutionOrchestrator(reflectionWrapper, assemblyLoader,
                                                                     mockActivationWrapper.Object,
                                                                     mockClassInstanceManager,
                                                                     mockHookExecuter.Object, mockStepExecuter.Object);

            mockHookExecuter.Setup(executor =>
                                   executor.Execute("hooks", hooksStrategy, new List <string>(), It.IsAny <ExecutionContext>())
                                   ).Returns(executionResult).Verifiable();
            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 screenshotEnabled = Utils.TryReadEnvValue("SCREENSHOT_ON_FAILURE");

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

            var result = orchestrator.ExecuteHooks("hooks", hooksStrategy, new List <string>(),
                                                   new ExecutionContext());

            mockHookExecuter.VerifyAll();
            Assert.True(result.Failed);
            Assert.True(result.FailureScreenshot.IsNullOrEmpty());
            Environment.SetEnvironmentVariable("SCREENSHOT_ON_FAILURE", screenshotEnabled);
        }
Ejemplo n.º 14
0
        public void ShouldFetchAllHooksWithSpecifiedTags()
        {
            var applicableHooks = new HooksStrategy().GetTaggedHooks(new List <string> {
                "Foo"
            }, _hookMethods).ToList();

            Assert.IsNotNull(applicableHooks);
            Assert.AreEqual(2, applicableHooks.Count);
            Assert.Contains(GetType().GetMethod("Foo").FullyQuallifiedName(), applicableHooks);
            Assert.Contains(GetType().GetMethod("Baz").FullyQuallifiedName(), applicableHooks);
        }
Ejemplo n.º 15
0
        public void ShouldExecuteHooks()
        {
            var mockSandBox     = new Mock <ISandbox>();
            var hooksStrategy   = new HooksStrategy();
            var executionResult = new ExecutionResult {
                Success = true
            };

            mockSandBox.Setup(sandbox =>
                              sandbox.ExecuteHooks("hooks", hooksStrategy, new List <string>(), It.IsAny <Gauge.CSharp.Lib.ExecutionContext>())
                              ).Returns(executionResult).Verifiable();

            new MethodExecutor(mockSandBox.Object).ExecuteHooks("hooks", hooksStrategy, new List <string>(), new Gauge.CSharp.Lib.ExecutionContext());

            mockSandBox.VerifyAll();
        }
        public void ShouldExecuteHooks()
        {
            var pendingMessages = new List <string> {
                "Foo", "Bar"
            };
            var pendingScrennshots = new List <byte[]> {
                Encoding.ASCII.GetBytes("screenshot")
            };
            var executionResult = new ExecutionResult {
                Success = true
            };
            var mockReflectionWrapper    = new Mock <IReflectionWrapper>();
            var mockAssemblyLoader       = new Mock <IAssemblyLoader>();
            var mockActivationWrapper    = new Mock <IActivatorWrapper>();
            var mockClassInstanceManager = new Mock <object>().Object;
            var hooksStrategy            = new HooksStrategy();
            var mockHookExecuter         = new Mock <IHookExecutor>();

            mockHookExecuter.Setup(m =>
                                   m.Execute("hooks", hooksStrategy, new List <string>(), It.IsAny <ExecutionContext>())
                                   ).Returns(executionResult).Verifiable();
            var mockStepExecuter  = new Mock <IStepExecutor>();
            var reflectionWrapper = mockReflectionWrapper.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 assemblyLoader        = mockAssemblyLoader.Object;
            var executionOrchestrator = new ExecutionOrchestrator(reflectionWrapper, assemblyLoader,
                                                                  mockActivationWrapper.Object,
                                                                  mockClassInstanceManager, mockHookExecuter.Object, mockStepExecuter.Object);

            var result = executionOrchestrator.ExecuteHooks("hooks", hooksStrategy, new List <string>(),
                                                            It.IsAny <ExecutionContext>());

            mockHookExecuter.VerifyAll();
            Assert.False(result.Failed);
        }
Ejemplo n.º 17
0
        public ProtoExecutionResult ExecuteHooks(string hookType, HooksStrategy strategy, IList <string> applicableTags,
                                                 ExecutionContext executionContext)
        {
            var stopwatch = Stopwatch.StartNew();
            var builder   = new ProtoExecutionResult
            {
                Failed = false
            };
            var executionResult = _sandbox.ExecuteHooks(hookType, strategy, applicableTags, executionContext);

            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);
        }
Ejemplo n.º 18
0
        public void ShouldExecuteHooksAndNotTakeScreenshotOnFailureWhenDisabled()
        {
            var hooksStrategy   = new HooksStrategy();
            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 mockStepExecuter         = new Mock <IStepExecutor>();
            var reflectionWrapper        = mockReflectionWrapper.Object;
            var assemblyLoader           = mockAssemblyLoader.Object;
            var orchestrator             = new ExecutionOrchestrator(reflectionWrapper, assemblyLoader,
                                                                     mockActivationWrapper.Object,
                                                                     mockClassInstanceManager,
                                                                     mockHookExecuter.Object, mockStepExecuter.Object);

            mockHookExecuter.Setup(executor =>
                                   executor.Execute("hooks", hooksStrategy, new List <string>(), It.IsAny <ExecutionContext>())
                                   ).Returns(executionResult).Verifiable();

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

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

            var result = orchestrator.ExecuteHooks("hooks", hooksStrategy, new List <string>(),
                                                   new ExecutionContext());

            mockHookExecuter.VerifyAll();
            Assert.True(result.Failed);
            Assert.True(result.ScreenShot.IsNullOrEmpty());
            Environment.SetEnvironmentVariable("SCREENSHOT_ON_FAILURE", screenshotEnabled);
        }
Ejemplo n.º 19
0
 protected HookExecutionProcessor(IExecutionOrchestrator executionOrchestrator)
 {
     ExecutionOrchestrator = executionOrchestrator;
     Strategy = new HooksStrategy();
 }
Ejemplo n.º 20
0
 protected HookExecutionProcessor(IMethodExecutor methodExecutor)
 {
     MethodExecutor = methodExecutor;
     Strategy       = new HooksStrategy();
 }
Ejemplo n.º 21
0
 protected HookExecutionProcessor(IHookRegistry hookRegistry, IMethodExecutor methodExecutor)
 {
     MethodExecutor = methodExecutor;
     Hooks          = hookRegistry;
     Strategy       = new HooksStrategy();
 }