public IntegrationTestCosmosDataStore() { _cosmosDataStoreConfiguration = new CosmosDataStoreConfiguration { Host = Environment.GetEnvironmentVariable("CosmosDb:Host") ?? CosmosDbLocalEmulator.Host, Key = Environment.GetEnvironmentVariable("CosmosDb:Key") ?? CosmosDbLocalEmulator.Key, DatabaseId = Environment.GetEnvironmentVariable("CosmosDb:DatabaseId") ?? "FhirTests", AllowDatabaseCreation = true, PreferredLocations = Environment.GetEnvironmentVariable("CosmosDb:PreferredLocations")?.Split(';', StringSplitOptions.RemoveEmptyEntries), }; _cosmosCollectionConfiguration = new CosmosCollectionConfiguration { CollectionId = Guid.NewGuid().ToString(), }; var fhirStoredProcs = typeof(IFhirStoredProcedure).Assembly .GetTypes() .Where(x => !x.IsAbstract && typeof(IFhirStoredProcedure).IsAssignableFrom(x)) .ToArray() .Select(type => (IFhirStoredProcedure)Activator.CreateInstance(type)); var optionsMonitor = Substitute.For <IOptionsMonitor <CosmosCollectionConfiguration> >(); optionsMonitor.Get(CosmosDb.Constants.CollectionConfigurationName).Returns(_cosmosCollectionConfiguration); var updaters = new IFhirCollectionUpdater[] { new FhirCollectionSettingsUpdater(_cosmosDataStoreConfiguration, optionsMonitor, NullLogger <FhirCollectionSettingsUpdater> .Instance), new FhirStoredProcedureInstaller(fhirStoredProcs), }; var dbLock = new CosmosDbDistributedLockFactory(Substitute.For <Func <IScoped <IDocumentClient> > >(), NullLogger <CosmosDbDistributedLock> .Instance); var upgradeManager = new FhirCollectionUpgradeManager(updaters, _cosmosDataStoreConfiguration, optionsMonitor, dbLock, NullLogger <FhirCollectionUpgradeManager> .Instance); IDocumentClientTestProvider testProvider = new DocumentClientReadWriteTestProvider(); var documentClientInitializer = new DocumentClientInitializer(testProvider, NullLogger <DocumentClientInitializer> .Instance); _documentClient = documentClientInitializer.CreateDocumentClient(_cosmosDataStoreConfiguration); var fhirCollectionInitializer = new CollectionInitializer(_cosmosCollectionConfiguration.CollectionId, _cosmosDataStoreConfiguration, _cosmosCollectionConfiguration.InitialCollectionThroughput, upgradeManager, NullLogger <CollectionInitializer> .Instance); documentClientInitializer.InitializeDataStore(_documentClient, _cosmosDataStoreConfiguration, new List <ICollectionInitializer> { fhirCollectionInitializer }).GetAwaiter().GetResult(); var cosmosDocumentQueryFactory = new FhirCosmosDocumentQueryFactory(Substitute.For <IFhirRequestContextAccessor>(), NullFhirDocumentQueryLogger.Instance); var fhirRequestContextAccessor = new FhirRequestContextAccessor(); _dataStore = new FhirDataStore( new NonDisposingScope(_documentClient), _cosmosDataStoreConfiguration, cosmosDocumentQueryFactory, new RetryExceptionPolicyFactory(_cosmosDataStoreConfiguration), fhirRequestContextAccessor, optionsMonitor, NullLogger <FhirDataStore> .Instance); }
public LoggerNetMetToCosmosDBSqlApiMeasurementTests() : base() { client = DocumentClientInitializer.InitializeDocumentClient(); // Setup, deletes all Measurements deleteAllDocuments(getAllMeasurements().ToList <IAmDocument>()); deleteAllDocuments(getAllEtlEvents().ToList <IAmDocument>()); }
public DocumentClientInitializerTests() { var documentClientTestProvider = Substitute.For <IDocumentClientTestProvider>(); _documentClientInitializer = new DocumentClientInitializer(documentClientTestProvider, NullLogger <DocumentClientInitializer> .Instance); _collectionInitializers = new List <ICollectionInitializer> { _collectionInitializer1, _collectionInitializer2 }; _documentClient.CreateDatabaseIfNotExistsAsync(Arg.Any <Database>(), Arg.Any <RequestOptions>()).Returns(Substitute.For <ResourceResponse <Database> >()); }
public IntegrationTestCosmosDataStore() { _cosmosDataStoreConfiguration = new CosmosDataStoreConfiguration { Host = Environment.GetEnvironmentVariable("CosmosDb:Host") ?? CosmosDbLocalEmulator.Host, Key = Environment.GetEnvironmentVariable("CosmosDb:Key") ?? CosmosDbLocalEmulator.Key, DatabaseId = Environment.GetEnvironmentVariable("CosmosDb:DatabaseId") ?? "FhirTests", CollectionId = Guid.NewGuid().ToString(), AllowDatabaseCreation = true, PreferredLocations = Environment.GetEnvironmentVariable("CosmosDb:PreferredLocations")?.Split(';', StringSplitOptions.RemoveEmptyEntries), }; var updaters = new ICollectionUpdater[] { new CollectionSettingsUpdater(NullLogger <CollectionSettingsUpdater> .Instance, _cosmosDataStoreConfiguration), new StoredProcedureInstaller(), }; var dbLock = new CosmosDbDistributedLockFactory(Substitute.For <Func <IScoped <IDocumentClient> > >(), NullLogger <CosmosDbDistributedLock> .Instance); var upgradeManager = new CollectionUpgradeManager(updaters, _cosmosDataStoreConfiguration, dbLock, NullLogger <CollectionUpgradeManager> .Instance); IDocumentClientTestProvider testProvider = new DocumentClientReadWriteTestProvider(); var documentClientInitializer = new DocumentClientInitializer(testProvider, NullLogger <DocumentClientInitializer> .Instance, upgradeManager, Substitute.For <IFhirRequestContextAccessor>()); _documentClient = documentClientInitializer.CreateDocumentClient(_cosmosDataStoreConfiguration); documentClientInitializer.InitializeDataStore(_documentClient, _cosmosDataStoreConfiguration).GetAwaiter().GetResult(); var cosmosDocumentQueryFactory = new CosmosDocumentQueryFactory(Substitute.For <IFhirRequestContextAccessor>(), NullFhirDocumentQueryLogger.Instance); _dataStore = new CosmosDataStore( new NonDisposingScope(_documentClient), _cosmosDataStoreConfiguration, cosmosDocumentQueryFactory, new RetryExceptionPolicyFactory(_cosmosDataStoreConfiguration), NullLogger <CosmosDataStore> .Instance); }