diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/RazorElement.cs b/src/Umbraco.Core/Configuration/UmbracoSettings/RazorElement.cs index 06d0abdf76..273977f298 100644 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/RazorElement.cs +++ b/src/Umbraco.Core/Configuration/UmbracoSettings/RazorElement.cs @@ -23,13 +23,7 @@ namespace Umbraco.Core.Configuration.UmbracoSettings var autoFill = this[prop] as ConfigurationElementCollection; if (autoFill != null && autoFill.ElementInformation.IsPresent == false) { - _defaultCollection = new NotDynamicXmlDocumentElementCollection - { - new NotDynamicXmlDocumentElement {RawValue = "p"}, - new NotDynamicXmlDocumentElement {RawValue = "div"}, - new NotDynamicXmlDocumentElement {RawValue = "ul"}, - new NotDynamicXmlDocumentElement {RawValue = "span"} - }; + _defaultCollection = GetDefaultNotDynamicXmlDocuments(); //must return the collection directly return _defaultCollection; @@ -39,6 +33,17 @@ namespace Umbraco.Core.Configuration.UmbracoSettings } } + internal static NotDynamicXmlDocumentElementCollection GetDefaultNotDynamicXmlDocuments() + { + return new NotDynamicXmlDocumentElementCollection + { + new NotDynamicXmlDocumentElement {RawValue = "p"}, + new NotDynamicXmlDocumentElement {RawValue = "div"}, + new NotDynamicXmlDocumentElement {RawValue = "ul"}, + new NotDynamicXmlDocumentElement {RawValue = "span"} + }; + } + [ConfigurationCollection(typeof (RazorStaticMappingCollection), AddItemName = "mapping")] [ConfigurationProperty("dataTypeModelStaticMappings", IsDefaultCollection = true)] internal RazorStaticMappingCollection DataTypeModelStaticMappings diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/UmbracoSettingsSection.cs b/src/Umbraco.Core/Configuration/UmbracoSettings/UmbracoSettingsSection.cs index bbfebf11ce..a84055f8a8 100644 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/UmbracoSettingsSection.cs +++ b/src/Umbraco.Core/Configuration/UmbracoSettings/UmbracoSettingsSection.cs @@ -1,5 +1,6 @@ using System; using System.Configuration; +using System.Linq; namespace Umbraco.Core.Configuration.UmbracoSettings { @@ -92,7 +93,14 @@ namespace Umbraco.Core.Configuration.UmbracoSettings return _defaultRepositories; } - return (RepositoriesElement)base["repositories"]; + //now we need to ensure there is *always* our umbraco repo! its hard coded in the codebase! + var reposElement = (RepositoriesElement)base["repositories"]; + if (reposElement.Repositories.All(x => x.Id != new Guid("65194810-1f85-11dd-bd0b-0800200c9a66"))) + { + reposElement.Repositories.Add(new RepositoryElement() { Name = "Umbraco package Repository", Id = new Guid("65194810-1f85-11dd-bd0b-0800200c9a66") }); + } + + return reposElement; } } diff --git a/src/Umbraco.Tests/CodeFirst/StronglyTypedMapperTest.cs b/src/Umbraco.Tests/CodeFirst/StronglyTypedMapperTest.cs index 740215016b..61d33cff9f 100644 --- a/src/Umbraco.Tests/CodeFirst/StronglyTypedMapperTest.cs +++ b/src/Umbraco.Tests/CodeFirst/StronglyTypedMapperTest.cs @@ -1,5 +1,4 @@ -using System.IO; -using System.Linq; +using System.Linq; using System.Text.RegularExpressions; using NUnit.Framework; using Umbraco.Core.Models; @@ -7,7 +6,6 @@ using Umbraco.Tests.CodeFirst.TestModels; using Umbraco.Tests.PublishedContent; using Umbraco.Tests.TestHelpers; using Umbraco.Web; -using Rhino.Mocks; namespace Umbraco.Tests.CodeFirst { diff --git a/src/Umbraco.Tests/Configurations/UmbracoSettings/CanGenerateMockSettings.cs b/src/Umbraco.Tests/Configurations/UmbracoSettings/CanGenerateMockSettings.cs deleted file mode 100644 index bc59526b1a..0000000000 --- a/src/Umbraco.Tests/Configurations/UmbracoSettings/CanGenerateMockSettings.cs +++ /dev/null @@ -1,28 +0,0 @@ -//using System.Linq; -//using NUnit.Framework; -//using Rhino.Mocks; -//using Umbraco.Core.Configuration; -//using Umbraco.Core.Configuration.UmbracoSettings; -//using Umbraco.Tests.TestHelpers; - -//namespace Umbraco.Tests.Configurations.UmbracoSettings -//{ -// [TestFixture] -// public class CanGenerateMockSettings -// { -// [Test] -// public void Can_Mock_Multi_Levels() -// { -// var repos = MockRepository.GenerateStub(); -// repos.Stub(x => x.Name).Return("This is a test"); - -// var settings = SettingsForTests.GetMockSettings(); -// settings.Stub(x => x.Content.UseLegacyXmlSchema).Return(true); -// settings.Stub(x => x.PackageRepositories.Repositories).Return(new[] {repos}); -// SettingsForTests.ConfigureSettings(settings); - -// Assert.AreEqual(true, UmbracoConfiguration.Current.UmbracoSettings.Content.UseLegacyXmlSchema); -// Assert.AreEqual("This is a test", UmbracoConfiguration.Current.UmbracoSettings.PackageRepositories.Repositories.Single().Name); -// } -// } -//} \ No newline at end of file diff --git a/src/Umbraco.Tests/Configurations/UmbracoSettings/umbracoSettings.minimal.config b/src/Umbraco.Tests/Configurations/UmbracoSettings/umbracoSettings.minimal.config index c03c08b1a0..f74879b193 100644 --- a/src/Umbraco.Tests/Configurations/UmbracoSettings/umbracoSettings.minimal.config +++ b/src/Umbraco.Tests/Configurations/UmbracoSettings/umbracoSettings.minimal.config @@ -1,11 +1,29 @@  + + + + + + + + + + + 1 - + + robot@umbraco.dk @@ -13,4 +31,45 @@ + + + + + + + Mvc + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Umbraco.Tests/Controllers/WebApiEditors/ContentControllerUnitTests.cs b/src/Umbraco.Tests/Controllers/WebApiEditors/ContentControllerUnitTests.cs index 5f24e12e21..02cdb6ae15 100644 --- a/src/Umbraco.Tests/Controllers/WebApiEditors/ContentControllerUnitTests.cs +++ b/src/Umbraco.Tests/Controllers/WebApiEditors/ContentControllerUnitTests.cs @@ -1,23 +1,11 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net.Http; -using System.Text; -using System.Threading.Tasks; +using System.Collections.Generic; using System.Web.Http; -using System.Web.Http.Controllers; -using System.Web.Http.SelfHost; using NUnit.Framework; using Rhino.Mocks; using Umbraco.Core.Models; using Umbraco.Core.Models.Membership; using Umbraco.Core.Services; -using Umbraco.Tests.TestHelpers; -using Umbraco.Web; using Umbraco.Web.Editors; -using Umbraco.Web.WebApi; -using Umbraco.Web.WebApi.Filters; -using umbraco.presentation.channels.businesslogic; namespace Umbraco.Tests.Controllers.WebApiEditors { diff --git a/src/Umbraco.Tests/CoreStrings/CmsHelperCasingTests.cs b/src/Umbraco.Tests/CoreStrings/CmsHelperCasingTests.cs index 2462f55a5d..57f0606361 100644 --- a/src/Umbraco.Tests/CoreStrings/CmsHelperCasingTests.cs +++ b/src/Umbraco.Tests/CoreStrings/CmsHelperCasingTests.cs @@ -1,12 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using NUnit.Framework; -using Rhino.Mocks; +using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Strings; -using Umbraco.Core.ObjectResolution; using Umbraco.Tests.TestHelpers; namespace Umbraco.Tests.CoreStrings diff --git a/src/Umbraco.Tests/HashCodeCombinerTests.cs b/src/Umbraco.Tests/HashCodeCombinerTests.cs index b1c808e7f8..8d1ad021dd 100644 --- a/src/Umbraco.Tests/HashCodeCombinerTests.cs +++ b/src/Umbraco.Tests/HashCodeCombinerTests.cs @@ -7,7 +7,7 @@ using Umbraco.Core; namespace Umbraco.Tests { [TestFixture] - public class HashCodeCombinerTests : PartialTrust.AbstractPartialTrustFixture + public class HashCodeCombinerTests { private DirectoryInfo PrepareFolder() @@ -141,14 +141,5 @@ namespace Umbraco.Tests Assert.AreNotEqual(combiner1.GetCombinedHashCode(), combiner3.GetCombinedHashCode()); } - public override void TestSetup() - { - - } - - public override void TestTearDown() - { - - } } } diff --git a/src/Umbraco.Tests/ObjectExtensionsTests.cs b/src/Umbraco.Tests/ObjectExtensionsTests.cs index 788a28c4f4..8c333e4296 100644 --- a/src/Umbraco.Tests/ObjectExtensionsTests.cs +++ b/src/Umbraco.Tests/ObjectExtensionsTests.cs @@ -3,17 +3,16 @@ using System.Collections.Generic; using System.Linq; using NUnit.Framework; using Umbraco.Core; -using Umbraco.Tests.PartialTrust; using Umbraco.Tests.TestHelpers; namespace Umbraco.Tests { [TestFixture] - public class ObjectExtensionsTests : AbstractPartialTrustFixture + public class ObjectExtensionsTests { - protected override void FixtureSetup() + [TestFixtureSetUp] + public void FixtureSetup() { - base.FixtureSetup(); TestHelper.SetupLog4NetForTests(); } @@ -114,21 +113,5 @@ namespace Umbraco.Tests Assert.AreEqual(DateTime.Equals(dateTime.Date, result.Result.Date), testCase.Value); } } - - /// - /// Run once before each test in derived test fixtures. - /// - public override void TestSetup() - { - return; - } - - /// - /// Run once after each test in derived test fixtures. - /// - public override void TestTearDown() - { - return; - } } } \ No newline at end of file diff --git a/src/Umbraco.Tests/PartialTrust/AbstractPartialTrustFixture.cs b/src/Umbraco.Tests/PartialTrust/AbstractPartialTrustFixture.cs deleted file mode 100644 index a9d4b22c03..0000000000 --- a/src/Umbraco.Tests/PartialTrust/AbstractPartialTrustFixture.cs +++ /dev/null @@ -1,106 +0,0 @@ -using System; -using System.Linq; -using NUnit.Framework; - -namespace Umbraco.Tests.PartialTrust -{ - [TestFixture] - public abstract class AbstractPartialTrustFixture : IPartialTrustFixture - where T : class, IPartialTrustFixture, new() - { - private AppDomain _partialTrustAppDomain; - private PartialTrustHelper.PartialTrustMethodRunner _methodRunner; - - /// - /// Run once by NUnit for this fixture. This will setup a new partial-trust - /// for the duration of this test fixture, and a which will also - /// survive for the life of the test fixture. - /// - [TestFixtureSetUp] - protected virtual void FixtureSetup() - { - _partialTrustAppDomain = PartialTrustHelper.CreatePartialTrustDomain(); - _methodRunner = PartialTrustHelper.GenerateMarshaller(_partialTrustAppDomain); - } - - /// - /// Causes the partial-trust to be unloaded. - /// - [TestFixtureTearDown] - protected void FixtureTearDown() - { - AppDomain.Unload(_partialTrustAppDomain); - } - - /// - /// This is run before each test by the NUnit runner. It will first cause to be - /// run on the derived test class in the partial-trust domain. It will then run the current test method - /// (obtained from NUnit's TestContext) in the same partial-trust domain. In order to prevent the same test - /// then being run a second time in our original full-trust , it then throws - /// an NUnit which counts as a Pass and prevents continued execution of the test. - /// - /// - /// If the test failed in partial trust, it will be marked as failed as normal - including any errors specific - /// to running it in a partial trust environment. - /// - [SetUp] - protected void PartialTrustSetup() - { - if (ShouldTestOnlyInFullTrust()) - { - // Do not run this test in partial trust - TestSetup(); - return; - } - - // First, run the TestSetup method in the partial trust domain - _methodRunner.Run(Umbraco.Core.ExpressionHelper.GetMethodInfo>(x => x.TestSetup())); - - // Now, run the actual test in the same appdomain - PartialTrustHelper.CheckRunNUnitTestInPartialTrust(_partialTrustAppDomain, _methodRunner); - - // If we get here, we've had no exceptions, so throw an NUnit SuccessException which will avoid rerunning the test - // in the existing full-trust appdomain and cause the test to pass - throw new SuccessException("Automatically avoided running test in full trust as it passed in partial trust"); - } - - private static bool ShouldTestOnlyInFullTrust() - { - var currentTest = PartialTrustHelper.FindCurrentTestMethodInfo(); - - // If we can't find a compatible test, it might be because we cannot run it remotely in the - // AppDomain e.g. if it's a parameterised test, in which case fail with a note - if (currentTest == null) Assert.Fail("Cannot find current test; is test parameterised?"); - - return currentTest.GetCustomAttributes(typeof(TestOnlyInFullTrustAttribute), false).Any(); - } - - /// - /// Run once before each test in derived test fixtures. - /// - public abstract void TestSetup(); - - /// - /// This is run once after each test by the NUnit runner. It will cause to be - /// run on the derived test class in the partial-trust domain. - /// - [TearDown] - public void PartialTrustTearDown() - { - if (ShouldTestOnlyInFullTrust()) - { - // Do not run this test in partial trust - TestTearDown(); - return; - } - - // Run the TestTearDown method in the partial trust domain - _methodRunner.Run(Umbraco.Core.ExpressionHelper.GetMethodInfo>(x => x.TestTearDown())); - } - - /// - /// Run once after each test in derived test fixtures. - /// - public abstract void TestTearDown(); - } -} \ No newline at end of file diff --git a/src/Umbraco.Tests/PartialTrust/IPartialTrustFixture.cs b/src/Umbraco.Tests/PartialTrust/IPartialTrustFixture.cs deleted file mode 100644 index edc364a86c..0000000000 --- a/src/Umbraco.Tests/PartialTrust/IPartialTrustFixture.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Web.Mvc; - -namespace Umbraco.Tests.PartialTrust -{ - public interface IPartialTrustFixture - { - /// - /// Run once before each test in derived test fixtures. - /// - void TestSetup(); - - /// - /// Run once after each test in derived test fixtures. - /// - void TestTearDown(); - } -} \ No newline at end of file diff --git a/src/Umbraco.Tests/PartialTrust/PartialTrustFixtureFixture.cs b/src/Umbraco.Tests/PartialTrust/PartialTrustFixtureFixture.cs deleted file mode 100644 index fb4479e8a2..0000000000 --- a/src/Umbraco.Tests/PartialTrust/PartialTrustFixtureFixture.cs +++ /dev/null @@ -1,55 +0,0 @@ -using System; -using System.Security; -using NUnit.Framework; - -namespace Umbraco.Tests.PartialTrust -{ - [TestFixture] - public class PartialTrustFixtureFixture : AbstractPartialTrustFixture - { - public override void TestSetup() - { - //LogHelper.TraceIfEnabled("Being setup"); - } - - public override void TestTearDown() - { - //LogHelper.TraceIfEnabled("Being torn down"); - } - - [Test] - public void InPartialTrust_WhenMethodShouldSucceed_PartialTrustHelper_ReportsSuccess() - { - //LogHelper.TraceIfEnabled("In WhenTestShouldSucceed_InPartialTrust_PartialTrustHelper_ReportsSuccess"); - var fakeFixture = new PartialTrustHelperFixture.FakeFixture(); - fakeFixture.PartialTrustShouldSucceed(); - } - - [Test] - public void InPartialTrust_WhenMethodShouldNotSucceed_PartialTrustHelper_ReportsFailure() - { - //LogHelper.TraceIfEnabled("In WhenTestShouldNotSucceed_InPartialTrust_PartialTrustHelper_ReportsFailure"); - try - { - var fakeFixture = new PartialTrustHelperFixture.FakeFixture(); - fakeFixture.PartialTrustShouldFail(); - } - catch (FieldAccessException ex) - { - Assert.Pass("FieldAccessException raised, message: " + ex.Message); - return; - } - catch (SecurityException ex) - { - Assert.Pass("SecurityException raised, message: " + ex.Message); - return; - } - catch (Exception ex) - { - Assert.Fail("Exception was raised but it was not SecurityException, was: " + ex.ToString()); - } - - Assert.Fail("No exception was raised"); - } - } -} \ No newline at end of file diff --git a/src/Umbraco.Tests/PartialTrust/PartialTrustHelper.cs b/src/Umbraco.Tests/PartialTrust/PartialTrustHelper.cs deleted file mode 100644 index cb1019b2cd..0000000000 --- a/src/Umbraco.Tests/PartialTrust/PartialTrustHelper.cs +++ /dev/null @@ -1,293 +0,0 @@ -using System; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Runtime.InteropServices; -using System.Security; -using System.Xml; -using System.Xml.Linq; -using NUnit.Framework; -using Umbraco.Core; - -namespace Umbraco.Tests.PartialTrust -{ - public static class PartialTrustHelper - where T : class, new() - { - public const string PartialTrustAppDomainName = "Partial Trust AppDomain"; - - public static void RunInPartial(MethodInfo methodInfo) - { - AppDomain partiallyTrustedDomain = CreatePartialTrustDomain(); - - try - { - RunInPartial(methodInfo, partiallyTrustedDomain); - } - finally - { - AppDomain.Unload(partiallyTrustedDomain); - } - } - - /// - /// Runs the provided in the . - /// If is provided, it will be used, otherwise a new one will be created. - /// - /// The method info. - /// The partially trusted domain. - /// The marshaller. - public static void RunInPartial(MethodInfo methodInfo, AppDomain partiallyTrustedDomain, PartialTrustMethodRunner marshaller = null) - { - // Ensure no mistakes creep in and this code is actually running on the fully trusted AppDomain - Assert.That(AppDomain.CurrentDomain.FriendlyName, Is.Not.StringStarting(PartialTrustAppDomainName)); - - if (marshaller == null) marshaller = GenerateMarshaller(partiallyTrustedDomain); - - try - { - marshaller.Run(methodInfo); - } - catch (PartialTrustTestException ex) - { - throw ex; - } - catch (TargetInvocationException ex) - { - // If this gets raised, it could be because the method failed, or an assertion was called (either pass or failure) - if (ex.InnerException != null) - { - if (ex.InnerException is SuccessException) - /* Do nothing but return - it's NUnit's way of exiting out of a method when Assert.Pass() is called */ - return; - Assert.Fail(ex.InnerException.ToString()); - } - Assert.Fail("Failed but InnerException was null; " + ex.Message); - } - catch (Exception ex) - { - Assert.Fail(ex.ToString()); - } - } - - /// - /// Generates a marshaller proxy of inside the provided . - /// - /// The partially trusted domain. - /// - public static PartialTrustMethodRunner GenerateMarshaller(AppDomain partiallyTrustedDomain) - { - var marshallerType = typeof(PartialTrustMethodRunner); - var marshaller = - partiallyTrustedDomain.CreateInstanceAndUnwrap(marshallerType.Assembly.FullName, marshallerType.FullName) as - PartialTrustMethodRunner; - return marshaller; - } - - /// - /// Creates the an with a partial trust . - /// - /// - public static AppDomain CreatePartialTrustDomain() - { - var setup = new AppDomainSetup { ApplicationBase = AppDomain.CurrentDomain.BaseDirectory }; - var permissions = MediumTrustConfigHelper.GetMediumTrustPermissionSet(); - return AppDomain.CreateDomain("Partial Trust AppDomain: " + DateTime.Now.Ticks, null, setup, permissions); - } - - public static void CheckRunNUnitTestInPartialTrust() - { - var findMethodInfo = FindCurrentTestMethodInfo(); - - try - { - RunInPartial(findMethodInfo); - } - catch (SuccessException assertPass) - { - /* This means the test passed with a direct call to Pass, so do nothing */ - throw; - } - } - - public static MethodInfo FindCurrentTestMethodInfo() - { - var nameOfTest = TestContext.CurrentContext.Test.Name; - var findMethodInfo = typeof(T).GetMethod(nameOfTest); - return findMethodInfo; - } - - public static void CheckRunNUnitTestInPartialTrust(AppDomain withAppDomain, PartialTrustMethodRunner marshaller) - { - var findMethodInfo = FindCurrentTestMethodInfo(); - - try - { - RunInPartial(findMethodInfo, withAppDomain, marshaller); - } - catch (SuccessException assertPass) - { - /* This means the test passed with a direct call to Pass, so do nothing */ - throw; - } - } - - [Serializable] - public class PartialTrustMethodRunner : MarshalByRefObject - where TFixture : class, new() - { - protected TFixture Instance { get; set; } - public Type TestClass { get { return typeof(TFixture); } } - - public void Run(MethodInfo methodToRun) - { - // Verify that we are definitely running in an appdomain that we made ourselves - Assert.That(AppDomain.CurrentDomain.FriendlyName, Is.StringStarting(PartialTrustAppDomainName)); - - try - { - // Support having the marshaller run multiple methods on the same instance by storing the instance locally - if (Instance == null) Instance = new TFixture(); - - // Run the method on the instance we've either created or cached locally - methodToRun.Invoke(Instance, null); - } - catch (TargetInvocationException ex) - { - if (ex.InnerException != null && (ex.InnerException is SecurityException || ex.InnerException is MemberAccessException)) - { - var inner = ex.InnerException; - throw new PartialTrustTestException("Test {0} fails in a partial trust environment, due to: {1}".InvariantFormat(methodToRun.Name, inner.Message), ex.InnerException); - } - throw; - } - } - } - - public static class MediumTrustConfigHelper - { - /// - /// Gets the medium trust permission set from the default config path. - /// - /// - public static NamedPermissionSet GetMediumTrustPermissionSet() - { - return GetMediumTrustPermissionSet(GetMediumTrustConfigPath()); - } - - /// - /// Gets the medium trust permission set. - /// - /// The path to the config file. - /// - public static NamedPermissionSet GetMediumTrustPermissionSet(string pathToConfigFile) - { - // Load the config file trusting that it exists. - var xDocument = XDocument.Load(pathToConfigFile); - - // Get all of the SecurityClass elements which we'll use later to look - // up a type strongname given a key - var securityClasses = xDocument.Descendants("SecurityClass").Select( - x => new - { - Name = (string)x.Attribute("Name"), - Type = (string)x.Attribute("Description") - }); - - // Get the first PermissionSet element where the Name attribute is "ASP.Net" - var namedSet = xDocument.Descendants("PermissionSet").Where(x => (string)x.Attribute("Name") == "ASP.Net").FirstOrDefault(); - - // If we didn't find it, that's a fail - Assert.NotNull(namedSet); - - // Create a new SecurityElement class to mimic what is represented in Xml - var secElement = new SecurityElement("PermissionSet"); - secElement.AddAttribute("Name", "ASP.Net"); - secElement.AddAttribute("class", "NamedPermissionSet"); - secElement.AddAttribute("version", "1"); - - // For each child of the ASP.Net PermissionSet, create a child SecurityElement representing the IPermission - foreach (var xElement in namedSet.Elements()) - { - var child = new SecurityElement("IPermission"); - - // Check if we need to do any string replacement on the Xml values first - ProcessIPermissionAttributeValue(xElement); - - // Get the attributes of the IPermission from Xml and put them onto our child SecurityElement - foreach (var xAttribute in xElement.Attributes()) - { - var attribName = xAttribute.Name.LocalName; - var value = xAttribute.Value; - - try - { - if (attribName == "class") - // This is the type key. Get the full type name from the SecurityClasses list we grabbed earlier - value = securityClasses.Where(x => x.Name == value).Select(x => x.Type).Single(); - } - catch (Exception ex) - { - throw new XmlException("Could not find the fully-qualified type name for " + value, ex); - } - - child.AddAttribute(attribName, value); - } - secElement.AddChild(child); - } - - // Create a new NamedPermissionSet, pass in the SecurityElement class representing the Xml - var permissionSet = new NamedPermissionSet("ASP.Net"); - permissionSet.FromXml(secElement); - return permissionSet; - } - - /// - /// Processes the custom attribute values of IPermission config elements to replicate what ASP.Net performs - /// when scanning the permission set. Primarily just replaces $AppDir$ on a FileIOPermission with the current - /// directory. - /// - /// The element. - public static void ProcessIPermissionAttributeValue(XElement element) - { - var classKey = (string)element.Attribute("class"); - if (classKey == null) return; - - // These attributes are on every IPermission, we can ignore them later - var ignoredAttributes = new[] { "class", "version" }; - - // Get all the attribute on this IPermission that are "custom" - var customAttributes = element.Attributes().Where(x => !ignoredAttributes.Contains(x.Name.LocalName)); - foreach (var customAttribute in customAttributes) - { - switch (classKey) - { - case "FileIOPermission": - switch (customAttribute.Name.LocalName) - { - case "Read": - case "Write": - case "Append": - case "PathDiscovery": - // Replace an $AppDir$ token with the current directory to mimic setting it to the IIS root - customAttribute.Value = customAttribute.Value.Replace("$AppDir$", Environment.CurrentDirectory); - break; - } - break; - } - } - } - - /// - /// Gets the medium trust config path for the current runtime environment. - /// - /// - public static string GetMediumTrustConfigPath() - { - var readFromDirectory = Path.GetDirectoryName(RuntimeEnvironment.SystemConfigurationFile); - var autoPath = Path.Combine(readFromDirectory, "web_mediumtrust.config"); - return autoPath; - } - } - } -} \ No newline at end of file diff --git a/src/Umbraco.Tests/PartialTrust/PartialTrustHelperFixture.cs b/src/Umbraco.Tests/PartialTrust/PartialTrustHelperFixture.cs deleted file mode 100644 index 3f17dacb1c..0000000000 --- a/src/Umbraco.Tests/PartialTrust/PartialTrustHelperFixture.cs +++ /dev/null @@ -1,72 +0,0 @@ -using System; -using System.Reflection; -using NUnit.Framework; - -namespace Umbraco.Tests.PartialTrust -{ - [TestFixture] - public class PartialTrustHelperFixture - { - [TestFixtureSetUp] - public void SetupFixture() - { - //TestHelper.SetupLog4NetForTests(); - } - - public class FakeFixture - { - public void PartialTrustShouldSucceed() - { - //LogHelper.TraceIfEnabled("In PartialTrustShouldSucceed, doing nothing much"); - } - - public void PartialTrustShouldFail() - { - //LogHelper.TraceIfEnabled("In PartialTrustShouldFail, about to try to access a private field"); - //using (DisposableTimer.TraceDuration("PartialTrustShouldFail", "PartialTrustShouldFail")) - //{ - var fieldInfo = typeof(Int32).GetField("m_value", BindingFlags.Instance | BindingFlags.NonPublic); - var value = fieldInfo.GetValue(1); - //LogHelper.TraceIfEnabled("value: {0}", () => value); - //} - } - } - - [Test] - public void InPartialTrust_WhenMethodShouldSucceed_PartialTrustHelper_ReportsSuccess() - { - //LogHelper.TraceIfEnabled("In WhenTestShouldSucceed_InPartialTrust_PartialTrustHelper_ReportsSuccess"); - PartialTrustHelper.RunInPartial(Umbraco.Core.ExpressionHelper.GetMethodInfo(x => x.PartialTrustShouldSucceed())); - Assert.Pass(); - } - - [Test] - public void InPartialTrust_WhenMethodShouldNotSucceed_PartialTrustHelper_ReportsFailure() - { - //LogHelper.TraceIfEnabled("In WhenTestShouldNotSucceed_InPartialTrust_PartialTrustHelper_ReportsFailure"); - try - { - PartialTrustHelper.RunInPartial(Umbraco.Core.ExpressionHelper.GetMethodInfo(x => x.PartialTrustShouldFail())); - } - catch (PartialTrustTestException ex) - { - Assert.Pass("PartialTrustTestException raised, message: " + ex.Message); - return; - } - catch (Exception ex) - { - Assert.Fail("Exception was raised but it was not PartialTrustTestException, was: " + ex.Message); - } - - Assert.Fail("No exception was raised"); - } - - // To have all tests in a fixture automatically checked under the medium trust settings on your machine (web_mediumtrust.config) - // add this to your test fixture (APN) - //[SetUp] - //public void PreTest() - //{ - // PartialTrustHelper.CheckRunNUnitTestInPartialTrust(); - //} - } -} \ No newline at end of file diff --git a/src/Umbraco.Tests/PartialTrust/PartialTrustTestException.cs b/src/Umbraco.Tests/PartialTrust/PartialTrustTestException.cs deleted file mode 100644 index 44aa08ae39..0000000000 --- a/src/Umbraco.Tests/PartialTrust/PartialTrustTestException.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Runtime.Serialization; - -namespace Umbraco.Tests.PartialTrust -{ - [Serializable] - public class PartialTrustTestException : Exception - { - protected PartialTrustTestException(SerializationInfo info, StreamingContext context) - : base(info, context) - { - } - - public PartialTrustTestException(string message, Exception innerException) - : base(message, innerException) - { - } - } -} \ No newline at end of file diff --git a/src/Umbraco.Tests/PartialTrust/TestOnlyInFullTrustAttribute.cs b/src/Umbraco.Tests/PartialTrust/TestOnlyInFullTrustAttribute.cs deleted file mode 100644 index cd994bb1e2..0000000000 --- a/src/Umbraco.Tests/PartialTrust/TestOnlyInFullTrustAttribute.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; - -namespace Umbraco.Tests.PartialTrust -{ - /// - /// Specifies that the will not run the decorated test in a partial trust AppDomain - /// - [AttributeUsage(AttributeTargets.Method)] - public class TestOnlyInFullTrustAttribute : Attribute - { - /// - /// Specifies that the will not run the decorated test in a partial trust AppDomain - /// - public TestOnlyInFullTrustAttribute() - { - } - } -} \ No newline at end of file diff --git a/src/Umbraco.Tests/PublishedCache/PublishedContentCacheTests.cs b/src/Umbraco.Tests/PublishedCache/PublishedContentCacheTests.cs index 94e32de997..e91f73fccc 100644 --- a/src/Umbraco.Tests/PublishedCache/PublishedContentCacheTests.cs +++ b/src/Umbraco.Tests/PublishedCache/PublishedContentCacheTests.cs @@ -1,17 +1,13 @@ using System; using System.Linq; using System.Xml; +using Moq; using NUnit.Framework; -using Rhino.Mocks; using Umbraco.Core; -using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.UmbracoSettings; -using Umbraco.Tests.PublishedContent; using Umbraco.Tests.TestHelpers; using Umbraco.Web; using Umbraco.Web.PublishedCache; using Umbraco.Web.PublishedCache.XmlPublishedCache; -using Umbraco.Web.Routing; using Umbraco.Web.Security; using umbraco.BusinessLogic; @@ -81,8 +77,9 @@ namespace Umbraco.Tests.PublishedCache //ensure the StateHelper is using our custom context StateHelper.HttpContext = _httpContextFactory.HttpContext; - var settings = MockRepository.GenerateStub(); - settings.Stub(x => x.Content.UseLegacyXmlSchema).Return(false); + var settings = SettingsForTests.GetMockSettings(); + var contentMock = Mock.Get(settings.Content); + contentMock.Setup(x => x.UseLegacyXmlSchema).Returns(false); SettingsForTests.ConfigureSettings(settings); var cache = new PublishedContentCache @@ -106,8 +103,9 @@ namespace Umbraco.Tests.PublishedCache private void SetupForLegacy() { - var settings = MockRepository.GenerateStub(); - settings.Stub(x => x.Content.UseLegacyXmlSchema).Return(true); + var settings = SettingsForTests.GetMockSettings(); + var contentMock = Mock.Get(settings.Content); + contentMock.Setup(x => x.UseLegacyXmlSchema).Returns(true); SettingsForTests.ConfigureSettings(settings); var cache = _umbracoContext.ContentCache.InnerCache as PublishedContentCache; diff --git a/src/Umbraco.Tests/PublishedContent/DynamicDocumentTestsBase.cs b/src/Umbraco.Tests/PublishedContent/DynamicDocumentTestsBase.cs index e0321e08d5..c5c4ff3891 100644 --- a/src/Umbraco.Tests/PublishedContent/DynamicDocumentTestsBase.cs +++ b/src/Umbraco.Tests/PublishedContent/DynamicDocumentTestsBase.cs @@ -3,8 +3,10 @@ using System.Collections; using System.Collections.Generic; using System.Linq; using System.Web; +using Moq; using NUnit.Framework; using Umbraco.Core; +using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Dynamics; using Umbraco.Tests.TestHelpers; @@ -13,6 +15,15 @@ namespace Umbraco.Tests.PublishedContent [TestFixture] public abstract class DynamicDocumentTestsBase : PublishedContentTestBase { + + public override void Initialize() + { + base.Initialize(); + + var scriptingMock = Mock.Get(UmbracoSettings.Scripting); + scriptingMock.Setup(x => x.DataTypeModelStaticMappings).Returns(new List()); + } + protected override DatabaseBehavior DatabaseTestBehavior { get { return DatabaseBehavior.NoDatabasePerFixture; } diff --git a/src/Umbraco.Tests/PublishedContent/DynamicXmlConverterTests.cs b/src/Umbraco.Tests/PublishedContent/DynamicXmlConverterTests.cs index f0ad32a1bc..473ece3e79 100644 --- a/src/Umbraco.Tests/PublishedContent/DynamicXmlConverterTests.cs +++ b/src/Umbraco.Tests/PublishedContent/DynamicXmlConverterTests.cs @@ -3,12 +3,11 @@ using System.Xml.Linq; using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Dynamics; -using Umbraco.Tests.PartialTrust; namespace Umbraco.Tests.PublishedContent { [TestFixture] - public class DynamicXmlConverterTests : AbstractPartialTrustFixture + public class DynamicXmlConverterTests { [Test] public void Convert_To_Raw_String() @@ -97,14 +96,5 @@ namespace Umbraco.Tests.PublishedContent Assert.IsTrue(result.Success); Assert.AreEqual(xml, result.Result.InnerXml); } - - public override void TestSetup() - { - - } - - public override void TestTearDown() - { - } } } \ No newline at end of file diff --git a/src/Umbraco.Tests/PublishedContent/LegacyExamineBackedMediaTests.cs b/src/Umbraco.Tests/PublishedContent/LegacyExamineBackedMediaTests.cs index f90a5c5cb4..3e2739bc9a 100644 --- a/src/Umbraco.Tests/PublishedContent/LegacyExamineBackedMediaTests.cs +++ b/src/Umbraco.Tests/PublishedContent/LegacyExamineBackedMediaTests.cs @@ -1,27 +1,25 @@ using System; -using System.IO; using System.Linq; using Lucene.Net.Documents; using Lucene.Net.Store; +using Moq; using NUnit.Framework; -using Rhino.Mocks; -using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.UmbracoExamine; using umbraco.MacroEngines; namespace Umbraco.Tests.PublishedContent { - public class LegacyExamineBackedMediaTests : ExamineBaseTest + public class LegacyExamineBackedMediaTests : ExamineBaseTest { public override void TestSetup() { base.TestSetup(); - var settings = MockRepository.GenerateStub(); - settings.Stub(x => x.Content.ForceSafeAliases).Return(true); - settings.Stub(x => x.Content.UmbracoLibraryCacheDuration).Return(1800); + var settings = SettingsForTests.GetMockSettings(); + var contentMock = Mock.Get(settings.Content); + contentMock.Setup(x => x.ForceSafeAliases).Returns(true); + contentMock.Setup(x => x.UmbracoLibraryCacheDuration).Returns(1800); SettingsForTests.ConfigureSettings(settings); } diff --git a/src/Umbraco.Tests/Routing/ContentFinderByPageIdQueryTests.cs b/src/Umbraco.Tests/Routing/ContentFinderByPageIdQueryTests.cs index 4807a02ae1..b21c8e66a5 100644 --- a/src/Umbraco.Tests/Routing/ContentFinderByPageIdQueryTests.cs +++ b/src/Umbraco.Tests/Routing/ContentFinderByPageIdQueryTests.cs @@ -2,8 +2,6 @@ using NUnit.Framework; using Rhino.Mocks; using Umbraco.Tests.TestHelpers; using Umbraco.Web.Routing; -using umbraco.BusinessLogic; -using umbraco.cms.businesslogic.template; namespace Umbraco.Tests.Routing { diff --git a/src/Umbraco.Tests/Routing/NiceUrlProviderTests.cs b/src/Umbraco.Tests/Routing/NiceUrlProviderTests.cs index 42d901d4ca..08c96c9207 100644 --- a/src/Umbraco.Tests/Routing/NiceUrlProviderTests.cs +++ b/src/Umbraco.Tests/Routing/NiceUrlProviderTests.cs @@ -1,11 +1,7 @@ using System; -using System.Configuration; using System.Collections.Generic; -using System.IO; -using System.Linq; +using Moq; using NUnit.Framework; -using Rhino.Mocks; -using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Tests.TestHelpers; using Umbraco.Web.PublishedCache.XmlPublishedCache; using Umbraco.Web.Routing; @@ -32,10 +28,9 @@ namespace Umbraco.Tests.Routing var routingContext = GetRoutingContext("/test", 1111); SettingsForTests.UseDirectoryUrls = true; SettingsForTests.HideTopLevelNodeFromPath = false; - //mock the Umbraco settings that we need - var settings = MockRepository.GenerateStub(); - settings.Stub(x => x.RequestHandler.AddTrailingSlash).Return(false);// (cached routes have none) - SettingsForTests.ConfigureSettings(settings); + + var requestHandlerMock = Mock.Get(UmbracoSettings.RequestHandler); + requestHandlerMock.Setup(x => x.AddTrailingSlash).Returns(false);// (cached routes have none) var samples = new Dictionary { { 1046, "/home" }, @@ -98,10 +93,8 @@ namespace Umbraco.Tests.Routing SettingsForTests.UseDirectoryUrls = true; SettingsForTests.HideTopLevelNodeFromPath = false; - //mock the Umbraco settings that we need - var settings = MockRepository.GenerateStub(); - settings.Stub(x => x.RequestHandler.UseDomainPrefixes).Return(false); - SettingsForTests.ConfigureSettings(settings); + var requestMock = Mock.Get(UmbracoSettings.RequestHandler); + requestMock.Setup(x => x.UseDomainPrefixes).Returns(false); var result = routingContext.UrlProvider.GetUrl(nodeId); Assert.AreEqual(niceUrlMatch, result); @@ -124,10 +117,8 @@ namespace Umbraco.Tests.Routing SettingsForTests.UseDirectoryUrls = true; SettingsForTests.HideTopLevelNodeFromPath = true; - //mock the Umbraco settings that we need - var settings = MockRepository.GenerateStub(); - settings.Stub(x => x.RequestHandler.UseDomainPrefixes).Return(false); - SettingsForTests.ConfigureSettings(settings); + var requestMock = Mock.Get(UmbracoSettings.RequestHandler); + requestMock.Setup(x => x.UseDomainPrefixes).Returns(false); var result = routingContext.UrlProvider.GetUrl(nodeId); Assert.AreEqual(niceUrlMatch, result); @@ -140,20 +131,15 @@ namespace Umbraco.Tests.Routing SettingsForTests.UseDirectoryUrls = true; SettingsForTests.HideTopLevelNodeFromPath = false; - - //mock the Umbraco settings that we need - var settings = MockRepository.GenerateStub(); - settings.Stub(x => x.RequestHandler.UseDomainPrefixes).Return(false); - SettingsForTests.ConfigureSettings(settings); + var requestMock = Mock.Get(UmbracoSettings.RequestHandler); + requestMock.Setup(x => x.UseDomainPrefixes).Returns(false); Assert.AreEqual("/home/sub1/custom-sub-1/", routingContext.UrlProvider.GetUrl(1177)); - - settings.Stub(x => x.RequestHandler.UseDomainPrefixes).Return(true); - SettingsForTests.ConfigureSettings(settings); + + requestMock.Setup(x => x.UseDomainPrefixes).Returns(true); Assert.AreEqual("http://example.com/home/sub1/custom-sub-1/", routingContext.UrlProvider.GetUrl(1177)); - settings.Stub(x => x.RequestHandler.UseDomainPrefixes).Return(false); - SettingsForTests.ConfigureSettings(settings); + requestMock.Setup(x => x.UseDomainPrefixes).Returns(false); routingContext.UrlProvider.Mode = UrlProviderMode.Absolute; Assert.AreEqual("http://example.com/home/sub1/custom-sub-1/", routingContext.UrlProvider.GetUrl(1177)); } @@ -167,19 +153,17 @@ namespace Umbraco.Tests.Routing SettingsForTests.HideTopLevelNodeFromPath = false; //mock the Umbraco settings that we need - var settings = MockRepository.GenerateStub(); - settings.Stub(x => x.RequestHandler.UseDomainPrefixes).Return(false); - SettingsForTests.ConfigureSettings(settings); + var requestMock = Mock.Get(UmbracoSettings.RequestHandler); + requestMock.Setup(x => x.UseDomainPrefixes).Returns(false); Assert.AreEqual("#", routingContext.UrlProvider.GetUrl(999999)); - settings.Stub(x => x.RequestHandler.UseDomainPrefixes).Return(true); - SettingsForTests.ConfigureSettings(settings); + requestMock.Setup(x => x.UseDomainPrefixes).Returns(true); Assert.AreEqual("#", routingContext.UrlProvider.GetUrl(999999)); - settings.Stub(x => x.RequestHandler.UseDomainPrefixes).Return(false); - SettingsForTests.ConfigureSettings(settings); + requestMock.Setup(x => x.UseDomainPrefixes).Returns(false); + routingContext.UrlProvider.Mode = UrlProviderMode.Absolute; Assert.AreEqual("#", routingContext.UrlProvider.GetUrl(999999)); diff --git a/src/Umbraco.Tests/Routing/NiceUrlsProviderWithDomainsTests.cs b/src/Umbraco.Tests/Routing/NiceUrlsProviderWithDomainsTests.cs index b9ad82e26b..fdc395e0cf 100644 --- a/src/Umbraco.Tests/Routing/NiceUrlsProviderWithDomainsTests.cs +++ b/src/Umbraco.Tests/Routing/NiceUrlsProviderWithDomainsTests.cs @@ -1,11 +1,8 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Configuration; +using Moq; using NUnit.Framework; -using Rhino.Mocks; -using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Tests.TestHelpers; using Umbraco.Web.PublishedCache.XmlPublishedCache; using Umbraco.Web.Routing; @@ -205,10 +202,8 @@ namespace Umbraco.Tests.Routing SettingsForTests.UseDirectoryUrls = true; SettingsForTests.HideTopLevelNodeFromPath = false; // ignored w/domains - //mock the Umbraco settings that we need - var settings = MockRepository.GenerateStub(); - settings.Stub(x => x.RequestHandler.UseDomainPrefixes).Return(false); - SettingsForTests.ConfigureSettings(settings); + var requestMock = Mock.Get(UmbracoSettings.RequestHandler); + requestMock.Setup(x => x.UseDomainPrefixes).Returns(false); InitializeLanguagesAndDomains(); SetDomains1(); @@ -237,10 +232,8 @@ namespace Umbraco.Tests.Routing SettingsForTests.UseDirectoryUrls = true; SettingsForTests.HideTopLevelNodeFromPath = false; // ignored w/domains - //mock the Umbraco settings that we need - var settings = MockRepository.GenerateStub(); - settings.Stub(x => x.RequestHandler.UseDomainPrefixes).Return(false); - SettingsForTests.ConfigureSettings(settings); + var requestMock = Mock.Get(UmbracoSettings.RequestHandler); + requestMock.Setup(x => x.UseDomainPrefixes).Returns(false); InitializeLanguagesAndDomains(); SetDomains2(); @@ -261,10 +254,8 @@ namespace Umbraco.Tests.Routing SettingsForTests.UseDirectoryUrls = true; SettingsForTests.HideTopLevelNodeFromPath = false; // ignored w/domains - //mock the Umbraco settings that we need - var settings = MockRepository.GenerateStub(); - settings.Stub(x => x.RequestHandler.UseDomainPrefixes).Return(false); - SettingsForTests.ConfigureSettings(settings); + var requestMock = Mock.Get(UmbracoSettings.RequestHandler); + requestMock.Setup(x => x.UseDomainPrefixes).Returns(false); InitializeLanguagesAndDomains(); SetDomains3(); @@ -291,10 +282,8 @@ namespace Umbraco.Tests.Routing SettingsForTests.UseDirectoryUrls = true; SettingsForTests.HideTopLevelNodeFromPath = false; // ignored w/domains - //mock the Umbraco settings that we need - var settings = MockRepository.GenerateStub(); - settings.Stub(x => x.RequestHandler.UseDomainPrefixes).Return(false); - SettingsForTests.ConfigureSettings(settings); + var requestMock = Mock.Get(UmbracoSettings.RequestHandler); + requestMock.Setup(x => x.UseDomainPrefixes).Returns(false); InitializeLanguagesAndDomains(); SetDomains4(); @@ -311,10 +300,8 @@ namespace Umbraco.Tests.Routing SettingsForTests.UseDirectoryUrls = true; SettingsForTests.HideTopLevelNodeFromPath = false; // ignored w/domains - //mock the Umbraco settings that we need - var settings = MockRepository.GenerateStub(); - settings.Stub(x => x.RequestHandler.UseDomainPrefixes).Return(false); - SettingsForTests.ConfigureSettings(settings); + var requestMock = Mock.Get(UmbracoSettings.RequestHandler); + requestMock.Setup(x => x.UseDomainPrefixes).Returns(false); InitializeLanguagesAndDomains(); SetDomains4(); @@ -380,21 +367,18 @@ namespace Umbraco.Tests.Routing SetDomains4(); //mock the Umbraco settings that we need - var settings = MockRepository.GenerateStub(); - settings.Stub(x => x.RequestHandler.UseDomainPrefixes).Return(false); - SettingsForTests.ConfigureSettings(settings); + var requestMock = Mock.Get(UmbracoSettings.RequestHandler); + requestMock.Setup(x => x.UseDomainPrefixes).Returns(false); Assert.AreEqual("/en/1001-1-1/", routingContext.UrlProvider.GetUrl(100111)); Assert.AreEqual("http://domain3.com/en/1003-1-1/", routingContext.UrlProvider.GetUrl(100311)); - settings.Stub(x => x.RequestHandler.UseDomainPrefixes).Return(true); - SettingsForTests.ConfigureSettings(settings); + requestMock.Setup(x => x.UseDomainPrefixes).Returns(true); Assert.AreEqual("http://domain1.com/en/1001-1-1/", routingContext.UrlProvider.GetUrl(100111)); Assert.AreEqual("http://domain3.com/en/1003-1-1/", routingContext.UrlProvider.GetUrl(100311)); - settings.Stub(x => x.RequestHandler.UseDomainPrefixes).Return(false); - SettingsForTests.ConfigureSettings(settings); + requestMock.Setup(x => x.UseDomainPrefixes).Returns(false); routingContext.UrlProvider.Mode = UrlProviderMode.Absolute; Assert.AreEqual("http://domain1.com/en/1001-1-1/", routingContext.UrlProvider.GetUrl(100111)); diff --git a/src/Umbraco.Tests/Routing/UrlsWithNestedDomains.cs b/src/Umbraco.Tests/Routing/UrlsWithNestedDomains.cs index 890d551754..dafb27a2b5 100644 --- a/src/Umbraco.Tests/Routing/UrlsWithNestedDomains.cs +++ b/src/Umbraco.Tests/Routing/UrlsWithNestedDomains.cs @@ -1,16 +1,12 @@ using System; -using System.Collections.Generic; using System.Linq; -using System.Text; +using Moq; using NUnit.Framework; -using Rhino.Mocks; -using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Tests.TestHelpers; using Umbraco.Web.PublishedCache.XmlPublishedCache; using umbraco.cms.businesslogic.web; using umbraco.cms.businesslogic.language; using Umbraco.Web.Routing; -using System.Configuration; namespace Umbraco.Tests.Routing { @@ -26,11 +22,9 @@ namespace Umbraco.Tests.Routing public void DoNotPolluteCache() { SettingsForTests.UseDirectoryUrls = true; - SettingsForTests.HideTopLevelNodeFromPath = false; // ignored w/domains - //mock the Umbraco settings that we need - var settings = MockRepository.GenerateStub(); - settings.Stub(x => x.RequestHandler.UseDomainPrefixes).Return(true); - SettingsForTests.ConfigureSettings(settings); + SettingsForTests.HideTopLevelNodeFromPath = false; // ignored w/domains + var requestMock = Mock.Get(UmbracoSettings.RequestHandler); + requestMock.Setup(x => x.UseDomainPrefixes).Returns(true); InitializeLanguagesAndDomains(); SetDomains1(); diff --git a/src/Umbraco.Tests/Routing/uQueryGetNodeIdByUrlTests.cs b/src/Umbraco.Tests/Routing/uQueryGetNodeIdByUrlTests.cs index 9364edc399..0798da0770 100644 --- a/src/Umbraco.Tests/Routing/uQueryGetNodeIdByUrlTests.cs +++ b/src/Umbraco.Tests/Routing/uQueryGetNodeIdByUrlTests.cs @@ -1,15 +1,7 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using Moq; using NUnit.Framework; -using Rhino.Mocks; -using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Tests.Stubs; using Umbraco.Tests.TestHelpers; -using System.Configuration; -using Umbraco.Web; -using Umbraco.Web.PublishedCache.XmlPublishedCache; using Umbraco.Web.Routing; using umbraco.BusinessLogic; using umbraco.cms.businesslogic.template; @@ -65,10 +57,8 @@ namespace Umbraco.Tests.Routing { SettingsForTests.UseDirectoryUrls = true; SettingsForTests.HideTopLevelNodeFromPath = false; - //mock the Umbraco settings that we need - var settings = MockRepository.GenerateStub(); - settings.Stub(x => x.RequestHandler.UseDomainPrefixes).Return(false); - SettingsForTests.ConfigureSettings(settings); + var requestMock = Mock.Get(UmbracoSettings.RequestHandler); + requestMock.Setup(x => x.UseDomainPrefixes).Returns(false); Assert.AreEqual(nodeId, global::umbraco.uQuery.GetNodeIdByUrl("http://example.com" + url)); } @@ -86,10 +76,8 @@ namespace Umbraco.Tests.Routing { SettingsForTests.UseDirectoryUrls = true; SettingsForTests.HideTopLevelNodeFromPath = false; - //mock the Umbraco settings that we need - var settings = MockRepository.GenerateStub(); - settings.Stub(x => x.RequestHandler.UseDomainPrefixes).Return(false); - SettingsForTests.ConfigureSettings(settings); + var requestMock = Mock.Get(UmbracoSettings.RequestHandler); + requestMock.Setup(x => x.UseDomainPrefixes).Returns(false); Assert.AreEqual(nodeId, global::umbraco.uQuery.GetNodeIdByUrl(url)); } diff --git a/src/Umbraco.Tests/TestHelpers/BaseUmbracoApplicationTest.cs b/src/Umbraco.Tests/TestHelpers/BaseUmbracoApplicationTest.cs index e010d9d936..760cf4514e 100644 --- a/src/Umbraco.Tests/TestHelpers/BaseUmbracoApplicationTest.cs +++ b/src/Umbraco.Tests/TestHelpers/BaseUmbracoApplicationTest.cs @@ -1,9 +1,6 @@ using AutoMapper; using NUnit.Framework; -using Rhino.Mocks; using Umbraco.Core; -using Umbraco.Core.Cache; -using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Models.Mapping; using Umbraco.Core.ObjectResolution; @@ -33,8 +30,6 @@ namespace Umbraco.Tests.TestHelpers //mock the Umbraco settings that we need var settings = SettingsForTests.GetMockSettings(); - - //sets the global singleton to use the mocked format SettingsForTests.ConfigureSettings(settings); //set our local variable for tests to use (preferably) diff --git a/src/Umbraco.Tests/TestHelpers/FakeHttpContextFactory.cs b/src/Umbraco.Tests/TestHelpers/FakeHttpContextFactory.cs index 97ad70f6cf..ba5a98b01d 100644 --- a/src/Umbraco.Tests/TestHelpers/FakeHttpContextFactory.cs +++ b/src/Umbraco.Tests/TestHelpers/FakeHttpContextFactory.cs @@ -1,10 +1,8 @@ using System; using System.Collections.Generic; using System.Collections.Specialized; -using System.Linq; using System.Security; using System.Security.Principal; -using System.Text; using System.Web; using System.Web.Routing; using Rhino.Mocks; diff --git a/src/Umbraco.Tests/TestHelpers/SettingsForTests.cs b/src/Umbraco.Tests/TestHelpers/SettingsForTests.cs index a841292762..c5bb374548 100644 --- a/src/Umbraco.Tests/TestHelpers/SettingsForTests.cs +++ b/src/Umbraco.Tests/TestHelpers/SettingsForTests.cs @@ -1,13 +1,10 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Text; using System.Configuration; -using Rhino.Mocks; +using Moq; +using Umbraco.Core; using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.UmbracoSettings; -using Umbraco.Tests.Configurations.UmbracoSettings; namespace Umbraco.Tests.TestHelpers { @@ -30,52 +27,51 @@ namespace Umbraco.Tests.TestHelpers /// public static IUmbracoSettingsSection GetMockSettings() { - var settings = MockRepository.GenerateStub(); + var settings = new Mock(); - var content = MockRepository.GenerateStub(); - var security = MockRepository.GenerateStub(); - var requestHandler = MockRepository.GenerateStub(); - var templates = MockRepository.GenerateStub(); - var dev = MockRepository.GenerateStub(); - var viewStateMover = MockRepository.GenerateStub(); - var logging = MockRepository.GenerateStub(); - var tasks = MockRepository.GenerateStub(); - var distCall = MockRepository.GenerateStub(); - var repos = MockRepository.GenerateStub(); - var providers = MockRepository.GenerateStub(); - var help = MockRepository.GenerateStub(); - var routing = MockRepository.GenerateStub(); - var scripting = MockRepository.GenerateStub(); + var content = new Mock(); + var security = new Mock(); + var requestHandler = new Mock(); + var templates = new Mock(); + var dev = new Mock(); + var viewStateMover = new Mock(); + var logging = new Mock(); + var tasks = new Mock(); + var distCall = new Mock(); + var repos = new Mock(); + var providers = new Mock(); + var help = new Mock(); + var routing = new Mock(); + var scripting = new Mock(); - settings.Stub(x => x.Content).Return(content); - settings.Stub(x => x.Security).Return(security); - settings.Stub(x => x.RequestHandler).Return(requestHandler); - settings.Stub(x => x.Templates).Return(templates); - settings.Stub(x => x.Developer).Return(dev); - settings.Stub(x => x.ViewStateMoverModule).Return(viewStateMover); - settings.Stub(x => x.Logging).Return(logging); - settings.Stub(x => x.ScheduledTasks).Return(tasks); - settings.Stub(x => x.DistributedCall).Return(distCall); - settings.Stub(x => x.PackageRepositories).Return(repos); - settings.Stub(x => x.Providers).Return(providers); - settings.Stub(x => x.Help).Return(help); - settings.Stub(x => x.WebRouting).Return(routing); - settings.Stub(x => x.Scripting).Return(scripting); + settings.Setup(x => x.Content).Returns(content.Object); + settings.Setup(x => x.Security).Returns(security.Object); + settings.Setup(x => x.RequestHandler).Returns(requestHandler.Object); + settings.Setup(x => x.Templates).Returns(templates.Object); + settings.Setup(x => x.Developer).Returns(dev.Object); + settings.Setup(x => x.ViewStateMoverModule).Returns(viewStateMover.Object); + settings.Setup(x => x.Logging).Returns(logging.Object); + settings.Setup(x => x.ScheduledTasks).Returns(tasks.Object); + settings.Setup(x => x.DistributedCall).Returns(distCall.Object); + settings.Setup(x => x.PackageRepositories).Returns(repos.Object); + settings.Setup(x => x.Providers).Returns(providers.Object); + settings.Setup(x => x.Help).Returns(help.Object); + settings.Setup(x => x.WebRouting).Returns(routing.Object); + settings.Setup(x => x.Scripting).Returns(scripting.Object); //Now configure some defaults - the defaults in the config section classes do NOT pertain to the mocked data!! - settings.Content.Stub(x => x.UseLegacyXmlSchema).Return(false); - settings.Content.Stub(x => x.ForceSafeAliases).Return(true); - settings.Content.Stub(x => x.ImageAutoFillProperties).Return(ContentImagingElement.GetDefaultImageAutoFillProperties()); - settings.Content.Stub(x => x.ImageFileTypes).Return(ContentImagingElement.GetDefaultImageFileTypes()); - settings.RequestHandler.Stub(x => x.AddTrailingSlash).Return(true); - settings.RequestHandler.Stub(x => x.UseDomainPrefixes).Return(false); - settings.RequestHandler.Stub(x => x.CharCollection).Return(RequestHandlerElement.GetDefaultCharReplacements()); - settings.Content.Stub(x => x.UmbracoLibraryCacheDuration).Return(1800); - settings.WebRouting.Stub(x => x.UrlProviderMode).Return("Auto"); - + settings.Setup(x => x.Content.UseLegacyXmlSchema).Returns(false); + settings.Setup(x => x.Content.ForceSafeAliases).Returns(true); + settings.Setup(x => x.Content.ImageAutoFillProperties).Returns(ContentImagingElement.GetDefaultImageAutoFillProperties()); + settings.Setup(x => x.Content.ImageFileTypes).Returns(ContentImagingElement.GetDefaultImageFileTypes()); + settings.Setup(x => x.RequestHandler.AddTrailingSlash).Returns(true); + settings.Setup(x => x.RequestHandler.UseDomainPrefixes).Returns(false); + settings.Setup(x => x.RequestHandler.CharCollection).Returns(RequestHandlerElement.GetDefaultCharReplacements()); + settings.Setup(x => x.Content.UmbracoLibraryCacheDuration).Returns(1800); + settings.Setup(x => x.WebRouting.UrlProviderMode).Returns("Auto"); + settings.Setup(x => x.Templates.DefaultRenderingEngine).Returns(RenderingEngine.Mvc); - - return settings; + return settings.Object; } // from appSettings diff --git a/src/Umbraco.Tests/TypeHelperTests.cs b/src/Umbraco.Tests/TypeHelperTests.cs index 355b218d76..d1017e9546 100644 --- a/src/Umbraco.Tests/TypeHelperTests.cs +++ b/src/Umbraco.Tests/TypeHelperTests.cs @@ -6,7 +6,6 @@ using System.Data.OleDb; using System.Data.SqlClient; using NUnit.Framework; using Umbraco.Core; -using Umbraco.Tests.PartialTrust; using Umbraco.Web; using UmbracoExamine; using UmbracoExamine.DataServices; @@ -21,7 +20,7 @@ namespace Umbraco.Tests /// Tests for TypeHelper /// [TestFixture] - public class TypeHelperTests : AbstractPartialTrustFixture + public class TypeHelperTests { [Test] @@ -74,12 +73,5 @@ namespace Umbraco.Tests } - public override void TestSetup() - { - } - - public override void TestTearDown() - { - } } } \ No newline at end of file diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index a3530e9792..3fd67c5fba 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -75,6 +75,9 @@ True ..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll + + ..\packages\Moq.4.1.1309.0919\lib\net40\Moq.dll + False ..\packages\Newtonsoft.Json.4.5.11\lib\net40\Newtonsoft.Json.dll @@ -203,7 +206,6 @@ - @@ -448,13 +450,6 @@ - - - - - - - diff --git a/src/Umbraco.Tests/UmbracoExamine/EventsTest.cs b/src/Umbraco.Tests/UmbracoExamine/EventsTest.cs index ede6c24b53..18343a96f5 100644 --- a/src/Umbraco.Tests/UmbracoExamine/EventsTest.cs +++ b/src/Umbraco.Tests/UmbracoExamine/EventsTest.cs @@ -3,13 +3,12 @@ using System.Linq; using Examine; using Lucene.Net.Store; using NUnit.Framework; -using Umbraco.Tests.PartialTrust; using UmbracoExamine; namespace Umbraco.Tests.UmbracoExamine { [TestFixture] - public class EventsTest : ExamineBaseTest + public class EventsTest : ExamineBaseTest { [Test] public void Events_Ignoring_Node() diff --git a/src/Umbraco.Tests/UmbracoExamine/ExamineBaseTest.cs b/src/Umbraco.Tests/UmbracoExamine/ExamineBaseTest.cs index 7f5969d984..85cd781946 100644 --- a/src/Umbraco.Tests/UmbracoExamine/ExamineBaseTest.cs +++ b/src/Umbraco.Tests/UmbracoExamine/ExamineBaseTest.cs @@ -1,17 +1,20 @@ -using Umbraco.Tests.PartialTrust; +using NUnit.Framework; using UmbracoExamine; namespace Umbraco.Tests.UmbracoExamine { - public abstract class ExamineBaseTest : AbstractPartialTrustFixture where T : class, IPartialTrustFixture, new() + [TestFixture] + public abstract class ExamineBaseTest { - public override void TestSetup() + [SetUp] + public virtual void TestSetup() { UmbracoExamineSearcher.DisableInitializationCheck = true; BaseUmbracoIndexer.DisableInitializationCheck = true; } - public override void TestTearDown() + [TearDown] + public virtual void TestTearDown() { UmbracoExamineSearcher.DisableInitializationCheck = null; BaseUmbracoIndexer.DisableInitializationCheck = null; diff --git a/src/Umbraco.Tests/UmbracoExamine/IndexTest.cs b/src/Umbraco.Tests/UmbracoExamine/IndexTest.cs index 9d177d6910..cf58f420ca 100644 --- a/src/Umbraco.Tests/UmbracoExamine/IndexTest.cs +++ b/src/Umbraco.Tests/UmbracoExamine/IndexTest.cs @@ -10,7 +10,6 @@ using Lucene.Net.Index; using Lucene.Net.Search; using Lucene.Net.Store; using NUnit.Framework; -using Umbraco.Tests.PartialTrust; using UmbracoExamine; namespace Umbraco.Tests.UmbracoExamine @@ -20,7 +19,7 @@ namespace Umbraco.Tests.UmbracoExamine /// Tests the standard indexing capabilities /// [TestFixture, RequiresSTA] - public class IndexTest : ExamineBaseTest + public class IndexTest : ExamineBaseTest { ///// diff --git a/src/Umbraco.Tests/UmbracoExamine/SearchTests.cs b/src/Umbraco.Tests/UmbracoExamine/SearchTests.cs index bab8eae88f..bcd9922e21 100644 --- a/src/Umbraco.Tests/UmbracoExamine/SearchTests.cs +++ b/src/Umbraco.Tests/UmbracoExamine/SearchTests.cs @@ -12,7 +12,7 @@ using Examine.LuceneEngine.SearchCriteria; namespace Umbraco.Tests.UmbracoExamine { [TestFixture] - public class SearchTests : ExamineBaseTest + public class SearchTests : ExamineBaseTest { [Test] diff --git a/src/Umbraco.Tests/UriUtilityTests.cs b/src/Umbraco.Tests/UriUtilityTests.cs index 148f014715..895ee247e8 100644 --- a/src/Umbraco.Tests/UriUtilityTests.cs +++ b/src/Umbraco.Tests/UriUtilityTests.cs @@ -1,9 +1,7 @@ using System; using System.Configuration; +using Moq; using NUnit.Framework; -using Rhino.Mocks; -using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Tests.TestHelpers; using Umbraco.Web; @@ -87,8 +85,9 @@ namespace Umbraco.Tests { ConfigurationManager.AppSettings.Set("umbracoUseDirectoryUrls", directoryUrls ? "true" : "false"); - var settings = MockRepository.GenerateStub(); - settings.Stub(x => x.RequestHandler.AddTrailingSlash).Return(trailingSlash); + var settings = SettingsForTests.GetMockSettings(); + var requestMock = Mock.Get(settings.RequestHandler); + requestMock.Setup(x => x.AddTrailingSlash).Returns(trailingSlash); SettingsForTests.ConfigureSettings(settings); UriUtility.SetAppDomainAppVirtualPath("/"); diff --git a/src/Umbraco.Tests/packages.config b/src/Umbraco.Tests/packages.config index 5ceb87abb1..cb3e047ba8 100644 --- a/src/Umbraco.Tests/packages.config +++ b/src/Umbraco.Tests/packages.config @@ -1,8 +1,8 @@  - + @@ -15,6 +15,7 @@ + diff --git a/src/Umbraco.Web.UI.Client/src/views/directives/umb-content-name.html b/src/Umbraco.Web.UI.Client/src/views/directives/umb-content-name.html index 6c6673e3ad..d98664bbf0 100644 --- a/src/Umbraco.Web.UI.Client/src/views/directives/umb-content-name.html +++ b/src/Umbraco.Web.UI.Client/src/views/directives/umb-content-name.html @@ -1,12 +1,15 @@
+ -

{{model}}

+

{{model}}

+ required + val-server-field="Name" /> Required {{contentNameForm.name.errorMsg}} +
+
diff --git a/src/Umbraco.Web/PropertyEditors/FileUploadPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/FileUploadPropertyEditor.cs index c52894e97a..57e9156f7b 100644 --- a/src/Umbraco.Web/PropertyEditors/FileUploadPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/FileUploadPropertyEditor.cs @@ -97,16 +97,16 @@ namespace Umbraco.Web.PropertyEditors private static void ResetProperties(IImagingAutoFillUploadField uploadFieldConfigNode, IContentBase content) { - if (content.Properties[uploadFieldConfigNode.WidthFieldAlias] != null) + if (content.Properties.Contains(uploadFieldConfigNode.WidthFieldAlias)) content.Properties[uploadFieldConfigNode.WidthFieldAlias].Value = string.Empty; - if (content.Properties[uploadFieldConfigNode.HeightFieldAlias] != null) + if (content.Properties.Contains(uploadFieldConfigNode.HeightFieldAlias)) content.Properties[uploadFieldConfigNode.HeightFieldAlias].Value = string.Empty; - if (content.Properties[uploadFieldConfigNode.LengthFieldAlias] != null) + if (content.Properties.Contains(uploadFieldConfigNode.LengthFieldAlias)) content.Properties[uploadFieldConfigNode.LengthFieldAlias].Value = string.Empty; - if (content.Properties[uploadFieldConfigNode.ExtensionFieldAlias] != null) + if (content.Properties.Contains(uploadFieldConfigNode.ExtensionFieldAlias)) content.Properties[uploadFieldConfigNode.ExtensionFieldAlias].Value = string.Empty; } @@ -114,16 +114,16 @@ namespace Umbraco.Web.PropertyEditors { var size = um.SupportsResizing ? (Size?)um.GetDimensions() : null; - if (content.Properties[uploadFieldConfigNode.WidthFieldAlias] != null) + if (content.Properties.Contains(uploadFieldConfigNode.WidthFieldAlias)) content.Properties[uploadFieldConfigNode.WidthFieldAlias].Value = size.HasValue ? size.Value.Width.ToInvariantString() : string.Empty; - if (content.Properties[uploadFieldConfigNode.HeightFieldAlias] != null) + if (content.Properties.Contains(uploadFieldConfigNode.HeightFieldAlias)) content.Properties[uploadFieldConfigNode.HeightFieldAlias].Value = size.HasValue ? size.Value.Height.ToInvariantString() : string.Empty; - if (content.Properties[uploadFieldConfigNode.LengthFieldAlias] != null) + if (content.Properties.Contains(uploadFieldConfigNode.LengthFieldAlias)) content.Properties[uploadFieldConfigNode.LengthFieldAlias].Value = um.Length; - if (content.Properties[uploadFieldConfigNode.ExtensionFieldAlias] != null) + if (content.Properties.Contains(uploadFieldConfigNode.ExtensionFieldAlias)) content.Properties[uploadFieldConfigNode.ExtensionFieldAlias].Value = um.Extension; }