public void PetaPoco_Add_Inserts_Item() { //Arrange DataUtil.SetUpDatabase(Constants.PETAPOCO_RecordCount); var dog = new Dog { Age = Constants.PETAPOCO_InsertDogAge, Name = Constants.PETAPOCO_InsertDogName }; using (var dataContext = new PetaPocoDataContext(ConnectionStringName)) { IRepository<Dog> dogRepository = dataContext.GetRepository<Dog>(); //Act dogRepository.Insert(dog); } //Assert int actualCount = DataUtil.GetRecordCount(Constants.PETAPOCO_DatabaseName, Constants.PETAPOCO_DogTableName); Assert.AreEqual(Constants.PETAPOCO_RecordCount + 1, actualCount); }
public void PetaPocoRepository_Update_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); 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_Update_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); var dog = new Dog { ID = Constants.PETAPOCO_UpdateDogId, Age = Constants.PETAPOCO_UpdateDogAge, Name = Constants.PETAPOCO_UpdateDogName }; //Act repository.Update(dog); //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_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_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 PetaPoco_Update_Updates_Item() { //Arrange DataUtil.SetUpDatabase(Constants.PETAPOCO_RecordCount); var dog = new Dog { ID = Constants.PETAPOCO_UpdateDogId, Age = Constants.PETAPOCO_UpdateDogAge, Name = Constants.PETAPOCO_UpdateDogName }; //Act using (var dataContext = new PetaPocoDataContext(ConnectionStringName)) { IRepository<Dog> dogRepository = dataContext.GetRepository<Dog>(); //Act dogRepository.Update(dog); } //Assert DataTable table = DataUtil.GetTable(Constants.PETAPOCO_DatabaseName, Constants.PETAPOCO_DogTableName); Assert.AreEqual(Constants.PETAPOCO_RecordCount, table.Rows.Count); foreach (DataRow row in table.Rows) { if ((int) row["ID"] == Constants.PETAPOCO_UpdateDogId) { Assert.AreEqual(row["Age"], Constants.PETAPOCO_UpdateDogAge); Assert.AreEqual(row["Name"], Constants.PETAPOCO_UpdateDogName); } } }