Beispiel #1
0
        public void ShouldExecutreBeforeScenarioHook()
        {
            var mockAssemblyLoader = new Mock <IAssemblyLoader>();
            var mockType           = new Mock <Type>().Object;

            mockAssemblyLoader.Setup(x => x.GetLibType(LibType.MessageCollector)).Returns(mockType);
            mockAssemblyLoader.Setup(x => x.GetLibType(LibType.ScreenshotCollector)).Returns(mockType);
            var scenarioExecutionStartingRequest = new ScenarioExecutionStartingRequest
            {
                CurrentExecutionInfo = new ExecutionInfo
                {
                    CurrentSpec     = new SpecInfo(),
                    CurrentScenario = new ScenarioInfo()
                }
            };
            var request = new Message
            {
                MessageId   = 20,
                MessageType = Message.Types.MessageType.SpecExecutionStarting,
                ScenarioExecutionStartingRequest = scenarioExecutionStartingRequest
            };

            var mockMethodExecutor   = new Mock <IExecutionOrchestrator>();
            var protoExecutionResult = new ProtoExecutionResult
            {
                ExecutionTime = 0,
                Failed        = false
            };
            IEnumerable <string> pendingMessages = new List <string> {
                "one", "two"
            };

            mockMethodExecutor.Setup(x =>
                                     x.ExecuteHooks("BeforeScenario", It.IsAny <HooksStrategy>(), It.IsAny <IList <string> >(),
                                                    It.IsAny <ExecutionContext>()))
            .Returns(protoExecutionResult);
            var mockReflectionWrapper = new Mock <IReflectionWrapper>();

            mockReflectionWrapper.Setup(x =>
                                        x.InvokeMethod(mockType, null, "GetAllPendingMessages", It.IsAny <BindingFlags>()))
            .Returns(pendingMessages);
            var pendingScreenshot = new List <byte[]> {
                Encoding.ASCII.GetBytes("Screenshot")
            };

            mockReflectionWrapper.Setup(x =>
                                        x.InvokeMethod(mockType, null, "GetAllPendingScreenshots", It.IsAny <BindingFlags>()))
            .Returns(pendingScreenshot);

            var processor = new ScenarioExecutionStartingProcessor(mockMethodExecutor.Object,
                                                                   mockAssemblyLoader.Object, mockReflectionWrapper.Object);

            var result = processor.Process(request);

            Assert.False(result.ExecutionStatusResponse.ExecutionResult.Failed);
            Assert.AreEqual(result.ExecutionStatusResponse.ExecutionResult.Message.ToList(), pendingMessages);
            Assert.AreEqual(result.ExecutionStatusResponse.ExecutionResult.ScreenShot.ToList(), pendingScreenshot);
        }
Beispiel #2
0
        public void ShouldExecutreBeforeScenarioHook()
        {
            var scenarioExecutionEndingRequest = new ScenarioExecutionStartingRequest
            {
                CurrentExecutionInfo = new ExecutionInfo
                {
                    CurrentSpec     = new SpecInfo(),
                    CurrentScenario = new ScenarioInfo()
                }
            };
            var request = new Message
            {
                MessageId   = 20,
                MessageType = Message.Types.MessageType.SpecExecutionStarting,
                ScenarioExecutionStartingRequest = scenarioExecutionEndingRequest
            };

            var mockMethodExecutor   = new Mock <IExecutionOrchestrator>();
            var protoExecutionResult = new ProtoExecutionResult
            {
                ExecutionTime = 0,
                Failed        = false
            };

            var pendingMessages = new List <string> {
                "one", "two"
            };
            var pendingScreenshots = new List <byte[]> {
                Encoding.ASCII.GetBytes("screenshot")
            };

            mockMethodExecutor.Setup(x =>
                                     x.ExecuteHooks("BeforeScenario", It.IsAny <HooksStrategy>(), It.IsAny <IList <string> >(),
                                                    It.IsAny <ExecutionContext>()))
            .Returns(protoExecutionResult);
            mockMethodExecutor.Setup(x =>
                                     x.GetAllPendingMessages()).Returns(pendingMessages);
            mockMethodExecutor.Setup(x =>
                                     x.GetAllPendingScreenshots()).Returns(pendingScreenshots);

            var processor = new ScenarioExecutionStartingProcessor(mockMethodExecutor.Object);

            var result = processor.Process(request);

            Assert.False(result.ExecutionStatusResponse.ExecutionResult.Failed);
            Assert.AreEqual(result.ExecutionStatusResponse.ExecutionResult.Message.ToList(), pendingMessages);
            Assert.AreEqual(result.ExecutionStatusResponse.ExecutionResult.Screenshots.ToList(), pendingScreenshots);
        }
        public void ShouldExecuteBeforeScenarioHook()
        {
            var scenarioExecutionEndingRequest = new ScenarioExecutionStartingRequest
            {
                CurrentExecutionInfo = new ExecutionInfo
                {
                    CurrentSpec     = new SpecInfo(),
                    CurrentScenario = new ScenarioInfo()
                }
            };

            var mockMethodExecutor   = new Mock <IExecutionOrchestrator>();
            var protoExecutionResult = new ProtoExecutionResult
            {
                ExecutionTime = 0,
                Failed        = false
            };

            var pendingMessages = new List <string> {
                "one", "two"
            };
            var pendingScreenshotFiles = new List <string> {
                "screenshot.png"
            };

            mockMethodExecutor.Setup(x =>
                                     x.ExecuteHooks("BeforeScenario", It.IsAny <HooksStrategy>(), It.IsAny <IList <string> >(),
                                                    It.IsAny <ExecutionInfo>()))
            .Returns(protoExecutionResult);
            mockMethodExecutor.Setup(x =>
                                     x.GetAllPendingMessages()).Returns(pendingMessages);
            mockMethodExecutor.Setup(x =>
                                     x.GetAllPendingScreenshotFiles()).Returns(pendingScreenshotFiles);

            var processor = new ScenarioExecutionStartingProcessor(mockMethodExecutor.Object);

            var result = processor.Process(scenarioExecutionEndingRequest);

            Assert.False(result.ExecutionResult.Failed);
            Assert.AreEqual(result.ExecutionResult.Message.ToList(), pendingMessages);
            Assert.AreEqual(result.ExecutionResult.ScreenshotFiles.ToList(), pendingScreenshotFiles);
        }