public void AddManyTest() { var p1 = new Person() { FirstName = "Person1_First", LastName = "AddMany", Email = "*****@*****.**" }; var p2 = new Person() { FirstName = "Person2_First", LastName = "AddMany", Email = "*****@*****.**" }; var p3 = new Person() { FirstName = "Person3_First", LastName = "AddMany", Email = "*****@*****.**" }; var pList = new List <Person>() { p1, p2, p3 }; using (_context = new AllTheSameDbContext()) { using (_personRepository = new PersonRepository(_context)) { //add many _personRepository.AddMany(pList.ToArray()); var list = _personRepository.FindBy(p => p.LastName == "AddMany"); list = list.ToList(); var found = list.Count() >= 3; Assert.IsTrue(found); } } }
// IDataStorageProvider /////////////////////////////////////////////////////////////////// public void Save(PersonDto[] persons) { var personsDb = _mapper.Map <PersonDb[]>(persons); _personRepository.CleanCollection(); _personRepository.AddMany(personsDb); }
public void RemoveManyTest() { var p1 = new Person() { FirstName = "Person1_First", LastName = "RemoveMany", Email = "*****@*****.**", UpdatedOn = DateTime.UtcNow }; var p2 = new Person() { FirstName = "Person2_First", LastName = "RemoveMany", Email = "*****@*****.**", UpdatedOn = DateTime.UtcNow }; var p3 = new Person() { FirstName = "Person3_First", LastName = "RemoveMany", Email = "*****@*****.**", UpdatedOn = DateTime.UtcNow }; var pList = new List <Person>() { p1, p2, p3 }; using (_context = new AllTheSameDbContext()) { using (_personRepository = new PersonRepository(_context)) { //add RemoveMany, so we can actually remove them _personRepository.AddMany(pList.ToArray()); Thread.Sleep(2000); var list = _personRepository.GetAll(); var initialCount = list.Count(); list = _personRepository.FindBy(p => p.LastName == "RemoveMany"); list = list.ToList(); var found = list.Count() >= 3; Assert.IsTrue(found); _personRepository.RemoveMany(pList.ToArray()); list = _personRepository.GetAll(); var afterCount = list.Count(); Assert.IsTrue(initialCount > afterCount); } } }