コード例 #1
0
        public async void TestGenericOperations_DependentEntityRepository()
        {
            var repo     = new TestDependentEntityRepo(_tableName, _serviceUrl);
            var parentId = "P0001";

            var list = await repo.TableQueryItemsByParentIdAsync(parentId);

            Assert.Equal(0, list.Count);

            var te1 = new TestEntity {
                Id = "TE1", Name = "TestEntity TE1"
            };
            await repo.AddItemAsync(parentId, "TE1", te1);

            list = await repo.TableQueryItemsByParentIdAsync(parentId);

            Assert.Equal(1, list.Count);

            var te2 = new TestEntity {
                Id = "TE2", Name = "TestEntity TE2"
            };
            await repo.AddItemAsync(parentId, "TE2", te2);

            list = await repo.TableQueryItemsByParentIdAsync(parentId);

            Assert.Equal(2, list.Count);

            var found1 = await repo.GetItemAsync(parentId, te1.Id);

            Assert.NotNull(found1);
            Assert.Equal("TE1", found1.Id);
            Assert.Equal("TestEntity TE1", found1.Name);

            var found2 = await repo.GetItemAsync(parentId, te2.Id);

            Assert.NotNull(found2);
            Assert.Equal("TE2", found2.Id);
            Assert.Equal("TestEntity TE2", found2.Name);

            await repo.DeleteItemAsync(parentId, te1.Id);

            list = await repo.TableQueryItemsByParentIdAsync(parentId);

            Assert.Equal(1, list.Count);

            var deleted1 = await repo.GetItemAsync(parentId, te1.Id);

            Assert.Null(deleted1);

            await repo.DeleteItemAsync(parentId, te2.Id);

            list = await repo.TableQueryItemsByParentIdAsync(parentId);

            Assert.Equal(0, list.Count);

            var deleted2 = await repo.GetItemAsync(parentId, te1.Id);

            Assert.Null(deleted2);
        }
コード例 #2
0
        public async void TestBatchOperations_DependentEntityRepository()
        {
            var parent = new TestEntity {
                Id = "PTE1"
            };
            var repo          = new TestDependentEntityRepo(_tableName, _serviceUrl);
            var itemsToCreate = new List <KeyValuePair <string, TestEntity> >();

            for (int i = 50; i < 60; i++)
            {
                var te = new TestEntity {
                    Id = "TE" + i, Name = "TestEntity TE" + i
                };
                itemsToCreate.Add(new KeyValuePair <string, TestEntity>(te.Id, te));
            }
            await repo.BatchAddItemsAsync(parent.Id, itemsToCreate);

            var list = await repo.TableQueryItemsByParentIdAsync(parent.Id);

            Assert.Equal(10, list.Count);

            for (int i = 0; i < 10; i++)
            {
                var item = list[i];
                var id   = i + 50;
                Assert.NotNull(item);
                Assert.Equal("TE" + id, item.Id);
                Assert.Equal("TestEntity TE" + id, item.Name);
            }

            var itemsToDelete = new List <string>();

            for (int i = 50; i < 60; i++)
            {
                var te = new TestEntity {
                    Id = "TE" + i
                };
                itemsToDelete.Add(te.Id);
            }
            await repo.BatchDeleteItemsAsync(parent.Id, itemsToDelete);

            var emptyList = await repo.TableQueryItemsByParentIdAsync(parent.Id);

            Assert.Empty(emptyList);
        }