Ejemplo n.º 1
0
        public async Task UpdateManyTest()
        {
            var list = new List <OrderObjectId>();

            for (var i = 0; i < 10; i++)
            {
                var order = new OrderObjectId {
                    Name = "123"
                };
                list.Add(order);
            }
            await _repository.InsertBatchAsync(list);

            var updater = new UpdateDefinitionBuilder <OrderObjectId>().Set(nameof(OrderObjectId.Name), "456");
            var result  = await _repository.UpdateManyAsync(a => a.Name == "123", updater);

            Assert.IsTrue(result.MatchedCount == 10);
            Assert.IsTrue(result.ModifiedCount == 10);
            var filter   = new FilterDefinitionBuilder <OrderObjectId>().Eq(nameof(OrderObjectId.Name), "456");
            var updater2 = new UpdateDefinitionBuilder <OrderObjectId>().Set(nameof(OrderObjectId.Name), "789");
            var result2  = await _repository.UpdateManyAsync(filter, updater2);

            Assert.IsTrue(result2.MatchedCount == 10);
            Assert.IsTrue(result2.ModifiedCount == 10);
            var result3 = await _repository.UpdateManyAsync(a => a.Name == "789", (bld) => {
                return(bld.Set(nameof(OrderIncId.Name), "012"));
            });

            Assert.IsTrue(result3.MatchedCount == 10);
            Assert.IsTrue(result3.ModifiedCount == 10);
            await _repository.DeleteManyAsync(a => a.Name == "012");
        }
Ejemplo n.º 2
0
        public async Task DeleteOneTest()
        {
            var order = new OrderObjectId {
                Name = Guid.NewGuid().ToString("N")
            };
            await _repository.InsertAsync(order);

            var result = await _repository.DeleteOneAsync(a => a.Name == order.Name);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.DeletedCount > 0);
        }
Ejemplo n.º 3
0
        public async Task ObjectInsertTest()
        {
            var order = new OrderObjectId {
                Name = Guid.NewGuid().ToString("N")
            };
            await _repository.InsertAsync(order);

            var result = await _repository.GetAsync(a => a.Name == order.Name);

            Assert.IsNotNull(result);
            Assert.AreEqual(result.Name, order.Name);
            Assert.IsFalse(string.IsNullOrEmpty(result.ID));
        }
Ejemplo n.º 4
0
        public async Task DeleteOneLambadaTest()
        {
            var order = new OrderObjectId {
                Name = Guid.NewGuid().ToString("N")
            };
            await _repository.InsertAsync(order);

            var filterBld = new FilterDefinitionBuilder <OrderObjectId>();
            var filter    = filterBld.Eq(nameof(OrderObjectId.Name), order.Name);
            var result    = await _repository.DeleteOneAsync(filter);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.DeletedCount > 0);
        }
Ejemplo n.º 5
0
        public async Task FindOneAndDeleteLambadaTest()
        {
            var order = new OrderObjectId {
                Name = Guid.NewGuid().ToString("N")
            };
            await _repository.InsertAsync(order);

            var getResult = await _repository.GetAsync(a => a.Name == order.Name);

            Assert.IsNotNull(getResult);
            var result = await _repository.FindOneAndDeleteAsync(a => a.ID == getResult.ID);

            Assert.IsNotNull(result);
            Assert.AreEqual(result.ID, getResult.ID);
            var deleteResult = await _repository.GetAsync(a => a.ID == getResult.ID);

            Assert.IsNull(deleteResult);
        }
Ejemplo n.º 6
0
        public async Task FindOneAndDeleteTest()
        {
            var order = new OrderObjectId {
                Name = Guid.NewGuid().ToString("N")
            };
            await _repository.InsertAsync(order);

            var getResult = await _repository.GetAsync(a => a.Name == order.Name);

            Assert.IsNotNull(getResult);
            var filterBld = new FilterDefinitionBuilder <OrderObjectId>();
            var filter    = filterBld.Eq(nameof(OrderObjectId.ID), getResult.ID);
            var result    = await _repository.FindOneAndDeleteAsync(filter);

            Assert.IsNotNull(result);
            Assert.AreEqual(result.ID, getResult.ID);
            var deleteResult = await _repository.GetAsync(filter);

            Assert.IsNull(deleteResult);
        }
Ejemplo n.º 7
0
        public async Task FindOneAndUpdateLambadaTest()
        {
            var order = new OrderObjectId {
                Name = Guid.NewGuid().ToString("N")
            };
            await _repository.InsertAsync(order);

            var getResult = await _repository.GetAsync(a => a.Name == order.Name);

            Assert.IsNotNull(getResult);
            var id      = Guid.NewGuid().ToString("N");
            var updater = new UpdateDefinitionBuilder <OrderObjectId>().Set(nameof(OrderObjectId.Name), id);
            var result  = await _repository.FindOneAndUpdateAsync(a => a.ID == getResult.ID, updater);

            Assert.IsNotNull(result);
            Assert.AreEqual(result.Name, order.Name);
            var newResult = await _repository.GetAsync(a => a.ID == getResult.ID);

            Assert.AreEqual(newResult.Name, id);
            await _repository.DeleteOneAsync(getResult.ID);
        }
Ejemplo n.º 8
0
        public async Task InsertBatchTest()
        {
            var list = new List <OrderObjectId>();

            for (var i = 0; i < 10; i++)
            {
                var order = new OrderObjectId {
                    Name = "123"
                };
                list.Add(order);
            }
            await _repository.InsertBatchAsync(list);

            var result = await _repository.GetListAsync(a => a.Name == "123");

            var filter  = new FilterDefinitionBuilder <OrderObjectId>().Eq(nameof(OrderObjectId.Name), "123");
            var result2 = await _repository.GetListAsync(filter);

            Assert.IsTrue(result.Count > 0);
            Assert.IsTrue(result2.Count > 0);
            await _repository.DeleteManyAsync(a => a.Name == "123");
        }