public async Task When_AddAsync()
        {
            // Arrange

            var cosmosDatabase =
                _cosmosClient.GetDatabase(
                    _configuration["AzureCosmosOptions:DatabaseId"]);

            var cosmosContainer =
                cosmosDatabase.GetContainer("todos");

            var toDoEntity =
                _faker.GenerateToDoEntity();

            await cosmosContainer.CreateItemAsync(
                toDoEntity,
                new PartitionKey(toDoEntity.Id));

            var entityDataStoreOptions =
                new EntityDataStoreOptions
            {
                CosmosClient = _cosmosClient,
                DatabaseId   = _configuration["AzureCosmosOptions:DatabaseId"]
            };

            var toDoCommentEntityDataStore =
                new ToDoCommentEntityDataStore(
                    entityDataStoreOptions);

            var toDoCommentEntity =
                _faker.GenerateToDoCommentEntity(
                    toDoEntity.Id);

            // Action

            await toDoCommentEntityDataStore.AddAsync(
                toDoEntity.Id,
                toDoCommentEntity);

            // Assert

            var itemResponse =
                await cosmosContainer.ReadItemAsync <ToDoCommentEntity>(
                    toDoCommentEntity.Id,
                    new PartitionKey(toDoEntity.Id));

            itemResponse.StatusCode.Should().Be(HttpStatusCode.OK);

            var toDoCommentEntityFetched =
                itemResponse.Resource;

            toDoCommentEntityFetched.Should().NotBeNull();
            toDoCommentEntityFetched.Id.Should().Be(toDoCommentEntity.Id);
            toDoCommentEntityFetched.ToDoId.Should().Be(toDoCommentEntity.ToDoId);
            toDoCommentEntityFetched.Body.Should().Be(toDoCommentEntity.Body);
        }
Ejemplo n.º 2
0
        public async Task When_AddAsync()
        {
            // Arrange

            var toDoEntity =
                _faker.GenerateToDoEntity();

            var cloudTable =
                _cloudTableClient.GetTableReference("todos");

            var tableOperation =
                TableOperation.Insert(toDoEntity);

            await cloudTable.ExecuteAsync(tableOperation);

            var entityDataStoreOptions =
                new EntityDataStoreOptions
            {
                PrimaryCloudTableClient = _cloudTableClient
            };

            var toDoCommentEntityDataStore =
                new ToDoCommentEntityDataStore(
                    entityDataStoreOptions);

            var toDoCommentEntity =
                _faker.GenerateToDoCommentEntity(toDoEntity.Id);

            // Action

            await toDoCommentEntityDataStore.AddAsync(
                toDoEntity.Id,
                toDoCommentEntity);

            // Assert

            cloudTable =
                _cloudTableClient.GetTableReference("todos");

            tableOperation =
                TableOperation.Retrieve <ToDoCommentEntity>(toDoCommentEntity.PartitionKey, toDoCommentEntity.RowKey);

            var tableResult =
                await cloudTable.ExecuteAsync(tableOperation);

            tableResult.HttpStatusCode.Should().Be((int)HttpStatusCode.OK);

            var toDoCommentEntityFetched =
                tableResult.Result as ToDoCommentEntity;

            toDoCommentEntityFetched.Should().NotBeNull();
            toDoCommentEntityFetched.RowKey.Should().Be(toDoCommentEntity.RowKey);
            toDoCommentEntityFetched.PartitionKey.Should().Be(toDoCommentEntity.PartitionKey);
            toDoCommentEntityFetched.Body.Should().Be(toDoCommentEntity.Body);
        }
        public async Task When_ListAsync()
        {
            // Arrange

            var cosmosDatabase =
                _cosmosClient.GetDatabase(
                    _configuration["AzureCosmosOptions:DatabaseId"]);

            var cosmosContainer =
                cosmosDatabase.GetContainer("todos");

            var toDoEntity =
                _faker.GenerateToDoEntity();

            await cosmosContainer.CreateItemAsync(
                toDoEntity,
                new PartitionKey(toDoEntity.ToDoId));

            for (var i = 0; i < 3; i++)
            {
                var toDoCommentEntity =
                    _faker.GenerateToDoCommentEntity(
                        toDoEntity.Id);

                await cosmosContainer.CreateItemAsync(
                    toDoCommentEntity,
                    new PartitionKey(toDoEntity.Id));
            }

            var entityDataStoreOptions =
                new EntityDataStoreOptions
            {
                CosmosClient = _cosmosClient,
                DatabaseId   = _configuration["AzureCosmosOptions:DatabaseId"]
            };

            var toDoCommentEntityDataStore =
                new ToDoCommentEntityDataStore(
                    entityDataStoreOptions);

            // Action

            var toDoCommentEntityList =
                await toDoCommentEntityDataStore.ListByToDoIdAsync(
                    toDoEntity.Id);

            // Assert

            toDoCommentEntityList.Should().NotBeNull();
            toDoCommentEntityList.Count().Should().Be(3);
        }
Ejemplo n.º 4
0
        public async Task When_ListAsync()
        {
            // Arrange

            var cloudTable =
                _cloudTableClient.GetTableReference("todos");

            var toDoEntity =
                _faker.GenerateToDoEntity();

            var tableOperation =
                TableOperation.Insert(toDoEntity);

            await cloudTable.ExecuteAsync(tableOperation);

            for (var i = 0; i < 3; i++)
            {
                var toDoCommentEntity =
                    _faker.GenerateToDoCommentEntity(
                        toDoEntity.Id);

                tableOperation =
                    TableOperation.Insert(toDoCommentEntity);

                await cloudTable.ExecuteAsync(tableOperation);
            }

            var entityDataStoreOptions =
                new EntityDataStoreOptions
            {
                PrimaryCloudTableClient = _cloudTableClient
            };

            var toDoCommentEntityDataStore =
                new ToDoCommentEntityDataStore(
                    entityDataStoreOptions);

            // Action

            var toDoCommentEntityList =
                await toDoCommentEntityDataStore.ListByToDoIdAsync(
                    toDoEntity.Id);

            // Assert

            toDoCommentEntityList.Should().NotBeNull();
            toDoCommentEntityList.Count().Should().Be(3);
        }