public async Task EncryptionBulkCrud() { TestDoc docToReplace = await EncryptionTests.CreateItemAsync(EncryptionTests.containerCore, EncryptionTests.dekId, TestDoc.PathsToEncrypt); docToReplace.NonSensitive = Guid.NewGuid().ToString(); docToReplace.Sensitive = Guid.NewGuid().ToString(); TestDoc docToUpsert = await EncryptionTests.CreateItemAsync(EncryptionTests.containerCore, EncryptionTests.dekId, TestDoc.PathsToEncrypt); docToUpsert.NonSensitive = Guid.NewGuid().ToString(); docToUpsert.Sensitive = Guid.NewGuid().ToString(); TestDoc docToDelete = await EncryptionTests.CreateItemAsync(EncryptionTests.containerCore, EncryptionTests.dekId, TestDoc.PathsToEncrypt); (string endpoint, string authKey) = TestCommon.GetAccountInfo(); CosmosClient clientWithBulk = new CosmosClientBuilder(endpoint, authKey) .WithEncryptionKeyWrapProvider(new TestKeyWrapProvider()) .WithBulkExecution(true) .Build(); DatabaseCore databaseWithBulk = (DatabaseInlineCore)clientWithBulk.GetDatabase(EncryptionTests.databaseCore.Id); ContainerCore containerWithBulk = (ContainerInlineCore)databaseWithBulk.GetContainer(EncryptionTests.container.Id); List <Task> tasks = new List <Task>(); tasks.Add(EncryptionTests.CreateItemAsync(containerWithBulk, EncryptionTests.dekId, TestDoc.PathsToEncrypt)); tasks.Add(EncryptionTests.UpsertItemAsync(containerWithBulk, TestDoc.Create(), EncryptionTests.dekId, TestDoc.PathsToEncrypt, HttpStatusCode.Created)); tasks.Add(EncryptionTests.ReplaceItemAsync(containerWithBulk, docToReplace, EncryptionTests.dekId, TestDoc.PathsToEncrypt)); tasks.Add(EncryptionTests.UpsertItemAsync(containerWithBulk, docToUpsert, EncryptionTests.dekId, TestDoc.PathsToEncrypt, HttpStatusCode.OK)); tasks.Add(EncryptionTests.DeleteItemAsync(containerWithBulk, docToDelete)); await Task.WhenAll(tasks); }
public async Task EncryptionResourceTokenAuth() { User user = EncryptionTests.databaseCore.GetUser(Guid.NewGuid().ToString()); await EncryptionTests.databaseCore.CreateUserAsync(user.Id); PermissionProperties permission = await user.CreatePermissionAsync( new PermissionProperties(Guid.NewGuid().ToString(), PermissionMode.All, EncryptionTests.container)); TestDoc testDoc = await EncryptionTests.CreateItemAsync(EncryptionTests.containerCore, EncryptionTests.dekId, TestDoc.PathsToEncrypt); (string endpoint, string _) = TestCommon.GetAccountInfo(); CosmosClient resourceTokenBasedClient = new CosmosClientBuilder(endpoint, permission.Token) .WithEncryptionKeyWrapProvider(new TestKeyWrapProvider()) .Build(); DatabaseCore databaseForTokenClient = (DatabaseInlineCore)resourceTokenBasedClient.GetDatabase(EncryptionTests.databaseCore.Id); Container containerForTokenClient = databaseForTokenClient.GetContainer(EncryptionTests.container.Id); await EncryptionTests.PerformForbiddenOperationAsync(() => databaseForTokenClient.GetDataEncryptionKey(EncryptionTests.dekId).ReadAsync(), "DEK.ReadAsync"); await EncryptionTests.PerformForbiddenOperationAsync(() => containerForTokenClient.ReadItemAsync <TestDoc>(testDoc.Id, new PartitionKey(testDoc.PK)), "ReadItemAsync"); await EncryptionTests.PerformForbiddenOperationAsync(() => containerForTokenClient.ReadItemStreamAsync(testDoc.Id, new PartitionKey(testDoc.PK)), "ReadItemStreamAsync"); }
[TestCategory("Quarantine")] // Not currently working with emulator public async Task CreateDropAutoscaleContainerStreamApi() { DatabaseCore database = (DatabaseInlineCore)await this.cosmosClient.CreateDatabaseAsync( Guid.NewGuid().ToString()); ThroughputResponse databaseThroughput = await database.ReadThroughputIfExistsAsync(requestOptions : null); Assert.IsNotNull(databaseThroughput); Assert.AreEqual(HttpStatusCode.NotFound, databaseThroughput.StatusCode); string streamContainerId = Guid.NewGuid().ToString(); using (ResponseMessage response = await database.CreateContainerStreamAsync( new ContainerProperties(streamContainerId, "/pk"), ThroughputProperties.CreateAutoscaleProvionedThroughput(5000))) { Assert.AreEqual(HttpStatusCode.Created, response.StatusCode); ContainerCore streamContainer = (ContainerInlineCore)database.GetContainer(streamContainerId); ThroughputResponse autoscaleIfExists = await streamContainer.ReadThroughputIfExistsAsync(requestOptions : null); Assert.IsNotNull(autoscaleIfExists); Assert.AreEqual(5000, autoscaleIfExists.Resource.MaxAutoscaleThroughput); } }
public async Task SingleTaskScheduler_ExecutorTest() { Mock <CosmosClient> mockClient = new Mock <CosmosClient>(); mockClient.Setup(x => x.Endpoint).Returns(new Uri("http://localhost")); CosmosClientContext context = new ClientContextCore( client: mockClient.Object, clientOptions: new CosmosClientOptions() { AllowBulkExecution = true }, userJsonSerializer: null, defaultJsonSerializer: null, sqlQuerySpecSerializer: null, cosmosResponseFactory: null, requestHandler: null, documentClient: null); DatabaseCore db = new DatabaseCore(context, "test"); List <Task <ContainerCore> > tasks = new List <Task <ContainerCore> >(); for (int i = 0; i < 20; i++) { tasks.Add( Task.Factory.StartNew(() => (ContainerCore)db.GetContainer("test"), CancellationToken.None, TaskCreationOptions.None, new SingleTaskScheduler())); } await Task.WhenAll(tasks); BatchAsyncContainerExecutor firstExecutor = tasks[0].Result.BatchExecutor; Assert.IsNotNull(firstExecutor); for (int i = 1; i < 20; i++) { BatchAsyncContainerExecutor otherExecutor = tasks[i].Result.BatchExecutor; Assert.AreEqual(firstExecutor, otherExecutor); } }
public void Null_When_OptionsOff() { Mock <CosmosClient> mockClient = new Mock <CosmosClient>(); mockClient.Setup(x => x.Endpoint).Returns(new Uri("http://localhost")); CosmosClientContext context = new ClientContextCore( client: mockClient.Object, clientOptions: new CosmosClientOptions() { }, userJsonSerializer: null, defaultJsonSerializer: null, sqlQuerySpecSerializer: null, cosmosResponseFactory: null, requestHandler: null, documentClient: null); DatabaseCore db = new DatabaseCore(context, "test"); ContainerCore container = (ContainerCore)db.GetContainer("test"); Assert.IsNull(container.BatchExecutor); }