public void ShouldProcessExecuteStepRequestForTableParam(Parameter.Types.ParameterType parameterType) { const string parsedStepText = "Foo"; var protoTable = new ProtoTable(); var headers = new ProtoTableRow(); headers.Cells.AddRange(new List <string> { "foo", "bar" }); protoTable.Headers = headers; var row = new ProtoTableRow(); row.Cells.AddRange(new List <string> { "foorow1", "foorow2" }); protoTable.Rows.AddRange(new List <ProtoTableRow>() { row }); var request = new Message() { MessageType = Message.Types.MessageType.ExecuteStep, ExecuteStepRequest = new ExecuteStepRequest() { ActualStepText = parsedStepText, ParsedStepText = parsedStepText, Parameters = { new Parameter() { ParameterType = parameterType, Table = protoTable } }, }, MessageId = 20 }; var mockStepRegistry = new Mock <IStepRegistry>(); mockStepRegistry.Setup(x => x.ContainsStep(parsedStepText)).Returns(true); var fooMethodInfo = new GaugeMethod { Name = "Foo", ParameterCount = 1 }; mockStepRegistry.Setup(x => x.MethodFor(parsedStepText)).Returns(fooMethodInfo); var mockMethodExecutor = new Mock <IMethodExecutor>(); mockMethodExecutor.Setup(e => e.Execute(fooMethodInfo, It.IsAny <string[]>())).Returns(() => new ProtoExecutionResult() { ExecutionTime = 1, Failed = false }); var response = new ExecuteStepProcessor(mockStepRegistry.Object, mockMethodExecutor.Object).Process(request); mockMethodExecutor.Verify(executor => executor.Execute(fooMethodInfo, It.Is <string[]>(strings => HasTable(strings)))); Assert.False(response.ExecutionStatusResponse.ExecutionResult.Failed); }
public void ShouldExecuteMethodFromRequest() { const string parameterizedStepText = "Step that takes a table {}"; const string stepText = "Step that takes a table <table>"; var sandbox = SandboxBuilder.Build(); var gaugeMethod = sandbox.GetStepMethods() .First(method => method.Name == "IntegrationTestSample.StepImplementation.ReadTable-Tabletable"); var scannedSteps = new List <KeyValuePair <string, GaugeMethod> > { new KeyValuePair <string, GaugeMethod>(parameterizedStepText, gaugeMethod) }; var aliases = new Dictionary <string, bool> { { parameterizedStepText, false } }; var stepTextMap = new Dictionary <string, string> { { parameterizedStepText, stepText } }; var stepRegistry = new StepRegistry(scannedSteps, stepTextMap, aliases); var executeStepProcessor = new ExecuteStepProcessor(stepRegistry, new MethodExecutor(sandbox)); var protoTable = new ProtoTable() { Headers = new ProtoTableRow() { Cells = { "foo", "bar" } }, Rows = { new ProtoTableRow() { Cells ={ "foorow1", "foorow2" } } } }; var message = new Message() { MessageId = 1234, MessageType = Message.Types.MessageType.ExecuteStep, ExecuteStepRequest = new ExecuteStepRequest() { ParsedStepText = parameterizedStepText, ActualStepText = stepText, Parameters = { new Parameter() { Name = "table", ParameterType = Parameter.Types.ParameterType.Table, Table = protoTable } } } }; var result = executeStepProcessor.Process(message); AssertRunnerDomainDidNotLoadUsersAssembly(); var protoExecutionResult = result.ExecutionStatusResponse.ExecutionResult; Assert.IsNotNull(protoExecutionResult); Assert.IsFalse(protoExecutionResult.Failed); }
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 assemblyLoader = new AssemblyLoader(new AssemblyWrapper(), new AssemblyLocater(new DirectoryWrapper(), new FileWrapper()).GetAllAssemblies(), reflectionWrapper); var classInstanceManager = assemblyLoader.GetClassInstanceManager(activatorWrapper); var mockOrchestrator = new ExecutionOrchestrator(reflectionWrapper, assemblyLoader, activatorWrapper, classInstanceManager, new HookExecutor(assemblyLoader, reflectionWrapper, classInstanceManager), new StepExecutor(assemblyLoader, reflectionWrapper, classInstanceManager)); var executeStepProcessor = new ExecuteStepProcessor(assemblyLoader.GetStepRegistry(), mockOrchestrator, new TableFormatter(assemblyLoader, activatorWrapper)); var protoTable = new ProtoTable { Headers = new ProtoTableRow { Cells = { "foo", "bar" } }, Rows = { new ProtoTableRow { Cells ={ "foorow1", "foorow2" } } } }; var message = new Message { MessageId = 1234, MessageType = Message.Types.MessageType.ExecuteStep, ExecuteStepRequest = new ExecuteStepRequest { ParsedStepText = parameterizedStepText, ActualStepText = stepText, Parameters = { new Parameter { Name = "table", ParameterType = Parameter.Types.ParameterType.Table, Table = protoTable } } } }; var result = executeStepProcessor.Process(message); AssertRunnerDomainDidNotLoadUsersAssembly(); var protoExecutionResult = result.ExecutionStatusResponse.ExecutionResult; Assert.IsNotNull(protoExecutionResult); Assert.IsFalse(protoExecutionResult.Failed); }
public void ShouldProcessExecuteStepRequestForTableParam(Parameter.Types.ParameterType parameterType) { const string parsedStepText = "Foo"; var protoTable = new ProtoTable(); var tableJSON = "{'headers':['foo', 'bar'],'rows':[['foorow1','barrow1']]}"; var request = new Message { MessageType = Message.Types.MessageType.ExecuteStep, ExecuteStepRequest = new ExecuteStepRequest { ActualStepText = parsedStepText, ParsedStepText = parsedStepText, Parameters = { new Parameter { ParameterType = parameterType, Table = protoTable } } }, MessageId = 20 }; var mockStepRegistry = new Mock <IStepRegistry>(); mockStepRegistry.Setup(x => x.ContainsStep(parsedStepText)).Returns(true); var fooMethodInfo = new GaugeMethod { Name = "Foo", ParameterCount = 1 }; mockStepRegistry.Setup(x => x.MethodFor(parsedStepText)).Returns(fooMethodInfo); var mockOrchestrator = new Mock <IExecutionOrchestrator>(); mockOrchestrator.Setup(e => e.ExecuteStep(fooMethodInfo, It.IsAny <string[]>())).Returns(() => new ProtoExecutionResult { ExecutionTime = 1, Failed = false }); var mockAssemblyLoader = new Mock <IAssemblyLoader>(); mockAssemblyLoader.Setup(x => x.GetLibType(LibType.MessageCollector)); var mockTableFormatter = new Mock <ITableFormatter>(); mockTableFormatter.Setup(x => x.GetJSON(protoTable)) .Returns(tableJSON); var response = new ExecuteStepProcessor(mockStepRegistry.Object, mockOrchestrator.Object, mockTableFormatter.Object) .Process(request); mockOrchestrator.Verify(executor => executor.ExecuteStep(fooMethodInfo, It.Is <string[]>(strings => strings[0] == tableJSON))); Assert.False(response.ExecutionStatusResponse.ExecutionResult.Failed); }
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); }
private string GetTableData(ProtoTable table) { var table1 = new Table(table.Headers.Cells.ToList()); foreach (var protoTableRow in table.Rows) { table1.AddRow(protoTableRow.Cells.ToList()); } var serializer = new DataContractJsonSerializer(typeof(Table)); using (var memoryStream = new MemoryStream()) { serializer.WriteObject(memoryStream, table1); return(Encoding.UTF8.GetString(memoryStream.ToArray())); } }
public string GetJSON(ProtoTable table) { Type tableType = _assemblyLoader.GetLibType(LibType.Table); dynamic table1 = _activatorWrapper.CreateInstance(tableType, table.Headers.Cells.ToList()); foreach (var protoTableRow in table.Rows) { table1.AddRow(protoTableRow.Cells.ToList()); } var serializer = new DataContractJsonSerializer(tableType); using (var memoryStream = new MemoryStream()) { serializer.WriteObject(memoryStream, table1); return(Encoding.UTF8.GetString(memoryStream.ToArray())); } }