public IDataSession GetDataSession(string connectionDetails) { PetaPocoRepository repository = null; if (string.IsNullOrEmpty(connectionDetails)) { throw new Exception("No connection details have been specified when requesting a data repository"); } else { repository = new PetaPocoRepository(connectionDetails); return repository; } }
public void PetaPocoRepository_Delete_Overload_Deletes_Item_From_DataBase_With_Correct_ID() { //Arrange var db = CreatePecaPocoDatabase(); var mapper = new PetaPocoMapper(String.Empty); DataUtil.SetUpDatabase(Constants.PETAPOCO_RecordCount); var repository = new PetaPocoRepository <Dog>(db, mapper); //Act repository.Delete("WHERE ID = @0", Constants.PETAPOCO_DeleteDogId); //Assert DataTable table = DataUtil.GetTable(Constants.PETAPOCO_DatabaseName, Constants.PETAPOCO_DogTableName); foreach (DataRow row in table.Rows) { Assert.IsFalse((int)row[Constants.TABLENAME_Key] == Constants.PETAPOCO_DeleteDogId); } }
public void PetaPocoRepository_Add_Inserts_Item_Into_DataBase() { //Arrange var mockCache = new Mock<ICacheProvider>(); SetUpDatabase(TestConstants.PETAPOCO_RecordCount); var repository = new PetaPocoRepository<Dog>(_petaPocoUnitOfWork, mockCache.Object); var dog = new Dog { Age = TestConstants.PETAPOCO_InsertDogAge, Name = TestConstants.PETAPOCO_InsertDogName }; //Act repository.Add(dog); //Assert int actualCount = DataUtil.GetRecordCount(TestConstants.PETAPOCO_DatabaseName, TestConstants.PETAPOCO_TableName); Assert.AreEqual(TestConstants.PETAPOCO_RecordCount + 1, actualCount); }
public void PetaPocoRepository_GetById_Returns_Null_If_InValid_Id_Using_FluentMapper() { //Arrange var db = CreatePecaPocoDatabase(); var mapper = new FluentMapper <Dog>(String.Empty); mapper.TableName(Constants.PETAPOCO_DogTableName); mapper.PrimaryKey("ID"); mapper.Property(d => d.ID, "ID"); mapper.Property(d => d.Age, "Age"); mapper.Property(d => d.Name, "Name"); DataUtil.SetUpDatabase(Constants.PETAPOCO_RecordCount); var repository = new PetaPocoRepository <Dog>(db, mapper); //Act var dog = repository.GetById(Constants.PETAPOCO_InvalidDogId); //Assert Assert.IsNull(dog); }
public void PetaPocoRepository_Add_Inserts_Item_Into_DataBase_With_Correct_ID() { //Arrange var mockCache = new Mock <ICacheProvider>(); SetUpDatabase(TestConstants.PETAPOCO_RecordCount); var repository = new PetaPocoRepository <Dog>(_petaPocoUnitOfWork, mockCache.Object); var dog = new Dog { Age = TestConstants.PETAPOCO_InsertDogAge, Name = TestConstants.PETAPOCO_InsertDogName }; //Act repository.Add(dog); //Assert int newId = DataUtil.GetLastAddedRecordID(TestConstants.PETAPOCO_DatabaseName, TestConstants.PETAPOCO_TableName, "ID"); Assert.AreEqual(TestConstants.PETAPOCO_RecordCount + 1, newId); }
public void PetaPocoRepository_Get_Returns_Models_With_Correct_Properties_Using_FluentMapper() { //Arrange var db = CreatePecaPocoDatabase(); var mapper = new FluentMapper <Dog>(String.Empty); mapper.TableName(Constants.PETAPOCO_DogTableName); mapper.Property(d => d.Age, "Age"); mapper.Property(d => d.Name, "Name"); DataUtil.SetUpDatabase(Constants.PETAPOCO_RecordCount); var repository = new PetaPocoRepository <Dog>(db, mapper); //Act var dogs = repository.Get(); //Assert var dog = dogs.First(); Assert.AreEqual(_dogAges[0], dog.Age.ToString()); Assert.AreEqual(_dogNames[0], dog.Name); }
public void PetaPocoRepository_GetById_Returns_Model_With_Correct_Properties_Using_FluentMapper() { //Arrange var db = CreatePecaPocoDatabase(); var mapper = new FluentMapper <Dog>(String.Empty); mapper.TableName(Constants.PETAPOCO_DogTableName); mapper.PrimaryKey("ID"); mapper.Property(d => d.ID, "ID"); mapper.Property(d => d.Age, "Age"); mapper.Property(d => d.Name, "Name"); DataUtil.SetUpDatabase(Constants.PETAPOCO_RecordCount); var repository = new PetaPocoRepository <Dog>(db, mapper); //Act var dog = repository.GetById(Constants.PETAPOCO_ValidDogId); //Assert Assert.AreEqual(Constants.PETAPOCO_ValidDogAge, dog.Age); Assert.AreEqual(Constants.PETAPOCO_ValidDogName, dog.Name); }
public void PetaPocoRepository_Add_Inserts_Item_Into_DataBase_With_Correct_ColumnValues() { //Arrange var mockCache = new Mock<ICacheProvider>(); SetUpDatabase(TestConstants.PETAPOCO_RecordCount); var repository = new PetaPocoRepository<Dog>(_pecaPocoDb, mockCache.Object); var dog = new Dog { Age = TestConstants.PETAPOCO_InsertDogAge, Name = TestConstants.PETAPOCO_InsertDogName }; //Act repository.Add(dog); //Assert DataTable table = DataUtil.GetTable(TestConstants.PETAPOCO_DatabaseName, TestConstants.PETAPOCO_TableName); DataRow row = table.Rows[table.Rows.Count - 1]; Assert.AreEqual(TestConstants.PETAPOCO_InsertDogAge, row["Age"]); Assert.AreEqual(TestConstants.PETAPOCO_InsertDogName, row["Name"]); }
public void PetaPocoRepository_Update_Updates_Item_With_Correct_ID_Using_FluentMapper() { //Arrange var db = CreatePecaPocoDatabase(); var mapper = new FluentMapper <Dog>(String.Empty); mapper.TableName(Constants.PETAPOCO_DogTableName); mapper.PrimaryKey("ID"); mapper.Property(d => d.ID, "ID"); mapper.Property(d => d.Age, "Age"); mapper.Property(d => d.Name, "Name"); DataUtil.SetUpDatabase(Constants.PETAPOCO_RecordCount); var repository = new PetaPocoRepository <Dog>(db, mapper); var dog = new Dog { ID = Constants.PETAPOCO_UpdateDogId, Age = Constants.PETAPOCO_UpdateDogAge, Name = Constants.PETAPOCO_UpdateDogName }; //Act repository.Update(dog); //Assert DataTable table = DataUtil.GetTable(Constants.PETAPOCO_DatabaseName, Constants.PETAPOCO_DogTableName); foreach (DataRow row in table.Rows) { if ((int)row[Constants.TABLENAME_Key] == Constants.PETAPOCO_UpdateDogId) { Assert.AreEqual(Constants.PETAPOCO_UpdateDogAge, row["Age"]); Assert.AreEqual(Constants.PETAPOCO_UpdateDogName, row["Name"]); } } }
public void PetaPocoRepository_Add_Inserts_Item_Into_DataBase_With_Correct_ID() { //Arrange var db = CreatePecaPocoDatabase(); var mapper = new PetaPocoMapper(String.Empty); DataUtil.SetUpDatabase(Constants.PETAPOCO_RecordCount); var repository = new PetaPocoRepository <Dog>(db, mapper); var dog = new Dog { Age = Constants.PETAPOCO_InsertDogAge, Name = Constants.PETAPOCO_InsertDogName }; //Act repository.Insert(dog); //Assert int newId = DataUtil.GetLastAddedRecordID(Constants.PETAPOCO_DatabaseName, Constants.PETAPOCO_DogTableName, Constants.TABLENAME_Key); Assert.AreEqual(Constants.PETAPOCO_RecordCount + 1, newId); }
public void PetaPocoRepository_Update_Updates_Item_In_DataBase() { //Arrange var mockCache = new Mock <ICacheProvider>(); SetUpDatabase(TestConstants.PETAPOCO_RecordCount); var repository = new PetaPocoRepository <Dog>(_petaPocoUnitOfWork, mockCache.Object); var dog = new Dog { ID = TestConstants.PETAPOCO_UpdateDogId, Age = TestConstants.PETAPOCO_UpdateDogAge, Name = TestConstants.PETAPOCO_UpdateDogName }; //Act repository.Update(dog); //Assert int actualCount = DataUtil.GetRecordCount(TestConstants.PETAPOCO_DatabaseName, TestConstants.PETAPOCO_TableName); Assert.AreEqual(TestConstants.PETAPOCO_RecordCount, actualCount); }
public void PetaPocoRepository_Add_Inserts_Item_Into_DataBase() { //Arrange var db = CreatePecaPocoDatabase(); var mapper = new PetaPocoMapper(String.Empty); DataUtil.SetUpDatabase(Constants.PETAPOCO_RecordCount); var repository = new PetaPocoRepository <Dog>(db, mapper); var dog = new Dog { Age = Constants.PETAPOCO_InsertDogAge, Name = Constants.PETAPOCO_InsertDogName }; //Act repository.Insert(dog); //Assert int actualCount = DataUtil.GetRecordCount(Constants.PETAPOCO_DatabaseName, Constants.PETAPOCO_DogTableName); Assert.AreEqual(Constants.PETAPOCO_RecordCount + 1, actualCount); }
public void PetaPocoRepository_Add_Inserts_Item_Into_DataBase_With_Correct_ColumnValues() { //Arrange var mockCache = new Mock <ICacheProvider>(); SetUpDatabase(TestConstants.PETAPOCO_RecordCount); var repository = new PetaPocoRepository <Dog>(_petaPocoUnitOfWork, mockCache.Object); var dog = new Dog { Age = TestConstants.PETAPOCO_InsertDogAge, Name = TestConstants.PETAPOCO_InsertDogName }; //Act repository.Add(dog); //Assert DataTable table = DataUtil.GetTable(TestConstants.PETAPOCO_DatabaseName, TestConstants.PETAPOCO_TableName); DataRow row = table.Rows[table.Rows.Count - 1]; Assert.AreEqual(TestConstants.PETAPOCO_InsertDogAge, row["Age"]); Assert.AreEqual(TestConstants.PETAPOCO_InsertDogName, row["Name"]); }
public void PetaPocoRepository_GetPage_Returns_Correct_Page(int pageIndex, int pageSize, int firstId) { //Arrange var mockCache = new Mock<ICacheProvider>(); SetUpDatabase(TestConstants.PAGE_TotalCount); var repository = new PetaPocoRepository<Dog>(_petaPocoUnitOfWork, mockCache.Object); //Act var dogs = repository.GetPage(pageIndex, pageSize); //Assert var dog = dogs.First(); Assert.AreEqual(firstId, dog.ID); }
public void PetaPocoRepository_GetById_Returns_Null_If_InValid_Id() { //Arrange var mockCache = new Mock<ICacheProvider>(); SetUpDatabase(5); var repository = new PetaPocoRepository<Dog>(_petaPocoUnitOfWork, mockCache.Object); //Act var dog = repository.GetById(TestConstants.PETAPOCO_InvalidDogId); //Assert Assert.IsNull(dog); }
public void PetaPocoRepository_GetByProperty_Returns_List_Of_Models_If_Valid_Property(string dogName, int count) { //Arrange var mockCache = new Mock<ICacheProvider>(); SetUpDatabase(5); var repository = new PetaPocoRepository<Dog>(_petaPocoUnitOfWork, mockCache.Object); //Act var dogs = repository.GetByProperty("Name", dogName); //Assert Assert.IsInstanceOf<IEnumerable<Dog>>(dogs); Assert.AreEqual(count, dogs.Count()); }
public void PetaPocoRepository_Update_Overload_Updates_Item_With_Correct_ID() { //Arrange var db = CreatePecaPocoDatabase(); var mapper = new PetaPocoMapper(String.Empty); DataUtil.SetUpDatabase(Constants.PETAPOCO_RecordCount); var repository = new PetaPocoRepository<Dog>(db, mapper); //Act repository.Update("SET Age=@1, Name=@2 WHERE ID=@0", Constants.PETAPOCO_UpdateDogId, Constants.PETAPOCO_UpdateDogAge, Constants.PETAPOCO_UpdateDogName); //Assert DataTable table = DataUtil.GetTable(Constants.PETAPOCO_DatabaseName, Constants.PETAPOCO_DogTableName); foreach (DataRow row in table.Rows) { if ((int)row[Constants.TABLENAME_Key] == Constants.PETAPOCO_UpdateDogId) { Assert.AreEqual(Constants.PETAPOCO_UpdateDogAge, row["Age"]); Assert.AreEqual(Constants.PETAPOCO_UpdateDogName, row["Name"]); } } }
public void PetaPocoRepository_GetPage_Overload_Returns_Correct_Page(int pageIndex, int pageSize, int firstId) { //Arrange var db = CreatePecaPocoDatabase(); var mapper = new PetaPocoMapper(String.Empty); DataUtil.SetUpDatabase(Constants.PAGE_TotalCount); var repository = new PetaPocoRepository<Dog>(db, mapper); //Act var dogs = repository.GetPage(pageIndex, pageSize); //Assert var dog = dogs.First(); Assert.AreEqual(firstId, dog.ID); }
public void PetaPocoRepository_GetPage_Overload_Returns_List_Of_Models() { //Arrange var db = CreatePecaPocoDatabase(); var mapper = new PetaPocoMapper(String.Empty); DataUtil.SetUpDatabase(Constants.PAGE_TotalCount); var repository = new PetaPocoRepository<Dog>(db, mapper); //Act var dogs = repository.GetPage(Constants.PAGE_First, Constants.PAGE_RecordCount); //Assert for (int i = 0; i < dogs.Count(); i++) { Assert.IsInstanceOf<Dog>(dogs[i]); } }
public void PetaPocoRepository_GetByProperty_Returns_Instance_Of_Model_If_Valid_Property() { //Arrange var mockCache = new Mock<ICacheProvider>(); SetUpDatabase(5); var dogName = _dogNames[2]; var repository = new PetaPocoRepository<Dog>(_petaPocoUnitOfWork, mockCache.Object); //Act var dog = repository.GetByProperty("Name", dogName).FirstOrDefault(); //Assert Assert.IsInstanceOf<Dog>(dog); }
public void PetaPocoRepository_GetByProperty_Returns_Empty_List_If_InValid_Proeprty() { //Arrange var mockCache = new Mock<ICacheProvider>(); SetUpDatabase(5); const string dogName = "Invalid"; var repository = new PetaPocoRepository<Dog>(_petaPocoUnitOfWork, mockCache.Object); //Act var dogs = repository.GetByProperty("Name", dogName); //Assert Assert.IsInstanceOf<IEnumerable<Dog>>(dogs); Assert.AreEqual(0, dogs.Count()); }
public void PetaPocoRepository_GetByProperty_Returns_Models_With_Correct_Properties(string dogName) { //Arrange var mockCache = new Mock<ICacheProvider>(); SetUpDatabase(5); var repository = new PetaPocoRepository<Dog>(_petaPocoUnitOfWork, mockCache.Object); //Act var dogs = repository.GetByProperty("Name", dogName); //Assert foreach (Dog dog in dogs) { Assert.AreEqual(dogName, dog.Name); } }
public void PetaPocoRepository_GetPage_Returns_List_Of_Models() { //Arrange var mockCache = new Mock<ICacheProvider>(); SetUpDatabase(TestConstants.PAGE_TotalCount); var repository = new PetaPocoRepository<Dog>(_petaPocoUnitOfWork, mockCache.Object); //Act var dogs = repository.GetPage(TestConstants.PAGE_First, TestConstants.PAGE_RecordCount); //Assert for (int i = 0; i < dogs.Count(); i++) { Assert.IsInstanceOf<Dog>(dogs[i]); } }
public void PetaPocoRepository_Update_Updates_Item_With_Correct_ID() { //Arrange var mockCache = new Mock<ICacheProvider>(); SetUpDatabase(TestConstants.PETAPOCO_RecordCount); var repository = new PetaPocoRepository<Dog>(_petaPocoUnitOfWork, mockCache.Object); var dog = new Dog { ID = TestConstants.PETAPOCO_UpdateDogId, Age = TestConstants.PETAPOCO_UpdateDogAge, Name = TestConstants.PETAPOCO_UpdateDogName }; //Act repository.Update(dog); //Assert DataTable table = DataUtil.GetTable(TestConstants.PETAPOCO_DatabaseName, TestConstants.PETAPOCO_TableName); foreach (DataRow row in table.Rows) { if ((int)row["ID"] == TestConstants.PETAPOCO_UpdateDogId) { Assert.AreEqual(TestConstants.PETAPOCO_UpdateDogAge, row["Age"]); Assert.AreEqual(TestConstants.PETAPOCO_UpdateDogName, row["Name"]); } } }
public void PetaPocoRepository_Delete_Overload_Does_Nothing_With_Invalid_ID() { //Arrange var db = CreatePecaPocoDatabase(); var mapper = new PetaPocoMapper(String.Empty); DataUtil.SetUpDatabase(Constants.PETAPOCO_RecordCount); var repository = new PetaPocoRepository<Dog>(db, mapper); //Act repository.Delete("WHERE ID = @0", Constants.PETAPOCO_InvalidDogId); //Assert int actualCount = DataUtil.GetRecordCount(Constants.PETAPOCO_DatabaseName, Constants.PETAPOCO_DogTableName); Assert.AreEqual(Constants.PETAPOCO_RecordCount, actualCount); }
public void PetaPocoRepository_Get_Returns_All_Rows(int count) { //Arrange var db = CreatePecaPocoDatabase(); var mapper = new PetaPocoMapper(String.Empty); DataUtil.SetUpDatabase(count); var repository = new PetaPocoRepository<Dog>(db, mapper); //Act IEnumerable<Dog> dogs = repository.Get(); //Assert Assert.AreEqual(count, dogs.Count()); }
public void PetaPocoRepository_Find_Returns_Correct_Rows(int count, string sqlCondition, object arg) { //Arrange var db = CreatePecaPocoDatabase(); var mapper = new PetaPocoMapper(String.Empty); DataUtil.SetUpDatabase(Constants.PETAPOCO_RecordCount); var repository = new PetaPocoRepository<Dog>(db, mapper); //Act IEnumerable<Dog> dogs = repository.Find(sqlCondition, arg); //Assert Assert.AreEqual(count, dogs.Count()); }
public void PetaPocoRepository_GetAll_Returns_All_Rows(int count) { //Arrange var mockCache = new Mock<ICacheProvider>(); SetUpDatabase(count); var repository = new PetaPocoRepository<Dog>(_petaPocoUnitOfWork, mockCache.Object); //Act IEnumerable<Dog> dogs = repository.GetAll(); //Assert Assert.AreEqual(count, dogs.Count()); }
public void PetaPocoRepository_GetPage_Overload_Returns_Models_With_Correct_Properties() { //Arrange var db = CreatePecaPocoDatabase(); var mapper = new PetaPocoMapper(String.Empty); DataUtil.SetUpDatabase(Constants.PAGE_TotalCount); var repository = new PetaPocoRepository<Dog>(db, mapper); //Act var dogs = repository.GetPage(Constants.PAGE_First, Constants.PAGE_RecordCount); //Assert var dog = dogs.First(); Assert.AreEqual(_dogAges[0], dog.Age.ToString()); Assert.AreEqual(_dogNames[0], dog.Name); }
public void PetaPocoRepository_GetById_Returns_Model_With_Correct_Properties() { //Arrange var db = CreatePecaPocoDatabase(); var mapper = new PetaPocoMapper(String.Empty); DataUtil.SetUpDatabase(Constants.PETAPOCO_RecordCount); var repository = new PetaPocoRepository<Dog>(db, mapper); //Act var dog = repository.GetById(Constants.PETAPOCO_ValidDogId); //Assert Assert.AreEqual(Constants.PETAPOCO_ValidDogAge, dog.Age); Assert.AreEqual(Constants.PETAPOCO_ValidDogName, dog.Name); }
public void PetaPocoRepository_Update_Overload_Updates_Item_In_DataBase() { //Arrange var db = CreatePecaPocoDatabase(); var mapper = new PetaPocoMapper(String.Empty); DataUtil.SetUpDatabase(Constants.PETAPOCO_RecordCount); var repository = new PetaPocoRepository<Dog>(db, mapper); //Act repository.Update("SET Age=@1, Name=@2 WHERE ID=@0", Constants.PETAPOCO_UpdateDogId, Constants.PETAPOCO_UpdateDogAge, Constants.PETAPOCO_UpdateDogName); //Assert int actualCount = DataUtil.GetRecordCount(Constants.PETAPOCO_DatabaseName, Constants.PETAPOCO_DogTableName); Assert.AreEqual(Constants.PETAPOCO_RecordCount, actualCount); }
public void PetaPocoRepository_Add_Inserts_Item_Into_DataBase_With_Correct_ID() { //Arrange var db = CreatePecaPocoDatabase(); var mapper = new PetaPocoMapper(String.Empty); DataUtil.SetUpDatabase(Constants.PETAPOCO_RecordCount); var repository = new PetaPocoRepository<Dog>(db, mapper); var dog = new Dog { Age = Constants.PETAPOCO_InsertDogAge, Name = Constants.PETAPOCO_InsertDogName }; //Act repository.Insert(dog); //Assert int newId = DataUtil.GetLastAddedRecordID(Constants.PETAPOCO_DatabaseName, Constants.PETAPOCO_DogTableName, Constants.TABLENAME_Key); Assert.AreEqual(Constants.PETAPOCO_RecordCount + 1, newId); }
public void PetaPocoRepository_Constructor_Registers_Mapper() { //Arrange var mockMapper = new Mock<IMapper>(); var db = new Database(connectionStringName); //Act #pragma warning disable 168 var repo = new PetaPocoRepository<Dog>(db, mockMapper.Object); #pragma warning restore 168 //Assert Assert.AreSame(mockMapper.Object, Mappers.GetMapper(typeof(Dog))); }
public void PetaPocoRepository_Add_Inserts_Item_Into_DataBase_With_Correct_ColumnValues() { //Arrange var db = CreatePecaPocoDatabase(); var mapper = new PetaPocoMapper(String.Empty); DataUtil.SetUpDatabase(Constants.PETAPOCO_RecordCount); var repository = new PetaPocoRepository<Dog>(db, mapper); var dog = new Dog { Age = Constants.PETAPOCO_InsertDogAge, Name = Constants.PETAPOCO_InsertDogName }; //Act repository.Insert(dog); //Assert DataTable table = DataUtil.GetTable(Constants.PETAPOCO_DatabaseName, Constants.PETAPOCO_DogTableName); DataRow row = table.Rows[table.Rows.Count - 1]; Assert.AreEqual(Constants.PETAPOCO_InsertDogAge, row["Age"]); Assert.AreEqual(Constants.PETAPOCO_InsertDogName, row["Name"]); }
public void PetaPocoRepository_GetById_Returns_Model_With_Correct_Properties() { //Arrange var mockCache = new Mock<ICacheProvider>(); SetUpDatabase(5); var repository = new PetaPocoRepository<Dog>(_petaPocoUnitOfWork, mockCache.Object); //Act var dog = repository.GetById(TestConstants.PETAPOCO_ValidDogId); //Assert Assert.AreEqual(TestConstants.PETAPOCO_ValidDogAge, dog.Age); Assert.AreEqual(TestConstants.PETAPOCO_ValidDogName, dog.Name); }
public void PetaPocoRepository_Delete_Deletes_Item_From_DataBase() { //Arrange var db = CreatePecaPocoDatabase(); var mapper = new PetaPocoMapper(String.Empty); DataUtil.SetUpDatabase(Constants.PETAPOCO_RecordCount); var repository = new PetaPocoRepository<Dog>(db, mapper); var dog = new Dog { ID = Constants.PETAPOCO_DeleteDogId, Age = Constants.PETAPOCO_DeleteDogAge, Name = Constants.PETAPOCO_DeleteDogName }; //Act repository.Delete(dog); //Assert int actualCount = DataUtil.GetRecordCount(Constants.PETAPOCO_DatabaseName, Constants.PETAPOCO_DogTableName); Assert.AreEqual(Constants.PETAPOCO_RecordCount - 1, actualCount); }
public void PetaPocoRepository_GetAll_Returns_List_Of_Models() { //Arrange var mockCache = new Mock<ICacheProvider>(); SetUpDatabase(5); var repository = new PetaPocoRepository<Dog>(_petaPocoUnitOfWork, mockCache.Object); //Act var dogs = repository.GetAll().ToList(); //Assert for (int i = 0; i < dogs.Count(); i++) { Assert.IsInstanceOf<Dog>(dogs[i]); } }
public void PetaPocoRepository_Delete_Overload_Deletes_Item_From_DataBase_With_Correct_ID() { //Arrange var db = CreatePecaPocoDatabase(); var mapper = new PetaPocoMapper(String.Empty); DataUtil.SetUpDatabase(Constants.PETAPOCO_RecordCount); var repository = new PetaPocoRepository<Dog>(db, mapper); //Act repository.Delete("WHERE ID = @0", Constants.PETAPOCO_DeleteDogId); //Assert DataTable table = DataUtil.GetTable(Constants.PETAPOCO_DatabaseName, Constants.PETAPOCO_DogTableName); foreach (DataRow row in table.Rows) { Assert.IsFalse((int)row[Constants.TABLENAME_Key] == Constants.PETAPOCO_DeleteDogId); } }
public void PetaPocoRepository_GetById_Returns_Null_If_InValid_Id() { //Arrange var db = CreatePecaPocoDatabase(); var mapper = new PetaPocoMapper(String.Empty); DataUtil.SetUpDatabase(Constants.PETAPOCO_RecordCount); var repository = new PetaPocoRepository<Dog>(db, mapper); //Act var dog = repository.GetById(Constants.PETAPOCO_InvalidDogId); //Assert Assert.IsNull(dog); }
public void PetaPocoRepository_GetPage_Returns_Models_With_Correct_Properties() { //Arrange var mockCache = new Mock<ICacheProvider>(); SetUpDatabase(TestConstants.PAGE_TotalCount); var repository = new PetaPocoRepository<Dog>(_petaPocoUnitOfWork, mockCache.Object); //Act var dogs = repository.GetPage(TestConstants.PAGE_First, TestConstants.PAGE_RecordCount); //Assert var dog = dogs.First(); Assert.AreEqual(_dogAges[0], dog.Age.ToString()); Assert.AreEqual(_dogNames[0], dog.Name); }