public void ShouldAddParameters() { const string parameterizedStepText = "Refactoring Say <what> to <who>"; const string stepValue = "Refactoring Say {} to {}"; var sandbox = SandboxBuilder.Build(); var gaugeMethod = sandbox.GetStepMethods() .First(method => method.Name == "IntegrationTestSample.RefactoringSample.RefactoringSaySomething-StringwhatStringwho"); var scannedSteps = new List <KeyValuePair <string, GaugeMethod> > { new KeyValuePair <string, GaugeMethod>(stepValue, gaugeMethod) }; var aliases = new Dictionary <string, bool> { { stepValue, false } }; var stepTextMap = new Dictionary <string, string> { { stepValue, parameterizedStepText } }; var stepRegistry = new StepRegistry(scannedSteps, stepTextMap, aliases); var message = new Message { MessageId = 1234, MessageType = Message.Types.MessageType.RefactorRequest, RefactorRequest = new RefactorRequest { OldStepValue = new ProtoStepValue { StepValue = stepValue, ParameterizedStepValue = parameterizedStepText, Parameters = { "what", "who" } }, NewStepValue = new ProtoStepValue { StepValue = "Refactoring Say {} to {} at {}", ParameterizedStepValue = "Refactoring Say <what> to <who> at <when>", Parameters = { "who", "what", "when" } }, ParamPositions = { new ParameterPosition { OldPosition = 0, NewPosition = 0 }, new ParameterPosition { OldPosition = 1, NewPosition = 1 }, new ParameterPosition { OldPosition = -1, NewPosition = 2 } } } }; var refactorProcessor = new RefactorProcessor(stepRegistry, sandbox); var result = refactorProcessor.Process(message); Assert.IsTrue(result.RefactorResponse.Success); }
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 ShouldRefactorAttributeText() { var sandbox = SandboxBuilder.Build(); var gaugeMethod = sandbox.GetStepMethods().First(info => info.Name == "IntegrationTestSample.RefactoringSample.RefactoringContext"); sandbox.Refactor(gaugeMethod, new List <Tuple <int, int> >(), new List <string>(), "foo"); AssertStepAttributeWithTextExists(gaugeMethod.Name, "foo"); }
public void ShouldNotLoadTargetLibAssemblyInRunnersDomain() { SandboxBuilder.Build(); // The sample project uses a special version of Gauge Lib, versioned 0.0.0 for testing. // The actual Gauge CSharp runner uses a different version of Lib // used by runner AssertRunnerDomainDidNotLoadUsersAssembly(); }
public void ShouldGetAllStepMethods() { var sandbox = SandboxBuilder.Build(); AssertRunnerDomainDidNotLoadUsersAssembly(); var stepMethods = sandbox.GetStepMethods(); Assert.AreEqual(12, stepMethods.Count); }
public override async Task ExecuteAsync() { var jenv = new SandboxBuilder(); if (Options.ForbidSystemCall) { jenv.ForbidSysCall(); } if (Options.TimeLimit > 0) { jenv.UserTime(Options.TimeLimit); } if (Options.MemoryLimit > 0) { jenv.Memory(Options.MemoryLimit); } if (Options.ProcessCountLimit > 0) { jenv.ProcessCount(Options.ProcessCountLimit); } var penv = new ProcessBuilder(); penv.UseExecutable(Options.ExecutableFile); if (Options.Arguments != null) { penv.UseArgument(Options.Arguments); } if (Options.WorkingDirectory != null) { penv.UseWorkingDir(Options.WorkingDirectory); } if (IOPorts.Count > 0) { penv.UseStdStream(true, true, true); } var cts = new CancellationTokenSource(); using (var jobObj = jenv.Build()) using (var proc = penv.Build(jobObj)) { IOPort = proc; var stats = IOPorts.Concat(Middlewares) .Select(func => func(cts.Token)).ToArray(); proc.WaitForExit(Math.Max(Options.TimeLimit * 10, 10000)); jobObj.Terminate(unchecked ((uint)Interop.ErrorCode.QuotaExceeded)); proc.ClosePipes(); cts.Cancel(); await Task.WhenAll(stats); IOPort = null; } }
public void ShouldRemoveParametersInAnyOrder() { var sandbox = SandboxBuilder.Build(); var gaugeMethod = sandbox.GetStepMethods().First(info => info.Name == "IntegrationTestSample.RefactoringSample.RefactoringSaySomething-StringwhatStringwho"); var parameterPositions = new[] { new Tuple <int, int>(1, 0) }; sandbox.Refactor(gaugeMethod, parameterPositions, new List <string>(), "Refactoring Say something to <who>"); AssertParametersExist(gaugeMethod.Name, new[] { "who" }); }
public void ShouldLoadTargetLibAssemblyInSandbox() { var sandbox = SandboxBuilder.Build(); // The sample project uses a special version of Gauge Lib, versioned 0.0.0 for testing. // The actual Gauge CSharp runner uses a different version of Lib // used by sample project Assert.AreEqual("0.6.999", sandbox.TargetLibAssemblyVersion); // used by runner AssertRunnerDomainDidNotLoadUsersAssembly(); }
public void ShouldGetPendingMessages() { var sandbox = SandboxBuilder.Build(); var stepMethods = sandbox.GetStepMethods(); var gaugeMethod = stepMethods.First(info => string.CompareOrdinal(info.Name, "IntegrationTestSample.StepImplementation.SaySomething-StringwhatStringwho") == 0); sandbox.ExecuteMethod(gaugeMethod, "hello", "world"); var pendingMessages = sandbox.GetAllPendingMessages().ToList(); Assert.Contains("hello, world!", pendingMessages); }
public void ShouldGetStepTextsForMethod() { var sandbox = SandboxBuilder.Build(); var stepMethods = sandbox.GetStepMethods(); var gaugeMethod = stepMethods.First(info => string.CompareOrdinal(info.Name, "IntegrationTestSample.StepImplementation.StepWithAliases") == 0); var stepTexts = sandbox.GetStepTexts(gaugeMethod).ToList(); Assert.Contains("Step with text", stepTexts); Assert.Contains("and an alias", stepTexts); }
public void RecoverableIsTrueOnExceptionThrownWhenContinueOnFailure() { var sandbox = SandboxBuilder.Build(); var stepMethods = sandbox.GetStepMethods(); var gaugeMethod = stepMethods.First(info => string.CompareOrdinal(info.Name, "IntegrationTestSample.StepImplementation.ContinueOnFailure") == 0); var executionResult = sandbox.ExecuteMethod(gaugeMethod); Assert.IsFalse(executionResult.Success); Assert.IsTrue(executionResult.Recoverable); }
public void ShouldRefactorAndReturnFilesChanged() { var sandbox = SandboxBuilder.Build(); var gaugeMethod = sandbox.GetStepMethods().First(info => info.Name == "IntegrationTestSample.RefactoringSample.RefactoringContext"); var expectedPath = Path.GetFullPath(Path.Combine(_testProjectPath, "RefactoringSample.cs")); var filesChanged = sandbox.Refactor(gaugeMethod, new List <Tuple <int, int> >(), new List <string>(), "foo").ToList(); Assert.AreEqual(1, filesChanged.Count); Assert.AreEqual(expectedPath, filesChanged.First()); }
public void ShouldExecuteMethodThatReturnsTaskAndReturnResult() { var sandbox = SandboxBuilder.Build(); var stepMethods = sandbox.GetStepMethods(); AssertRunnerDomainDidNotLoadUsersAssembly(); var gaugeMethod = stepMethods.First(info => string.CompareOrdinal(info.Name, "IntegrationTestSample.StepImplementation.AsyncStep") == 0); var executionResult = sandbox.ExecuteMethod(gaugeMethod); Assert.False(executionResult.Success); }
public void ShouldGetStacktraceForAggregateException() { var sandbox = SandboxBuilder.Build(); var stepMethods = sandbox.GetStepMethods(); var gaugeMethod = stepMethods.First(info => string.CompareOrdinal(info.Name, "IntegrationTestSample.StepImplementation.AsyncExeption") == 0); var executionResult = sandbox.ExecuteMethod(gaugeMethod); Assert.AreEqual(false, executionResult.Success); Assert.True(executionResult.StackTrace.Contains("First Exception")); Assert.True(executionResult.StackTrace.Contains("Second Exception")); }
public void SuccessIsFalseOnSerializableExceptionThrown() { const string expectedMessage = "I am a custom serializable exception"; var sandbox = SandboxBuilder.Build(); var stepMethods = sandbox.GetStepMethods(); var gaugeMethod = stepMethods.First(info => string.CompareOrdinal(info.Name, "IntegrationTestSample.StepImplementation.ThrowSerializableException") == 0); var executionResult = sandbox.ExecuteMethod(gaugeMethod); Assert.False(executionResult.Success); Assert.AreEqual(expectedMessage, executionResult.ExceptionMessage); StringAssert.Contains("IntegrationTestSample.StepImplementation.ThrowSerializableException", executionResult.StackTrace); }
public void ShouldAddParametersWithReservedKeywordName() { const string newStepValue = "Refactoring this is a test step <class>"; var sandbox = SandboxBuilder.Build(); var gaugeMethod = sandbox.GetStepMethods().First(info => info.Name == "IntegrationTestSample.RefactoringSample.RefactoringSampleTest"); var parameterPositions = new[] { new Tuple <int, int>(-1, 0) }; sandbox.Refactor(gaugeMethod, parameterPositions, new List <string> { "class" }, newStepValue); AssertStepAttributeWithTextExists(gaugeMethod.Name, newStepValue); AssertParametersExist(gaugeMethod.Name, new[] { "@class" }); }
public void ShouldGetAllStepTexts() { var sandbox = SandboxBuilder.Build(); var stepTexts = sandbox.GetAllStepTexts().ToList(); new List <string> { "Say <what> to <who>", "A context step which gets executed before every scenario", "Step that takes a table <table>", "Refactoring Say <what> to <who>", "Refactoring A context step which gets executed before every scenario", "Refactoring Step that takes a table <table>" }.ForEach(s => Assert.Contains(s, stepTexts)); }
public void ShouldAddParameters() { const string newStepValue = "Refactoring Say <what> to <who> in <where>"; var sandbox = SandboxBuilder.Build(); var gaugeMethod = sandbox.GetStepMethods().First(info => info.Name == "IntegrationTestSample.RefactoringSample.RefactoringSaySomething-StringwhatStringwho"); var parameterPositions = new[] { new Tuple <int, int>(0, 0), new Tuple <int, int>(1, 1), new Tuple <int, int>(-1, 2) }; sandbox.Refactor(gaugeMethod, parameterPositions, new List <string> { "what", "who", "where" }, newStepValue); AssertStepAttributeWithTextExists(gaugeMethod.Name, newStepValue); AssertParametersExist(gaugeMethod.Name, new[] { "what", "who", "where" }); }
public void ShouldCreateTableFromTargetType() { var sandbox = SandboxBuilder.Build(); var stepMethods = sandbox.GetStepMethods(); var gaugeMethod = stepMethods.First(info => string.CompareOrdinal(info.Name, "IntegrationTestSample.StepImplementation.ReadTable-Tabletable") == 0); 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 = sandbox.ExecuteMethod(gaugeMethod, SerializeTable(table)); Assert.True(executionResult.Success); }
public void ShouldCaptureScreenshotOnFailure() { const string parameterizedStepText = "I throw a serializable exception"; const string stepText = "I throw a serializable exception"; var sandbox = SandboxBuilder.Build(); var gaugeMethod = sandbox.GetStepMethods() .First(method => method.Name == "IntegrationTestSample.StepImplementation.ThrowSerializableException"); 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 message = new Message { MessageType = Message.Types.MessageType.ExecuteStep, ExecuteStepRequest = new ExecuteStepRequest { ParsedStepText = parameterizedStepText, ActualStepText = stepText } }; var result = executeStepProcessor.Process(message); var protoExecutionResult = result.ExecutionStatusResponse.ExecutionResult; Assert.IsNotNull(protoExecutionResult); Assert.IsTrue(protoExecutionResult.Failed); Assert.AreEqual(Encoding.UTF8.GetString(protoExecutionResult.FailureScreenshot.ToByteArray()), "ScreenShot"); }
public void ShouldPasssExecutionContextToHook() { var sandbox = SandboxBuilder.Build(); var stepExecutionStartingProcessor = new StepExecutionStartingProcessor(new MethodExecutor(sandbox)); var message = new Message { MessageId = 1234, MessageType = Message.Types.MessageType.StepExecutionStarting, StepExecutionStartingRequest = new StepExecutionStartingRequest { CurrentExecutionInfo = new ExecutionInfo { CurrentSpec = new SpecInfo { Name = "Foo Spec" }, CurrentScenario = new ScenarioInfo { Name = "Foo Scenario" }, CurrentStep = new StepInfo { Step = new ExecuteStepRequest { ParsedStepText = "Foo Step", ActualStepText = "Foo Step" } } } } }; var result = stepExecutionStartingProcessor.Process(message); AssertRunnerDomainDidNotLoadUsersAssembly(); var protoExecutionResult = result.ExecutionStatusResponse.ExecutionResult; Assert.IsNotNull(protoExecutionResult); Assert.IsFalse(protoExecutionResult.Failed); }