public void mongo_task_entity_update_by_express_test() { var dateTime = DateTime.Now; var timeSpan = new TimeSpan(1, 1, 1); var task = GetMongoTaskEntity(dateTime, timeSpan); var repo = new MongoTestDB <MongoTaskEntity>(); repo.Insert(task); var id = task.Id; var newTimeSpan = new TimeSpan(3, 3, 3); var newDateTime = dateTime.AddDays(-1); var newName = "newMongoTest"; task.SetUpdate(() => task.TaskEntity.StartTime, newTimeSpan); task.SetUpdate(() => task.TaskStatusEntity.LastRunTime, newDateTime); task.SetUpdate(() => task.Name, newName); repo.Update(p => p.Id == id, task); var updatedTaskList = repo.GetAll(); updatedTaskList.Should().NotBeNull(); var updatedTask = updatedTaskList.FirstOrDefault(); updatedTask.Should().NotBeNull(); updatedTask.TaskEntity.StartTime.Should().Be(newTimeSpan); updatedTask.TaskStatusEntity.LastRunTime.Day.Should().Be(dateTime.AddDays(-1).Day); updatedTask.Name.Should().Be(newName); }
public void mongo_task_entity_update_immediate_test() { var dateTime = DateTime.Now; var timeSpan = new TimeSpan(1, 1, 1); var task = GetMongoTaskEntity(dateTime, timeSpan); var repo = new MongoTestDB <MongoTaskEntity>(); repo.Insert(task); var id = task.Id; var newTimeSpan = new TimeSpan(3, 3, 3); var newDateTime = dateTime.AddDays(-1); var newName = "newMongoTest"; var dic = new Dictionary <string, object>(); dic.Add("TaskEntity.StartTime", newTimeSpan); dic.Add("TaskStatusEntity.LastRunTime", newDateTime); dic.Add("Name", newName); repo.Update(p => p.Id == id, dic); //var updatedTask = repo.GetAll().First(); var updatedTask = repo.GetByKey(id); updatedTask.TaskEntity.StartTime.Should().Be(newTimeSpan); updatedTask.TaskStatusEntity.LastRunTime.Day.Should().Be(dateTime.AddDays(-1).Day); updatedTask.Name.Should().Be(newName); }
public void mongo_add_and_update_test() { var customerRepo = new MongoTestDB <Customer>(); var customer = CreateCustomer(); customerRepo.Insert(customer); customer.Id.Should().NotBeNull(); var alreadyAddedCustomer = customerRepo.GetBy(c => c.FirstName == "Bob").Single(); alreadyAddedCustomer.Should().NotBeNull(); alreadyAddedCustomer.FirstName.Should().Be(customer.FirstName); alreadyAddedCustomer.HomeAddress.Address1.Should().Be(customer.HomeAddress.Address1); alreadyAddedCustomer.CreateDate.Should().BeBefore(DateTime.Now); alreadyAddedCustomer.Phone = "10110111"; alreadyAddedCustomer.Email = "*****@*****.**"; customerRepo.Update(alreadyAddedCustomer); var updatedCustomer = customerRepo.GetByKey(customer.Id); updatedCustomer.Should().NotBeNull(); updatedCustomer.Phone.Should().Be(alreadyAddedCustomer.Phone); updatedCustomer.Email.Should().Be(alreadyAddedCustomer.Email); var isExists = customerRepo.Exists(c => c.HomeAddress.Country == "Alaska"); isExists.Should().Be(true); }
public void mongo_update_assign_field() { var customerRepo = new MongoTestDB <Customer>(); var customer = CreateCustomer(); customerRepo.Insert(customer); var updateFields = new Dictionary <string, object>(); updateFields.Add("FirstName", "JiaJia"); updateFields.Add("Phone", "123"); customerRepo.Update(q => q.Id == customer.Id, updateFields); var updatedCustomer = customerRepo.GetByKey(customer.Id); updatedCustomer.FirstName.Should().Be("JiaJia"); updatedCustomer.Phone.Should().Be("123"); }
public void mongo_batch_test() { var customerRepo = new MongoTestDB <Customer>(); var custlist = new List <Customer>(new Customer[] { new Customer() { FirstName = "Customer A" }, new Customer() { FirstName = "Client B" }, new Customer() { FirstName = "Customer C" }, new Customer() { FirstName = "Client D" }, new Customer() { FirstName = "Customer E" }, new Customer() { FirstName = "Client F" }, new Customer() { FirstName = "Customer G" }, }); //Insert batch customerRepo.Insert(custlist); var count = customerRepo.GetAll().Count(); count.Should().Be(7); foreach (Customer c in custlist) { c.Id.Should().NotBe(new string('0', 24)); } //Update batch foreach (Customer c in custlist) { c.LastName = c.FirstName; } customerRepo.Update(custlist); var updateList = customerRepo.GetAll(); foreach (Customer c in updateList) { c.LastName.Should().Be(c.FirstName); } //Delete by criteria customerRepo.Delete(f => f.FirstName.StartsWith("Client")); count = customerRepo.GetAll().Count(); count.Should().Be(4); //Delete specific object customerRepo.Delete(custlist[0]); //Test AsQueryable var selectedcustomers = customerRepo.GetBy( cust => cust.LastName.EndsWith("C") || cust.LastName.EndsWith("G")); selectedcustomers.ToList().Count.Should().Be(2); count = customerRepo.GetAll().Count(); count.Should().Be(3); }