public async Task TestItemAggregation()
        {
            var aggregate = GrainClient.GrainFactory.GetGrain <IStreamProcessorSelectAggregate <int, int> >(Guid.NewGuid());
            await aggregate.SetFunction(_ => _);

            var itemsToSend = new List <int> {
                1, 5, 32, -12
            };

            var provider       = GrainClient.GetStreamProvider(StreamProvider);
            var inputAggregate = new MultiStreamProvider <int>(provider, 2);

            await aggregate.SetInput(await inputAggregate.GetStreamIdentities());

            Assert.AreEqual(2, (await aggregate.GetStreamIdentities()).Count);

            var consumerAggregate = new TestTransactionalStreamConsumerAggregate <int>(provider);
            await consumerAggregate.SetInput(await aggregate.GetStreamIdentities());

            var tid = await inputAggregate.SendItems(itemsToSend);

            var waitForTransaction = consumerAggregate.TransactionComplete(tid);

            var resultItems = consumerAggregate.Items;

            Assert.AreEqual(4, resultItems.Count);
            CollectionAssert.AreEquivalent(itemsToSend, resultItems);

            Assert.IsFalse(await consumerAggregate.AllConsumersTearDownCalled());
            await inputAggregate.TearDown();

            Assert.IsTrue(await consumerAggregate.AllConsumersTearDownCalled());
        }
        public async Task TestAggregateCleanupSuccessful()
        {
            var aggregate = GrainClient.GrainFactory.GetGrain <IStreamProcessorSelectAggregate <int, int> >(Guid.NewGuid());
            await aggregate.SetFunction(_ => _);

            var itemsToSend = new List <int> {
                1, 5, 32, -12
            };

            var provider       = GrainClient.GetStreamProvider(StreamProvider);
            var inputAggregate = new MultiStreamProvider <int>(provider, 2);;

            await aggregate.SetInput(await inputAggregate.GetStreamIdentities());

            var streamIdentitiesProcessor = await aggregate.GetStreamIdentities();

            Assert.AreEqual(2, (await aggregate.GetStreamIdentities()).Count);

            var consumerAggregate = new TestTransactionalStreamConsumerAggregate <int>(provider);
            await consumerAggregate.SetInput(await aggregate.GetStreamIdentities());

            var subscriptionHdl1 = await GetStreamSubscriptionHandles <IStreamMessage>(streamIdentitiesProcessor[0].StreamIdentifier);

            var subscriptionHdl2 = await GetStreamSubscriptionHandles <IStreamMessage>(streamIdentitiesProcessor[1].StreamIdentifier);

            Assert.AreEqual(1, subscriptionHdl1.Count);
            Assert.AreEqual(1, subscriptionHdl2.Count);

            await inputAggregate.TearDown();

            var tid = await inputAggregate.SendItems(itemsToSend);

            var taskCompleted = consumerAggregate.TransactionComplete(tid).Wait(TimeSpan.FromSeconds(5));

            Assert.IsFalse(taskCompleted);

            subscriptionHdl1 = await GetStreamSubscriptionHandles <IStreamMessage>(streamIdentitiesProcessor[0].StreamIdentifier);

            subscriptionHdl2 = await GetStreamSubscriptionHandles <IStreamMessage>(streamIdentitiesProcessor[1].StreamIdentifier);

            Assert.AreEqual(0, subscriptionHdl1.Count);
            Assert.AreEqual(0, subscriptionHdl2.Count);
        }