예제 #1
0
        public async void CanDeleteAllDocumentsAsync()
        {
            var customerRepository = new MongoRepository <Customer>();

            await customerRepository.AddAsync(this.TestCustomers);

            await customerRepository.DeleteAllAsync();

            customerRepository.Count().ShouldBe(0);
        }
        public async Task CustomerMasterRepositoryTest001_CreateFindDeleteAsync_ExpectNoExceptions()
        {
            // Test cases for async API

            await repo.DeleteAllAsync();

            Assert.Equal(0, repo.Count());

            // Add an entity
            Customer entity = new Customer("CustomerMasterRepositoryTest001_cname", "1-800-start");
            await repo.AddAsync(entity);

            this.testLogger.LogDebug($"New entity: {entity.ToJson()}");

            // Count should increase by 1
            Assert.Equal(1, await repo.CountAsync());

            // Test get by id
            var fetch = await repo.GetByEntityIdAsync(entity.entityid);

            Assert.NotNull(fetch);
            // Assert.Equal(fetch,entity);

            // Test search API
            var searchresult = await repo.GetAsync(e => e.phone == "1-800-start");

            Assert.Equal(1, searchresult.Count);

            // Test Update API
            entity.phone = "1-800-updated";
            await repo.UpdateAsync(entity);

            Assert.Equal(1, (await repo.GetAsync(e => e.phone == "1-800-updated")).Count);

            await repo.DeleteAsync(entity.entityid);

            await Assert.ThrowsAsync <Exception>(async() => fetch = await repo.GetByEntityIdAsync(entity.entityid));
        }