/// <summary> /// The Event handler method for the renames button click /// </summary> /// <param name="sender">The button control that was clicked</param> /// <param name="e">Any arguments that are associated with the event</param> protected void OnRenameButtonClick(object sender, EventArgs e) { // Make sure the button that was clicked was a rename button Button btClicked = ((Button)sender); if (btClicked.CommandName.CompareTo("Rename") == 0) { // Now get the textbox that was defined in the command argument TextBox textBox = (TextBox)FindControl(btClicked.CommandArgument); if (textBox != null) { // Get the id of the namespace and rename the item with the text in the text box string cmdArg = btClicked.CommandArgument; int ID = Convert.ToInt32(cmdArg.Substring(4)); // Check to make sure that we're not creating an existsing namespace if (CheckToMakeSureNameDoesNotAlreadyExist(textBox.Text)) { // Now put the textbox back to it's original value string original = GetOriginalTextForTextBox(textBox.Text); if (original != "") { // The name already exists! textBox.Text = original; txtWarning.Height = new Unit("26px"); txtWarning.Visible = true; txtWarning.Text = "A namespace already exists with that name!"; } return; } // Rename the namespace to it's new name NameSpaces siteNameSpaces = new NameSpaces(_basePage); siteNameSpaces.RenameNameSpaceForSite(_basePage.CurrentSite.SiteID, ID, textBox.Text); } } }
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"); } } }