using umbraco.cms.businesslogic.template; using Microsoft.VisualStudio.TestTools.UnitTesting; using System; using System.Collections.Generic; using System.Xml; using umbraco.BusinessLogic; using System.Collections; using umbraco.cms.businesslogic.web; namespace umbraco.Test { /// ///This is a test class for TemplateTest and is intended ///to contain all TemplateTest Unit Tests /// [TestClass()] public class TemplateTest { /// /// create a new template /// [TestMethod()] public void Template_Make_New() { var t = Template.MakeNew(Guid.NewGuid().ToString("N"), m_User); Assert.IsTrue(t.Id > 0); Assert.IsInstanceOfType(t, typeof(Template)); t.delete(); Assert.IsFalse(Template.IsNode(t.Id)); } /// /// Make a new template as a master and a child template. Then try to delete the master template and ensure that it can't be deleted /// without first changning the child template to have a null parent. /// [TestMethod()] public void Template_Make_New_With_Master_And_Remove_Heirarchy_And_Delete() { var t = Template.MakeNew(Guid.NewGuid().ToString("N"), m_User); var child = Template.MakeNew(Guid.NewGuid().ToString("N"), m_User, t); Assert.IsTrue(t.Id > 0); Assert.IsInstanceOfType(t, typeof(Template)); //verify heirarchy Assert.IsTrue(child.HasMasterTemplate); Assert.IsTrue(t.HasChildren); //make sure we can't delete it var hasException = false; try { t.delete(); } catch (InvalidOperationException) { hasException = true; } Assert.IsTrue(hasException); //System.Diagnostics.Debugger.Launch(); //now we need to update the heirarchy... //though, this call will make changes in the database, it won't change our child object as our data layer doesn't have object //persistenece. t.RemoveAllReferences(); //so we'll manually update our master page reference as well (0 = null) child.MasterTemplate = 0; //verify heirarchy Assert.IsFalse(child.HasMasterTemplate); Assert.IsFalse(t.HasChildren); //now delete it, should work now t.delete(); Assert.IsFalse(Template.IsNode(t.Id)); //remove the child child.delete(); Assert.IsFalse(Template.IsNode(child.Id)); } /// /// Creates a new document type, new template, asssign the template to the document type, create a new document using the new template /// then delete the template. This should throw an exception. We will not allow deleting a template that is currently in use /// [TestMethod()] public void Template_Assign_To_Document_And_Delete() { //create the doc type, template and document var dt = DocumentType.MakeNew(m_User, Guid.NewGuid().ToString("N")); var t = Template.MakeNew(Guid.NewGuid().ToString("N"), m_User); //set the allowed templates dt.allowedTemplates = new Template[] { t }; //now set the default dt.DefaultTemplate = t.Id; //create the document (this should have the default template set) var doc = Document.MakeNew(Guid.NewGuid().ToString("N"), dt, m_User, -1); Assert.AreEqual(t.Id, doc.Template); //now delete, this should throw the exception // changed by NH as the API will cleanup instead! /* var hasException = false; try { t.delete(); } catch (InvalidOperationException) { hasException = true; } Assert.IsTrue(hasException); */ //ok, now that we've proved it can't be removed, we'll remove the data in order doc.delete(true); Assert.IsFalse(Document.IsNode(doc.Id)); dt.delete(); Assert.IsFalse(DocumentType.IsNode(dt.Id)); t.delete(); Assert.IsFalse(Template.IsNode(t.Id)); } private User m_User = new User(0); #region Tests to write ///// /////A test for Template Constructor ///// //[TestMethod()] //public void TemplateConstructorTest() //{ // Guid id = new Guid(); // TODO: Initialize to an appropriate value // Template target = new Template(id); // Assert.Inconclusive("TODO: Implement code to verify target"); //} ///// /////A test for Template Constructor ///// //[TestMethod()] //public void TemplateConstructorTest1() //{ // int id = 0; // TODO: Initialize to an appropriate value // Template target = new Template(id); // Assert.Inconclusive("TODO: Implement code to verify target"); //} ///// /////A test for ConvertToMasterPageSyntax ///// //[TestMethod()] //public void ConvertToMasterPageSyntaxTest() //{ // Guid id = new Guid(); // TODO: Initialize to an appropriate value // Template target = new Template(id); // TODO: Initialize to an appropriate value // string templateDesign = string.Empty; // TODO: Initialize to an appropriate value // string expected = string.Empty; // TODO: Initialize to an appropriate value // string actual; // actual = target.ConvertToMasterPageSyntax(templateDesign); // Assert.AreEqual(expected, actual); // Assert.Inconclusive("Verify the correctness of this test method."); //} ///// /////A test for EnsureMasterPageSyntax ///// //[TestMethod()] //public void EnsureMasterPageSyntaxTest() //{ // Guid id = new Guid(); // TODO: Initialize to an appropriate value // Template target = new Template(id); // TODO: Initialize to an appropriate value // string masterPageContent = string.Empty; // TODO: Initialize to an appropriate value // string expected = string.Empty; // TODO: Initialize to an appropriate value // string actual; // actual = target.EnsureMasterPageSyntax(masterPageContent); // Assert.AreEqual(expected, actual); // Assert.Inconclusive("Verify the correctness of this test method."); //} ///// /////A test for GetAllAsList ///// //[TestMethod()] //public void GetAllAsListTest() //{ // List