public EventFlowValidator <TRequestContext> Complete() { // Add general handler for result handling Context.Setup(rc => rc.SendResult(It.IsAny <TRequestContext>())) .Callback <TRequestContext>(r => ReceivedEvents.Add(new ReceivedEvent { EventObject = r, EventType = EventTypes.Result })) .Returns(Task.FromResult(0)); // Add general handler for error event Context.AddErrorHandling((msg, code) => { ReceivedEvents.Add(new ReceivedEvent { EventObject = new Error { Message = msg, Code = code }, EventType = EventTypes.Error }); }); _completed = true; return(this); }
public void WaitAssert(Action <T[]> assertionFunc, int retryCount, int retryTimeoutRatioMs) { var policy = Policy .Handle <TException>() .WaitAndRetry(retryCount, i => TimeSpan.FromMilliseconds(i * retryTimeoutRatioMs)); policy.Execute(() => assertionFunc(ReceivedEvents.ToArray())); }
public async Task WaitAssertAsync(Func <T[], Task> assertionFunc, int retryCount, int retryTimeoutRatioMs) { var policy = Policy .Handle <TException>() .WaitAndRetryAsync(retryCount, i => TimeSpan.FromMilliseconds(i * retryTimeoutRatioMs)); await policy.ExecuteAsync(async() => await assertionFunc(ReceivedEvents.ToArray())); }
public override string ToString() { string retVal = "{"; retVal += "AuthenticationKey = " + AuthenticationKey + Environment.NewLine; retVal += "Balance = " + Balance + Environment.NewLine; retVal += "DelegatedWithdrawalCapability = " + DelegatedWithdrawalCapability + Environment.NewLine; retVal += "ReceivedEvents = " + ReceivedEvents.ByteArryToString() + Environment.NewLine; retVal += "SentEvents = " + SentEvents.ByteArryToString() + Environment.NewLine; retVal += "SequenceNumber = " + SequenceNumber + Environment.NewLine; retVal += "}"; return(retVal); }
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 }
private void ObserveBarEvent(BarEvent e) { ReceivedEvents.Add(e); }
private void ObserveFooEvent(FooEvent e) { ReceivedEvents.Add(e); }
public void ReceiveEvent(BaseEvent ev) { ReceivedEvents.Add(ev); }
public void ClearEvents() { while (ReceivedEvents.TryTake(out _)) { } }
public Task ConsumeAsync(IntegrationEvent <T> integrationEvent) { ReceivedEvents.Add(integrationEvent.Content); return(Task.CompletedTask); }
protected override void OnEvent(TestEvent @event) { ReceivedEvents.Add(@event); }