public void DataService_UpdateHeirarchicalTerm_Updates_Record_But_Does_Not_Modify_Other_Terms_If_ParentID_Does_Not_Change() { //Arrange int rowCount = DataUtil.GetRecordCount(DataTestHelper.ConnectionString, ContentDataTestHelper.TermsTableName); DataUtil.AddDatabaseObject(virtualScriptFilePath, updateHeirarchicalTerm); Term term = new Term(4) { TermId = 17, Name = "Test Update", ParentTermId = null, Weight = 0, Description = "Updated" }; DataService ds = new DataService(); //Act ds.UpdateHeirarchicalTerm(term, Constants.USER_ValidId); //Assert DatabaseAssert.RecordCountIsEqual(DataTestHelper.ConnectionString, ContentDataTestHelper.TermsTableName, rowCount); //Assert that electronics terms are untouched //Televisions, Id = 1, Left=12, Right=17 TestTerm(1, 12, 17); //Flash, Id = 9, Left=8, Right=9 TestTerm(9, 8, 9); //Electronics, Id = 12, Left=1, Right=18 TestTerm(12, 1, 18); }
public void DataService_UpdateHeirarchicalTerm_Throws_On_Invalid_VocabularyId() { //Arrange DataUtil.AddDatabaseObject(virtualScriptFilePath, updateHeirarchicalTerm); Term term = ContentTestHelper.CreateValidHeirarchicalTerm(Constants.VOCABULARY_InValidVocabularyId, Constants.TERM_ValidParentTermId); term.TermId = Constants.TERM_UpdateTermId; term.Name = Constants.TERM_UpdateName; term.Weight = Constants.TERM_UpdateWeight; DataService ds = new DataService(); //Act/Assert Assert.Throws<SqlException>(() => ds.UpdateHeirarchicalTerm(term, Constants.USER_ValidId)); }
public void DataService_UpdateHeirarchicalTerm_Updates_Records_On_Change_Parent_To_Sibling_Of_Parent() { //Arrange int rowCount = DataUtil.GetRecordCount(DataTestHelper.ConnectionString, ContentDataTestHelper.TermsTableName); DataUtil.AddDatabaseObject(virtualScriptFilePath, updateHeirarchicalTerm); Term term = new Term(2) { TermId = 6, Name = "MP3 Players", ParentTermId = 12 /*Electronics*/, Weight = 0, Description = "MP3 Players" }; DataService ds = new DataService(); //Act ds.UpdateHeirarchicalTerm(term, Constants.USER_ValidId); //Assert DatabaseAssert.RecordCountIsEqual(DataTestHelper.ConnectionString, ContentDataTestHelper.TermsTableName, rowCount); //Assert that existing terms are correct //Televisions, Id = 1, Left=12, Right=17 - should be Left=12, Right=17 TestTerm(1, 12, 17); //2-Way, Id = 8, Left=3, Right=4 - should be Left=7, Right=8 TestTerm(8, 7, 8); //Electronics, Id = 12, Left=1, Right=18 - should be Left=1, Right=18 TestTerm(12, 1, 18); //MP3 Players, Id = 6, Left=7, Right=10 - should be Left=2, Right=5 TestTerm(6, 2, 5); //Flash Players, Id = 9, Left=8, Right=9 - should be Left=3, Right=4 TestTerm(9, 3, 4); }
public void DataService_UpdateHeirarchicalTerm_Does_Nothing_On_InValid_Term() { //Arrange int rowCount = DataUtil.GetRecordCount(DataTestHelper.ConnectionString, ContentDataTestHelper.TermsTableName); DataUtil.AddDatabaseObject(virtualScriptFilePath, updateHeirarchicalTerm); Term term = ContentTestHelper.CreateValidHeirarchicalTerm(Constants.VOCABULARY_ValidVocabularyId, Constants.TERM_ValidParentTermId); term.TermId = Constants.TERM_InValidTermId; term.Name = Constants.TERM_UpdateName; term.Weight = Constants.TERM_UpdateWeight; DataService ds = new DataService(); //Act ds.UpdateHeirarchicalTerm(term, Constants.USER_ValidId); //Assert using (SqlConnection connection = new SqlConnection(DataTestHelper.ConnectionString)) { connection.Open(); DatabaseAssert.RecordCountIsEqual(connection, ContentDataTestHelper.TermsTableName, rowCount); //Check that values have not changed IDataReader dataReader = DataUtil.GetRecordsByField(connection, ContentDataTestHelper.TermsTableName, keyField, Constants.TERM_UpdateTermId.ToString()); while (dataReader.Read()) { DatabaseAssert.ReaderColumnIsEqual(dataReader, "Name", Constants.TERM_OriginalUpdateName); } dataReader.Close(); } }