private void CheckState(TestScope scope, TestScenario scenario) { var repository = scope.GetService <RepositoryStub>(); for (var i = 0; i < scenario.ExpectedEndState.Length; i++) { var outcome = scenario.ExpectedEndState[i]; var matches = repository.Store.Where(storedEntity => storedEntity.Type == outcome.Entity.Type && storedEntity.ValidFrom == outcome.Entity.ValidFrom && storedEntity.ValidTo == outcome.Entity.ValidTo && AreEqual(outcome.Entity.Entities, storedEntity.Entities)) .ToArray(); Assert.AreEqual(1, matches.Length, $"Expected outcome {outcome.Name} (index {i}) to match a single stored entity but matched {matches.Length}"); } }
private async Task ReceiveEventsAsync(TestScope scope, TestScenario scenario, CancellationToken cancellationToken) { var receiveFunction = scope.GetService <ReceiveEntityEvent>(); for (var i = 0; i < scenario.Events.Length; i++) { var @event = scenario.Events[i]; try { var httpRequest = new DefaultHttpRequest(new DefaultHttpContext()) { Body = new MemoryStream(Encoding.UTF8.GetBytes(@event.Payload.ToString())), }; await receiveFunction.RunAsync(httpRequest, @event.EntityType, @event.SourceSystemName, cancellationToken); } catch (Exception ex) { throw new Exception($"Error receiving event {@event.Name} (index {i}): {ex.Message}", ex); } } }
private async Task ProcessEventsAsync(TestScope scope, CancellationToken cancellationToken) { var queue = scope.GetService <SyncQueueStub>(); await queue.DrainQueueAsync(cancellationToken); }