Beispiel #1
0
        public static void CreateClient_Creates_Client_From_Service_Provider_With_Locations()
        {
            // Arrange
            var options = new UserStoreOptions()
            {
                ServiceUri      = new Uri("https://cosmosdb.azure.local"),
                AccessKey       = "bpfYUKmfV0arChaIPI3hU3+bn3w=",
                DatabaseName    = "my-database",
                CollectionName  = "my-collection",
                CurrentLocation = "UK South",
            };

            var services = new ServiceCollection()
                           .AddHttpClient()
                           .AddSingleton(Options.Create(new JsonOptions()))
                           .AddSingleton(options);

            using var serviceProvider = services.BuildServiceProvider();

            // Act
            using CosmosClient actual = DocumentHelpers.CreateClient(serviceProvider);

            // Assert
            actual.ShouldNotBeNull();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DocumentCollectionInitializer"/> class.
        /// </summary>
        /// <param name="telemetry">The <see cref="TelemetryClient"/> to use.</param>
        /// <param name="options">The <see cref="UserStoreOptions"/> to use.</param>
        /// <param name="logger">The <see cref="ILogger{DocumentCollectionInitializer}"/> to use.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="options"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// <paramref name="options"/> is invalid.
        /// </exception>
        public DocumentCollectionInitializer(
            TelemetryClient telemetry,
            UserStoreOptions options,
            ILogger <DocumentCollectionInitializer> logger)
        {
            _client = DocumentHelpers.CreateClient(options);
            _existingCollections = new ConcurrentDictionary <string, bool>();

            _telemetry    = telemetry;
            _logger       = logger;
            _databaseName = options.DatabaseName;
        }
Beispiel #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DocumentClientWrapper"/> class.
        /// </summary>
        /// <param name="initializer">The <see cref="IDocumentCollectionInitializer"/> to use.</param>
        /// <param name="telemetry">The <see cref="TelemetryClient"/> to use.</param>
        /// <param name="options">The <see cref="UserStoreOptions"/> to use.</param>
        /// <param name="logger">The <see cref="ILogger{DocumentClientWrapper}"/> to use.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="options"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// <paramref name="options"/> is invalid.
        /// </exception>
        public DocumentClientWrapper(
            IDocumentCollectionInitializer initializer,
            TelemetryClient telemetry,
            UserStoreOptions options,
            ILogger <DocumentClientWrapper> logger)
        {
            _initializer = initializer ?? throw new ArgumentNullException(nameof(initializer));
            _client      = DocumentHelpers.CreateClient(options);

            _telemetry = telemetry;
            _options   = options;
            _logger    = logger;
        }
        public static void CreateClient_Throws_If_Options_Has_No_Database_Name(string databaseName)
        {
            // Arrange
            var options = new UserStoreOptions()
            {
                ServiceUri     = new Uri("https://cosmosdb.azure.local"),
                AccessKey      = "bpfYUKmfV0arChaIPI3hU3+bn3w=",
                DatabaseName   = databaseName,
                CollectionName = "my-collection",
            };

            // Act and Assert
            Assert.Throws <ArgumentException>("options", () => DocumentHelpers.CreateClient(options));
        }
        public static void CreateClient_Throws_If_Options_Has_No_Access_Key(string accessKey)
        {
            // Arrange
            var options = new UserStoreOptions()
            {
                ServiceUri     = new Uri("https://cosmosdb.azure.local"),
                AccessKey      = accessKey,
                DatabaseName   = "my-database",
                CollectionName = "my-collection",
            };

            // Act and Assert
            Assert.Throws <ArgumentException>("options", () => DocumentHelpers.CreateClient(options));
        }
        public static void CreateClient_Throws_If_Options_Has_Relative_Service_Endpoint()
        {
            // Arrange
            var options = new UserStoreOptions()
            {
                ServiceUri     = new Uri("/", UriKind.Relative),
                AccessKey      = "bpfYUKmfV0arChaIPI3hU3+bn3w=",
                DatabaseName   = "my-database",
                CollectionName = "my-collection",
            };

            // Act and Assert
            Assert.Throws <ArgumentException>("options", () => DocumentHelpers.CreateClient(options));
        }
Beispiel #7
0
        public static void CreateClient_Throws_If_Options_Has_No_Service_Endpoint()
        {
            // Arrange
            var options = new UserStoreOptions()
            {
                ServiceUri     = null,
                AccessKey      = "bpfYUKmfV0arChaIPI3hU3+bn3w=",
                DatabaseName   = "my-database",
                CollectionName = "my-collection",
            };

            var httpClientFactory = Mock.Of <IHttpClientFactory>();

            // Act and Assert
            Assert.Throws <ArgumentException>("options", () => DocumentHelpers.CreateClient(options, httpClientFactory));
        }