public void InMemoryStoreUpdateTest() { var user = new Data.Entities.User { LastName ="Update", FirstName = "FirstName " + DateTime.Now.ToString() }; UnitOfWork unit = new UnitOfWork(store); unit.UserRepository.Insert(user); unit.Save(); unit = new UnitOfWork(store); var datauser = unit.UserRepository.GetByID(user.Id); Assert.IsNotNull(datauser); Assert.AreEqual(datauser.FirstName, user.FirstName); var firstNameUpdated = "FirstName updated"; datauser.FirstName = firstNameUpdated; unit.UserRepository.Update(datauser); unit.Save(); unit = new UnitOfWork(store); datauser = unit.UserRepository.GetByID(user.Id); Assert.IsNotNull(datauser); Assert.AreEqual(datauser.FirstName, firstNameUpdated); unit.UserRepository.Delete(user); unit.Save(); }
public void CacheStoreDeleteTest() { var user = new Data.Entities.User { LastName = "Delete", FirstName = "FirstName " + DateTime.Now.ToString() }; UnitOfWork unit = new UnitOfWork(store); unit.UserRepository.Insert(user); unit.Save(); unit = new UnitOfWork(store); unit.UserRepository.Delete(user.Id); unit.Save(); unit = new UnitOfWork(store); var datauser = unit.UserRepository.GetByID(user.Id); Assert.IsNull(datauser); }
public void MongoDbStoreInsertTest() { var user=new Data.Entities.User { LastName = "Insert", FirstName = "FirstName "+DateTime.Now.ToString() }; UnitOfWork unit = new UnitOfWork(store); unit.UserRepository.Insert(user); unit.Save(); unit = new UnitOfWork(store); var datauser=unit.UserRepository.GetByID(user.Id); Assert.IsNotNull(datauser); Assert.AreEqual(datauser.FirstName, user.FirstName); unit.UserRepository.Delete(user); unit.Save(); }
static void Main(string[] args) { var unit = new UnitOfWork(new Context()); //new Context(new InMemoryStoreStrategy()) //INSERT Console.WriteLine("INSERT PAUL"); unit.UserRepository.Insert(new User() { UserName = "******", FirstName = "Paul", LastName = "Mizel", Birthday = new DateTime(1980, 4, 1) }); Console.WriteLine("INSERT FABIAN"); unit.UserRepository.Insert(new User() { UserName = "******", FirstName = "Fabian", LastName = "Raetz", Birthday = new DateTime(1989, 4, 1) }); unit.Save(); Console.WriteLine("GET ALL"); var users = unit.UserRepository.Get(); //GET ALL foreach (var user in users) { Console.WriteLine("{0} {1} ({2})", user.FirstName, user.LastName, user.UserName); } Console.WriteLine("GET Youngest"); var youngest = unit.UserRepository.Get(orderBy: o => o.OrderByDescending(i => i.Birthday)).First(); Console.WriteLine("{0} {1} ({2}) - {3:dd.MM.yyyy}", youngest.FirstName, youngest.LastName, youngest.UserName, youngest.Birthday); Console.WriteLine("GET PAULs"); users = unit.UserRepository.Get(f => f.FirstName == "Paul"); //GET ALL foreach (var user in users) { Console.WriteLine("{0} {1} ({2})", user.FirstName, user.LastName, user.UserName); } Console.WriteLine("UPDATE PAULs to PABLOs"); foreach (var user in users) { user.FirstName = "Pablo"; unit.UserRepository.Update(user); } unit.Save(); Console.WriteLine("GET ALL"); users = unit.UserRepository.Get(); //GET ALL foreach (var user in users) { Console.WriteLine("{0} {1} ({2})", user.FirstName, user.LastName, user.UserName); } //DELETE ALL Console.WriteLine("DELETE ALL"); unit.UserRepository.Delete(unit.UserRepository.Get()); users = unit.UserRepository.Get(); foreach (var user in users) { Console.WriteLine("{0} {1} ({2})", user.FirstName, user.LastName, user.UserName); } unit.Save(); Console.ReadKey(); }
public void XmlStoreUpdateDisconnectedTest() { var expected = "UpdatedLastname"; var id = Guid.NewGuid(); var user = new Data.Entities.User { Id = id, LastName = "New", FirstName = "FirstName " + DateTime.Now.ToString() }; UnitOfWork unit = new UnitOfWork(store); unit.UserRepository.Insert(user); unit.Save(); user = new Data.Entities.User { Id = id, LastName = expected, FirstName = "FirstName " + DateTime.Now.ToString() }; unit.UserRepository.Update(user); unit.Save(); user = unit.UserRepository.GetByID(id); Assert.IsNotNull(user); Assert.AreEqual(user.LastName, expected); }