public async Task ExecuteAsync(IDocumentClient client, DocumentCollection collection, Uri relativeCollectionUri)
        {
            EnsureArg.IsNotNull(client, nameof(client));
            EnsureArg.IsNotNull(collection, nameof(collection));

            var thisVersion = await GetLatestCollectionVersion(client, collection);

            if (thisVersion.Version < CollectionSettingsVersion)
            {
                _logger.LogDebug("Ensuring indexes are up-to-date {CollectionUri}", _configuration.GetAbsoluteCollectionUri(_collectionConfiguration.CollectionId));

                collection.IndexingPolicy = new IndexingPolicy
                {
                    IncludedPaths = new Collection <IncludedPath>
                    {
                        new IncludedPath
                        {
                            Path    = "/*",
                            Indexes = new Collection <Index>
                            {
                                new RangeIndex(DataType.Number, -1),
                                new RangeIndex(DataType.String, -1),
                            },
                        },
                    },
                    ExcludedPaths = new Collection <ExcludedPath>
                    {
                        new ExcludedPath
                        {
                            Path = $"/{KnownResourceWrapperProperties.RawResource}/*",
                        },
                    },
                };

                // Setting the DefaultTTL to -1 means that by default all documents in the collection will live forever
                // but the Cosmos DB service should monitor this collection for documents that have overridden this default.
                // See: https://docs.microsoft.com/en-us/azure/cosmos-db/time-to-live
                collection.DefaultTimeToLive = -1;

                await client.ReplaceDocumentCollectionAsync(collection);

                thisVersion.Version = CollectionSettingsVersion;
                await client.UpsertDocumentAsync(relativeCollectionUri, thisVersion);
            }
        }
        /// <inheritdoc />
        public async Task OpenDocumentClient(IDocumentClient client, CosmosDataStoreConfiguration configuration, CosmosCollectionConfiguration cosmosCollectionConfiguration)
        {
            EnsureArg.IsNotNull(client, nameof(client));
            EnsureArg.IsNotNull(configuration, nameof(configuration));

            Uri absoluteCollectionUri = configuration.GetAbsoluteCollectionUri(cosmosCollectionConfiguration.CollectionId);

            _logger.LogInformation("Opening DocumentClient connection to {CollectionUri}", absoluteCollectionUri);
            try
            {
                await _testProvider.PerformTest(client, configuration, cosmosCollectionConfiguration);

                _logger.LogInformation("Established DocumentClient connection to {CollectionUri}", absoluteCollectionUri);
            }
            catch (Exception e)
            {
                _logger.LogCritical(e, "Failed to connect to DocumentClient collection {CollectionUri}", absoluteCollectionUri);
                throw;
            }
        }
        public async Task SetupCollectionAsync(IDocumentClient documentClient, DocumentCollection collection)
        {
            EnsureArg.IsNotNull(documentClient, nameof(documentClient));
            EnsureArg.IsNotNull(collection, nameof(collection));

            using (var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromMinutes(5)))
            {
                using (var distributedLock = _lockFactory.Create(documentClient, _configuration.GetRelativeCollectionUri(_collectionConfiguration.CollectionId), $"UpgradeLock:{CollectionSettingsVersion}"))
                {
                    _logger.LogDebug("Attempting to acquire upgrade lock");

                    await distributedLock.AcquireLock(cancellationTokenSource.Token);

                    foreach (var updater in _collectionUpdater)
                    {
                        _logger.LogDebug("Running {CollectionUpdater} on {CollectionUri}", updater.GetType().Name, _configuration.GetAbsoluteCollectionUri(_collectionConfiguration.CollectionId));

                        await updater.ExecuteAsync(documentClient, collection, _configuration.GetRelativeCollectionUri(_collectionConfiguration.CollectionId));
                    }

                    await distributedLock.ReleaseLock();
                }
            }
        }