Esempio n. 1
0
        public async void CanCountDocumentsAsync()
        {
            var customerRepository = new MongoRepository <Customer>();

            await customerRepository.AddAsync(this.TestCustomers);

            var count = await customerRepository.CountAsync();

            count.ShouldBe(this.TestCustomers.Count);

            await customerRepository.DeleteAsync(this.TestCustomers);
        }
Esempio n. 2
0
        public async Task CountAsync_Success()
        {
            var result = await Repository.CountAsync();

            Assert.AreEqual(result, 0);

            var batch = new List <MongoTestEntity>();

            for (int i = 1; i <= 1000; i++)
            {
                batch.Add(new MongoTestEntity()
                {
                    Number = i,
                    Bool   = false,
                    String = "String " + i
                });
            }

            await Repository.CreateAsync(batch);

            result = await Repository.CountAsync();

            Assert.AreEqual(result, batch.Count);
        }
        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));
        }