diff --git a/src/Umbraco.Core/TypeFinder.cs b/src/Umbraco.Core/TypeFinder.cs index 15315572ec..e327b3df00 100644 --- a/src/Umbraco.Core/TypeFinder.cs +++ b/src/Umbraco.Core/TypeFinder.cs @@ -560,7 +560,8 @@ namespace Umbraco.Core try { - return a.GetExportedTypes(); + //return a.GetExportedTypes(); + return a.GetTypes(); } catch (ReflectionTypeLoadException ex) { diff --git a/src/Umbraco.Tests/TestHelpers/BaseUmbracoApplicationTest.cs b/src/Umbraco.Tests/TestHelpers/BaseUmbracoApplicationTest.cs index db73ea7da8..51c71edad8 100644 --- a/src/Umbraco.Tests/TestHelpers/BaseUmbracoApplicationTest.cs +++ b/src/Umbraco.Tests/TestHelpers/BaseUmbracoApplicationTest.cs @@ -1,6 +1,8 @@ -using NUnit.Framework; +using AutoMapper; +using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Core.Models.Mapping; using Umbraco.Core.ObjectResolution; using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.UnitOfWork; @@ -22,8 +24,9 @@ namespace Umbraco.Tests.TestHelpers { TestHelper.SetupLog4NetForTests(); TestHelper.InitializeContentDirectories(); - SetupPluginManager(); + SetupPluginManager(); SetupApplicationContext(); + InitializeMappers(); FreezeResolution(); } @@ -40,6 +43,18 @@ namespace Umbraco.Tests.TestHelpers ResetPluginManager(); } + private void InitializeMappers() + { + Mapper.Initialize(configuration => + { + var mappers = PluginManager.Current.FindAndCreateInstances(); + foreach (var mapper in mappers) + { + mapper.ConfigureMappings(configuration); + } + }); + } + /// /// By default this returns false which means the plugin manager will not be reset so it doesn't need to re-scan /// all of the assemblies. Inheritors can override this if plugin manager resetting is required, generally needs diff --git a/src/Umbraco.Tests/BusinessLogic/ApplicationTreeTest.cs b/src/Umbraco.Tests/TreesAndSections/ApplicationTreeTest.cs similarity index 94% rename from src/Umbraco.Tests/BusinessLogic/ApplicationTreeTest.cs rename to src/Umbraco.Tests/TreesAndSections/ApplicationTreeTest.cs index 109e8178cf..03a8f00882 100644 --- a/src/Umbraco.Tests/BusinessLogic/ApplicationTreeTest.cs +++ b/src/Umbraco.Tests/TreesAndSections/ApplicationTreeTest.cs @@ -1,359 +1,360 @@ -using NUnit.Framework; -using umbraco.BusinessLogic; -using System; -using System.Linq; - -namespace Umbraco.Tests.BusinessLogic -{ - - - /// - ///This is a test class for ApplicationTreeTest and is intended - ///to contain all ApplicationTreeTest Unit Tests - /// - [TestFixture()] - public class ApplicationTreeTest : BaseTest - { - - - - /// - /// Creates a new app tree linked to an application, then delete the application and make sure the tree is gone as well - /// - [Test()] - public void ApplicationTree_Make_New_Then_Delete_App() - { - //create new app - var name = Guid.NewGuid().ToString("N"); - Application.MakeNew(name, name, "icon.jpg"); - - //check if it exists - var app = Application.getByAlias(name); - Assert.IsNotNull(app); - - //create the new app tree assigned to the new app - ApplicationTree.MakeNew(false, false, 0, app.alias, name, name, "icon.jpg", "icon.jpg", "nullassembly", "nulltype", string.Empty); - var tree = ApplicationTree.getByAlias(name); - Assert.IsNotNull(tree); - - //now delete the app - app.Delete(); - - //check that the tree is gone - Assert.AreEqual(0, ApplicationTree.getApplicationTree(name).Count()); - } - - - #region Tests to write - ///// - /////A test for ApplicationTree Constructor - ///// - //[TestMethod()] - //public void ApplicationTreeConstructorTest() - //{ - // bool silent = false; // TODO: Initialize to an appropriate value - // bool initialize = false; // TODO: Initialize to an appropriate value - // byte sortOrder = 0; // TODO: Initialize to an appropriate value - // string applicationAlias = string.Empty; // TODO: Initialize to an appropriate value - // string alias = string.Empty; // TODO: Initialize to an appropriate value - // string title = string.Empty; // TODO: Initialize to an appropriate value - // string iconClosed = string.Empty; // TODO: Initialize to an appropriate value - // string iconOpened = string.Empty; // TODO: Initialize to an appropriate value - // string assemblyName = string.Empty; // TODO: Initialize to an appropriate value - // string type = string.Empty; // TODO: Initialize to an appropriate value - // string action = string.Empty; // TODO: Initialize to an appropriate value - // ApplicationTree target = new ApplicationTree(silent, initialize, sortOrder, applicationAlias, alias, title, iconClosed, iconOpened, assemblyName, type, action); - // Assert.Inconclusive("TODO: Implement code to verify target"); - //} - - ///// - /////A test for ApplicationTree Constructor - ///// - //[TestMethod()] - //public void ApplicationTreeConstructorTest1() - //{ - // ApplicationTree target = new ApplicationTree(); - // Assert.Inconclusive("TODO: Implement code to verify target"); - //} - - ///// - /////A test for Delete - ///// - //[TestMethod()] - //public void DeleteTest() - //{ - // ApplicationTree target = new ApplicationTree(); // TODO: Initialize to an appropriate value - // target.Delete(); - // Assert.Inconclusive("A method that does not return a value cannot be verified."); - //} - - - ///// - /////A test for Save - ///// - //[TestMethod()] - //public void SaveTest() - //{ - // ApplicationTree target = new ApplicationTree(); // TODO: Initialize to an appropriate value - // target.Save(); - // Assert.Inconclusive("A method that does not return a value cannot be verified."); - //} - - ///// - /////A test for getAll - ///// - //[TestMethod()] - //public void getAllTest() - //{ - // ApplicationTree[] expected = null; // TODO: Initialize to an appropriate value - // ApplicationTree[] actual; - // actual = ApplicationTree.getAll(); - // Assert.AreEqual(expected, actual); - // Assert.Inconclusive("Verify the correctness of this test method."); - //} - - ///// - /////A test for getApplicationTree - ///// - //[TestMethod()] - //public void getApplicationTreeTest() - //{ - // string applicationAlias = string.Empty; // TODO: Initialize to an appropriate value - // ApplicationTree[] expected = null; // TODO: Initialize to an appropriate value - // ApplicationTree[] actual; - // actual = ApplicationTree.getApplicationTree(applicationAlias); - // Assert.AreEqual(expected, actual); - // Assert.Inconclusive("Verify the correctness of this test method."); - //} - - ///// - /////A test for getApplicationTree - ///// - //[TestMethod()] - //public void getApplicationTreeTest1() - //{ - // string applicationAlias = string.Empty; // TODO: Initialize to an appropriate value - // bool onlyInitializedApplications = false; // TODO: Initialize to an appropriate value - // ApplicationTree[] expected = null; // TODO: Initialize to an appropriate value - // ApplicationTree[] actual; - // actual = ApplicationTree.getApplicationTree(applicationAlias, onlyInitializedApplications); - // Assert.AreEqual(expected, actual); - // Assert.Inconclusive("Verify the correctness of this test method."); - //} - - ///// - /////A test for getByAlias - ///// - //[TestMethod()] - //public void getByAliasTest() - //{ - // string treeAlias = string.Empty; // TODO: Initialize to an appropriate value - // ApplicationTree expected = null; // TODO: Initialize to an appropriate value - // ApplicationTree actual; - // actual = ApplicationTree.getByAlias(treeAlias); - // Assert.AreEqual(expected, actual); - // Assert.Inconclusive("Verify the correctness of this test method."); - //} - - ///// - /////A test for Action - ///// - //[TestMethod()] - //public void ActionTest() - //{ - // ApplicationTree target = new ApplicationTree(); // TODO: Initialize to an appropriate value - // string expected = string.Empty; // TODO: Initialize to an appropriate value - // string actual; - // target.Action = expected; - // actual = target.Action; - // Assert.AreEqual(expected, actual); - // Assert.Inconclusive("Verify the correctness of this test method."); - //} - - ///// - /////A test for Alias - ///// - //[TestMethod()] - //public void AliasTest() - //{ - // ApplicationTree target = new ApplicationTree(); // TODO: Initialize to an appropriate value - // string actual; - // actual = target.Alias; - // Assert.Inconclusive("Verify the correctness of this test method."); - //} - - ///// - /////A test for ApplicationAlias - ///// - //[TestMethod()] - //public void ApplicationAliasTest() - //{ - // ApplicationTree target = new ApplicationTree(); // TODO: Initialize to an appropriate value - // string actual; - // actual = target.ApplicationAlias; - // Assert.Inconclusive("Verify the correctness of this test method."); - //} - - ///// - /////A test for AssemblyName - ///// - //[TestMethod()] - //public void AssemblyNameTest() - //{ - // ApplicationTree target = new ApplicationTree(); // TODO: Initialize to an appropriate value - // string expected = string.Empty; // TODO: Initialize to an appropriate value - // string actual; - // target.AssemblyName = expected; - // actual = target.AssemblyName; - // Assert.AreEqual(expected, actual); - // Assert.Inconclusive("Verify the correctness of this test method."); - //} - - ///// - /////A test for IconClosed - ///// - //[TestMethod()] - //public void IconClosedTest() - //{ - // ApplicationTree target = new ApplicationTree(); // TODO: Initialize to an appropriate value - // string expected = string.Empty; // TODO: Initialize to an appropriate value - // string actual; - // target.IconClosed = expected; - // actual = target.IconClosed; - // Assert.AreEqual(expected, actual); - // Assert.Inconclusive("Verify the correctness of this test method."); - //} - - ///// - /////A test for IconOpened - ///// - //[TestMethod()] - //public void IconOpenedTest() - //{ - // ApplicationTree target = new ApplicationTree(); // TODO: Initialize to an appropriate value - // string expected = string.Empty; // TODO: Initialize to an appropriate value - // string actual; - // target.IconOpened = expected; - // actual = target.IconOpened; - // Assert.AreEqual(expected, actual); - // Assert.Inconclusive("Verify the correctness of this test method."); - //} - - ///// - /////A test for Initialize - ///// - //[TestMethod()] - //public void InitializeTest() - //{ - // ApplicationTree target = new ApplicationTree(); // TODO: Initialize to an appropriate value - // bool expected = false; // TODO: Initialize to an appropriate value - // bool actual; - // target.Initialize = expected; - // actual = target.Initialize; - // Assert.AreEqual(expected, actual); - // Assert.Inconclusive("Verify the correctness of this test method."); - //} - - ///// - /////A test for Silent - ///// - //[TestMethod()] - //public void SilentTest() - //{ - // ApplicationTree target = new ApplicationTree(); // TODO: Initialize to an appropriate value - // bool expected = false; // TODO: Initialize to an appropriate value - // bool actual; - // target.Silent = expected; - // actual = target.Silent; - // Assert.AreEqual(expected, actual); - // Assert.Inconclusive("Verify the correctness of this test method."); - //} - - ///// - /////A test for SortOrder - ///// - //[TestMethod()] - //public void SortOrderTest() - //{ - // ApplicationTree target = new ApplicationTree(); // TODO: Initialize to an appropriate value - // byte expected = 0; // TODO: Initialize to an appropriate value - // byte actual; - // target.SortOrder = expected; - // actual = target.SortOrder; - // Assert.AreEqual(expected, actual); - // Assert.Inconclusive("Verify the correctness of this test method."); - //} - - ///// - /////A test for SqlHelper - ///// - //[TestMethod()] - //public void SqlHelperTest() - //{ - // ISqlHelper actual; - // actual = ApplicationTree.SqlHelper; - // Assert.Inconclusive("Verify the correctness of this test method."); - //} - - ///// - /////A test for Title - ///// - //[TestMethod()] - //public void TitleTest() - //{ - // ApplicationTree target = new ApplicationTree(); // TODO: Initialize to an appropriate value - // string expected = string.Empty; // TODO: Initialize to an appropriate value - // string actual; - // target.Title = expected; - // actual = target.Title; - // Assert.AreEqual(expected, actual); - // Assert.Inconclusive("Verify the correctness of this test method."); - //} - - ///// - /////A test for Type - ///// - //[TestMethod()] - //public void TypeTest() - //{ - // ApplicationTree target = new ApplicationTree(); // TODO: Initialize to an appropriate value - // string expected = string.Empty; // TODO: Initialize to an appropriate value - // string actual; - // target.Type = expected; - // actual = target.Type; - // Assert.AreEqual(expected, actual); - // Assert.Inconclusive("Verify the correctness of this test method."); - //} - #endregion - - #region Additional test attributes - // - //You can use the following additional attributes as you write your tests: - // - //Use ClassInitialize to run code before running the first test in the class - //[ClassInitialize()] - //public static void MyClassInitialize(TestContext testContext) - //{ - //} - // - //Use ClassCleanup to run code after all tests in a class have run - //[ClassCleanup()] - //public static void MyClassCleanup() - //{ - //} - // - //Use TestInitialize to run code before running each test - //[TestInitialize()] - //public void MyTestInitialize() - //{ - //} - // - //Use TestCleanup to run code after each test has run - //[TestCleanup()] - //public void MyTestCleanup() - //{ - //} - // - #endregion - } -} +using NUnit.Framework; +using Umbraco.Core.Sections; +using Umbraco.Core.Trees; +using Umbraco.Tests.TestHelpers; +using System; +using System.Linq; +using ApplicationTree = umbraco.BusinessLogic.ApplicationTree; + +namespace Umbraco.Tests.TreesAndSections +{ + + + /// + ///This is a test class for ApplicationTreeTest and is intended + ///to contain all ApplicationTreeTest Unit Tests + /// + [TestFixture()] + public class ApplicationTreeTest : BaseDatabaseFactoryTest + { + + /// + /// Creates a new app tree linked to an application, then delete the application and make sure the tree is gone as well + /// + [Test()] + public void ApplicationTree_Make_New_Then_Delete_App() + { + //create new app + var name = Guid.NewGuid().ToString("N"); + SectionCollection.MakeNew(name, name, "icon.jpg"); + + //check if it exists + var app = SectionCollection.GetByAlias(name); + Assert.IsNotNull(app); + + //create the new app tree assigned to the new app + ApplicationTreeCollection.MakeNew(false, 0, app.Alias, name, name, "icon.jpg", "icon.jpg", "nulltype"); + var tree = ApplicationTreeCollection.GetByAlias(name); + Assert.IsNotNull(tree); + + //now delete the app + SectionCollection.DeleteSection(app); + + //check that the tree is gone + Assert.AreEqual(0, ApplicationTree.getApplicationTree(name).Count()); + } + + + #region Tests to write + ///// + /////A test for ApplicationTree Constructor + ///// + //[TestMethod()] + //public void ApplicationTreeConstructorTest() + //{ + // bool silent = false; // TODO: Initialize to an appropriate value + // bool initialize = false; // TODO: Initialize to an appropriate value + // byte sortOrder = 0; // TODO: Initialize to an appropriate value + // string applicationAlias = string.Empty; // TODO: Initialize to an appropriate value + // string alias = string.Empty; // TODO: Initialize to an appropriate value + // string title = string.Empty; // TODO: Initialize to an appropriate value + // string iconClosed = string.Empty; // TODO: Initialize to an appropriate value + // string iconOpened = string.Empty; // TODO: Initialize to an appropriate value + // string assemblyName = string.Empty; // TODO: Initialize to an appropriate value + // string type = string.Empty; // TODO: Initialize to an appropriate value + // string action = string.Empty; // TODO: Initialize to an appropriate value + // ApplicationTree target = new ApplicationTree(silent, initialize, sortOrder, applicationAlias, alias, title, iconClosed, iconOpened, assemblyName, type, action); + // Assert.Inconclusive("TODO: Implement code to verify target"); + //} + + ///// + /////A test for ApplicationTree Constructor + ///// + //[TestMethod()] + //public void ApplicationTreeConstructorTest1() + //{ + // ApplicationTree target = new ApplicationTree(); + // Assert.Inconclusive("TODO: Implement code to verify target"); + //} + + ///// + /////A test for Delete + ///// + //[TestMethod()] + //public void DeleteTest() + //{ + // ApplicationTree target = new ApplicationTree(); // TODO: Initialize to an appropriate value + // target.Delete(); + // Assert.Inconclusive("A method that does not return a value cannot be verified."); + //} + + + ///// + /////A test for Save + ///// + //[TestMethod()] + //public void SaveTest() + //{ + // ApplicationTree target = new ApplicationTree(); // TODO: Initialize to an appropriate value + // target.Save(); + // Assert.Inconclusive("A method that does not return a value cannot be verified."); + //} + + ///// + /////A test for getAll + ///// + //[TestMethod()] + //public void getAllTest() + //{ + // ApplicationTree[] expected = null; // TODO: Initialize to an appropriate value + // ApplicationTree[] actual; + // actual = ApplicationTree.getAll(); + // Assert.AreEqual(expected, actual); + // Assert.Inconclusive("Verify the correctness of this test method."); + //} + + ///// + /////A test for getApplicationTree + ///// + //[TestMethod()] + //public void getApplicationTreeTest() + //{ + // string applicationAlias = string.Empty; // TODO: Initialize to an appropriate value + // ApplicationTree[] expected = null; // TODO: Initialize to an appropriate value + // ApplicationTree[] actual; + // actual = ApplicationTree.getApplicationTree(applicationAlias); + // Assert.AreEqual(expected, actual); + // Assert.Inconclusive("Verify the correctness of this test method."); + //} + + ///// + /////A test for getApplicationTree + ///// + //[TestMethod()] + //public void getApplicationTreeTest1() + //{ + // string applicationAlias = string.Empty; // TODO: Initialize to an appropriate value + // bool onlyInitializedApplications = false; // TODO: Initialize to an appropriate value + // ApplicationTree[] expected = null; // TODO: Initialize to an appropriate value + // ApplicationTree[] actual; + // actual = ApplicationTree.getApplicationTree(applicationAlias, onlyInitializedApplications); + // Assert.AreEqual(expected, actual); + // Assert.Inconclusive("Verify the correctness of this test method."); + //} + + ///// + /////A test for getByAlias + ///// + //[TestMethod()] + //public void getByAliasTest() + //{ + // string treeAlias = string.Empty; // TODO: Initialize to an appropriate value + // ApplicationTree expected = null; // TODO: Initialize to an appropriate value + // ApplicationTree actual; + // actual = ApplicationTree.getByAlias(treeAlias); + // Assert.AreEqual(expected, actual); + // Assert.Inconclusive("Verify the correctness of this test method."); + //} + + ///// + /////A test for Action + ///// + //[TestMethod()] + //public void ActionTest() + //{ + // ApplicationTree target = new ApplicationTree(); // TODO: Initialize to an appropriate value + // string expected = string.Empty; // TODO: Initialize to an appropriate value + // string actual; + // target.Action = expected; + // actual = target.Action; + // Assert.AreEqual(expected, actual); + // Assert.Inconclusive("Verify the correctness of this test method."); + //} + + ///// + /////A test for Alias + ///// + //[TestMethod()] + //public void AliasTest() + //{ + // ApplicationTree target = new ApplicationTree(); // TODO: Initialize to an appropriate value + // string actual; + // actual = target.Alias; + // Assert.Inconclusive("Verify the correctness of this test method."); + //} + + ///// + /////A test for ApplicationAlias + ///// + //[TestMethod()] + //public void ApplicationAliasTest() + //{ + // ApplicationTree target = new ApplicationTree(); // TODO: Initialize to an appropriate value + // string actual; + // actual = target.ApplicationAlias; + // Assert.Inconclusive("Verify the correctness of this test method."); + //} + + ///// + /////A test for AssemblyName + ///// + //[TestMethod()] + //public void AssemblyNameTest() + //{ + // ApplicationTree target = new ApplicationTree(); // TODO: Initialize to an appropriate value + // string expected = string.Empty; // TODO: Initialize to an appropriate value + // string actual; + // target.AssemblyName = expected; + // actual = target.AssemblyName; + // Assert.AreEqual(expected, actual); + // Assert.Inconclusive("Verify the correctness of this test method."); + //} + + ///// + /////A test for IconClosed + ///// + //[TestMethod()] + //public void IconClosedTest() + //{ + // ApplicationTree target = new ApplicationTree(); // TODO: Initialize to an appropriate value + // string expected = string.Empty; // TODO: Initialize to an appropriate value + // string actual; + // target.IconClosed = expected; + // actual = target.IconClosed; + // Assert.AreEqual(expected, actual); + // Assert.Inconclusive("Verify the correctness of this test method."); + //} + + ///// + /////A test for IconOpened + ///// + //[TestMethod()] + //public void IconOpenedTest() + //{ + // ApplicationTree target = new ApplicationTree(); // TODO: Initialize to an appropriate value + // string expected = string.Empty; // TODO: Initialize to an appropriate value + // string actual; + // target.IconOpened = expected; + // actual = target.IconOpened; + // Assert.AreEqual(expected, actual); + // Assert.Inconclusive("Verify the correctness of this test method."); + //} + + ///// + /////A test for Initialize + ///// + //[TestMethod()] + //public void InitializeTest() + //{ + // ApplicationTree target = new ApplicationTree(); // TODO: Initialize to an appropriate value + // bool expected = false; // TODO: Initialize to an appropriate value + // bool actual; + // target.Initialize = expected; + // actual = target.Initialize; + // Assert.AreEqual(expected, actual); + // Assert.Inconclusive("Verify the correctness of this test method."); + //} + + ///// + /////A test for Silent + ///// + //[TestMethod()] + //public void SilentTest() + //{ + // ApplicationTree target = new ApplicationTree(); // TODO: Initialize to an appropriate value + // bool expected = false; // TODO: Initialize to an appropriate value + // bool actual; + // target.Silent = expected; + // actual = target.Silent; + // Assert.AreEqual(expected, actual); + // Assert.Inconclusive("Verify the correctness of this test method."); + //} + + ///// + /////A test for SortOrder + ///// + //[TestMethod()] + //public void SortOrderTest() + //{ + // ApplicationTree target = new ApplicationTree(); // TODO: Initialize to an appropriate value + // byte expected = 0; // TODO: Initialize to an appropriate value + // byte actual; + // target.SortOrder = expected; + // actual = target.SortOrder; + // Assert.AreEqual(expected, actual); + // Assert.Inconclusive("Verify the correctness of this test method."); + //} + + ///// + /////A test for SqlHelper + ///// + //[TestMethod()] + //public void SqlHelperTest() + //{ + // ISqlHelper actual; + // actual = ApplicationTree.SqlHelper; + // Assert.Inconclusive("Verify the correctness of this test method."); + //} + + ///// + /////A test for Title + ///// + //[TestMethod()] + //public void TitleTest() + //{ + // ApplicationTree target = new ApplicationTree(); // TODO: Initialize to an appropriate value + // string expected = string.Empty; // TODO: Initialize to an appropriate value + // string actual; + // target.Title = expected; + // actual = target.Title; + // Assert.AreEqual(expected, actual); + // Assert.Inconclusive("Verify the correctness of this test method."); + //} + + ///// + /////A test for Type + ///// + //[TestMethod()] + //public void TypeTest() + //{ + // ApplicationTree target = new ApplicationTree(); // TODO: Initialize to an appropriate value + // string expected = string.Empty; // TODO: Initialize to an appropriate value + // string actual; + // target.Type = expected; + // actual = target.Type; + // Assert.AreEqual(expected, actual); + // Assert.Inconclusive("Verify the correctness of this test method."); + //} + #endregion + + #region Additional test attributes + // + //You can use the following additional attributes as you write your tests: + // + //Use ClassInitialize to run code before running the first test in the class + //[ClassInitialize()] + //public static void MyClassInitialize(TestContext testContext) + //{ + //} + // + //Use ClassCleanup to run code after all tests in a class have run + //[ClassCleanup()] + //public static void MyClassCleanup() + //{ + //} + // + //Use TestInitialize to run code before running each test + //[TestInitialize()] + //public void MyTestInitialize() + //{ + //} + // + //Use TestCleanup to run code after each test has run + //[TestCleanup()] + //public void MyTestCleanup() + //{ + //} + // + #endregion + } +} diff --git a/src/Umbraco.Tests/BusinessLogic/ApplicationTest.cs b/src/Umbraco.Tests/TreesAndSections/SectionTests.cs similarity index 92% rename from src/Umbraco.Tests/BusinessLogic/ApplicationTest.cs rename to src/Umbraco.Tests/TreesAndSections/SectionTests.cs index 1bcd405c67..6f6d0d8056 100644 --- a/src/Umbraco.Tests/BusinessLogic/ApplicationTest.cs +++ b/src/Umbraco.Tests/TreesAndSections/SectionTests.cs @@ -1,269 +1,271 @@ -using NUnit.Framework; -using umbraco.BusinessLogic; -using System; -using System.Linq; -using Umbraco.Core; - -namespace Umbraco.Tests.BusinessLogic -{ - /// - ///This is a test class for ApplicationTest and is intended - ///to contain all ApplicationTest Unit Tests - /// - [TestFixture()] - public class ApplicationTest : BaseTest - { - - /// - /// Create a new application and delete it - /// - [Test()] - public void Application_Make_New() - { - var name = Guid.NewGuid().ToString("N"); - Application.MakeNew(name, name, "icon.jpg"); - - //check if it exists - var app = Application.getByAlias(name); - Assert.IsNotNull(app); - - //now remove it - app.Delete(); - Assert.IsNull(Application.getByAlias(name)); - } - - /// - /// Creates a new user, assigns the user to existing application, - /// then deletes the user - /// - [Test()] - public void Application_Create_New_User_Assign_Application_And_Delete_User() - { - var name = Guid.NewGuid().ToString("N"); - - //new user - var ut = UserType.GetAllUserTypes().First(); - var user = User.MakeNew(name, name, name, ut); - - //get application - //var app = Application.getAll().First(); - - //assign the app - user.addApplication(Constants.Applications.Content); - //ensure it's added - Assert.AreEqual(1, user.Applications.Count(x => x.alias == Constants.Applications.Content)); - - //delete the user - user.delete(); - - //make sure the assigned applications are gone - Assert.AreEqual(0, user.Applications.Count(x => x.alias == name)); - } - - /// - /// create a new application and assigne an new user and deletes the application making sure the assignments are removed - /// - [Test()] - public void Application_Make_New_Assign_User_And_Delete() - { - var name = Guid.NewGuid().ToString("N"); - - //new user - var ut = UserType.GetAllUserTypes().First(); - var user = User.MakeNew(name, name, name, ut); - - Application.MakeNew(name, name, "icon.jpg"); - - //check if it exists - var app = Application.getByAlias(name); - Assert.IsNotNull(app); - - //assign the app - user.addApplication(app.alias); - //ensure it's added - Assert.AreEqual(1, user.Applications.Count(x => x.alias == app.alias)); - - //delete the app - app.Delete(); - - //make sure the assigned applications are gone - Assert.AreEqual(0, user.Applications.Count(x => x.alias == name)); - } - - #region Tests to write - - - ///// - /////A test for Application Constructor - ///// - //[TestMethod()] - //public void ApplicationConstructorTest() - //{ - // string name = string.Empty; // TODO: Initialize to an appropriate value - // string alias = string.Empty; // TODO: Initialize to an appropriate value - // string icon = string.Empty; // TODO: Initialize to an appropriate value - // Application target = new Application(name, alias, icon); - // Assert.Inconclusive("TODO: Implement code to verify target"); - //} - - ///// - /////A test for Application Constructor - ///// - //[TestMethod()] - //public void ApplicationConstructorTest1() - //{ - // Application target = new Application(); - // Assert.Inconclusive("TODO: Implement code to verify target"); - //} - - ///// - /////A test for Delete - ///// - //[TestMethod()] - //public void DeleteTest() - //{ - // Application target = new Application(); // TODO: Initialize to an appropriate value - // target.Delete(); - // Assert.Inconclusive("A method that does not return a value cannot be verified."); - //} - - - - ///// - /////A test for MakeNew - ///// - //[TestMethod()] - //public void MakeNewTest1() - //{ - // string name = string.Empty; // TODO: Initialize to an appropriate value - // string alias = string.Empty; // TODO: Initialize to an appropriate value - // string icon = string.Empty; // TODO: Initialize to an appropriate value - // Application.MakeNew(name, alias, icon); - // Assert.Inconclusive("A method that does not return a value cannot be verified."); - //} - - ///// - /////A test for RegisterIApplications - ///// - //[TestMethod()] - //public void RegisterIApplicationsTest() - //{ - // Application.RegisterIApplications(); - // Assert.Inconclusive("A method that does not return a value cannot be verified."); - //} - - ///// - /////A test for getAll - ///// - //[TestMethod()] - //public void getAllTest() - //{ - // List expected = null; // TODO: Initialize to an appropriate value - // List actual; - // actual = Application.getAll(); - // Assert.AreEqual(expected, actual); - // Assert.Inconclusive("Verify the correctness of this test method."); - //} - - ///// - /////A test for getByAlias - ///// - //[TestMethod()] - //public void getByAliasTest() - //{ - // string appAlias = string.Empty; // TODO: Initialize to an appropriate value - // Application expected = null; // TODO: Initialize to an appropriate value - // Application actual; - // actual = Application.getByAlias(appAlias); - // Assert.AreEqual(expected, actual); - // Assert.Inconclusive("Verify the correctness of this test method."); - //} - - ///// - /////A test for SqlHelper - ///// - //[TestMethod()] - //public void SqlHelperTest() - //{ - // ISqlHelper actual; - // actual = Application.SqlHelper; - // Assert.Inconclusive("Verify the correctness of this test method."); - //} - - ///// - /////A test for alias - ///// - //[TestMethod()] - //public void aliasTest() - //{ - // Application target = new Application(); // TODO: Initialize to an appropriate value - // string expected = string.Empty; // TODO: Initialize to an appropriate value - // string actual; - // target.alias = expected; - // actual = target.alias; - // Assert.AreEqual(expected, actual); - // Assert.Inconclusive("Verify the correctness of this test method."); - //} - - ///// - /////A test for icon - ///// - //[TestMethod()] - //public void iconTest() - //{ - // Application target = new Application(); // TODO: Initialize to an appropriate value - // string expected = string.Empty; // TODO: Initialize to an appropriate value - // string actual; - // target.icon = expected; - // actual = target.icon; - // Assert.AreEqual(expected, actual); - // Assert.Inconclusive("Verify the correctness of this test method."); - //} - - ///// - /////A test for name - ///// - //[TestMethod()] - //public void nameTest() - //{ - // Application target = new Application(); // TODO: Initialize to an appropriate value - // string expected = string.Empty; // TODO: Initialize to an appropriate value - // string actual; - // target.name = expected; - // actual = target.name; - // Assert.AreEqual(expected, actual); - // Assert.Inconclusive("Verify the correctness of this test method."); - //} - #endregion - - #region Additional test attributes - // - //You can use the following additional attributes as you write your tests: - // - //Use ClassInitialize to run code before running the first test in the class - //[ClassInitialize()] - //public static void MyClassInitialize(TestContext testContext) - //{ - //} - // - //Use ClassCleanup to run code after all tests in a class have run - //[ClassCleanup()] - //public static void MyClassCleanup() - //{ - //} - // - //Use TestInitialize to run code before running each test - //[TestInitialize()] - //public void MyTestInitialize() - //{ - //} - // - //Use TestCleanup to run code after each test has run - //[TestCleanup()] - //public void MyTestCleanup() - //{ - //} - // - #endregion - } -} +using NUnit.Framework; +using Umbraco.Core.Sections; +using Umbraco.Tests.TestHelpers; +using umbraco.BusinessLogic; +using System; +using System.Linq; +using Umbraco.Core; + +namespace Umbraco.Tests.TreesAndSections +{ + /// + ///This is a test class for ApplicationTest and is intended + ///to contain all ApplicationTest Unit Tests + /// + [TestFixture()] + public class SectionTests : BaseDatabaseFactoryTest + { + + /// + /// Create a new application and delete it + /// + [Test()] + public void Application_Make_New() + { + var name = Guid.NewGuid().ToString("N"); + SectionCollection.MakeNew(name, name, "icon.jpg"); + + //check if it exists + var app = SectionCollection.GetByAlias(name); + Assert.IsNotNull(app); + + //now remove it + SectionCollection.DeleteSection(app); + Assert.IsNull(SectionCollection.GetByAlias(name)); + } + + /// + /// Creates a new user, assigns the user to existing application, + /// then deletes the user + /// + [Test()] + public void Application_Create_New_User_Assign_Application_And_Delete_User() + { + var name = Guid.NewGuid().ToString("N"); + + //new user + var ut = UserType.GetAllUserTypes().First(); + var user = User.MakeNew(name, name, name, ut); + + //get application + //var app = Application.getAll().First(); + + //assign the app + user.addApplication(Constants.Applications.Content); + //ensure it's added + Assert.AreEqual(1, user.Applications.Count(x => x.alias == Constants.Applications.Content)); + + //delete the user + user.delete(); + + //make sure the assigned applications are gone + Assert.AreEqual(0, user.Applications.Count(x => x.alias == name)); + } + + /// + /// create a new application and assigne an new user and deletes the application making sure the assignments are removed + /// + [Test()] + public void Application_Make_New_Assign_User_And_Delete() + { + var name = Guid.NewGuid().ToString("N"); + + //new user + var ut = UserType.GetAllUserTypes().First(); + var user = User.MakeNew(name, name, name, ut); + + SectionCollection.MakeNew(name, name, "icon.jpg"); + + //check if it exists + var app = SectionCollection.GetByAlias(name); + Assert.IsNotNull(app); + + //assign the app + user.addApplication(app.Alias); + //ensure it's added + Assert.AreEqual(1, user.Applications.Count(x => x.alias == app.Alias)); + + //delete the app + SectionCollection.DeleteSection(app); + + //make sure the assigned applications are gone + Assert.AreEqual(0, user.Applications.Count(x => x.alias == name)); + } + + #region Tests to write + + + ///// + /////A test for Application Constructor + ///// + //[TestMethod()] + //public void ApplicationConstructorTest() + //{ + // string name = string.Empty; // TODO: Initialize to an appropriate value + // string alias = string.Empty; // TODO: Initialize to an appropriate value + // string icon = string.Empty; // TODO: Initialize to an appropriate value + // Application target = new Application(name, alias, icon); + // Assert.Inconclusive("TODO: Implement code to verify target"); + //} + + ///// + /////A test for Application Constructor + ///// + //[TestMethod()] + //public void ApplicationConstructorTest1() + //{ + // Application target = new Application(); + // Assert.Inconclusive("TODO: Implement code to verify target"); + //} + + ///// + /////A test for Delete + ///// + //[TestMethod()] + //public void DeleteTest() + //{ + // Application target = new Application(); // TODO: Initialize to an appropriate value + // target.Delete(); + // Assert.Inconclusive("A method that does not return a value cannot be verified."); + //} + + + + ///// + /////A test for MakeNew + ///// + //[TestMethod()] + //public void MakeNewTest1() + //{ + // string name = string.Empty; // TODO: Initialize to an appropriate value + // string alias = string.Empty; // TODO: Initialize to an appropriate value + // string icon = string.Empty; // TODO: Initialize to an appropriate value + // Application.MakeNew(name, alias, icon); + // Assert.Inconclusive("A method that does not return a value cannot be verified."); + //} + + ///// + /////A test for RegisterIApplications + ///// + //[TestMethod()] + //public void RegisterIApplicationsTest() + //{ + // Application.RegisterIApplications(); + // Assert.Inconclusive("A method that does not return a value cannot be verified."); + //} + + ///// + /////A test for getAll + ///// + //[TestMethod()] + //public void getAllTest() + //{ + // List expected = null; // TODO: Initialize to an appropriate value + // List actual; + // actual = Application.getAll(); + // Assert.AreEqual(expected, actual); + // Assert.Inconclusive("Verify the correctness of this test method."); + //} + + ///// + /////A test for getByAlias + ///// + //[TestMethod()] + //public void getByAliasTest() + //{ + // string appAlias = string.Empty; // TODO: Initialize to an appropriate value + // Application expected = null; // TODO: Initialize to an appropriate value + // Application actual; + // actual = Application.getByAlias(appAlias); + // Assert.AreEqual(expected, actual); + // Assert.Inconclusive("Verify the correctness of this test method."); + //} + + ///// + /////A test for SqlHelper + ///// + //[TestMethod()] + //public void SqlHelperTest() + //{ + // ISqlHelper actual; + // actual = Application.SqlHelper; + // Assert.Inconclusive("Verify the correctness of this test method."); + //} + + ///// + /////A test for alias + ///// + //[TestMethod()] + //public void aliasTest() + //{ + // Application target = new Application(); // TODO: Initialize to an appropriate value + // string expected = string.Empty; // TODO: Initialize to an appropriate value + // string actual; + // target.alias = expected; + // actual = target.alias; + // Assert.AreEqual(expected, actual); + // Assert.Inconclusive("Verify the correctness of this test method."); + //} + + ///// + /////A test for icon + ///// + //[TestMethod()] + //public void iconTest() + //{ + // Application target = new Application(); // TODO: Initialize to an appropriate value + // string expected = string.Empty; // TODO: Initialize to an appropriate value + // string actual; + // target.icon = expected; + // actual = target.icon; + // Assert.AreEqual(expected, actual); + // Assert.Inconclusive("Verify the correctness of this test method."); + //} + + ///// + /////A test for name + ///// + //[TestMethod()] + //public void nameTest() + //{ + // Application target = new Application(); // TODO: Initialize to an appropriate value + // string expected = string.Empty; // TODO: Initialize to an appropriate value + // string actual; + // target.name = expected; + // actual = target.name; + // Assert.AreEqual(expected, actual); + // Assert.Inconclusive("Verify the correctness of this test method."); + //} + #endregion + + #region Additional test attributes + // + //You can use the following additional attributes as you write your tests: + // + //Use ClassInitialize to run code before running the first test in the class + //[ClassInitialize()] + //public static void MyClassInitialize(TestContext testContext) + //{ + //} + // + //Use ClassCleanup to run code after all tests in a class have run + //[ClassCleanup()] + //public static void MyClassCleanup() + //{ + //} + // + //Use TestInitialize to run code before running each test + //[TestInitialize()] + //public void MyTestInitialize() + //{ + //} + // + //Use TestCleanup to run code after each test has run + //[TestCleanup()] + //public void MyTestCleanup() + //{ + //} + // + #endregion + } +}