コード例 #1
0
        public void UpdateManySuccess()
        {
            var models = TestModelFactory.GetModels(5);

            ZaabeeMongoClient.AddRange(models);
            var strings = models.Select(p => p.String);
            var ids     = models.Select(p => p.Id);
            var now     = DateTime.Now;
            var utcNow  = DateTime.UtcNow;
            var name    = Guid.NewGuid().ToString();
            var kids    = new List <TestModel>
            {
                new TestModel {
                    Id = Guid.NewGuid(), DateTime = DateTime.Now, DateTimeUtc = DateTime.UtcNow
                }
            };
            var modifyQuantity = ZaabeeMongoClient.Update(
                () => new TestModel
            {
                DateTime    = now,
                DateTimeUtc = utcNow,
                String      = name,
                KidList     = kids,
                EnumInt     = EnumInt.Banana
            },
                p => strings.Contains(p.String));

            models.ForEach(model =>
            {
                model.DateTime    = now;
                model.DateTimeUtc = utcNow;
                model.String      = name;
                model.KidList     = kids;
                model.EnumInt     = EnumInt.Banana;
            });

            var results = ZaabeeMongoClient.GetQueryable <TestModel>().Where(p => ids.Contains(p.Id)).ToList();

            Assert.Equal(5L, modifyQuantity);
            Assert.Equal(models.OrderBy(p => p.Id).ToList().ToJson(), results.OrderBy(p => p.Id).ToList().ToJson());
        }