public void ShouldRegisterScreenshotWriterFromReference(string referenceType, string stepText, string expected) { Environment.SetEnvironmentVariable("GAUGE_PROJECT_ROOT", TestUtils.GetIntegrationTestSampleDirectory(referenceType)); var reflectionWrapper = new ReflectionWrapper(); var activatorWrapper = new ActivatorWrapper(); var path = new AssemblyLocater(new DirectoryWrapper()).GetTestAssembly(); var assemblyLoader = new AssemblyLoader(path, new GaugeLoadContext(path), reflectionWrapper, activatorWrapper, new StepRegistry()); var classInstanceManager = new ThreadLocal <object>(() => assemblyLoader.GetClassInstanceManager()).Value; var executionInfoMapper = new ExecutionInfoMapper(assemblyLoader, activatorWrapper); var executionOrchestrator = new ExecutionOrchestrator(reflectionWrapper, assemblyLoader, classInstanceManager, new HookExecutor(assemblyLoader, reflectionWrapper, classInstanceManager, executionInfoMapper), new StepExecutor(assemblyLoader, reflectionWrapper, classInstanceManager)); var executeStepProcessor = new ExecuteStepProcessor(assemblyLoader.GetStepRegistry(), executionOrchestrator, new TableFormatter(assemblyLoader, activatorWrapper)); var message = new ExecuteStepRequest { ParsedStepText = stepText, ActualStepText = stepText }; var result = executeStepProcessor.Process(message); var protoExecutionResult = result.ExecutionResult; Assert.IsNotNull(protoExecutionResult); Console.WriteLine(protoExecutionResult.ScreenshotFiles[0]); Assert.AreEqual(protoExecutionResult.ScreenshotFiles[0], expected); }
public void ShouldCreateTableFromTargetType() { var reflectionWrapper = new ReflectionWrapper(); var activatorWrapper = new ActivatorWrapper(); var path = new AssemblyLocater(new DirectoryWrapper()).GetTestAssembly(); var assemblyLoader = new AssemblyLoader(path, new GaugeLoadContext(path), reflectionWrapper, activatorWrapper, new StepRegistry()); var classInstanceManager = assemblyLoader.GetClassInstanceManager(); var executionInfoMapper = new ExecutionInfoMapper(assemblyLoader, activatorWrapper); var orchestrator = new ExecutionOrchestrator(reflectionWrapper, assemblyLoader, classInstanceManager, new HookExecutor(assemblyLoader, reflectionWrapper, classInstanceManager, executionInfoMapper), 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); }
public void ShouldCaptureScreenshotOnFailure() { const string stepText = "I throw a serializable exception"; var reflectionWrapper = new ReflectionWrapper(); var activatorWrapper = new ActivatorWrapper(); var path = new AssemblyLocater(new DirectoryWrapper()).GetTestAssembly(); var assemblyLoader = new AssemblyLoader(path, new GaugeLoadContext(path), reflectionWrapper, activatorWrapper, new StepRegistry()); var classInstanceManager = new ThreadLocal <object>(() => assemblyLoader.GetClassInstanceManager()); var executionInfoMapper = new ExecutionInfoMapper(assemblyLoader, activatorWrapper); var orchestrator = new ExecutionOrchestrator(reflectionWrapper, assemblyLoader, classInstanceManager, new HookExecutor(assemblyLoader, reflectionWrapper, classInstanceManager, executionInfoMapper), new StepExecutor(assemblyLoader, reflectionWrapper, classInstanceManager)); var executeStepProcessor = new ExecuteStepProcessor(assemblyLoader.GetStepRegistry(), orchestrator, new TableFormatter(assemblyLoader, activatorWrapper)); var message = new ExecuteStepRequest { ParsedStepText = stepText, ActualStepText = stepText }; var result = executeStepProcessor.Process(message); var protoExecutionResult = result.ExecutionResult; Assert.IsNotNull(protoExecutionResult); Assert.IsTrue(protoExecutionResult.Failed); Assert.AreEqual("screenshot.png", protoExecutionResult.FailureScreenshotFile); }
public void ShouldExecuteMethodFromRequest() { const string parameterizedStepText = "Step that takes a table {}"; const string stepText = "Step that takes a table <table>"; var reflectionWrapper = new ReflectionWrapper(); var activatorWrapper = new ActivatorWrapper(); var path = new AssemblyLocater(new DirectoryWrapper()).GetTestAssembly(); var assemblyLoader = new AssemblyLoader(path, new GaugeLoadContext(path), reflectionWrapper, activatorWrapper, new StepRegistry()); var executionInfoMapper = new ExecutionInfoMapper(assemblyLoader, activatorWrapper); var classInstanceManager = assemblyLoader.GetClassInstanceManager(); var orchestrator = new ExecutionOrchestrator(reflectionWrapper, assemblyLoader, classInstanceManager, new HookExecutor(assemblyLoader, reflectionWrapper, classInstanceManager, executionInfoMapper), new StepExecutor(assemblyLoader, reflectionWrapper, classInstanceManager)); var executeStepProcessor = new ExecuteStepProcessor(assemblyLoader.GetStepRegistry(), orchestrator, new TableFormatter(assemblyLoader, activatorWrapper)); var protoTable = new ProtoTable { Headers = new ProtoTableRow { Cells = { "foo", "bar" } }, Rows = { new ProtoTableRow { Cells ={ "foorow1", "foorow2" } } } }; var message = new ExecuteStepRequest { ParsedStepText = parameterizedStepText, ActualStepText = stepText, Parameters = { new Parameter { Name = "table", ParameterType = Parameter.Types.ParameterType.Table, Table = protoTable } } }; var result = executeStepProcessor.Process(message); var protoExecutionResult = result.ExecutionResult; Assert.IsNotNull(protoExecutionResult); Assert.IsFalse(protoExecutionResult.Failed); }
public void ShouldGetAssembliesFromGaugeBin() { var expectedAssemblies = new[] { "fooAssemblyLocation", "barAssemblyLocation" }; _mockDirectoryWrapper.Setup(wrapper => wrapper.EnumerateFiles(Utils.GetGaugeBinDir(), "*.dll", SearchOption.TopDirectoryOnly)) .Returns(expectedAssemblies); var assemblyLocater = new AssemblyLocater(_mockDirectoryWrapper.Object, _mockFileWrapper.Object); var assemblies = assemblyLocater.GetAllAssemblies(); Assert.AreEqual(expectedAssemblies, assemblies); }
public void ShouldNotAddAssembliesFromInvalidFile() { Environment.SetEnvironmentVariable("GAUGE_ADDITIONAL_LIBS", "foo.dll"); _mockFileWrapper.Setup(wrapper => wrapper.Exists(Path.GetFullPath("foo.dll"))).Returns(false); _mockDirectoryWrapper.Setup(wrapper => wrapper.EnumerateFiles(Utils.GetGaugeBinDir(), "*.dll", SearchOption.TopDirectoryOnly)) .Returns(Enumerable.Empty <string>()); var assemblyLocater = new AssemblyLocater(_mockDirectoryWrapper.Object, _mockFileWrapper.Object); var assemblies = assemblyLocater.GetAllAssemblies(); Assert.IsEmpty(assemblies); }
public void ShouldGetStepTextsForMethod() { var reflectionWrapper = new ReflectionWrapper(); var activatorWrapper = new ActivatorWrapper(); var path = new AssemblyLocater(new DirectoryWrapper()).GetTestAssembly(); var assemblyLoader = new AssemblyLoader(path, new GaugeLoadContext(path), reflectionWrapper, activatorWrapper, new StepRegistry()); var registry = assemblyLoader.GetStepRegistry(); var gaugeMethod = registry.MethodFor("and an alias"); var stepTexts = gaugeMethod.Aliases.ToList(); Assert.Contains("Step with text", stepTexts); Assert.Contains("and an alias", stepTexts); }
public void ShouldGetAssembliesFromGaugeBin() { var expected = "fooAssemblyLocation"; var expectedAssemblies = new[] { $"{expected}.deps.json" }; _mockDirectoryWrapper.Setup(wrapper => wrapper.EnumerateFiles(Utils.GetGaugeBinDir(), "*.deps.json", SearchOption.TopDirectoryOnly)) .Returns(expectedAssemblies); var assemblyLocater = new AssemblyLocater(_mockDirectoryWrapper.Object); var assembly = assemblyLocater.GetTestAssembly(); Assert.AreEqual($"{expected}.dll", (string)assembly); }
public void ShouldAddAssembliyFromGaugeAdditionalLibFile() { Environment.SetEnvironmentVariable("GAUGE_ADDITIONAL_LIBS", "foo.dll"); var expectedAssemblies = new[] { Path.GetFullPath("foo.dll") }; _mockDirectoryWrapper.Setup(wrapper => wrapper.EnumerateFiles(Utils.GetGaugeBinDir(), "*.dll", SearchOption.TopDirectoryOnly)) .Returns(Enumerable.Empty <string>()); _mockFileWrapper.Setup(wrapper => wrapper.Exists(Path.GetFullPath("foo.dll"))).Returns(true); var assemblyLocater = new AssemblyLocater(_mockDirectoryWrapper.Object, _mockFileWrapper.Object); var assemblies = assemblyLocater.GetAllAssemblies(); Assert.AreEqual(expectedAssemblies, assemblies); }
private IEnumerable <Type> GetTypesWithAttribute(Type attributeType) { var locater = new AssemblyLocater(); foreach (var assembly in locater.LocateAssemblyWithAttributedTypes(attributeType.Name)) { foreach (var type in assembly.ExportedTypes) { if (Attribute.IsDefined(type, attributeType)) { yield return(type); } } } }
public void ShouldGetStepsFromReference(string referenceType, string stepText, string stepValue, string parameterizedStepValue) { Environment.SetEnvironmentVariable("GAUGE_PROJECT_ROOT", TestUtils.GetIntegrationTestSampleDirectory(referenceType)); var path = new AssemblyLocater(new DirectoryWrapper()).GetTestAssembly(); var assemblyLoader = new AssemblyLoader(path, new GaugeLoadContext(path), new ReflectionWrapper(), new ActivatorWrapper(), new StepRegistry()); var stepValidationProcessor = new StepValidationProcessor(assemblyLoader.GetStepRegistry()); var message = new StepValidateRequest { StepText = stepText, StepValue = new ProtoStepValue { StepValue = stepValue, ParameterizedStepValue = parameterizedStepValue }, NumberOfParameters = 1, }; var result = stepValidationProcessor.Process(message); Assert.IsTrue(result.IsValid, $"Expected valid step text, got error: {result.ErrorMessage}"); }
public void ShouldGetStepsFromReference(string stepText, string stepValue, string parameterizedStepValue) { var assemblies = new AssemblyLocater(new DirectoryWrapper(), new FileWrapper()).GetAllAssemblies(); var assemblyLoader = new AssemblyLoader(new AssemblyWrapper(), assemblies, new ReflectionWrapper(), new ActivatorWrapper(), new StepRegistry()); var stepValidationProcessor = new StepValidationProcessor(assemblyLoader.GetStepRegistry()); var message = new StepValidateRequest { StepText = stepText, StepValue = new ProtoStepValue { StepValue = stepValue, ParameterizedStepValue = parameterizedStepValue }, NumberOfParameters = 1, }; var result = stepValidationProcessor.Process(message); Assert.IsTrue(result.IsValid, $"Expected valid step text, got error: {result.ErrorMessage}"); }
public void ShouldExecuteMethodAndReturnResult() { var reflectionWrapper = new ReflectionWrapper(); var activatorWrapper = new ActivatorWrapper(); var path = new AssemblyLocater(new DirectoryWrapper()).GetTestAssembly(); var assemblyLoader = new AssemblyLoader(path, new GaugeLoadContext(path), reflectionWrapper, activatorWrapper, new StepRegistry()); var classInstanceManager = assemblyLoader.GetClassInstanceManager(); var executionInfoMapper = new ExecutionInfoMapper(assemblyLoader, activatorWrapper); var orchestrator = new ExecutionOrchestrator(reflectionWrapper, assemblyLoader, classInstanceManager, new HookExecutor(assemblyLoader, reflectionWrapper, classInstanceManager, executionInfoMapper), 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); }
public void RecoverableIsTrueOnExceptionThrownWhenContinueOnFailure() { var reflectionWrapper = new ReflectionWrapper(); var activatorWrapper = new ActivatorWrapper(); var path = new AssemblyLocater(new DirectoryWrapper()).GetTestAssembly(); var assemblyLoader = new AssemblyLoader(path, new GaugeLoadContext(path), reflectionWrapper, activatorWrapper, new StepRegistry()); var classInstanceManager = assemblyLoader.GetClassInstanceManager(); var executionInfoMapper = new ExecutionInfoMapper(assemblyLoader, activatorWrapper); var orchestrator = new ExecutionOrchestrator(reflectionWrapper, assemblyLoader, classInstanceManager, new HookExecutor(assemblyLoader, reflectionWrapper, classInstanceManager, executionInfoMapper), 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); }
public void ShouldGetStacktraceForAggregateException() { var reflectionWrapper = new ReflectionWrapper(); var activatorWrapper = new ActivatorWrapper(); var path = new AssemblyLocater(new DirectoryWrapper()).GetTestAssembly(); var assemblyLoader = new AssemblyLoader(path, new GaugeLoadContext(path), reflectionWrapper, activatorWrapper, new StepRegistry()); var classInstanceManager = assemblyLoader.GetClassInstanceManager(); var executionInfoMapper = new ExecutionInfoMapper(assemblyLoader, activatorWrapper); var executionOrchestrator = new ExecutionOrchestrator(reflectionWrapper, assemblyLoader, classInstanceManager, new HookExecutor(assemblyLoader, reflectionWrapper, classInstanceManager, executionInfoMapper), 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")); }
public void ShouldGetPendingMessages() { var reflectionWrapper = new ReflectionWrapper(); var activatorWrapper = new ActivatorWrapper(); var path = new AssemblyLocater(new DirectoryWrapper()).GetTestAssembly(); var assemblyLoader = new AssemblyLoader(path, new GaugeLoadContext(path), reflectionWrapper, activatorWrapper, new StepRegistry()); var classInstanceManager = assemblyLoader.GetClassInstanceManager(); var executionInfoMapper = new ExecutionInfoMapper(assemblyLoader, activatorWrapper); var executionOrchestrator = new ExecutionOrchestrator(reflectionWrapper, assemblyLoader, classInstanceManager, new HookExecutor(assemblyLoader, reflectionWrapper, classInstanceManager, executionInfoMapper), 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); }
public void SuccessIsFalseOnUnserializableExceptionThrown() { const string expectedMessage = "I am a custom exception"; var reflectionWrapper = new ReflectionWrapper(); var activatorWrapper = new ActivatorWrapper(); var path = new AssemblyLocater(new DirectoryWrapper()).GetTestAssembly(); var assemblyLoader = new AssemblyLoader(path, new GaugeLoadContext(path), reflectionWrapper, activatorWrapper, new StepRegistry()); var classInstanceManager = assemblyLoader.GetClassInstanceManager(); var executionInfoMapper = new ExecutionInfoMapper(assemblyLoader, activatorWrapper); var executionOrchestrator = new ExecutionOrchestrator(reflectionWrapper, assemblyLoader, classInstanceManager, new HookExecutor(assemblyLoader, reflectionWrapper, classInstanceManager, executionInfoMapper), 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); }