/// <summary> /// Creates a table row that consists of a textbox for the name and rename, show phrases, delete buttons for a given name space item /// </summary> /// <param name="nameSpaceItem">The item that you want to insert into the table</param> /// <returns>The new table row to be inserted into the table</returns> private TableRow CreateNameSpaceTableItem(NameSpaceItem nameSpaceItem) { // Create the row TableRow newRow = new TableRow(); newRow.ID = "namespaceitem" + nameSpaceItem.ID; // Now create the name cell TableCell nameCell = new TableCell(); TextBox tbName = new TextBox(); tbName.Width = 300; tbName.Text = nameSpaceItem.Name; tbName.ID = "Name" + nameSpaceItem.ID; tbName.EnableViewState = true; nameCell.Controls.Add(tbName); newRow.Cells.Add(nameCell); nameCell.Width = 300; displayNames.Add(tbName); // Add the rename link TableCell renameCell = new TableCell(); Button btRename = new Button(); btRename.Text = "Rename"; btRename.ID = "Rename" + nameSpaceItem.ID; btRename.EnableViewState = true; btRename.Click += new EventHandler(OnRenameButtonClick); btRename.CommandArgument = "Name" + nameSpaceItem.ID; btRename.CommandName = "Rename"; renameCell.Controls.Add(btRename); newRow.Cells.Add(renameCell); renameCell.Width = btRename.Width; // Add the show phrases button TableCell showCell = new TableCell(); Button btShowPhrases = new Button(); btShowPhrases.Text = "Show Phrases"; btShowPhrases.ID = "Show" + nameSpaceItem.ID; btShowPhrases.EnableViewState = true; btShowPhrases.Click += new EventHandler(OnShowButtonClick); btShowPhrases.CommandArgument = "Show" + nameSpaceItem.ID; btShowPhrases.CommandName = "Show"; showCell.Controls.Add(btShowPhrases); newRow.Cells.Add(showCell); renameCell.Width = btShowPhrases.Width; // Add the delete button TableCell deleteCell = new TableCell(); Button btDelete = new Button(); btDelete.Text = "Delete"; btDelete.ID = "Delete" + nameSpaceItem.ID; btDelete.Click += new EventHandler(OnDeleteButtonClick); btDelete.CommandArgument = "Name" + nameSpaceItem.ID; btDelete.CommandName = "Delete"; btDelete.OnClientClick = @"return confirm('Are you sure want to delete this namespace?');"; deleteCell.Controls.Add(btDelete); newRow.Cells.Add(deleteCell); deleteCell.Width = btDelete.Width; // Return the new row return newRow; }
public void TestRenameNameSpaceForSite() { IInputContext context = DnaMockery.CreateDatabaseInputContext(); // Create the namespace object and call the add namespace method NameSpaces testNameSpace = new NameSpaces(context); // Create the list of anmespace to add List<NameSpaceItem> namespaces = new List<NameSpaceItem>(); namespaces.Add(AddNameSpaceToSite(1, "category")); namespaces.Add(AddNameSpaceToSite(1, "mood")); namespaces.Add(AddNameSpaceToSite(1, "people")); namespaces.Add(AddNameSpaceToSite(1, "places")); foreach (NameSpaceItem name in namespaces) { // check to make sure the name was added correctly Assert.IsTrue(name.ID > 0, "NameSpaceId is zero! Failed to create new name space. namespace being added = " + name.Name); } // Create the stored procedure reader for the namespace object using (IDnaDataReader reader = context.CreateDnaDataReader("renamenamespace")) { // Now rename one of the namespaces NameSpaceItem renamed = new NameSpaceItem(namespaces[1].Name + "-renamed", namespaces[1].ID); namespaces.RemoveAt(1); namespaces.Insert(1, renamed); testNameSpace.RenameNameSpaceForSite(1, namespaces[1].ID, namespaces[1].Name); } // Now get all the namespaces for the site using (IDnaDataReader reader2 = context.CreateDnaDataReader("getnamespacesforsite")) { // Now get all the namespaces for the site and comparte the results with the known values. List<NameSpaceItem> foundNameSpaces = testNameSpace.GetNameSpacesForSite(1); for (int i = 0; i < foundNameSpaces.Count; i++) { Assert.AreEqual(namespaces[i].Name, foundNameSpaces[i].Name, "The namespaces found are not the same as the ones added for Names"); Assert.AreEqual(namespaces[i].ID, foundNameSpaces[i].ID, "The namespaces found are not the same as the ones added for IDs"); } } }