public void Initialize( AsaOutputStorageType outputStorageType, CosmosDbTableConfiguration config) { this.storageType = outputStorageType; this.cosmosDbConfig = config; this.initialized = true; }
// Initialize the instance, required before running any other method // Returns the instance so that the method can be chained to the ctor. public ICosmosDbSql Initialize(CosmosDbTableConfiguration config) { this.connectionString = config.ConnectionString; this.consistencyLevel = config.ConsistencyLevel; this.database = config.Database; this.collection = config.Collection; this.RUs = config.RUs; this.initialized = true; return(this); }
public void ItValidatesTheConnectionString() { // Arrange var config = new CosmosDbTableConfiguration { ConnectionString = "missing" }; this.target.Initialize(config); // Act + Assert Assert.ThrowsAsync <InvalidConfigurationException>( async() => await this.target.CreateDatabaseAndCollectionsIfNotExistAsync()) .Wait(TEST_TIMEOUT_MSECS); }
public void ItInitializesCosmosDbSqlStorage() { // Arrange var config = new CosmosDbTableConfiguration { ConnectionString = "foo" }; this.target.Initialize(AsaOutputStorageType.CosmosDbSql, config); this.cosmosDbSql .Setup(x => x.Initialize(It.IsAny <CosmosDbTableConfiguration>())) .Returns(this.cosmosDbSql.Object); // Act this.target.SetupOutputStorageAsync().Wait(TEST_TIMEOUT_MSECS); // Assert this.cosmosDbSql.Verify( x => x.Initialize(It.Is <CosmosDbTableConfiguration>(c => c.ConnectionString == "foo")), Times.Once); this.cosmosDbSql.Verify(x => x.CreateDatabaseAndCollectionsIfNotExistAsync(), Times.Once); }
public void ItCreatesDatabaseAndCollection() { // Arrange const string ENDPOINT = "https://localhost/"; const string KEY = "MYKEY"; var config = new CosmosDbTableConfiguration { ConnectionString = $"AccountEndpoint={ENDPOINT};AccountKey={KEY};", Database = Guid.NewGuid().ToString(), Collection = Guid.NewGuid().ToString(), ConsistencyLevel = ConsistencyLevel.Session, RUs = 1234 }; this.target.Initialize(config); // Act this.target.CreateDatabaseAndCollectionsIfNotExistAsync().Wait(TEST_TIMEOUT_MSECS); // Assert this.cosmosSqlWrapper.Verify( x => x.CreateDatabaseIfNotExistsAsync( It.Is <Uri>(u => u.AbsoluteUri == ENDPOINT), KEY, Microsoft.Azure.Documents.ConsistencyLevel.Session, config.Database), Times.Once); this.cosmosSqlWrapper.Verify( x => x.CreateDocumentCollectionIfNotExistsAsync( It.Is <Uri>(u => u.AbsoluteUri == ENDPOINT), KEY, Microsoft.Azure.Documents.ConsistencyLevel.Session, config.Database, config.Collection, 1234), Times.Once); }