public void AddTaskResultShouldThrowValidationExceptionWhenInvalidRequestId() { var sender = new object(); var functionResult = new FunctionResult() { RequestId = "unknown request id" }; var functionsManager = new FunctionsManager("component", "statemachine"); functionsManager.AddTask(new object(), new object(), new object(), new object(), sender, "function"); while (true) { var postedTask = functionsManager.GetTask(); if (postedTask != null) { break; } Thread.Sleep(TimeSpan.FromSeconds(1)); } var exception = Assert.Throws <ValidationException>(() => functionsManager.AddTaskResult(functionResult)); Assert.IsTrue(exception.Message.Contains("unknown request id"), "Exception message should show where is the problem"); }
public async Task AddTaskAsyncShouldReturnPostedResult() { var functionsManager = new FunctionsManager("component", "statemachine"); var xcEvent = new object(); var publicMember = new object(); var internalMember = new object(); var context = new object(); var sender = Substitute.For <ISender>(); var task = functionsManager.AddTaskAsync(xcEvent, publicMember, internalMember, context, sender, "function"); var enqueuedParameter = functionsManager.GetTask(); var functionResult = new FunctionResult() { ComponentName = "component", StateMachineName = "statemachine", PublicMember = "{}", InternalMember = "{}", Senders = null, RequestId = enqueuedParameter.RequestId, }; functionsManager.AddTaskResult(functionResult); var publishedResult = await task; Assert.AreEqual(functionResult, publishedResult); }
public void NullFunctionResultThrowsValidationException() { var functionsManager = new FunctionsManager("component", "statemachine"); var exception = Assert.Throws <ValidationException>(() => functionsManager.AddTaskResult(null)); Assert.IsTrue(exception.Message.Contains("null"), "Exception message should show where is the problem"); }
public async Task AddTaskShouldApplyPostedResultAndCallSenders() { var functionsManager = new FunctionsManager("component", "statemachine"); var xcEvent = new object(); var publicMember = new PublicMember() { State = "before" }; var internalMember = new object(); var context = new object(); var sender = Substitute.For <ISender>(); var task = functionsManager.AddTask(xcEvent, publicMember, internalMember, context, sender, "function"); Task.Run(() => { while (true) { var postedTask = functionsManager.GetTask(); if (postedTask != null) { var functionResult = new FunctionResult() { ComponentName = "component", StateMachineName = "statemachine", PublicMember = "{ \"State\": \"after\" }", Senders = new List <SenderResult> { new SenderResult { SenderName = "Do", SenderParameter = "{ \"Value\": \"do\" }", UseContext = true }, new SenderResult { SenderName = "Undo", SenderParameter = "{ \"Value\": \"undo\" }", UseContext = false }, new SenderResult { SenderName = "Reply", UseContext = true } }, RequestId = postedTask.RequestId, }; functionsManager.AddTaskResult(functionResult); break; } Thread.Sleep(TimeSpan.FromSeconds(1)); } }); await task; Assert.AreEqual("after", publicMember.State); sender.Received().Do(context, Arg.Is <DoEvent>(evt => evt.Value == "do"), null); sender.Received().SendEvent(Arg.Is <UndoEvent>(evt => evt.Value == "undo")); sender.Received().Reply(context, Arg.Any <object>(), null); }