public async Task ThenTheTransfersAreStored() { // arrange var expectedTransfers = ConfigureEventsApi().OrderBy(t => t.TransferId).ToList(); var cancellationTokenSource = new CancellationTokenSource(); var cancellationToken = cancellationTokenSource.Token; // act Task.Run(() => WorkerRole.Run(), cancellationToken); var periodEndFinished = TestHelper.ConditionMet(PeriodEndProcessed, TimeSpan.FromSeconds(60)); cancellationTokenSource.Cancel(); // assert Assert.IsTrue(periodEndFinished); var actualTransfers = (await EventTestsRepository.GetTransfers()).OrderBy(t => t.TransferId).ToList(); Assert.AreEqual(expectedTransfers.Count, actualTransfers.Count); for (var i = 0; i < actualTransfers.Count; i++) { Assert.AreEqual(expectedTransfers[i].TransferId, actualTransfers[i].TransferId); Assert.AreEqual(expectedTransfers[i].Amount, actualTransfers[i].Amount); Assert.AreEqual(expectedTransfers[i].SenderAccountId, actualTransfers[i].SenderAccountId); Assert.AreEqual(expectedTransfers[i].ReceiverAccountId, actualTransfers[i].ReceiverAccountId); Assert.AreEqual(expectedTransfers[i].RequiredPaymentId, actualTransfers[i].RequiredPaymentId); Assert.AreEqual(expectedTransfers[i].Type, actualTransfers[i].Type); Assert.AreEqual(expectedTransfers[i].CommitmentId, actualTransfers[i].CommitmentId); Assert.AreEqual(expectedTransfers[i].CollectionPeriodName, actualTransfers[i].CollectionPeriodName); } }