/// <summary> /// Adds results of command execution to context. /// </summary> /// <param name="command">Executed command.</param> /// <param name="integrationEvent">Expected event.</param> /// <param name="result">Execution result.</param> /// <returns>Updated execution context.</returns> public TestFlowExecutionContext Update(Command command, IntegrationEvent integrationEvent, IExecutionResult result) { return(new TestFlowExecutionContext( Host, AggregateVersions, ExecutedCommands.Add(command), ExpectedEvents.Add(integrationEvent), ExecutionResults.Add(result))); }
public EventFlowValidator <TRequestContext> AddResultValidation(Action <TRequestContext> resultValidation) { // Add the expected event ExpectedEvents.Add(new ExpectedEvent { EventType = EventTypes.Result, ParamType = typeof(TRequestContext), Validator = resultValidation }); return(this); }
protected TestFlowExecutionContextBase( SubdomainTestHost host, ImmutableDictionary <string, int> aggregateVersions, ImmutableList <Command> commands, ImmutableList <IntegrationEvent> expectedEvents, ImmutableList <IExecutionResult> results) { Host = host; AggregateVersions = AggregateVersions.AddRange(aggregateVersions); ExecutedCommands = ExecutedCommands.AddRange(commands); ExpectedEvents = ExpectedEvents.AddRange(expectedEvents); ExecutionResults = ExecutionResults.AddRange(results); }
public void ExpectedOutput_InCorrectOrder() { var notFound = new List <string>(); var notExpected = new List <string>(); foreach (var item in ExpectedEvents) { if (!ActionAttributeFixture.Events.Contains(item)) { notFound.Add(item); } } foreach (var item in ActionAttributeFixture.Events) { if (!ExpectedEvents.Contains(item)) { notExpected.Add(item); } } if (notFound.Count > 0 || notExpected.Count > 0) { var sb = new StringBuilder("Expected and actual events do not match."); if (notFound.Count > 0) { sb.Append(Environment.NewLine + " Missing:"); foreach (var item in notFound) { sb.Append(Environment.NewLine + " " + item); } } if (notExpected.Count > 0) { sb.Append(Environment.NewLine + " Extra:"); foreach (var item in notExpected) { sb.Append(Environment.NewLine + " " + item); } } Assert.Fail(sb.ToString()); } }
public EventFlowValidator <TRequestContext> AddSimpleErrorValidation(Action <string, int> paramValidation) { // Put together a validator that ensures a null data // Add the expected result ExpectedEvents.Add(new ExpectedEvent { EventType = EventTypes.Error, ParamType = typeof(Error), Validator = (Action <Error>)(e => { Assert.NotNull(e); paramValidation(e.Message, e.Code); }) }); return(this); }
public EventFlowValidator <TRequestContext> AddEventValidation <TParams>(EventType <TParams> expectedEvent, Action <TParams> paramValidation, Action <TParams> userCallback = null) { ExpectedEvents.Add(new ExpectedEvent { EventType = EventTypes.Event, ParamType = typeof(TParams), Validator = paramValidation }); Context.Setup(rc => rc.SendEvent(expectedEvent, It.IsAny <TParams>())) .Callback <EventType <TParams>, TParams>((et, p) => { ReceivedEvents.Add(new ReceivedEvent { EventObject = p, EventType = EventTypes.Event }); userCallback?.DynamicInvoke(p); }) .Returns(Task.FromResult(0)); return(this); }
public void Validate() { // Make sure the handlers have been added if (!_completed) { throw new Exception("EventFlowValidator must be completed before it can be validated."); } // Iterate over the two lists in sync to see if they are the same for (int i = 0; i < Math.Max(ExpectedEvents.Count, ReceivedEvents.Count); i++) { // Step 0) Make sure both events exist if (i >= ExpectedEvents.Count) { throw new Exception($"Unexpected event received: [{ReceivedEvents[i].EventType}] {ReceivedEvents[i].EventObject}"); } ExpectedEvent expected = ExpectedEvents[i]; if (i >= ReceivedEvents.Count) { throw new Exception($"Expected additional events: [{ExpectedEvents[i].EventType}] {ExpectedEvents[i].ParamType}"); } ReceivedEvent received = ReceivedEvents[i]; // Step 1) Make sure the event type matches Assert.True(expected.EventType.Equals(received.EventType), string.Format("Expected EventType {0} but got {1}. Received object is {2}", expected.EventType, received.EventType, received.EventObject.ToString())); // Step 2) Make sure the param type matches Assert.True(expected.ParamType == received.EventObject.GetType() , $"expected and received event types differ for event Number: {i+1}. Expected EventType: {expected.ParamType} & Received EventType: {received.EventObject.GetType()}\r\n" + $"\there is the full list of expected and received events::" + $"\r\n\t\t expected event types:{string.Join("\r\n\t\t", ExpectedEvents.ConvertAll(evt=>evt.ParamType))}" + $"\r\n\t\t received event types:{string.Join("\r\n\t\t", ReceivedEvents.ConvertAll(evt=>evt.EventObject.GetType()))}" ); // Step 3) Run the validator on the param object Assert.NotNull(received.EventObject); expected.Validator?.DynamicInvoke(received.EventObject); } // Iterate over updates events if any to ensure that they are conforming }