public async Task GivenUnchangedEventHubOptions_WhenResetCheckpointsAsyncCalled_ThenNoCheckpointsAreDeleted()
        {
            _eventHubClientOptions.EventHubNamespaceFQDN = _eventHubNamespaceFQDN;
            _eventHubClientOptions.EventHubName          = _eventHubName;

            var storageClient = new StorageCheckpointClient(_blobContainerClient, _storageCheckpointOptions, _eventHubClientOptions, _logger);
            await storageClient.ResetCheckpointsAsync();

            // Given that the source event hub didn't change, verify that no checkpoint deletions occured.
            _blobContainerClient.Received(1).GetBlobs(states: BlobStates.All, prefix: _blobCheckpointPrefix, cancellationToken: CancellationToken.None);
            await _blobContainerClient.ReceivedWithAnyArgs(0).DeleteBlobAsync(null);
        }
        public async Task GivenUnchangedEventHubOptionsWithConnectionString_WhenResetCheckpointsAsyncCalled_ThenNoCheckpointsAreDeleted()
        {
            var eventHubClientOptions = new EventHubClientOptions()
            {
                AuthenticationType = AuthenticationType.ConnectionString,
                ConnectionString   = "Endpoint=sb://test.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=test123;EntityPath=devicedata"
            };

            var storageClient = new StorageCheckpointClient(_blobContainerClient, _storageCheckpointOptions, eventHubClientOptions, _logger);
            await storageClient.ResetCheckpointsAsync();

            // Given that the source event hub didn't change, verify that no checkpoint deletions occured.
            _blobContainerClient.Received(1).GetBlobs(states: BlobStates.All, prefix: _blobCheckpointPrefix, cancellationToken: CancellationToken.None);
            await _blobContainerClient.ReceivedWithAnyArgs(0).DeleteBlobAsync(null);
        }
        public async Task GivenUpdatedEventHubNamespaceAndEventHubName_WhenResetCheckpointsAsyncCalled_ThenPreviousCheckpointsAreDeleted()
        {
            _eventHubClientOptions.EventHubNamespaceFQDN = "newtest.servicebus.windows.net";
            _eventHubClientOptions.EventHubName          = "newdevicedata";

            var storageClient = new StorageCheckpointClient(_blobContainerClient, _storageCheckpointOptions, _eventHubClientOptions, _logger);
            await storageClient.ResetCheckpointsAsync();

            // Given that the event hub namespace and the event hub name changed and is therefore a new source, verify that the checkpoints corresponding to the old source will be deleted.
            _blobContainerClient.Received(1).GetBlobs(states: BlobStates.All, prefix: _blobCheckpointPrefix, cancellationToken: CancellationToken.None);
            await _blobContainerClient.ReceivedWithAnyArgs(3).DeleteBlobAsync(null);

            await _blobContainerClient.Received(1).DeleteBlobAsync($"{_blobPath}1");

            await _blobContainerClient.Received(1).DeleteBlobAsync($"{_blobPath}10");

            await _blobContainerClient.Received(1).DeleteBlobAsync($"{_blobPath}20");
        }
        public async Task GivenDifferentAppType_WhenResetCheckpointsAsyncCalled_ThenCheckpointsOfOtherAppsAreNotDeleted()
        {
            _eventHubClientOptions.EventHubNamespaceFQDN = _eventHubNamespaceFQDN;
            _eventHubClientOptions.EventHubName          = "newdevicedata";
            _storageCheckpointOptions.BlobPrefix         = "MeasurementToFhir";
            var fhirconvBlobCheckpointPrefix = $"{_storageCheckpointOptions.BlobPrefix }/checkpoint/";
            var fhirconvBlobPath             = $"{fhirconvBlobCheckpointPrefix}{_eventHubNamespaceFQDN}/{_eventHubName}/";

            IReadOnlyList <BlobItem> mockBlobItems = new List <BlobItem>()
            {
                BlobsModelFactory.BlobItem(name: $"{fhirconvBlobPath}1"),
                BlobsModelFactory.BlobItem(name: $"{fhirconvBlobPath}10"),
                BlobsModelFactory.BlobItem(name: $"{fhirconvBlobPath}20")
            };

            var mockPageBlobItems = Page <BlobItem> .FromValues(mockBlobItems, "continuationToken", Substitute.For <Response>());

            var mockPageableBlobItems = Pageable <BlobItem> .FromPages(new[] { mockPageBlobItems });

            _blobContainerClient.GetBlobs(states: BlobStates.All, prefix: fhirconvBlobCheckpointPrefix, cancellationToken: CancellationToken.None)
            .Returns(mockPageableBlobItems);

            var storageClient = new StorageCheckpointClient(_blobContainerClient, _storageCheckpointOptions, _eventHubClientOptions, _logger);
            await storageClient.ResetCheckpointsAsync();

            // Given that we are processing events for a different app type and the source changed, verify that the previous checkpoints corresponding to this app are deleted.
            _blobContainerClient.Received(1).GetBlobs(states: BlobStates.All, prefix: fhirconvBlobCheckpointPrefix, cancellationToken: CancellationToken.None);
            await _blobContainerClient.ReceivedWithAnyArgs(3).DeleteBlobAsync(null);

            await _blobContainerClient.Received(1).DeleteBlobAsync($"{fhirconvBlobPath}1");

            await _blobContainerClient.Received(1).DeleteBlobAsync($"{fhirconvBlobPath}10");

            await _blobContainerClient.Received(1).DeleteBlobAsync($"{fhirconvBlobPath}20");

            // Given that we are processing events for a different app type, verify that the checkpoints corresponding to the other apps are not deleted.
            _blobContainerClient.Received(0).GetBlobs(states: BlobStates.All, prefix: _blobCheckpointPrefix, cancellationToken: CancellationToken.None);
            await _blobContainerClient.Received(0).DeleteBlobAsync($"{_blobPath}1");

            await _blobContainerClient.Received(0).DeleteBlobAsync($"{_blobPath}10");

            await _blobContainerClient.Received(0).DeleteBlobAsync($"{_blobPath}20");
        }