public void WillBindToParamlessMethod() { //Given CustomExecMethodTaskWrapper wrapper = new CustomExecMethodTaskWrapper(new WrappedTask(), "TaskMethodTwo"); //When object result = wrapper.Execute(new TaskContext("hi")); //Then Assert.AreEqual(result, "Task Method Two - at your service"); }
public void ShouldPreferOverloadWithTaskContextParam() { //Given CustomExecMethodTaskWrapper wrapper = new CustomExecMethodTaskWrapper(new WrappedTask(), "TestMethodOne"); //When object result = wrapper.Execute(new TaskContext("hi")); //Then Assert.That(result, Is.EqualTo("hi")); }
public void ShouldExecAlternativeMethodWhenInvoked() { //Given CustomExecMethodTaskWrapper wrapper = new CustomExecMethodTaskWrapper(new WrappedTask(), "SmokeTest"); //When object result = wrapper.Execute(new TaskContext(1)); //Then Assert.That(result, Is.EqualTo(1)); }
public void WillExecuteVoidTaskMethod() { //Given CustomExecMethodTaskWrapper wrapper = new CustomExecMethodTaskWrapper(new WrappedTask(), "TaskMethodThree"); TaskContext context = new TaskContext("a"); //When object result = wrapper.Execute(context); //Then Assert.IsNull(result); Assert.AreEqual(context.ContextObject, "And now for something new"); }
public void ShouldThrowExceptionWhenUsedWithUnknownMethodName() { //Given CustomExecMethodTaskWrapper wrapper = new CustomExecMethodTaskWrapper(new WrappedTask(), "NoNoNo"); Exception expected = null; //When try { wrapper.Execute(new TaskContext("a")); } catch (Exception ex) { expected = ex; } //Then Assert.IsInstanceOfType(typeof(ArgumentException), expected); }
public virtual object Execute(StateMachineActionContext context) { if (!ActionName.Contains("::")) { return(StateMachine.ActionTaskManager.ExecuteTask(ActionName, context)); } //An alternate task execute syntax is being supported now that will //allow any method on a named task to be invoked using the ::, following the syntax //TaskName::MethodName string taskName = ActionName.Substring(0, ActionName.IndexOf("::")); string methodName = ActionName.Substring(ActionName.IndexOf("::") + 2); ITask task = StateMachine.ActionTaskManager.CreateTask(taskName); if (task != null) { var wrapper = new CustomExecMethodTaskWrapper(task, methodName); return(wrapper.Execute(StateMachine.ActionTaskManager.CreateTaskContext(context))); } throw new ArgumentException("A task with the name " + taskName + " could not be found."); }