public async Task should_retrieve_the_checkpoint()
        {
            var wasRetrieved = false;

            Func<CloudBlockBlob, Task<PartitionCheckpoint>> getCheckpoint = _ =>
            {
                wasRetrieved = true;
                return Task.FromResult(new PartitionCheckpoint());
            };

            var manager = new PartitionCheckpointManager(
                ConsumerGroupName,
                new[] { PartitionId },
                GetCloudBlobContainerStub(),
                _ => Task.FromResult(new DateTimeOffset()),
                getCheckpoint);

            await manager.GetLastCheckpointAsync(PartitionId);

            Assert.True(wasRetrieved);
        }
        public async Task should_check_the_last_modified_date_of_the_blob()
        {
            var dateWasChecked = false;

            Func<CloudBlockBlob, Task<DateTimeOffset>> getLastModified = _ =>
            {
                dateWasChecked = true;
                return Task.FromResult(new DateTimeOffset());
            };

            var manager = new PartitionCheckpointManager(
                ConsumerGroupName,
                new[] { PartitionId },
                GetCloudBlobContainerStub(),
                getLastModified,
                _ => Task.FromResult(new PartitionCheckpoint()));

            await manager.GetLastCheckpointAsync(PartitionId);

            Assert.True(dateWasChecked);
        }
            public when_looking_up_the_blob_reference_for_a_partition()
            {
                var manager = new PartitionCheckpointManager(
                    ConsumerGroupName,
                    new[] { PartitionId },
                    GetCloudBlobContainerStub(),
                    b =>
                    {
                        _blobForLastModified = b;
                        return Task.FromResult(new DateTimeOffset());
                    },
                    b =>
                    {
                        _blobForRetrieval = b;
                        return Task.FromResult(new PartitionCheckpoint());
                    });

                manager.GetLastCheckpointAsync(PartitionId).Wait();
            }
            public async Task should_throw()
            {
                var manager = new PartitionCheckpointManager(
                    ConsumerGroupName,
                    new string[] { },
                    GetCloudBlobContainerStub(),
                    _ => Task.FromResult(new DateTimeOffset()),
                    _ => Task.FromResult(new PartitionCheckpoint()));

                await Assert.ThrowsAnyAsync<ArgumentException>(async () =>
                 {
                     await manager.GetLastCheckpointAsync("unknown");
                 });
            }
            public async Task should_return_a_cached_checkpoint()
            {
                var lastModified = new DateTimeOffset();
                Func<CloudBlockBlob, Task<DateTimeOffset>> getLastModified = _ => Task.FromResult(lastModified);
                Func<CloudBlockBlob, Task<PartitionCheckpoint>> getCheckpoint = _ => Task.FromResult(new PartitionCheckpoint());

                var manager = new PartitionCheckpointManager(
                    ConsumerGroupName,
                    new[] { PartitionId },
                    GetCloudBlobContainerStub(),
                    getLastModified,
                    getCheckpoint);

                var checkpoint1 = await manager.GetLastCheckpointAsync(PartitionId);
                var checkpoint2 = await manager.GetLastCheckpointAsync(PartitionId);

                Assert.Equal(checkpoint1, checkpoint2);
            }
            public async Task should_not_retrieve_the_checkpoint()
            {
                var timesRetrieved = 0;
                var lastModified = new DateTimeOffset();
                Func<CloudBlockBlob, Task<DateTimeOffset>> getLastModified = _ => Task.FromResult(lastModified);
                Func<CloudBlockBlob, Task<PartitionCheckpoint>> getCheckpoint = _ =>
                {
                    timesRetrieved++;
                    return Task.FromResult(new PartitionCheckpoint());
                };

                var manager = new PartitionCheckpointManager(
                    ConsumerGroupName,
                    new[] { PartitionId },
                    GetCloudBlobContainerStub(),
                    getLastModified,
                    getCheckpoint);

                await manager.GetLastCheckpointAsync(PartitionId);
                // since the last modified stamp hasn't changed, 
                // we should not attempt to retrieve the blob
                await manager.GetLastCheckpointAsync(PartitionId);

                Assert.Equal(1, timesRetrieved);
            }