public void Update_Should_Update_Multiple_Items(ICompoundKeyRepository <User, string, int> repository) { var users = new List <User> { new User { Username = "******", Age = 11, FullName = "Test User - 11" }, new User { Username = "******", Age = 21, FullName = "Test User - 21" }, new User { Username = "******", Age = 11, FullName = "Test User 2- 11" }, }; repository.Add(users); var items = repository.GetAll().ToList(); items.Count().ShouldBe(3); foreach (var user in users.Take(2)) { user.FullName += "UPDATED"; } repository.Update(users); items = repository.GetAll().ToList(); items.Count(x => x.FullName.EndsWith("UPDATED")).ShouldBe(2); }
public void Delete_Should_Remove_Multiple_Items(ICompoundKeyRepository <User, string, int> repository) { IList <User> users = new List <User> { new User { Username = "******", Age = 11, FullName = "Test User - 11" }, new User { Username = "******", Age = 21, FullName = "Test User - 21" }, new User { Username = "******", Age = 11, FullName = "Test User 2- 11" }, }; repository.Add(users); var items = repository.GetAll().ToList(); items.Count().ShouldBe(3); repository.Delete(users.Take(2)); items = repository.GetAll().ToList(); items.Count().ShouldBe(1); items.First().Username.ShouldBe("Test User 2"); }
public void Add_Should_Result_In_Proper_Total_Items(ICompoundKeyRepository<User, string, int> repository) { repository.Add(new User { Username = "******", Age = 11, FullName = "Test User - 11"}); var result = repository.GetAll(); result.Count().ShouldEqual(1); }
public void Add_InBatchMode_Should_Delay_The_Action(ICompoundKeyRepository<User, string, int> repository) { using (var batch = repository.BeginBatch()) { batch.Add(new User { Username = "******", Age = 11, FullName = "Test User - 11" }); repository.GetAll().Count().ShouldEqual(0); // shouldn't have really been added yet batch.Add(new User { Username = "******", Age = 21, FullName = "Test User - 21" }); repository.GetAll().Count().ShouldEqual(0); // shouldn't have really been added yet batch.Commit(); } repository.GetAll().Count().ShouldEqual(2); }
public void Delete_Should_Remove_Multiple_Items(ICompoundKeyRepository<User, string, int> repository) { IList<User> users = new List<User> { new User { Username = "******", Age = 11, FullName = "Test User - 11" }, new User { Username = "******", Age = 21, FullName = "Test User - 21" }, new User { Username = "******", Age = 11, FullName = "Test User 2- 11" }, }; repository.Add(users); var items = repository.GetAll().ToList(); items.Count().ShouldEqual(3); repository.Delete(users.Take(2)); items = repository.GetAll().ToList(); items.Count().ShouldEqual(1); items.First().Username.ShouldEqual("Test User 2"); }
public void GetAll_With_Selector_Should_Return_Every_Item(ICompoundKeyRepository<User, string, int> repository) { for (var i = 1; i <= 5; i++) { repository.Add(new User { Username = "******" + i, Age = i }); } var result = repository.GetAll(c => c.Username); result.Count().ShouldEqual(5); }
public void Add_Should_Result_In_Proper_Total_Items(ICompoundKeyRepository <User, string, int> repository) { repository.Add(new User { Username = "******", Age = 11, FullName = "Test User - 11" }); var result = repository.GetAll(); result.Count().ShouldBe(1); }
public void Using_TransactionScope_Without_Complete_Should_Not_Add(ICompoundKeyRepository<User, string, int> repository) { repository.Get("test", 1); // used to create the SqlCe database before being inside the transaction scope since that throws an error using (var trans = new TransactionScope()) { repository.Add(new User { Username = "******", Age = 11, FullName = "Test User - 11" }); } repository.GetAll().Count().ShouldEqual(0); }
public void Add_InBatchMode_Should_Delay_The_Action(ICompoundKeyRepository <User, string, int> repository) { using (var batch = repository.BeginBatch()) { batch.Add(new User { Username = "******", Age = 11, FullName = "Test User - 11" }); repository.GetAll().Count().ShouldBe(0); // shouldn't have really been added yet batch.Add(new User { Username = "******", Age = 21, FullName = "Test User - 21" }); repository.GetAll().Count().ShouldBe(0); // shouldn't have really been added yet batch.Commit(); } repository.GetAll().Count().ShouldBe(2); }
public void GetAll_With_Selector_Should_Return_Every_Item(ICompoundKeyRepository <User, string, int> repository) { for (var i = 1; i <= 5; i++) { repository.Add(new User { Username = "******" + i, Age = i }); } var result = repository.GetAll(c => c.Username); result.Count().ShouldBe(5); }
public void GetAll_Should_Return_Every_Item(ICompoundKeyRepository <User, string, int> repository) { for (var i = 1; i <= 5; i++) { repository.Add(new User { Username = "******" + i, Age = i }); } var result = repository.GetAll().ToList(); result.Count().ShouldEqual(5); }
public void Update_Should_Update_Multiple_Items(ICompoundKeyRepository<User, string, int> repository) { var users = new List<User> { new User { Username = "******", Age = 11, FullName = "Test User - 11" }, new User { Username = "******", Age = 21, FullName = "Test User - 21" }, new User { Username = "******", Age = 11, FullName = "Test User 2- 11" }, }; repository.Add(users); var items = repository.GetAll().ToList(); items.Count().ShouldEqual(3); foreach (var user in users.Take(2)) { user.FullName += "UPDATED"; } repository.Update(users); items = repository.GetAll().ToList(); items.Count(x => x.FullName.EndsWith("UPDATED")).ShouldEqual(2); }
public void Using_TransactionScope_Without_Complete_Should_Not_Add(ICompoundKeyRepository <User, string, int> repository) { repository.Get("test", 1); // used to create the SqlCe database before being inside the transaction scope since that throws an error using (var trans = new TransactionScope()) { repository.Add(new User { Username = "******", Age = 11, FullName = "Test User - 11" }); } repository.GetAll().Count().ShouldBe(0); }
public void GetAll_Should_Return_Every_Items_With_Paging(ICompoundKeyRepository<User, string, int> repository) { const int resultingPage = 2; const int pageSize = 2; const int totalItems = 5; var queryOptions = new PagingOptions<User>(resultingPage, pageSize, "Username"); for (var i = 1; i <= totalItems; i++) { repository.Add(new User { Username = "******" + i, Age = i }); } var result = repository.GetAll(queryOptions).ToList(); result.Count().ShouldEqual(pageSize); queryOptions.TotalItems.ShouldEqual(totalItems); result.First().Username.ShouldEqual("Test User 3"); }
public void GetAll_With_Anonymous_Selector_Should_Return_Every_Item(ICompoundKeyRepository<User, string, int> repository) { for (var i = 1; i <= 5; i++) { repository.Add(new User { Username = "******" + i, Age = i }); } var results = repository.GetAll(c => new {c.Username, c.Age}); var total = 0; foreach (var result in results) { result.Username.ShouldStartWith("Test User"); total++; } total.ShouldEqual(5); }
public void GetAll_With_Anonymous_Selector_Should_Return_Every_Item(ICompoundKeyRepository <User, string, int> repository) { for (var i = 1; i <= 5; i++) { repository.Add(new User { Username = "******" + i, Age = i }); } var results = repository.GetAll(c => new { c.Username, c.Age }); var total = 0; foreach (var result in results) { result.Username.ShouldStartWith("Test User"); total++; } total.ShouldBe(5); }
public void GetAll_With_Selector_Should_Return_Every_Items_With_Paging(ICompoundKeyRepository <User, string, int> repository) { const int resultingPage = 2; const int pageSize = 2; const int totalItems = 5; var queryOptions = new PagingOptions <User>(resultingPage, pageSize, "Username"); for (var i = 1; i <= totalItems; i++) { repository.Add(new User { Username = "******" + i, Age = i }); } var result = repository.GetAll(c => c.Username, queryOptions).ToList(); result.Count().ShouldBe(pageSize); queryOptions.TotalItems.ShouldBe(totalItems); result.First().ShouldBe("Test User 3"); }
public IEnumerable <T> GetAll() { return(Repository.GetAll()); }