Keep structuring tests

This commit is contained in:
Stephan
2016-11-07 19:12:09 +01:00
parent 224986d56c
commit 2967add41a
56 changed files with 1541 additions and 1621 deletions

View File

@@ -1,9 +1,7 @@
using System;
namespace Umbraco.Tests.TestHelpers
namespace Umbraco.Core
{
// fixme - belongs to Core?
/// <summary>
/// Represents a value that can be assigned a value.
/// </summary>

View File

@@ -554,6 +554,7 @@
<Compile Include="Services\OperationStatusType.cs" />
<Compile Include="Services\ServiceWithResultExtensions.cs" />
<Compile Include="Services\TaskService.cs" />
<Compile Include="Settable.cs" />
<Compile Include="Strategies\ManifestWatcherComponent.cs" />
<Compile Include="Strings\Css\StylesheetHelper.cs" />
<Compile Include="Models\IPartialView.cs" />

View File

@@ -1,25 +1,24 @@
using System;
using NUnit.Framework;
using Umbraco.Core;
namespace Umbraco.Tests
{
[TestFixture]
public class AttemptTests
{
[Test]
public void AttemptIf()
{
// just making sure that it is ok to use TryParse as a condition
int value;
var attempt = Attempt.If(int.TryParse("1234", out value), value);
Assert.IsTrue(attempt.Success);
Assert.AreEqual(1234, attempt.Result);
attempt = Attempt.If(int.TryParse("12xxx34", out value), value);
Assert.IsFalse(attempt.Success);
}
}
}
using NUnit.Framework;
using Umbraco.Core;
namespace Umbraco.Tests.CoreThings
{
[TestFixture]
public class AttemptTests
{
[Test]
public void AttemptIf()
{
// just making sure that it is ok to use TryParse as a condition
int value;
var attempt = Attempt.If(int.TryParse("1234", out value), value);
Assert.IsTrue(attempt.Success);
Assert.AreEqual(1234, attempt.Result);
attempt = Attempt.If(int.TryParse("12xxx34", out value), value);
Assert.IsFalse(attempt.Success);
}
}
}

View File

@@ -2,7 +2,7 @@
using NUnit.Framework;
using Umbraco.Core;
namespace Umbraco.Tests
namespace Umbraco.Tests.CoreThings
{
[TestFixture]
public class CallContextTests
@@ -35,11 +35,11 @@ namespace Umbraco.Tests
SafeCallContext.Clear();
}
//[TearDown]
//public void TearDown()
//{
// SafeCallContext.Clear();
//}
[TearDown]
public void TearDown()
{
SafeCallContext.Clear();
}
[Test]
public void Test1()

View File

@@ -3,16 +3,15 @@ using Lucene.Net.Index;
using NUnit.Framework;
using Umbraco.Core;
namespace Umbraco.Tests
namespace Umbraco.Tests.CoreThings
{
[TestFixture]
public class DelegateExtensionsTests
{
[Test]
public void Only_Executes_Specific_Count()
{
var maxTries = 5;
const int maxTries = 5;
var totalTries = 0;
DelegateExtensions.RetryUntilSuccessOrMaxAttempts((currentTry) =>
{
@@ -26,21 +25,14 @@ namespace Umbraco.Tests
[Test]
public void Quits_On_Success_Count()
{
var maxTries = 5;
var totalTries = 0;
DelegateExtensions.RetryUntilSuccessOrMaxAttempts((currentTry) =>
{
totalTries = currentTry;
if (totalTries == 2)
{
return Attempt<string>.Succeed();
}
return Attempt<string>.Fail();
return totalTries == 2 ? Attempt<string>.Succeed() : Attempt<string>.Fail();
}, 5, TimeSpan.FromMilliseconds(10));
Assert.AreEqual(2, totalTries);
}
}
}

View File

@@ -1,196 +1,197 @@
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Tests;
using umbraco.BusinessLogic;
namespace Umbraco.Tests
{
[TestFixture]
public class EnumerableExtensionsTests
{
[Test]
public void Unsorted_Sequence_Equal()
{
var list1 = new[] { 1, 2, 3, 4, 5, 6 };
var list2 = new[] { 6, 5, 3, 2, 1, 4 };
var list3 = new[] { 6, 5, 4, 3, 2, 2 };
Assert.IsTrue(list1.UnsortedSequenceEqual(list2));
Assert.IsTrue(list2.UnsortedSequenceEqual(list1));
Assert.IsFalse(list1.UnsortedSequenceEqual(list3));
Assert.IsTrue(((IEnumerable<object>)null).UnsortedSequenceEqual(null));
Assert.IsFalse(((IEnumerable<int>)null).UnsortedSequenceEqual(list1));
Assert.IsFalse(list1.UnsortedSequenceEqual(null));
}
[Test]
public void Contains_All()
{
var list1 = new[] {1, 2, 3, 4, 5, 6};
var list2 = new[] {6, 5, 3, 2, 1, 4};
var list3 = new[] {6, 5, 4, 3};
Assert.IsTrue(list1.ContainsAll(list2));
Assert.IsTrue(list2.ContainsAll(list1));
Assert.IsTrue(list1.ContainsAll(list3));
Assert.IsFalse(list3.ContainsAll(list1));
}
[Test]
public void Flatten_List_2()
{
var hierarchy = new TestItem()
{
Children = new List<TestItem>()
{
new TestItem(),
new TestItem(),
new TestItem()
}
};
var flattened = hierarchy.Children.FlattenList(x => x.Children);
var selectRecursive = hierarchy.Children.SelectRecursive(x => x.Children);
Assert.AreEqual(3, flattened.Count());
Assert.AreEqual(3, selectRecursive.Count());
Assert.IsTrue(flattened.SequenceEqual(selectRecursive));
}
[Test]
public void Flatten_List()
{
var hierarchy = new TestItem()
{
Children = new List<TestItem>()
{
new TestItem()
{
Children = new List<TestItem>()
{
new TestItem()
{
Children = new List<TestItem>()
{
new TestItem()
{
Children = new List<TestItem>()
{
new TestItem(),
new TestItem()
}
}
}
}
}
},
new TestItem()
{
Children = new List<TestItem>()
{
new TestItem()
{
Children = new List<TestItem>()
{
new TestItem()
{
Children = new List<TestItem>()
}
}
},
new TestItem()
{
Children = new List<TestItem>()
{
new TestItem()
{
Children = new List<TestItem>()
}
}
}
}
},
}
};
var flattened = hierarchy.Children.FlattenList(x => x.Children);
var selectRecursive = hierarchy.Children.FlattenList(x => x.Children);
Assert.AreEqual(10, flattened.Count());
Assert.AreEqual(10, selectRecursive.Count());
Assert.IsTrue(flattened.SequenceEqual(selectRecursive));
}
private class TestItem
{
public TestItem()
{
Children = Enumerable.Empty<TestItem>();
}
public IEnumerable<TestItem> Children { get; set; }
}
[Test]
public void InGroupsOf_ReturnsAllElements()
{
var integers = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
var groupsOfTwo = integers.InGroupsOf(2).ToArray();
var flattened = groupsOfTwo.SelectMany(x => x).ToArray();
Assert.That(groupsOfTwo.Length, Is.EqualTo(5));
Assert.That(flattened.Length, Is.EqualTo(integers.Length));
CollectionAssert.AreEquivalent(integers, flattened);
var groupsOfMassive = integers.InGroupsOf(100).ToArray();
Assert.That(groupsOfMassive.Length, Is.EqualTo(1));
flattened = groupsOfMassive.SelectMany(x => x).ToArray();
Assert.That(flattened.Length, Is.EqualTo(integers.Length));
CollectionAssert.AreEquivalent(integers, flattened);
}
[Test]
public void InGroupsOf_CanRepeat()
{
var integers = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
var inGroupsOf = integers.InGroupsOf(2);
Assert.AreEqual(5, inGroupsOf.Count());
Assert.AreEqual(5, inGroupsOf.Count()); // again
}
[TestCase]
public void DistinctBy_ReturnsDistinctElements_AndResetsIteratorCorrectly()
{
// Arrange
var tuple1 = new System.Tuple<string, string>("fruit", "apple");
var tuple2 = new System.Tuple<string, string>("fruit", "orange");
var tuple3 = new System.Tuple<string, string>("fruit", "banana");
var tuple4 = new System.Tuple<string, string>("fruit", "banana"); // Should be filtered out
var list = new List<System.Tuple<string, string>>()
{
tuple1,
tuple2,
tuple3,
tuple4
};
// Act
var iteratorSource = list.DistinctBy(x => x.Item2);
// Assert
// First check distinction
Assert.AreEqual(3, iteratorSource.Count());
// Check for iterator block mistakes - reset to original query first
iteratorSource = list.DistinctBy(x => x.Item2);
Assert.AreEqual(iteratorSource.Count(), iteratorSource.ToList().Count());
}
}
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using Umbraco.Core;
namespace Umbraco.Tests.CoreThings
{
[TestFixture]
public class EnumerableExtensionsTests
{
[Test]
public void Unsorted_Sequence_Equal()
{
var list1 = new[] { 1, 2, 3, 4, 5, 6 };
var list2 = new[] { 6, 5, 3, 2, 1, 4 };
var list3 = new[] { 6, 5, 4, 3, 2, 2 };
Assert.IsTrue(list1.UnsortedSequenceEqual(list2));
Assert.IsTrue(list2.UnsortedSequenceEqual(list1));
Assert.IsFalse(list1.UnsortedSequenceEqual(list3));
Assert.IsTrue(((IEnumerable<object>)null).UnsortedSequenceEqual(null));
Assert.IsFalse(((IEnumerable<int>)null).UnsortedSequenceEqual(list1));
Assert.IsFalse(list1.UnsortedSequenceEqual(null));
}
[Test]
public void Contains_All()
{
var list1 = new[] {1, 2, 3, 4, 5, 6};
var list2 = new[] {6, 5, 3, 2, 1, 4};
var list3 = new[] {6, 5, 4, 3};
Assert.IsTrue(list1.ContainsAll(list2));
Assert.IsTrue(list2.ContainsAll(list1));
Assert.IsTrue(list1.ContainsAll(list3));
Assert.IsFalse(list3.ContainsAll(list1));
}
[Test]
public void Flatten_List_2()
{
var hierarchy = new TestItem
{
Children = new List<TestItem>
{
new TestItem(),
new TestItem(),
new TestItem()
}
};
#pragma warning disable CS0618 // Type or member is obsolete
var flattened = hierarchy.Children.FlattenList(x => x.Children);
#pragma warning restore CS0618 // Type or member is obsolete
var selectRecursive = hierarchy.Children.SelectRecursive(x => x.Children);
Assert.AreEqual(3, flattened.Count());
Assert.AreEqual(3, selectRecursive.Count());
Assert.IsTrue(flattened.SequenceEqual(selectRecursive));
}
[Test]
public void Flatten_List()
{
var hierarchy = new TestItem
{
Children = new List<TestItem>
{
new TestItem
{
Children = new List<TestItem>
{
new TestItem
{
Children = new List<TestItem>
{
new TestItem
{
Children = new List<TestItem>
{
new TestItem(),
new TestItem()
}
}
}
}
}
},
new TestItem
{
Children = new List<TestItem>
{
new TestItem
{
Children = new List<TestItem>
{
new TestItem
{
Children = new List<TestItem>()
}
}
},
new TestItem
{
Children = new List<TestItem>
{
new TestItem
{
Children = new List<TestItem>()
}
}
}
}
}
}
};
#pragma warning disable CS0618 // Type or member is obsolete
var flattened = hierarchy.Children.FlattenList(x => x.Children);
#pragma warning restore CS0618 // Type or member is obsolete
var selectRecursive = hierarchy.Children.SelectRecursive(x => x.Children);
Assert.AreEqual(10, flattened.Count());
Assert.AreEqual(10, selectRecursive.Count());
Assert.IsTrue(flattened.SequenceEqual(selectRecursive));
}
private class TestItem
{
public TestItem()
{
Children = Enumerable.Empty<TestItem>();
}
public IEnumerable<TestItem> Children { get; set; }
}
[Test]
public void InGroupsOf_ReturnsAllElements()
{
var integers = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
var groupsOfTwo = integers.InGroupsOf(2).ToArray();
var flattened = groupsOfTwo.SelectMany(x => x).ToArray();
Assert.That(groupsOfTwo.Length, Is.EqualTo(5));
Assert.That(flattened.Length, Is.EqualTo(integers.Length));
CollectionAssert.AreEquivalent(integers, flattened);
var groupsOfMassive = integers.InGroupsOf(100).ToArray();
Assert.That(groupsOfMassive.Length, Is.EqualTo(1));
flattened = groupsOfMassive.SelectMany(x => x).ToArray();
Assert.That(flattened.Length, Is.EqualTo(integers.Length));
CollectionAssert.AreEquivalent(integers, flattened);
}
[Test]
public void InGroupsOf_CanRepeat()
{
var integers = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
var inGroupsOf = integers.InGroupsOf(2);
Assert.AreEqual(5, inGroupsOf.Count());
Assert.AreEqual(5, inGroupsOf.Count()); // again
}
[TestCase]
public void DistinctBy_ReturnsDistinctElements_AndResetsIteratorCorrectly()
{
// Arrange
var tuple1 = new System.Tuple<string, string>("fruit", "apple");
var tuple2 = new System.Tuple<string, string>("fruit", "orange");
var tuple3 = new System.Tuple<string, string>("fruit", "banana");
var tuple4 = new System.Tuple<string, string>("fruit", "banana"); // Should be filtered out
var list = new List<System.Tuple<string, string>>()
{
tuple1,
tuple2,
tuple3,
tuple4
};
// Act
var iteratorSource = list.DistinctBy(x => x.Item2);
// Assert
// First check distinction
Assert.AreEqual(3, iteratorSource.Count());
// Check for iterator block mistakes - reset to original query first
iteratorSource = list.DistinctBy(x => x.Item2);
Assert.AreEqual(iteratorSource.Count(), iteratorSource.ToList().Count());
}
}
}

View File

@@ -1,198 +1,185 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading;
using System.Web.UI.WebControls;
using NUnit.Framework;
using Umbraco.Core;
namespace Umbraco.Tests
{
[TestFixture]
public class ObjectExtensionsTests
{
[TestFixtureSetUp]
public void FixtureSetup()
{
}
[Test]
public void CanParseStringToUnit()
{
var stringUnit = "1234px";
object objUnit = "1234px";
var result = stringUnit.TryConvertTo<Unit>();
var result2 = objUnit.TryConvertTo<Unit>();
var unit = new Unit("1234px");
Assert.IsTrue(result.Success);
Assert.IsTrue(result2.Success);
Assert.AreEqual(unit, result.Result);
Assert.AreEqual(unit, result2.Result);
}
[Test]
public void Can_Convert_List_To_Enumerable()
{
var list = new List<string>() {"hello", "world", "awesome"};
var result = list.TryConvertTo<IEnumerable<string>>();
Assert.IsTrue(result.Success);
Assert.AreEqual(3, result.Result.Count());
}
[Test]
public void ObjectExtensions_Object_To_Dictionary()
{
//Arrange
var obj = new { Key1 = "value1", Key2 = "value2", Key3 = "value3" };
//Act
var d = obj.ToDictionary<string>();
//Assert
Assert.IsTrue(d.Keys.Contains("Key1"));
Assert.IsTrue(d.Keys.Contains("Key2"));
Assert.IsTrue(d.Keys.Contains("Key3"));
Assert.AreEqual(d["Key1"], "value1");
Assert.AreEqual(d["Key2"], "value2");
Assert.AreEqual(d["Key3"], "value3");
}
[Test]
public void CanConvertIntToNullableInt()
{
var i = 1;
var result = i.TryConvertTo<int?>();
Assert.That(result.Success, Is.True);
}
[Test]
public void CanConvertNullableIntToInt()
{
int? i = 1;
var result = i.TryConvertTo<int>();
Assert.That(result.Success, Is.True);
}
[Test]
public virtual void CanConvertStringToBool()
{
var testCases = new Dictionary<string, bool>
{
{"TRUE", true},
{"True", true},
{"true", true},
{"1", true},
{"FALSE", false},
{"False", false},
{"false", false},
{"0", false},
{"", false}
};
foreach (var testCase in testCases)
{
var result = testCase.Key.TryConvertTo<bool>();
Assert.IsTrue(result.Success, testCase.Key);
Assert.AreEqual(testCase.Value, result.Result, testCase.Key);
}
}
[TestCase("2012-11-10", true)]
[TestCase("2012/11/10", true)]
[TestCase("10/11/2012", true)]// assuming your culture uses DD/MM/YYYY
[TestCase("11/10/2012", false)]// assuming your culture uses DD/MM/YYYY
[TestCase("Sat 10, Nov 2012", true)]
[TestCase("Saturday 10, Nov 2012", true)]
[TestCase("Sat 10, November 2012", true)]
[TestCase("Saturday 10, November 2012", true)]
[TestCase("2012-11-10 13:14:15", true)]
[TestCase("2012-11-10T13:14:15Z", true)]
public virtual void CanConvertStringToDateTime(string date, bool outcome)
{
var dateTime = new DateTime(2012, 11, 10, 13, 14, 15);
var result = date.TryConvertTo<DateTime>();
Assert.IsTrue(result.Success, date);
Assert.AreEqual(DateTime.Equals(dateTime.Date, result.Result.Date), outcome, date);
}
[Test]
public virtual void CanConvertBlankStringToNullDateTime()
{
var result = "".TryConvertTo<DateTime?>();
Assert.IsTrue(result.Success);
Assert.IsNull(result.Result);
}
[Test]
public virtual void CanConvertBlankStringToNullBool()
{
var result = "".TryConvertTo<bool?>();
Assert.IsTrue(result.Success);
Assert.IsNull(result.Result);
}
[Test]
public virtual void CanConvertBlankStringToDateTime()
{
var result = "".TryConvertTo<DateTime>();
Assert.IsTrue(result.Success);
Assert.AreEqual(DateTime.MinValue, result.Result);
}
[Test]
public virtual void CanConvertObjectToString_Using_ToString_Overload()
{
var result = new MyTestObject().TryConvertTo<string>();
Assert.IsTrue(result.Success);
Assert.AreEqual("Hello world", result.Result);
}
[Test]
public virtual void CanConvertObjectToSameObject()
{
var obj = new MyTestObject();
var result = obj.TryConvertTo<object>();
Assert.AreEqual(obj, result.Result);
}
private CultureInfo savedCulture;
/// <summary>
/// Run once before each test in derived test fixtures.
/// </summary>
[SetUp]
public void TestSetup()
{
savedCulture = Thread.CurrentThread.CurrentCulture;
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB"); // make sure the dates parse correctly
return;
}
/// <summary>
/// Run once after each test in derived test fixtures.
/// </summary>
[TearDown]
public void TestTearDown()
{
Thread.CurrentThread.CurrentCulture = savedCulture;
return;
}
private class MyTestObject
{
public override string ToString()
{
return "Hello world";
}
}
}
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading;
using System.Web.UI.WebControls;
using NUnit.Framework;
using Umbraco.Core;
namespace Umbraco.Tests.CoreThings
{
[TestFixture]
public class ObjectExtensionsTests
{
private CultureInfo _savedCulture;
[SetUp]
public void TestSetup()
{
_savedCulture = Thread.CurrentThread.CurrentCulture;
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB"); // make sure the dates parse correctly
}
[TearDown]
public void TestTearDown()
{
Thread.CurrentThread.CurrentCulture = _savedCulture;
}
[Test]
public void CanParseStringToUnit()
{
const string stringUnit = "1234px";
object objUnit = "1234px";
var result = stringUnit.TryConvertTo<Unit>();
var result2 = objUnit.TryConvertTo<Unit>();
var unit = new Unit("1234px");
Assert.IsTrue(result.Success);
Assert.IsTrue(result2.Success);
Assert.AreEqual(unit, result.Result);
Assert.AreEqual(unit, result2.Result);
}
[Test]
public void Can_Convert_List_To_Enumerable()
{
var list = new List<string> {"hello", "world", "awesome"};
var result = list.TryConvertTo<IEnumerable<string>>();
Assert.IsTrue(result.Success);
Assert.AreEqual(3, result.Result.Count());
}
[Test]
public void ObjectExtensions_Object_To_Dictionary()
{
//Arrange
var obj = new { Key1 = "value1", Key2 = "value2", Key3 = "value3" };
//Act
var d = obj.ToDictionary<string>();
//Assert
Assert.IsTrue(d.Keys.Contains("Key1"));
Assert.IsTrue(d.Keys.Contains("Key2"));
Assert.IsTrue(d.Keys.Contains("Key3"));
Assert.AreEqual(d["Key1"], "value1");
Assert.AreEqual(d["Key2"], "value2");
Assert.AreEqual(d["Key3"], "value3");
}
[Test]
public void CanConvertIntToNullableInt()
{
var i = 1;
var result = i.TryConvertTo<int?>();
Assert.That(result.Success, Is.True);
}
[Test]
public void CanConvertNullableIntToInt()
{
int? i = 1;
var result = i.TryConvertTo<int>();
Assert.That(result.Success, Is.True);
}
[Test]
public virtual void CanConvertStringToBool()
{
var testCases = new Dictionary<string, bool>
{
{"TRUE", true},
{"True", true},
{"true", true},
{"1", true},
{"FALSE", false},
{"False", false},
{"false", false},
{"0", false},
{"", false}
};
foreach (var testCase in testCases)
{
var result = testCase.Key.TryConvertTo<bool>();
Assert.IsTrue(result.Success, testCase.Key);
Assert.AreEqual(testCase.Value, result.Result, testCase.Key);
}
}
[TestCase("2012-11-10", true)]
[TestCase("2012/11/10", true)]
[TestCase("10/11/2012", true)]// assuming your culture uses DD/MM/YYYY
[TestCase("11/10/2012", false)]// assuming your culture uses DD/MM/YYYY
[TestCase("Sat 10, Nov 2012", true)]
[TestCase("Saturday 10, Nov 2012", true)]
[TestCase("Sat 10, November 2012", true)]
[TestCase("Saturday 10, November 2012", true)]
[TestCase("2012-11-10 13:14:15", true)]
[TestCase("2012-11-10T13:14:15Z", true)]
public virtual void CanConvertStringToDateTime(string date, bool outcome)
{
var dateTime = new DateTime(2012, 11, 10, 13, 14, 15);
var result = date.TryConvertTo<DateTime>();
Assert.IsTrue(result.Success, date);
Assert.AreEqual(DateTime.Equals(dateTime.Date, result.Result.Date), outcome, date);
}
[Test]
public virtual void CanConvertBlankStringToNullDateTime()
{
var result = "".TryConvertTo<DateTime?>();
Assert.IsTrue(result.Success);
Assert.IsNull(result.Result);
}
[Test]
public virtual void CanConvertBlankStringToNullBool()
{
var result = "".TryConvertTo<bool?>();
Assert.IsTrue(result.Success);
Assert.IsNull(result.Result);
}
[Test]
public virtual void CanConvertBlankStringToDateTime()
{
var result = "".TryConvertTo<DateTime>();
Assert.IsTrue(result.Success);
Assert.AreEqual(DateTime.MinValue, result.Result);
}
[Test]
public virtual void CanConvertObjectToString_Using_ToString_Overload()
{
var result = new MyTestObject().TryConvertTo<string>();
Assert.IsTrue(result.Success);
Assert.AreEqual("Hello world", result.Result);
}
[Test]
public virtual void CanConvertObjectToSameObject()
{
var obj = new MyTestObject();
var result = obj.TryConvertTo<object>();
Assert.AreEqual(obj, result.Result);
}
private class MyTestObject
{
public override string ToString()
{
return "Hello world";
}
}
}
}

View File

@@ -1,12 +1,11 @@
using System;
using LightInject;
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.Strings;
using Umbraco.Tests.TestHelpers;
using Umbraco.Core.DI;
namespace Umbraco.Tests
namespace Umbraco.Tests.CoreThings
{
[TestFixture]
public class TryConvertToTests : UmbracoTestBase

View File

@@ -1,213 +1,218 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.IO;
namespace Umbraco.Tests
{
[TestFixture]
public class UriExtensionsTests
{
[TearDown]
public void TearDown()
{
SystemDirectories.Root = "";
}
[TestCase("http://www.domain.com/umbraco", "", true)]
[TestCase("http://www.domain.com/Umbraco/", "", true)]
[TestCase("http://www.domain.com/umbraco/default.aspx", "", true)]
[TestCase("http://www.domain.com/umbraco/test/test", "", false)]
[TestCase("http://www.domain.com/umbraco/test/test/test", "", false)]
[TestCase("http://www.domain.com/Umbraco/test/test.aspx", "", true)]
[TestCase("http://www.domain.com/umbraco/test/test.js", "", true)]
[TestCase("http://www.domain.com/umbrac", "", false)]
[TestCase("http://www.domain.com/test", "", false)]
[TestCase("http://www.domain.com/test/umbraco", "", false)]
[TestCase("http://www.domain.com/test/umbraco.aspx", "", false)]
[TestCase("http://www.domain.com/Umbraco/restServices/blah", "", true)]
[TestCase("http://www.domain.com/Umbraco/Backoffice/blah", "", true)]
[TestCase("http://www.domain.com/Umbraco/anything", "", true)]
[TestCase("http://www.domain.com/Umbraco/anything/", "", true)]
[TestCase("http://www.domain.com/Umbraco/surface/blah", "", false)]
[TestCase("http://www.domain.com/umbraco/api/blah", "", false)]
[TestCase("http://www.domain.com/myvdir/umbraco/api/blah", "myvdir", false)]
[TestCase("http://www.domain.com/MyVdir/umbraco/api/blah", "/myvdir", false)]
[TestCase("http://www.domain.com/MyVdir/Umbraco/", "myvdir", true)]
[TestCase("http://www.domain.com/MyVdir/Umbraco/restServices/blah", "/myvdir", true)]
[TestCase("http://www.domain.com/umbraco/webservices/legacyAjaxCalls.asmx/js", "", true)]
[TestCase("http://www.domain.com/umbraco/test/legacyAjaxCalls.ashx?some=query&blah=js", "", true)]
public void Is_Back_Office_Request(string input, string virtualPath, bool expected)
{
SystemDirectories.Root = virtualPath;
var source = new Uri(input);
Assert.AreEqual(expected, source.IsBackOfficeRequest(virtualPath));
}
[TestCase("http://www.domain.com/install", true)]
[TestCase("http://www.domain.com/Install/", true)]
[TestCase("http://www.domain.com/install/default.aspx", true)]
[TestCase("http://www.domain.com/install/test/test", true)]
[TestCase("http://www.domain.com/Install/test/test.aspx", true)]
[TestCase("http://www.domain.com/install/test/test.js", true)]
[TestCase("http://www.domain.com/instal", false)]
[TestCase("http://www.domain.com/umbraco", false)]
[TestCase("http://www.domain.com/umbraco/umbraco", false)]
[TestCase("http://www.domain.com/test/umbraco.aspx", false)]
public void Is_Installer_Request(string input, bool expected)
{
var source = new Uri(input);
Assert.AreEqual(expected, source.IsInstallerRequest());
}
[TestCase("http://www.domain.com/foo/bar", "/", "http://www.domain.com/")]
[TestCase("http://www.domain.com/foo/bar#hop", "/", "http://www.domain.com/")]
[TestCase("http://www.domain.com/foo/bar?q=2#hop", "/", "http://www.domain.com/?q=2")]
[TestCase("http://www.domain.com/foo/bar", "/path/to/page", "http://www.domain.com/path/to/page")]
[TestCase("http://www.domain.com/foo/bar", "/path/to/page/", "http://www.domain.com/path/to/page/")]
[TestCase("http://www.domain.com/", "/path/to/page/", "http://www.domain.com/path/to/page/")]
[TestCase("http://www.domain.com", "/path/to/page/", "http://www.domain.com/path/to/page/")]
[TestCase("http://www.domain.com/foo?q=3", "/path/to/page/", "http://www.domain.com/path/to/page/?q=3")]
[TestCase("http://www.domain.com/foo#bang", "/path/to/page/", "http://www.domain.com/path/to/page/")]
[TestCase("http://www.domain.com/foo?q=3#bang", "/path/to/page/", "http://www.domain.com/path/to/page/?q=3")]
public void RewritePath(string input, string path, string expected)
{
var source = new Uri(input);
var output = source.Rewrite(path);
Assert.AreEqual(expected, output.ToString());
}
[TestCase("http://www.domain.com/", "path/to/page/", typeof(ArgumentException))]
[TestCase("http://www.domain.com", "path/to/page/", typeof(ArgumentException))]
public void RewritePath_Exceptions(string input, string path, Type exception)
{
var source = new Uri(input);
Assert.Throws(exception, () =>
{
var output = source.Rewrite(path);
});
}
[TestCase("http://www.domain.com/foo/bar", "/path/to/page", "", "http://www.domain.com/path/to/page")]
[TestCase("http://www.domain.com/foo/bar?k=3", "/path/to/page", "", "http://www.domain.com/path/to/page")]
[TestCase("http://www.domain.com/foo/bar?k=3#hop", "/path/to/page", "", "http://www.domain.com/path/to/page")]
[TestCase("http://www.domain.com/foo/bar", "/path/to/page", "?x=12", "http://www.domain.com/path/to/page?x=12")]
[TestCase("http://www.domain.com/foo/bar#hop", "/path/to/page", "?x=12", "http://www.domain.com/path/to/page?x=12")]
[TestCase("http://www.domain.com/foo/bar?k=3", "/path/to/page", "?x=12", "http://www.domain.com/path/to/page?x=12")]
[TestCase("http://www.domain.com/foo/bar?k=3#hop", "/path/to/page", "?x=12", "http://www.domain.com/path/to/page?x=12")]
public void RewritePathAndQuery(string input, string path, string query, string expected)
{
var source = new Uri(input);
var output = source.Rewrite(path, query);
Assert.AreEqual(expected, output.ToString());
}
[TestCase("http://www.domain.com/", "path/to/page/", "", typeof(ArgumentException))]
[TestCase("http://www.domain.com/", "/path/to/page/", "x=27", typeof(ArgumentException))]
public void RewritePathAndQuery_Exceptions(string input, string path, string query, Type exception)
{
var source = new Uri(input);
Assert.Throws(exception, () =>
{
var output = source.Rewrite(path, query);
});
}
[TestCase("http://www.domain.com", "/")]
[TestCase("http://www.domain.com/", "/")]
[TestCase("http://www.domain.com/foo", "/foo")]
[TestCase("http://www.domain.com/foo/", "/foo/")]
[TestCase("http://www.domain.com/foo/bar", "/foo/bar")]
[TestCase("http://www.domain.com/foo/bar%20nix", "/foo/bar%20nix")]
[TestCase("http://www.domain.com/foo/bar?q=7#hop", "/foo/bar")]
[TestCase("/", "/")]
[TestCase("/foo", "/foo")]
[TestCase("/foo/", "/foo/")]
[TestCase("/foo/bar", "/foo/bar")]
[TestCase("/foo/bar?q=7#hop", "/foo/bar")]
[TestCase("/foo%20bar/pof", "/foo%20bar/pof")]
public void GetSafeAbsolutePath(string input, string expected)
{
var source = new Uri(input, UriKind.RelativeOrAbsolute);
var output = source.GetSafeAbsolutePath();
Assert.AreEqual(expected, output);
}
[TestCase("http://www.domain.com/foo/bar%20nix", "/foo/bar nix")]
public void GetAbsolutePathDecoded(string input, string expected)
{
var source = new Uri(input, UriKind.RelativeOrAbsolute);
var output = source.GetAbsolutePathDecoded();
Assert.AreEqual(expected, output);
}
[TestCase("http://www.domain.com/foo/bar%20nix", "/foo/bar nix")]
[TestCase("/foo%20bar/pof", "/foo bar/pof")]
public void GetSafeAbsolutePathDecoded(string input, string expected)
{
var source = new Uri(input, UriKind.RelativeOrAbsolute);
var output = source.GetSafeAbsolutePathDecoded();
Assert.AreEqual(expected, output);
}
[TestCase("http://www.domain.com/path/to/page", "http://www.domain.com/path/to/page/")]
[TestCase("http://www.domain.com/path/to/", "http://www.domain.com/path/to/")]
[TestCase("http://www.domain.com/", "http://www.domain.com/")]
[TestCase("http://www.domain.com", "http://www.domain.com/")]
[TestCase("http://www.domain.com/path/to?q=3#yop", "http://www.domain.com/path/to/?q=3")]
public void EndPathWithSlash(string input, string expected)
{
var source = new Uri(input);
var output = source.EndPathWithSlash();
Assert.AreEqual(expected, output.ToString());
}
[TestCase("http://www.domain.com/path/to/page", "http://www.domain.com/path/to/page")]
[TestCase("http://www.domain.com/path/to/", "http://www.domain.com/path/to")]
[TestCase("http://www.domain.com/", "http://www.domain.com/")]
[TestCase("http://www.domain.com", "http://www.domain.com/")]
[TestCase("http://www.domain.com/path/to/?q=3#yop", "http://www.domain.com/path/to?q=3")]
public void TrimPathEndSlash(string input, string expected)
{
var source = new Uri(input);
var output = source.TrimPathEndSlash();
Assert.AreEqual(expected, output.ToString());
}
[TestCase("/foo/bar", "http://www.domain.com", "http://www.domain.com/foo/bar")]
[TestCase("/foo/bar", "http://www.domain.com/dang/dang", "http://www.domain.com/foo/bar")]
[TestCase("/", "http://www.domain.com/dang/dang", "http://www.domain.com/")]
[TestCase("/foo/bar", "http://www.domain.com/dang/dang?q=3#dang", "http://www.domain.com/foo/bar")]
[TestCase("/foo/bar?k=6#yop", "http://www.domain.com/dang/dang?q=3#dang", "http://www.domain.com/foo/bar?k=6")]
public void MakeAbsolute(string input, string reference, string expected)
{
var source = new Uri(input, UriKind.Relative);
var absolute = new Uri(reference);
var output = source.MakeAbsolute(absolute);
Assert.AreEqual(expected, output.ToString());
}
[TestCase("http://www.domain.com/path/to/page", "http://www.domain.com/path/to/page")]
[TestCase("http://www.domain.com/path/to/page/", "http://www.domain.com/path/to/page/")]
[TestCase("http://www.domain.com", "http://www.domain.com/")]
[TestCase("http://www.domain.com/", "http://www.domain.com/")]
[TestCase("http://www.domain.com/path/to?q=3#yop", "http://www.domain.com/path/to?q=3#yop")]
[TestCase("http://www.domain.com/path/to/?q=3#yop", "http://www.domain.com/path/to/?q=3#yop")]
[TestCase("http://www.domain.com:666/path/to/page", "http://www.domain.com/path/to/page")]
[TestCase("http://www.domain.com:666/path/to/page/", "http://www.domain.com/path/to/page/")]
[TestCase("http://www.domain.com:666", "http://www.domain.com/")]
[TestCase("http://www.domain.com:666/", "http://www.domain.com/")]
[TestCase("http://www.domain.com:666/path/to?q=3#yop", "http://www.domain.com/path/to?q=3#yop")]
[TestCase("http://www.domain.com:666/path/to/?q=3#yop", "http://www.domain.com/path/to/?q=3#yop")]
public void WithoutPort(string input, string expected)
{
var source = new Uri(input);
var output = source.WithoutPort();
Assert.AreEqual(expected, output.ToString());
}
}
}
using System;
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.IO;
namespace Umbraco.Tests.CoreThings
{
[TestFixture]
public class UriExtensionsTests
{
private string _root;
[SetUp]
public void SetUp()
{
_root = SystemDirectories.Root;
}
[TearDown]
public void TearDown()
{
SystemDirectories.Root = _root;
}
[TestCase("http://www.domain.com/umbraco", "", true)]
[TestCase("http://www.domain.com/Umbraco/", "", true)]
[TestCase("http://www.domain.com/umbraco/default.aspx", "", true)]
[TestCase("http://www.domain.com/umbraco/test/test", "", false)]
[TestCase("http://www.domain.com/umbraco/test/test/test", "", false)]
[TestCase("http://www.domain.com/Umbraco/test/test.aspx", "", true)]
[TestCase("http://www.domain.com/umbraco/test/test.js", "", true)]
[TestCase("http://www.domain.com/umbrac", "", false)]
[TestCase("http://www.domain.com/test", "", false)]
[TestCase("http://www.domain.com/test/umbraco", "", false)]
[TestCase("http://www.domain.com/test/umbraco.aspx", "", false)]
[TestCase("http://www.domain.com/Umbraco/restServices/blah", "", true)]
[TestCase("http://www.domain.com/Umbraco/Backoffice/blah", "", true)]
[TestCase("http://www.domain.com/Umbraco/anything", "", true)]
[TestCase("http://www.domain.com/Umbraco/anything/", "", true)]
[TestCase("http://www.domain.com/Umbraco/surface/blah", "", false)]
[TestCase("http://www.domain.com/umbraco/api/blah", "", false)]
[TestCase("http://www.domain.com/myvdir/umbraco/api/blah", "myvdir", false)]
[TestCase("http://www.domain.com/MyVdir/umbraco/api/blah", "/myvdir", false)]
[TestCase("http://www.domain.com/MyVdir/Umbraco/", "myvdir", true)]
[TestCase("http://www.domain.com/MyVdir/Umbraco/restServices/blah", "/myvdir", true)]
[TestCase("http://www.domain.com/umbraco/webservices/legacyAjaxCalls.asmx/js", "", true)]
[TestCase("http://www.domain.com/umbraco/test/legacyAjaxCalls.ashx?some=query&blah=js", "", true)]
public void Is_Back_Office_Request(string input, string virtualPath, bool expected)
{
SystemDirectories.Root = virtualPath;
var source = new Uri(input);
Assert.AreEqual(expected, source.IsBackOfficeRequest(virtualPath));
}
[TestCase("http://www.domain.com/install", true)]
[TestCase("http://www.domain.com/Install/", true)]
[TestCase("http://www.domain.com/install/default.aspx", true)]
[TestCase("http://www.domain.com/install/test/test", true)]
[TestCase("http://www.domain.com/Install/test/test.aspx", true)]
[TestCase("http://www.domain.com/install/test/test.js", true)]
[TestCase("http://www.domain.com/instal", false)]
[TestCase("http://www.domain.com/umbraco", false)]
[TestCase("http://www.domain.com/umbraco/umbraco", false)]
[TestCase("http://www.domain.com/test/umbraco.aspx", false)]
public void Is_Installer_Request(string input, bool expected)
{
var source = new Uri(input);
Assert.AreEqual(expected, source.IsInstallerRequest());
}
[TestCase("http://www.domain.com/foo/bar", "/", "http://www.domain.com/")]
[TestCase("http://www.domain.com/foo/bar#hop", "/", "http://www.domain.com/")]
[TestCase("http://www.domain.com/foo/bar?q=2#hop", "/", "http://www.domain.com/?q=2")]
[TestCase("http://www.domain.com/foo/bar", "/path/to/page", "http://www.domain.com/path/to/page")]
[TestCase("http://www.domain.com/foo/bar", "/path/to/page/", "http://www.domain.com/path/to/page/")]
[TestCase("http://www.domain.com/", "/path/to/page/", "http://www.domain.com/path/to/page/")]
[TestCase("http://www.domain.com", "/path/to/page/", "http://www.domain.com/path/to/page/")]
[TestCase("http://www.domain.com/foo?q=3", "/path/to/page/", "http://www.domain.com/path/to/page/?q=3")]
[TestCase("http://www.domain.com/foo#bang", "/path/to/page/", "http://www.domain.com/path/to/page/")]
[TestCase("http://www.domain.com/foo?q=3#bang", "/path/to/page/", "http://www.domain.com/path/to/page/?q=3")]
public void RewritePath(string input, string path, string expected)
{
var source = new Uri(input);
var output = source.Rewrite(path);
Assert.AreEqual(expected, output.ToString());
}
[TestCase("http://www.domain.com/", "path/to/page/", typeof(ArgumentException))]
[TestCase("http://www.domain.com", "path/to/page/", typeof(ArgumentException))]
public void RewritePath_Exceptions(string input, string path, Type exception)
{
var source = new Uri(input);
Assert.Throws(exception, () =>
{
var output = source.Rewrite(path);
});
}
[TestCase("http://www.domain.com/foo/bar", "/path/to/page", "", "http://www.domain.com/path/to/page")]
[TestCase("http://www.domain.com/foo/bar?k=3", "/path/to/page", "", "http://www.domain.com/path/to/page")]
[TestCase("http://www.domain.com/foo/bar?k=3#hop", "/path/to/page", "", "http://www.domain.com/path/to/page")]
[TestCase("http://www.domain.com/foo/bar", "/path/to/page", "?x=12", "http://www.domain.com/path/to/page?x=12")]
[TestCase("http://www.domain.com/foo/bar#hop", "/path/to/page", "?x=12", "http://www.domain.com/path/to/page?x=12")]
[TestCase("http://www.domain.com/foo/bar?k=3", "/path/to/page", "?x=12", "http://www.domain.com/path/to/page?x=12")]
[TestCase("http://www.domain.com/foo/bar?k=3#hop", "/path/to/page", "?x=12", "http://www.domain.com/path/to/page?x=12")]
public void RewritePathAndQuery(string input, string path, string query, string expected)
{
var source = new Uri(input);
var output = source.Rewrite(path, query);
Assert.AreEqual(expected, output.ToString());
}
[TestCase("http://www.domain.com/", "path/to/page/", "", typeof(ArgumentException))]
[TestCase("http://www.domain.com/", "/path/to/page/", "x=27", typeof(ArgumentException))]
public void RewritePathAndQuery_Exceptions(string input, string path, string query, Type exception)
{
var source = new Uri(input);
Assert.Throws(exception, () =>
{
var output = source.Rewrite(path, query);
});
}
[TestCase("http://www.domain.com", "/")]
[TestCase("http://www.domain.com/", "/")]
[TestCase("http://www.domain.com/foo", "/foo")]
[TestCase("http://www.domain.com/foo/", "/foo/")]
[TestCase("http://www.domain.com/foo/bar", "/foo/bar")]
[TestCase("http://www.domain.com/foo/bar%20nix", "/foo/bar%20nix")]
[TestCase("http://www.domain.com/foo/bar?q=7#hop", "/foo/bar")]
[TestCase("/", "/")]
[TestCase("/foo", "/foo")]
[TestCase("/foo/", "/foo/")]
[TestCase("/foo/bar", "/foo/bar")]
[TestCase("/foo/bar?q=7#hop", "/foo/bar")]
[TestCase("/foo%20bar/pof", "/foo%20bar/pof")]
public void GetSafeAbsolutePath(string input, string expected)
{
var source = new Uri(input, UriKind.RelativeOrAbsolute);
var output = source.GetSafeAbsolutePath();
Assert.AreEqual(expected, output);
}
[TestCase("http://www.domain.com/foo/bar%20nix", "/foo/bar nix")]
public void GetAbsolutePathDecoded(string input, string expected)
{
var source = new Uri(input, UriKind.RelativeOrAbsolute);
var output = source.GetAbsolutePathDecoded();
Assert.AreEqual(expected, output);
}
[TestCase("http://www.domain.com/foo/bar%20nix", "/foo/bar nix")]
[TestCase("/foo%20bar/pof", "/foo bar/pof")]
public void GetSafeAbsolutePathDecoded(string input, string expected)
{
var source = new Uri(input, UriKind.RelativeOrAbsolute);
var output = source.GetSafeAbsolutePathDecoded();
Assert.AreEqual(expected, output);
}
[TestCase("http://www.domain.com/path/to/page", "http://www.domain.com/path/to/page/")]
[TestCase("http://www.domain.com/path/to/", "http://www.domain.com/path/to/")]
[TestCase("http://www.domain.com/", "http://www.domain.com/")]
[TestCase("http://www.domain.com", "http://www.domain.com/")]
[TestCase("http://www.domain.com/path/to?q=3#yop", "http://www.domain.com/path/to/?q=3")]
public void EndPathWithSlash(string input, string expected)
{
var source = new Uri(input);
var output = source.EndPathWithSlash();
Assert.AreEqual(expected, output.ToString());
}
[TestCase("http://www.domain.com/path/to/page", "http://www.domain.com/path/to/page")]
[TestCase("http://www.domain.com/path/to/", "http://www.domain.com/path/to")]
[TestCase("http://www.domain.com/", "http://www.domain.com/")]
[TestCase("http://www.domain.com", "http://www.domain.com/")]
[TestCase("http://www.domain.com/path/to/?q=3#yop", "http://www.domain.com/path/to?q=3")]
public void TrimPathEndSlash(string input, string expected)
{
var source = new Uri(input);
var output = source.TrimPathEndSlash();
Assert.AreEqual(expected, output.ToString());
}
[TestCase("/foo/bar", "http://www.domain.com", "http://www.domain.com/foo/bar")]
[TestCase("/foo/bar", "http://www.domain.com/dang/dang", "http://www.domain.com/foo/bar")]
[TestCase("/", "http://www.domain.com/dang/dang", "http://www.domain.com/")]
[TestCase("/foo/bar", "http://www.domain.com/dang/dang?q=3#dang", "http://www.domain.com/foo/bar")]
[TestCase("/foo/bar?k=6#yop", "http://www.domain.com/dang/dang?q=3#dang", "http://www.domain.com/foo/bar?k=6")]
public void MakeAbsolute(string input, string reference, string expected)
{
var source = new Uri(input, UriKind.Relative);
var absolute = new Uri(reference);
var output = source.MakeAbsolute(absolute);
Assert.AreEqual(expected, output.ToString());
}
[TestCase("http://www.domain.com/path/to/page", "http://www.domain.com/path/to/page")]
[TestCase("http://www.domain.com/path/to/page/", "http://www.domain.com/path/to/page/")]
[TestCase("http://www.domain.com", "http://www.domain.com/")]
[TestCase("http://www.domain.com/", "http://www.domain.com/")]
[TestCase("http://www.domain.com/path/to?q=3#yop", "http://www.domain.com/path/to?q=3#yop")]
[TestCase("http://www.domain.com/path/to/?q=3#yop", "http://www.domain.com/path/to/?q=3#yop")]
[TestCase("http://www.domain.com:666/path/to/page", "http://www.domain.com/path/to/page")]
[TestCase("http://www.domain.com:666/path/to/page/", "http://www.domain.com/path/to/page/")]
[TestCase("http://www.domain.com:666", "http://www.domain.com/")]
[TestCase("http://www.domain.com:666/", "http://www.domain.com/")]
[TestCase("http://www.domain.com:666/path/to?q=3#yop", "http://www.domain.com/path/to?q=3#yop")]
[TestCase("http://www.domain.com:666/path/to/?q=3#yop", "http://www.domain.com/path/to/?q=3#yop")]
public void WithoutPort(string input, string expected)
{
var source = new Uri(input);
var output = source.WithoutPort();
Assert.AreEqual(expected, output.ToString());
}
}
}

View File

@@ -2,7 +2,7 @@
using NUnit.Framework;
using Umbraco.Core;
namespace Umbraco.Tests
namespace Umbraco.Tests.CoreThings
{
[TestFixture]
public class VersionExtensionTests

View File

@@ -3,7 +3,7 @@ using System.Xml.Linq;
using NUnit.Framework;
using Umbraco.Core;
namespace Umbraco.Tests
namespace Umbraco.Tests.CoreThings
{
[TestFixture]
public class XmlExtensionsTests

View File

@@ -4,7 +4,7 @@ using Umbraco.Web;
using Umbraco.Web.UI.Pages;
using Umbraco.Web._Legacy.Actions;
namespace Umbraco.Tests.DependencyInjection
namespace Umbraco.Tests.DI
{
[TestFixture]
public class ActionCollectionTests : ResolverBaseTest

View File

@@ -5,7 +5,7 @@ using LightInject;
using NUnit.Framework;
using Umbraco.Core.DI;
namespace Umbraco.Tests.DependencyInjection
namespace Umbraco.Tests.DI
{
[TestFixture]
public class CollectionBuildersTests

View File

@@ -6,7 +6,7 @@ using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.DI;
namespace Umbraco.Tests.DependencyInjection
namespace Umbraco.Tests.DI
{
[TestFixture]
public class LazyCollectionBuilderTests

View File

@@ -7,7 +7,7 @@ using Umbraco.Core.DI;
using Umbraco.Core.Plugins;
using Umbraco.Core._Legacy.PackageActions;
namespace Umbraco.Tests.DependencyInjection
namespace Umbraco.Tests.DI
{
[TestFixture]
public class PackageActionCollectionTests : ResolverBaseTest

View File

@@ -7,7 +7,7 @@ using Umbraco.Core.DI;
using Umbraco.Core.Logging;
using Umbraco.Core.Plugins;
namespace Umbraco.Tests.DependencyInjection
namespace Umbraco.Tests.DI
{
public abstract class ResolverBaseTest // fixme rename, do something!
{

View File

@@ -1,21 +0,0 @@
using LightInject;
using NUnit.Framework;
using Umbraco.Core.DI;
using Umbraco.Web.Routing;
namespace Umbraco.Tests.DependencyInjection
{
[TestFixture]
public class TempTests
{
//[Test]
public void Test()
{
var container = new ServiceContainer();
container.ConfigureUmbracoCore();
container.RegisterCollectionBuilder<UrlProviderCollectionBuilder>()
.Append<DefaultUrlProvider>();
var col = container.GetInstance<UrlProviderCollection>();
}
}
}

View File

@@ -4,7 +4,7 @@ using NUnit.Framework;
using Umbraco.Core.Macros;
using Umbraco.Web;
namespace Umbraco.Tests.DependencyInjection
namespace Umbraco.Tests.DI
{
[TestFixture]
public class XsltExtensionsResolverTests : ResolverBaseTest

View File

@@ -6,11 +6,11 @@ using Moq;
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.Configuration.UmbracoSettings;
using Umbraco.Core.DI;
using Umbraco.Core.Logging;
using Umbraco.Core.Sync;
using Umbraco.Core.DI;
namespace Umbraco.Tests
namespace Umbraco.Tests.Misc
{
[TestFixture]
public class ApplicationUrlHelperTests

View File

@@ -1,145 +1,145 @@
using System;
using System.IO;
using System.Reflection;
using NUnit.Framework;
using Umbraco.Core;
namespace Umbraco.Tests
{
[TestFixture]
public class HashCodeCombinerTests
{
private DirectoryInfo PrepareFolder()
{
var assDir = new FileInfo(Assembly.GetExecutingAssembly().Location).Directory;
var dir = Directory.CreateDirectory(Path.Combine(assDir.FullName, "HashCombiner", Guid.NewGuid().ToString("N")));
foreach (var f in dir.GetFiles())
{
f.Delete();
}
return dir;
}
[Test]
public void HashCombiner_Test_String()
{
var combiner1 = new HashCodeCombiner();
combiner1.AddCaseInsensitiveString("Hello");
var combiner2 = new HashCodeCombiner();
combiner2.AddCaseInsensitiveString("hello");
Assert.AreEqual(combiner1.GetCombinedHashCode(), combiner2.GetCombinedHashCode());
combiner2.AddCaseInsensitiveString("world");
Assert.AreNotEqual(combiner1.GetCombinedHashCode(), combiner2.GetCombinedHashCode());
}
[Test]
public void HashCombiner_Test_Int()
{
var combiner1 = new HashCodeCombiner();
combiner1.AddInt(1234);
var combiner2 = new HashCodeCombiner();
combiner2.AddInt(1234);
Assert.AreEqual(combiner1.GetCombinedHashCode(), combiner2.GetCombinedHashCode());
combiner2.AddInt(1);
Assert.AreNotEqual(combiner1.GetCombinedHashCode(), combiner2.GetCombinedHashCode());
}
[Test]
public void HashCombiner_Test_DateTime()
{
var dt = DateTime.Now;
var combiner1 = new HashCodeCombiner();
combiner1.AddDateTime(dt);
var combiner2 = new HashCodeCombiner();
combiner2.AddDateTime(dt);
Assert.AreEqual(combiner1.GetCombinedHashCode(), combiner2.GetCombinedHashCode());
combiner2.AddDateTime(DateTime.Now);
Assert.AreNotEqual(combiner1.GetCombinedHashCode(), combiner2.GetCombinedHashCode());
}
[Test]
public void HashCombiner_Test_File()
{
var dir = PrepareFolder();
var file1Path = Path.Combine(dir.FullName, "hastest1.txt");
File.Delete(file1Path);
using (var file1 = File.CreateText(Path.Combine(dir.FullName, "hastest1.txt")))
{
file1.WriteLine("hello");
}
var file2Path = Path.Combine(dir.FullName, "hastest2.txt");
File.Delete(file2Path);
using (var file2 = File.CreateText(Path.Combine(dir.FullName, "hastest2.txt")))
{
//even though files are the same, the dates are different
file2.WriteLine("hello");
}
var combiner1 = new HashCodeCombiner();
combiner1.AddFile(new FileInfo(file1Path));
var combiner2 = new HashCodeCombiner();
combiner2.AddFile(new FileInfo(file1Path));
var combiner3 = new HashCodeCombiner();
combiner3.AddFile(new FileInfo(file2Path));
Assert.AreEqual(combiner1.GetCombinedHashCode(), combiner2.GetCombinedHashCode());
Assert.AreNotEqual(combiner1.GetCombinedHashCode(), combiner3.GetCombinedHashCode());
combiner2.AddFile(new FileInfo(file2Path));
Assert.AreNotEqual(combiner1.GetCombinedHashCode(), combiner2.GetCombinedHashCode());
}
[Test]
public void HashCombiner_Test_Folder()
{
var dir = PrepareFolder();
var file1Path = Path.Combine(dir.FullName, "hastest1.txt");
File.Delete(file1Path);
using (var file1 = File.CreateText(Path.Combine(dir.FullName, "hastest1.txt")))
{
file1.WriteLine("hello");
}
//first test the whole folder
var combiner1 = new HashCodeCombiner();
combiner1.AddFolder(dir);
var combiner2 = new HashCodeCombiner();
combiner2.AddFolder(dir);
Assert.AreEqual(combiner1.GetCombinedHashCode(), combiner2.GetCombinedHashCode());
//now add a file to the folder
var file2Path = Path.Combine(dir.FullName, "hastest2.txt");
File.Delete(file2Path);
using (var file2 = File.CreateText(Path.Combine(dir.FullName, "hastest2.txt")))
{
//even though files are the same, the dates are different
file2.WriteLine("hello");
}
var combiner3 = new HashCodeCombiner();
combiner3.AddFolder(dir);
Assert.AreNotEqual(combiner1.GetCombinedHashCode(), combiner3.GetCombinedHashCode());
}
}
}
using System;
using System.IO;
using System.Reflection;
using NUnit.Framework;
using Umbraco.Core;
namespace Umbraco.Tests.Misc
{
[TestFixture]
public class HashCodeCombinerTests
{
private DirectoryInfo PrepareFolder()
{
var assDir = new FileInfo(Assembly.GetExecutingAssembly().Location).Directory;
var dir = Directory.CreateDirectory(Path.Combine(assDir.FullName, "HashCombiner", Guid.NewGuid().ToString("N")));
foreach (var f in dir.GetFiles())
{
f.Delete();
}
return dir;
}
[Test]
public void HashCombiner_Test_String()
{
var combiner1 = new HashCodeCombiner();
combiner1.AddCaseInsensitiveString("Hello");
var combiner2 = new HashCodeCombiner();
combiner2.AddCaseInsensitiveString("hello");
Assert.AreEqual(combiner1.GetCombinedHashCode(), combiner2.GetCombinedHashCode());
combiner2.AddCaseInsensitiveString("world");
Assert.AreNotEqual(combiner1.GetCombinedHashCode(), combiner2.GetCombinedHashCode());
}
[Test]
public void HashCombiner_Test_Int()
{
var combiner1 = new HashCodeCombiner();
combiner1.AddInt(1234);
var combiner2 = new HashCodeCombiner();
combiner2.AddInt(1234);
Assert.AreEqual(combiner1.GetCombinedHashCode(), combiner2.GetCombinedHashCode());
combiner2.AddInt(1);
Assert.AreNotEqual(combiner1.GetCombinedHashCode(), combiner2.GetCombinedHashCode());
}
[Test]
public void HashCombiner_Test_DateTime()
{
var dt = DateTime.Now;
var combiner1 = new HashCodeCombiner();
combiner1.AddDateTime(dt);
var combiner2 = new HashCodeCombiner();
combiner2.AddDateTime(dt);
Assert.AreEqual(combiner1.GetCombinedHashCode(), combiner2.GetCombinedHashCode());
combiner2.AddDateTime(DateTime.Now);
Assert.AreNotEqual(combiner1.GetCombinedHashCode(), combiner2.GetCombinedHashCode());
}
[Test]
public void HashCombiner_Test_File()
{
var dir = PrepareFolder();
var file1Path = Path.Combine(dir.FullName, "hastest1.txt");
File.Delete(file1Path);
using (var file1 = File.CreateText(Path.Combine(dir.FullName, "hastest1.txt")))
{
file1.WriteLine("hello");
}
var file2Path = Path.Combine(dir.FullName, "hastest2.txt");
File.Delete(file2Path);
using (var file2 = File.CreateText(Path.Combine(dir.FullName, "hastest2.txt")))
{
//even though files are the same, the dates are different
file2.WriteLine("hello");
}
var combiner1 = new HashCodeCombiner();
combiner1.AddFile(new FileInfo(file1Path));
var combiner2 = new HashCodeCombiner();
combiner2.AddFile(new FileInfo(file1Path));
var combiner3 = new HashCodeCombiner();
combiner3.AddFile(new FileInfo(file2Path));
Assert.AreEqual(combiner1.GetCombinedHashCode(), combiner2.GetCombinedHashCode());
Assert.AreNotEqual(combiner1.GetCombinedHashCode(), combiner3.GetCombinedHashCode());
combiner2.AddFile(new FileInfo(file2Path));
Assert.AreNotEqual(combiner1.GetCombinedHashCode(), combiner2.GetCombinedHashCode());
}
[Test]
public void HashCombiner_Test_Folder()
{
var dir = PrepareFolder();
var file1Path = Path.Combine(dir.FullName, "hastest1.txt");
File.Delete(file1Path);
using (var file1 = File.CreateText(Path.Combine(dir.FullName, "hastest1.txt")))
{
file1.WriteLine("hello");
}
//first test the whole folder
var combiner1 = new HashCodeCombiner();
combiner1.AddFolder(dir);
var combiner2 = new HashCodeCombiner();
combiner2.AddFolder(dir);
Assert.AreEqual(combiner1.GetCombinedHashCode(), combiner2.GetCombinedHashCode());
//now add a file to the folder
var file2Path = Path.Combine(dir.FullName, "hastest2.txt");
File.Delete(file2Path);
using (var file2 = File.CreateText(Path.Combine(dir.FullName, "hastest2.txt")))
{
//even though files are the same, the dates are different
file2.WriteLine("hello");
}
var combiner3 = new HashCodeCombiner();
combiner3.AddFolder(dir);
Assert.AreNotEqual(combiner1.GetCombinedHashCode(), combiner3.GetCombinedHashCode());
}
}
}

View File

@@ -1,176 +1,169 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Configuration;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.PropertyEditors;
using Umbraco.Tests.PublishedContent;
using Umbraco.Tests.TestHelpers;
using Umbraco.Web;
using Umbraco.Web.PublishedCache;
using Umbraco.Web.PublishedCache.XmlPublishedCache;
using umbraco;
using Umbraco.Core.DI;
namespace Umbraco.Tests
{
/// <summary>
/// Tests for the legacy library class
/// </summary>
[TestFixture]
public class LibraryTests : BaseWebTest
{
public override void SetUp()
{
base.SetUp();
// need to specify a custom callback for unit tests
// AutoPublishedContentTypes generates properties automatically
// when they are requested, but we must declare those that we
// explicitely want to be here...
var propertyTypes = new[]
{
// AutoPublishedContentType will auto-generate other properties
new PublishedPropertyType("content", 0, "?"),
};
var type = new AutoPublishedContentType(0, "anything", propertyTypes);
ContentTypesCache.GetPublishedContentTypeByAlias = (alias) => type;
Debug.Print("INIT LIB {0}",
ContentTypesCache.Get(PublishedItemType.Content, "anything")
.PropertyTypes.Count());
var umbracoContext = GetUmbracoContext("/test");
Umbraco.Web.Current.UmbracoContextAccessor.UmbracoContext = umbracoContext;
}
/// <summary>
/// sets up resolvers before resolution is frozen
/// </summary>
protected override void MoreSetUp()
{
// required so we can access property.Value
Container.RegisterCollectionBuilder<PropertyValueConverterCollectionBuilder>();
base.MoreSetUp();
}
[Test]
public void Json_To_Xml_Object()
{
var json = "{ id: 1, name: 'hello', children: [{id: 2, name: 'child1'}, {id:3, name: 'child2'}]}";
var result = library.JsonToXml(json);
Assert.AreEqual(@"<json>
<id>1</id>
<name>hello</name>
<children>
<id>2</id>
<name>child1</name>
</children>
<children>
<id>3</id>
<name>child2</name>
</children>
</json>", result.Current.OuterXml);
}
[Test]
public void Json_To_Xml_Array()
{
var json = "[{id: 2, name: 'child1'}, {id:3, name: 'child2'}]";
var result = library.JsonToXml(json);
Assert.AreEqual(@"<json>
<arrayitem>
<id>2</id>
<name>child1</name>
</arrayitem>
<arrayitem>
<id>3</id>
<name>child2</name>
</arrayitem>
</json>", result.Current.OuterXml);
}
[Test]
public void Json_To_Xml_Error()
{
var json = "{ id: 1, name: 'hello', children: }";
var result = library.JsonToXml(json);
Assert.IsTrue(result.Current.OuterXml.StartsWith("<error>"));
}
[Test]
public void Get_Item_User_Property()
{
var val = library.GetItem(1173, "content");
var legacyVal = LegacyGetItem(1173, "content");
Assert.AreEqual(legacyVal, val);
Assert.AreEqual("<div>This is some content</div>", val);
}
[Test]
public void Get_Item_Document_Property()
{
//first test a single static val
var val = library.GetItem(1173, "template");
var legacyVal = LegacyGetItem(1173, "template");
Assert.AreEqual(legacyVal, val);
Assert.AreEqual("1234", val);
//now test them all to see if they all match legacy
foreach(var s in new[]{"id","parentID","level","writerID","template","sortOrder","createDate","updateDate","nodeName","writerName","path"})
{
val = library.GetItem(1173, s);
legacyVal = LegacyGetItem(1173, s);
Assert.AreEqual(legacyVal, val);
}
}
[Test]
public void Get_Item_Invalid_Property()
{
var val = library.GetItem(1173, "dontfindme");
var legacyVal = LegacyGetItem(1173, "dontfindme");
Assert.AreEqual(legacyVal, val);
Assert.AreEqual("", val);
}
/// <summary>
/// The old method, just using this to make sure we're returning the correct exact data as before.
/// </summary>
/// <param name="nodeId"></param>
/// <param name="alias"></param>
/// <returns></returns>
private string LegacyGetItem(int nodeId, string alias)
{
var cache = UmbracoContext.Current.ContentCache as PublishedContentCache;
if (cache == null) throw new Exception("Unsupported IPublishedContentCache, only the Xml one is supported.");
var umbracoXML = cache.GetXml(UmbracoContext.Current.InPreviewMode);
string xpath = "./{0}";
if (umbracoXML.GetElementById(nodeId.ToString()) != null)
if (
",id,parentID,level,writerID,template,sortOrder,createDate,updateDate,nodeName,writerName,path,"
.
IndexOf("," + alias + ",") > -1)
return umbracoXML.GetElementById(nodeId.ToString()).Attributes.GetNamedItem(alias).Value;
else if (
umbracoXML.GetElementById(nodeId.ToString()).SelectSingleNode(string.Format(xpath, alias)) !=
null)
return
umbracoXML.GetElementById(nodeId.ToString()).SelectSingleNode(string.Format(xpath, alias)).ChildNodes[0].
Value; //.Value + "*";
else
return string.Empty;
else
return string.Empty;
}
}
}
using System;
using System.Diagnostics;
using System.Linq;
using NUnit.Framework;
using umbraco;
using Umbraco.Core.DI;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.PropertyEditors;
using Umbraco.Tests.PublishedContent;
using Umbraco.Tests.TestHelpers;
using Umbraco.Web;
using Umbraco.Web.PublishedCache.XmlPublishedCache;
namespace Umbraco.Tests.Misc
{
/// <summary>
/// Tests for the legacy library class
/// </summary>
[TestFixture]
public class LibraryTests : BaseWebTest
{
public override void SetUp()
{
base.SetUp();
// need to specify a custom callback for unit tests
// AutoPublishedContentTypes generates properties automatically
// when they are requested, but we must declare those that we
// explicitely want to be here...
var propertyTypes = new[]
{
// AutoPublishedContentType will auto-generate other properties
new PublishedPropertyType("content", 0, "?"),
};
var type = new AutoPublishedContentType(0, "anything", propertyTypes);
ContentTypesCache.GetPublishedContentTypeByAlias = (alias) => type;
Debug.Print("INIT LIB {0}",
ContentTypesCache.Get(PublishedItemType.Content, "anything")
.PropertyTypes.Count());
var umbracoContext = GetUmbracoContext("/test");
Umbraco.Web.Current.UmbracoContextAccessor.UmbracoContext = umbracoContext;
}
/// <summary>
/// sets up resolvers before resolution is frozen
/// </summary>
protected override void MoreSetUp()
{
// required so we can access property.Value
Container.RegisterCollectionBuilder<PropertyValueConverterCollectionBuilder>();
base.MoreSetUp();
}
[Test]
public void Json_To_Xml_Object()
{
var json = "{ id: 1, name: 'hello', children: [{id: 2, name: 'child1'}, {id:3, name: 'child2'}]}";
var result = library.JsonToXml(json);
Assert.AreEqual(@"<json>
<id>1</id>
<name>hello</name>
<children>
<id>2</id>
<name>child1</name>
</children>
<children>
<id>3</id>
<name>child2</name>
</children>
</json>", result.Current.OuterXml);
}
[Test]
public void Json_To_Xml_Array()
{
var json = "[{id: 2, name: 'child1'}, {id:3, name: 'child2'}]";
var result = library.JsonToXml(json);
Assert.AreEqual(@"<json>
<arrayitem>
<id>2</id>
<name>child1</name>
</arrayitem>
<arrayitem>
<id>3</id>
<name>child2</name>
</arrayitem>
</json>", result.Current.OuterXml);
}
[Test]
public void Json_To_Xml_Error()
{
var json = "{ id: 1, name: 'hello', children: }";
var result = library.JsonToXml(json);
Assert.IsTrue(result.Current.OuterXml.StartsWith("<error>"));
}
[Test]
public void Get_Item_User_Property()
{
var val = library.GetItem(1173, "content");
var legacyVal = LegacyGetItem(1173, "content");
Assert.AreEqual(legacyVal, val);
Assert.AreEqual("<div>This is some content</div>", val);
}
[Test]
public void Get_Item_Document_Property()
{
//first test a single static val
var val = library.GetItem(1173, "template");
var legacyVal = LegacyGetItem(1173, "template");
Assert.AreEqual(legacyVal, val);
Assert.AreEqual("1234", val);
//now test them all to see if they all match legacy
foreach(var s in new[]{"id","parentID","level","writerID","template","sortOrder","createDate","updateDate","nodeName","writerName","path"})
{
val = library.GetItem(1173, s);
legacyVal = LegacyGetItem(1173, s);
Assert.AreEqual(legacyVal, val);
}
}
[Test]
public void Get_Item_Invalid_Property()
{
var val = library.GetItem(1173, "dontfindme");
var legacyVal = LegacyGetItem(1173, "dontfindme");
Assert.AreEqual(legacyVal, val);
Assert.AreEqual("", val);
}
/// <summary>
/// The old method, just using this to make sure we're returning the correct exact data as before.
/// </summary>
/// <param name="nodeId"></param>
/// <param name="alias"></param>
/// <returns></returns>
private string LegacyGetItem(int nodeId, string alias)
{
var cache = UmbracoContext.Current.ContentCache as PublishedContentCache;
if (cache == null) throw new Exception("Unsupported IPublishedContentCache, only the Xml one is supported.");
var umbracoXML = cache.GetXml(UmbracoContext.Current.InPreviewMode);
string xpath = "./{0}";
if (umbracoXML.GetElementById(nodeId.ToString()) != null)
if (
",id,parentID,level,writerID,template,sortOrder,createDate,updateDate,nodeName,writerName,path,"
.
IndexOf("," + alias + ",") > -1)
return umbracoXML.GetElementById(nodeId.ToString()).Attributes.GetNamedItem(alias).Value;
else if (
umbracoXML.GetElementById(nodeId.ToString()).SelectSingleNode(string.Format(xpath, alias)) !=
null)
return
umbracoXML.GetElementById(nodeId.ToString()).SelectSingleNode(string.Format(xpath, alias)).ChildNodes[0].
Value; //.Value + "*";
else
return string.Empty;
else
return string.Empty;
}
}
}

View File

@@ -1,139 +1,138 @@
using System;
using System.Configuration;
using Moq;
using NUnit.Framework;
using Umbraco.Tests.TestHelpers;
using Umbraco.Web;
namespace Umbraco.Tests
{
// fixme - not testing virtual directory!
[TestFixture]
public class UriUtilityTests
{
[TearDown]
public void TearDown()
{
SettingsForTests.Reset();
}
// test normal urls
[TestCase("http://LocalHost/", "http://localhost/")]
[TestCase("http://LocalHost/?x=y", "http://localhost/?x=y")]
[TestCase("http://LocalHost/Home", "http://localhost/home")]
[TestCase("http://LocalHost/Home?x=y", "http://localhost/home?x=y")]
[TestCase("http://LocalHost/Home/Sub1", "http://localhost/home/sub1")]
[TestCase("http://LocalHost/Home/Sub1?x=y", "http://localhost/home/sub1?x=y")]
// same with .aspx
[TestCase("http://LocalHost/Home.aspx", "http://localhost/home")]
[TestCase("http://LocalHost/Home.aspx?x=y", "http://localhost/home?x=y")]
[TestCase("http://LocalHost/Home/Sub1.aspx", "http://localhost/home/sub1")]
[TestCase("http://LocalHost/Home/Sub1.aspx?x=y", "http://localhost/home/sub1?x=y")]
// test that the trailing slash goes but not on hostname
[TestCase("http://LocalHost/", "http://localhost/")]
[TestCase("http://LocalHost/Home/", "http://localhost/home")]
[TestCase("http://LocalHost/Home/?x=y", "http://localhost/home?x=y")]
[TestCase("http://LocalHost/Home/Sub1/", "http://localhost/home/sub1")]
[TestCase("http://LocalHost/Home/Sub1/?x=y", "http://localhost/home/sub1?x=y")]
// test that default.aspx goes, even with parameters
[TestCase("http://LocalHost/deFault.aspx", "http://localhost/")]
[TestCase("http://LocalHost/deFault.aspx?x=y", "http://localhost/?x=y")]
// test with inner .aspx
[TestCase("http://Localhost/Home/Sub1.aspx/Sub2", "http://localhost/home/sub1/sub2")]
[TestCase("http://Localhost/Home/Sub1.aspx/Sub2?x=y", "http://localhost/home/sub1/sub2?x=y")]
[TestCase("http://Localhost/Home.aspx/Sub1.aspx/Sub2?x=y", "http://localhost/home/sub1/sub2?x=y")]
[TestCase("http://Localhost/deFault.aspx/Home.aspx/deFault.aspx/Sub1.aspx", "http://localhost/home/default/sub1")]
public void Uri_To_Umbraco(string sourceUrl, string expectedUrl)
{
UriUtility.SetAppDomainAppVirtualPath("/");
var expectedUri = new Uri(expectedUrl);
var sourceUri = new Uri(sourceUrl);
var resultUri = UriUtility.UriToUmbraco(sourceUri);
Assert.AreEqual(expectedUri.ToString(), resultUri.ToString());
}
// test directoryUrl false, trailingSlash false
[TestCase("/", "/", false, false)]
[TestCase("/home", "/home.aspx", false, false)]
[TestCase("/home/sub1", "/home/sub1.aspx", false, false)]
// test directoryUrl false, trailingSlash true
[TestCase("/", "/", false, true)]
[TestCase("/home", "/home.aspx", false, true)]
[TestCase("/home/sub1", "/home/sub1.aspx", false, true)]
// test directoryUrl true, trailingSlash false
[TestCase("/", "/", true, false)]
[TestCase("/home", "/home", true, false)]
[TestCase("/home/sub1", "/home/sub1", true, false)]
// test directoryUrl true, trailingSlash true
[TestCase("/", "/", true, true)]
[TestCase("/home", "/home/", true, true)]
[TestCase("/home/sub1", "/home/sub1/", true, true)]
public void Uri_From_Umbraco(string sourceUrl, string expectedUrl, bool directoryUrls, bool trailingSlash)
{
ConfigurationManager.AppSettings.Set("umbracoUseDirectoryUrls", directoryUrls ? "true" : "false");
var settings = SettingsForTests.GenerateMockSettings();
var requestMock = Mock.Get(settings.RequestHandler);
requestMock.Setup(x => x.AddTrailingSlash).Returns(trailingSlash);
SettingsForTests.ConfigureSettings(settings);
UriUtility.SetAppDomainAppVirtualPath("/");
var expectedUri = NewUri(expectedUrl);
var sourceUri = NewUri(sourceUrl);
var resultUri = UriUtility.UriFromUmbraco(sourceUri);
Assert.AreEqual(expectedUri.ToString(), resultUri.ToString());
}
Uri NewUri(string url)
{
return new Uri(url, url.StartsWith("http:") ? UriKind.Absolute : UriKind.Relative);
}
//
[TestCase("/", "/", "/")]
[TestCase("/", "/foo", "/foo")]
[TestCase("/", "~/foo", "/foo")]
[TestCase("/vdir", "/", "/vdir/")]
[TestCase("/vdir", "/foo", "/vdir/foo")]
[TestCase("/vdir", "/foo/", "/vdir/foo/")]
[TestCase("/vdir", "~/foo", "/vdir/foo")]
public void Uri_To_Absolute(string virtualPath, string sourceUrl, string expectedUrl)
{
UriUtility.SetAppDomainAppVirtualPath(virtualPath);
var resultUrl = UriUtility.ToAbsolute(sourceUrl);
Assert.AreEqual(expectedUrl, resultUrl);
}
//
[TestCase("/", "/", "/")]
[TestCase("/", "/foo", "/foo")]
[TestCase("/", "/foo/", "/foo/")]
[TestCase("/vdir", "/vdir", "/")]
[TestCase("/vdir", "/vdir/", "/")]
[TestCase("/vdir", "/vdir/foo", "/foo")]
[TestCase("/vdir", "/vdir/foo/", "/foo/")]
public void Url_To_App_Relative(string virtualPath, string sourceUrl, string expectedUrl)
{
UriUtility.SetAppDomainAppVirtualPath(virtualPath);
var resultUrl = UriUtility.ToAppRelative(sourceUrl);
Assert.AreEqual(expectedUrl, resultUrl);
}
}
using System;
using System.Configuration;
using Moq;
using NUnit.Framework;
using Umbraco.Tests.TestHelpers;
using Umbraco.Web;
namespace Umbraco.Tests.Misc
{
// fixme - not testing virtual directory!
[TestFixture]
public class UriUtilityTests
{
[TearDown]
public void TearDown()
{
SettingsForTests.Reset();
}
// test normal urls
[TestCase("http://LocalHost/", "http://localhost/")]
[TestCase("http://LocalHost/?x=y", "http://localhost/?x=y")]
[TestCase("http://LocalHost/Home", "http://localhost/home")]
[TestCase("http://LocalHost/Home?x=y", "http://localhost/home?x=y")]
[TestCase("http://LocalHost/Home/Sub1", "http://localhost/home/sub1")]
[TestCase("http://LocalHost/Home/Sub1?x=y", "http://localhost/home/sub1?x=y")]
// same with .aspx
[TestCase("http://LocalHost/Home.aspx", "http://localhost/home")]
[TestCase("http://LocalHost/Home.aspx?x=y", "http://localhost/home?x=y")]
[TestCase("http://LocalHost/Home/Sub1.aspx", "http://localhost/home/sub1")]
[TestCase("http://LocalHost/Home/Sub1.aspx?x=y", "http://localhost/home/sub1?x=y")]
// test that the trailing slash goes but not on hostname
[TestCase("http://LocalHost/", "http://localhost/")]
[TestCase("http://LocalHost/Home/", "http://localhost/home")]
[TestCase("http://LocalHost/Home/?x=y", "http://localhost/home?x=y")]
[TestCase("http://LocalHost/Home/Sub1/", "http://localhost/home/sub1")]
[TestCase("http://LocalHost/Home/Sub1/?x=y", "http://localhost/home/sub1?x=y")]
// test that default.aspx goes, even with parameters
[TestCase("http://LocalHost/deFault.aspx", "http://localhost/")]
[TestCase("http://LocalHost/deFault.aspx?x=y", "http://localhost/?x=y")]
// test with inner .aspx
[TestCase("http://Localhost/Home/Sub1.aspx/Sub2", "http://localhost/home/sub1/sub2")]
[TestCase("http://Localhost/Home/Sub1.aspx/Sub2?x=y", "http://localhost/home/sub1/sub2?x=y")]
[TestCase("http://Localhost/Home.aspx/Sub1.aspx/Sub2?x=y", "http://localhost/home/sub1/sub2?x=y")]
[TestCase("http://Localhost/deFault.aspx/Home.aspx/deFault.aspx/Sub1.aspx", "http://localhost/home/default/sub1")]
public void Uri_To_Umbraco(string sourceUrl, string expectedUrl)
{
UriUtility.SetAppDomainAppVirtualPath("/");
var expectedUri = new Uri(expectedUrl);
var sourceUri = new Uri(sourceUrl);
var resultUri = UriUtility.UriToUmbraco(sourceUri);
Assert.AreEqual(expectedUri.ToString(), resultUri.ToString());
}
// test directoryUrl false, trailingSlash false
[TestCase("/", "/", false, false)]
[TestCase("/home", "/home.aspx", false, false)]
[TestCase("/home/sub1", "/home/sub1.aspx", false, false)]
// test directoryUrl false, trailingSlash true
[TestCase("/", "/", false, true)]
[TestCase("/home", "/home.aspx", false, true)]
[TestCase("/home/sub1", "/home/sub1.aspx", false, true)]
// test directoryUrl true, trailingSlash false
[TestCase("/", "/", true, false)]
[TestCase("/home", "/home", true, false)]
[TestCase("/home/sub1", "/home/sub1", true, false)]
// test directoryUrl true, trailingSlash true
[TestCase("/", "/", true, true)]
[TestCase("/home", "/home/", true, true)]
[TestCase("/home/sub1", "/home/sub1/", true, true)]
public void Uri_From_Umbraco(string sourceUrl, string expectedUrl, bool directoryUrls, bool trailingSlash)
{
ConfigurationManager.AppSettings.Set("umbracoUseDirectoryUrls", directoryUrls ? "true" : "false");
var settings = SettingsForTests.GenerateMockSettings();
var requestMock = Mock.Get(settings.RequestHandler);
requestMock.Setup(x => x.AddTrailingSlash).Returns(trailingSlash);
SettingsForTests.ConfigureSettings(settings);
UriUtility.SetAppDomainAppVirtualPath("/");
var expectedUri = NewUri(expectedUrl);
var sourceUri = NewUri(sourceUrl);
var resultUri = UriUtility.UriFromUmbraco(sourceUri);
Assert.AreEqual(expectedUri.ToString(), resultUri.ToString());
}
Uri NewUri(string url)
{
return new Uri(url, url.StartsWith("http:") ? UriKind.Absolute : UriKind.Relative);
}
//
[TestCase("/", "/", "/")]
[TestCase("/", "/foo", "/foo")]
[TestCase("/", "~/foo", "/foo")]
[TestCase("/vdir", "/", "/vdir/")]
[TestCase("/vdir", "/foo", "/vdir/foo")]
[TestCase("/vdir", "/foo/", "/vdir/foo/")]
[TestCase("/vdir", "~/foo", "/vdir/foo")]
public void Uri_To_Absolute(string virtualPath, string sourceUrl, string expectedUrl)
{
UriUtility.SetAppDomainAppVirtualPath(virtualPath);
var resultUrl = UriUtility.ToAbsolute(sourceUrl);
Assert.AreEqual(expectedUrl, resultUrl);
}
//
[TestCase("/", "/", "/")]
[TestCase("/", "/foo", "/foo")]
[TestCase("/", "/foo/", "/foo/")]
[TestCase("/vdir", "/vdir", "/")]
[TestCase("/vdir", "/vdir/", "/")]
[TestCase("/vdir", "/vdir/foo", "/foo")]
[TestCase("/vdir", "/vdir/foo/", "/foo/")]
public void Url_To_App_Relative(string virtualPath, string sourceUrl, string expectedUrl)
{
UriUtility.SetAppDomainAppVirtualPath(virtualPath);
var resultUrl = UriUtility.ToAppRelative(sourceUrl);
Assert.AreEqual(expectedUrl, resultUrl);
}
}
}

View File

@@ -1,278 +1,270 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.XPath;
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.Configuration;
using umbraco;
using Umbraco.Core.Configuration.UmbracoSettings;
using Umbraco.Core.Persistence.UnitOfWork;
using Umbraco.Core.Xml;
using Umbraco.Tests.Models;
namespace Umbraco.Tests
{
[TestFixture]
public class XmlHelperTests
{
[SetUp]
public void Setup()
{
}
[NUnit.Framework.Ignore("This is a benchmark test so is ignored by default")]
[Test]
public void Sort_Nodes_Benchmark_Legacy()
{
var xmlContent = GetXmlContent(1);
var xml = new XmlDocument();
xml.LoadXml(xmlContent);
var original = xml.GetElementById(1173.ToString());
Assert.IsNotNull(original);
long totalTime = 0;
var watch = new Stopwatch();
var iterations = 10000;
for (var i = 0; i < iterations; i++)
{
//don't measure the time for clone!
var parentNode = original.Clone();
watch.Start();
LegacySortNodes(ref parentNode);
watch.Stop();
totalTime += watch.ElapsedMilliseconds;
watch.Reset();
//do assertions just to make sure it is working properly.
var currSort = 0;
foreach (var child in parentNode.SelectNodes("./* [@id]").Cast<XmlNode>())
{
Assert.AreEqual(currSort, int.Parse(child.Attributes["sortOrder"].Value));
currSort++;
}
//ensure the parent node's properties still exist first
Assert.AreEqual("content", parentNode.ChildNodes[0].Name);
Assert.AreEqual("umbracoUrlAlias", parentNode.ChildNodes[1].Name);
//then the child nodes should come straight after
Assert.IsTrue(parentNode.ChildNodes[2].Attributes["id"] != null);
}
Debug.WriteLine("Total time for " + iterations + " iterations is " + totalTime);
}
[NUnit.Framework.Ignore("This is a benchmark test so is ignored by default")]
[Test]
public void Sort_Nodes_Benchmark_New()
{
var xmlContent = GetXmlContent(1);
var xml = new XmlDocument();
xml.LoadXml(xmlContent);
var original = xml.GetElementById(1173.ToString());
Assert.IsNotNull(original);
long totalTime = 0;
var watch = new Stopwatch();
var iterations = 10000;
for (var i = 0; i < iterations; i++)
{
//don't measure the time for clone!
var parentNode = (XmlElement)original.Clone();
watch.Start();
XmlHelper.SortNodes(
parentNode,
"./* [@id]",
x => x.AttributeValue<int>("sortOrder"));
watch.Stop();
totalTime += watch.ElapsedMilliseconds;
watch.Reset();
//do assertions just to make sure it is working properly.
var currSort = 0;
foreach (var child in parentNode.SelectNodes("./* [@id]").Cast<XmlNode>())
{
Assert.AreEqual(currSort, int.Parse(child.Attributes["sortOrder"].Value));
currSort++;
}
//ensure the parent node's properties still exist first
Assert.AreEqual("content", parentNode.ChildNodes[0].Name);
Assert.AreEqual("umbracoUrlAlias", parentNode.ChildNodes[1].Name);
//then the child nodes should come straight after
Assert.IsTrue(parentNode.ChildNodes[2].Attributes["id"] != null);
}
Debug.WriteLine("Total time for " + iterations + " iterations is " + totalTime);
}
[Test]
public void Sort_Nodes()
{
var xmlContent = GetXmlContent(1);
var xml = new XmlDocument();
xml.LoadXml(xmlContent);
var original = xml.GetElementById(1173.ToString());
Assert.IsNotNull(original);
var parentNode = (XmlElement)original.Clone();
XmlHelper.SortNodes(
parentNode,
"./* [@id]",
x => x.AttributeValue<int>("sortOrder"));
//do assertions just to make sure it is working properly.
var currSort = 0;
foreach (var child in parentNode.SelectNodes("./* [@id]").Cast<XmlNode>())
{
Assert.AreEqual(currSort, int.Parse(child.Attributes["sortOrder"].Value));
currSort++;
}
//ensure the parent node's properties still exist first
Assert.AreEqual("content", parentNode.ChildNodes[0].Name);
Assert.AreEqual("umbracoUrlAlias", parentNode.ChildNodes[1].Name);
//then the child nodes should come straight after
Assert.IsTrue(parentNode.ChildNodes[2].Attributes["id"] != null);
}
/// <summary>
/// This was the logic to sort before and now lives here just to show the benchmarks tests above.
/// </summary>
/// <param name="parentNode"></param>
private static void LegacySortNodes(ref XmlNode parentNode)
{
XmlNode n = parentNode.CloneNode(true);
// remove all children from original node
string xpath = "./* [@id]";
foreach (XmlNode child in parentNode.SelectNodes(xpath))
parentNode.RemoveChild(child);
XPathNavigator nav = n.CreateNavigator();
XPathExpression expr = nav.Compile(xpath);
expr.AddSort("@sortOrder", XmlSortOrder.Ascending, XmlCaseOrder.None, "", XmlDataType.Number);
XPathNodeIterator iterator = nav.Select(expr);
while (iterator.MoveNext())
parentNode.AppendChild(
((IHasXmlNode)iterator.Current).GetNode());
}
/// <summary>
/// returns xml with a reverse sort order
/// </summary>
/// <param name="templateId"></param>
/// <returns></returns>
private string GetXmlContent(int templateId)
{
return @"<?xml version=""1.0"" encoding=""utf-8""?>
<!DOCTYPE root[
<!ELEMENT Home ANY>
<!ATTLIST Home id ID #REQUIRED>
<!ELEMENT CustomDocument ANY>
<!ATTLIST CustomDocument id ID #REQUIRED>
]>
<root id=""-1"">
<Home id=""1046"" parentID=""-1"" level=""1"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""0"" createDate=""2012-06-12T14:13:17"" updateDate=""2012-07-20T18:50:43"" nodeName=""Home"" urlName=""home"" writerName=""admin"" creatorName=""admin"" path=""-1,1046"" isDoc="""">
<content><![CDATA[]]></content>
<umbracoUrlAlias><![CDATA[this/is/my/alias, anotheralias]]></umbracoUrlAlias>
<umbracoNaviHide>1</umbracoNaviHide>
<Home id=""1173"" parentID=""1046"" level=""2"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""0"" createDate=""2012-07-20T18:06:45"" updateDate=""2012-07-20T19:07:31"" nodeName=""Sub1"" urlName=""sub1"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173"" isDoc="""">
<content><![CDATA[<div>This is some content</div>]]></content>
<umbracoUrlAlias><![CDATA[page2/alias, 2ndpagealias]]></umbracoUrlAlias>
<Home id=""1174"" parentID=""1173"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""3"" createDate=""2012-07-20T18:07:54"" updateDate=""2012-07-20T19:10:27"" nodeName=""Sub2"" urlName=""sub2"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1174"" isDoc="""">
<content><![CDATA[]]></content>
<umbracoUrlAlias><![CDATA[only/one/alias]]></umbracoUrlAlias>
<creatorName><![CDATA[Custom data with same property name as the member name]]></creatorName>
</Home>
<Home id=""1176"" parentID=""1173"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""2"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""sub-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1176"" isDoc="""">
<content><![CDATA[]]></content>
</Home>
<CustomDocument id=""1177"" parentID=""1173"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1234"" template=""" + templateId + @""" sortOrder=""1"" createDate=""2012-07-16T15:26:59"" updateDate=""2012-07-18T14:23:35"" nodeName=""custom sub 1"" urlName=""custom-sub-1"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1177"" isDoc="""" />
<CustomDocument id=""1178"" parentID=""1173"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1234"" template=""" + templateId + @""" sortOrder=""0"" createDate=""2012-07-16T15:26:59"" updateDate=""2012-07-16T14:23:35"" nodeName=""custom sub 2"" urlName=""custom-sub-2"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1178"" isDoc="""" />
<Home id=""1176"" parentID=""1179"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""26"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""sub-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1176"" isDoc="""">
<content><![CDATA[]]></content>
</Home>
<Home id=""1176"" parentID=""1180"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""25"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""sub-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1176"" isDoc="""">
<content><![CDATA[]]></content>
</Home>
<Home id=""1176"" parentID=""1181"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""24"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""sub-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1176"" isDoc="""">
<content><![CDATA[]]></content>
</Home>
<Home id=""1176"" parentID=""1182"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""23"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""sub-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1176"" isDoc="""">
<content><![CDATA[]]></content>
</Home>
<Home id=""1176"" parentID=""1183"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""22"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""sub-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1176"" isDoc="""">
<content><![CDATA[]]></content>
</Home>
<Home id=""1176"" parentID=""1184"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""21"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""sub-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1176"" isDoc="""">
<content><![CDATA[]]></content>
</Home>
<Home id=""1176"" parentID=""1185"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""20"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""sub-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1176"" isDoc="""">
<content><![CDATA[]]></content>
</Home>
<Home id=""1176"" parentID=""1186"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""19"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""sub-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1176"" isDoc="""">
<content><![CDATA[]]></content>
</Home>
<Home id=""1176"" parentID=""1187"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""18"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""sub-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1176"" isDoc="""">
<content><![CDATA[]]></content>
</Home>
<Home id=""1176"" parentID=""1188"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""17"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""sub-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1176"" isDoc="""">
<content><![CDATA[]]></content>
</Home>
<Home id=""1176"" parentID=""1189"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""16"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""sub-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1176"" isDoc="""">
<content><![CDATA[]]></content>
</Home>
<Home id=""1176"" parentID=""1190"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""15"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""sub-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1176"" isDoc="""">
<content><![CDATA[]]></content>
</Home>
<Home id=""1176"" parentID=""1191"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""14"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""sub-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1176"" isDoc="""">
<content><![CDATA[]]></content>
</Home>
<Home id=""1176"" parentID=""1192"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""13"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""sub-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1176"" isDoc="""">
<content><![CDATA[]]></content>
</Home>
<Home id=""1176"" parentID=""1193"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""12"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""sub-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1176"" isDoc="""">
<content><![CDATA[]]></content>
</Home>
<Home id=""1176"" parentID=""1194"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""11"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""sub-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1176"" isDoc="""">
<content><![CDATA[]]></content>
</Home>
<Home id=""1176"" parentID=""1195"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""10"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""sub-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1176"" isDoc="""">
<content><![CDATA[]]></content>
</Home>
<Home id=""1176"" parentID=""1196"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""9"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""sub-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1176"" isDoc="""">
<content><![CDATA[]]></content>
</Home>
<Home id=""1176"" parentID=""1197"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""8"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""sub-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1176"" isDoc="""">
<content><![CDATA[]]></content>
</Home>
<Home id=""1176"" parentID=""1198"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""7"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""sub-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1176"" isDoc="""">
<content><![CDATA[]]></content>
</Home>
<Home id=""1176"" parentID=""1199"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""6"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""sub-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1176"" isDoc="""">
<content><![CDATA[]]></content>
</Home>
<Home id=""1176"" parentID=""1200"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""5"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""sub-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1176"" isDoc="""">
<content><![CDATA[]]></content>
</Home>
<Home id=""1176"" parentID=""1201"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""4"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""sub-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1176"" isDoc="""">
<content><![CDATA[]]></content>
</Home>
</Home>
<Home id=""1175"" parentID=""1046"" level=""2"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""1"" createDate=""2012-07-20T18:08:01"" updateDate=""2012-07-20T18:49:32"" nodeName=""Sub 2"" urlName=""sub-2"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1175"" isDoc=""""><content><![CDATA[]]></content>
</Home>
</Home>
<CustomDocument id=""1172"" parentID=""-1"" level=""1"" writerID=""0"" creatorID=""0"" nodeType=""1234"" template=""" + templateId + @""" sortOrder=""1"" createDate=""2012-07-16T15:26:59"" updateDate=""2012-07-18T14:23:35"" nodeName=""Test"" urlName=""test-page"" writerName=""admin"" creatorName=""admin"" path=""-1,1172"" isDoc="""" />
</root>";
}
}
}
using System.Diagnostics;
using System.Linq;
using System.Xml;
using System.Xml.XPath;
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.Xml;
namespace Umbraco.Tests.Misc
{
[TestFixture]
public class XmlHelperTests
{
[SetUp]
public void Setup()
{
}
[Ignore("This is a benchmark test so is ignored by default")]
[Test]
public void Sort_Nodes_Benchmark_Legacy()
{
var xmlContent = GetXmlContent(1);
var xml = new XmlDocument();
xml.LoadXml(xmlContent);
var original = xml.GetElementById(1173.ToString());
Assert.IsNotNull(original);
long totalTime = 0;
var watch = new Stopwatch();
var iterations = 10000;
for (var i = 0; i < iterations; i++)
{
//don't measure the time for clone!
var parentNode = original.Clone();
watch.Start();
LegacySortNodes(ref parentNode);
watch.Stop();
totalTime += watch.ElapsedMilliseconds;
watch.Reset();
//do assertions just to make sure it is working properly.
var currSort = 0;
foreach (var child in parentNode.SelectNodes("./* [@id]").Cast<XmlNode>())
{
Assert.AreEqual(currSort, int.Parse(child.Attributes["sortOrder"].Value));
currSort++;
}
//ensure the parent node's properties still exist first
Assert.AreEqual("content", parentNode.ChildNodes[0].Name);
Assert.AreEqual("umbracoUrlAlias", parentNode.ChildNodes[1].Name);
//then the child nodes should come straight after
Assert.IsTrue(parentNode.ChildNodes[2].Attributes["id"] != null);
}
Debug.WriteLine("Total time for " + iterations + " iterations is " + totalTime);
}
[Ignore("This is a benchmark test so is ignored by default")]
[Test]
public void Sort_Nodes_Benchmark_New()
{
var xmlContent = GetXmlContent(1);
var xml = new XmlDocument();
xml.LoadXml(xmlContent);
var original = xml.GetElementById(1173.ToString());
Assert.IsNotNull(original);
long totalTime = 0;
var watch = new Stopwatch();
var iterations = 10000;
for (var i = 0; i < iterations; i++)
{
//don't measure the time for clone!
var parentNode = (XmlElement)original.Clone();
watch.Start();
XmlHelper.SortNodes(
parentNode,
"./* [@id]",
x => x.AttributeValue<int>("sortOrder"));
watch.Stop();
totalTime += watch.ElapsedMilliseconds;
watch.Reset();
//do assertions just to make sure it is working properly.
var currSort = 0;
foreach (var child in parentNode.SelectNodes("./* [@id]").Cast<XmlNode>())
{
Assert.AreEqual(currSort, int.Parse(child.Attributes["sortOrder"].Value));
currSort++;
}
//ensure the parent node's properties still exist first
Assert.AreEqual("content", parentNode.ChildNodes[0].Name);
Assert.AreEqual("umbracoUrlAlias", parentNode.ChildNodes[1].Name);
//then the child nodes should come straight after
Assert.IsTrue(parentNode.ChildNodes[2].Attributes["id"] != null);
}
Debug.WriteLine("Total time for " + iterations + " iterations is " + totalTime);
}
[Test]
public void Sort_Nodes()
{
var xmlContent = GetXmlContent(1);
var xml = new XmlDocument();
xml.LoadXml(xmlContent);
var original = xml.GetElementById(1173.ToString());
Assert.IsNotNull(original);
var parentNode = (XmlElement)original.Clone();
XmlHelper.SortNodes(
parentNode,
"./* [@id]",
x => x.AttributeValue<int>("sortOrder"));
//do assertions just to make sure it is working properly.
var currSort = 0;
foreach (var child in parentNode.SelectNodes("./* [@id]").Cast<XmlNode>())
{
Assert.AreEqual(currSort, int.Parse(child.Attributes["sortOrder"].Value));
currSort++;
}
//ensure the parent node's properties still exist first
Assert.AreEqual("content", parentNode.ChildNodes[0].Name);
Assert.AreEqual("umbracoUrlAlias", parentNode.ChildNodes[1].Name);
//then the child nodes should come straight after
Assert.IsTrue(parentNode.ChildNodes[2].Attributes["id"] != null);
}
/// <summary>
/// This was the logic to sort before and now lives here just to show the benchmarks tests above.
/// </summary>
/// <param name="parentNode"></param>
private static void LegacySortNodes(ref XmlNode parentNode)
{
XmlNode n = parentNode.CloneNode(true);
// remove all children from original node
string xpath = "./* [@id]";
foreach (XmlNode child in parentNode.SelectNodes(xpath))
parentNode.RemoveChild(child);
XPathNavigator nav = n.CreateNavigator();
XPathExpression expr = nav.Compile(xpath);
expr.AddSort("@sortOrder", XmlSortOrder.Ascending, XmlCaseOrder.None, "", XmlDataType.Number);
XPathNodeIterator iterator = nav.Select(expr);
while (iterator.MoveNext())
parentNode.AppendChild(
((IHasXmlNode)iterator.Current).GetNode());
}
/// <summary>
/// returns xml with a reverse sort order
/// </summary>
/// <param name="templateId"></param>
/// <returns></returns>
private string GetXmlContent(int templateId)
{
return @"<?xml version=""1.0"" encoding=""utf-8""?>
<!DOCTYPE root[
<!ELEMENT Home ANY>
<!ATTLIST Home id ID #REQUIRED>
<!ELEMENT CustomDocument ANY>
<!ATTLIST CustomDocument id ID #REQUIRED>
]>
<root id=""-1"">
<Home id=""1046"" parentID=""-1"" level=""1"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""0"" createDate=""2012-06-12T14:13:17"" updateDate=""2012-07-20T18:50:43"" nodeName=""Home"" urlName=""home"" writerName=""admin"" creatorName=""admin"" path=""-1,1046"" isDoc="""">
<content><![CDATA[]]></content>
<umbracoUrlAlias><![CDATA[this/is/my/alias, anotheralias]]></umbracoUrlAlias>
<umbracoNaviHide>1</umbracoNaviHide>
<Home id=""1173"" parentID=""1046"" level=""2"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""0"" createDate=""2012-07-20T18:06:45"" updateDate=""2012-07-20T19:07:31"" nodeName=""Sub1"" urlName=""sub1"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173"" isDoc="""">
<content><![CDATA[<div>This is some content</div>]]></content>
<umbracoUrlAlias><![CDATA[page2/alias, 2ndpagealias]]></umbracoUrlAlias>
<Home id=""1174"" parentID=""1173"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""3"" createDate=""2012-07-20T18:07:54"" updateDate=""2012-07-20T19:10:27"" nodeName=""Sub2"" urlName=""sub2"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1174"" isDoc="""">
<content><![CDATA[]]></content>
<umbracoUrlAlias><![CDATA[only/one/alias]]></umbracoUrlAlias>
<creatorName><![CDATA[Custom data with same property name as the member name]]></creatorName>
</Home>
<Home id=""1176"" parentID=""1173"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""2"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""sub-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1176"" isDoc="""">
<content><![CDATA[]]></content>
</Home>
<CustomDocument id=""1177"" parentID=""1173"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1234"" template=""" + templateId + @""" sortOrder=""1"" createDate=""2012-07-16T15:26:59"" updateDate=""2012-07-18T14:23:35"" nodeName=""custom sub 1"" urlName=""custom-sub-1"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1177"" isDoc="""" />
<CustomDocument id=""1178"" parentID=""1173"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1234"" template=""" + templateId + @""" sortOrder=""0"" createDate=""2012-07-16T15:26:59"" updateDate=""2012-07-16T14:23:35"" nodeName=""custom sub 2"" urlName=""custom-sub-2"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1178"" isDoc="""" />
<Home id=""1176"" parentID=""1179"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""26"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""sub-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1176"" isDoc="""">
<content><![CDATA[]]></content>
</Home>
<Home id=""1176"" parentID=""1180"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""25"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""sub-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1176"" isDoc="""">
<content><![CDATA[]]></content>
</Home>
<Home id=""1176"" parentID=""1181"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""24"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""sub-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1176"" isDoc="""">
<content><![CDATA[]]></content>
</Home>
<Home id=""1176"" parentID=""1182"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""23"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""sub-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1176"" isDoc="""">
<content><![CDATA[]]></content>
</Home>
<Home id=""1176"" parentID=""1183"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""22"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""sub-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1176"" isDoc="""">
<content><![CDATA[]]></content>
</Home>
<Home id=""1176"" parentID=""1184"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""21"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""sub-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1176"" isDoc="""">
<content><![CDATA[]]></content>
</Home>
<Home id=""1176"" parentID=""1185"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""20"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""sub-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1176"" isDoc="""">
<content><![CDATA[]]></content>
</Home>
<Home id=""1176"" parentID=""1186"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""19"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""sub-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1176"" isDoc="""">
<content><![CDATA[]]></content>
</Home>
<Home id=""1176"" parentID=""1187"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""18"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""sub-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1176"" isDoc="""">
<content><![CDATA[]]></content>
</Home>
<Home id=""1176"" parentID=""1188"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""17"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""sub-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1176"" isDoc="""">
<content><![CDATA[]]></content>
</Home>
<Home id=""1176"" parentID=""1189"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""16"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""sub-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1176"" isDoc="""">
<content><![CDATA[]]></content>
</Home>
<Home id=""1176"" parentID=""1190"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""15"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""sub-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1176"" isDoc="""">
<content><![CDATA[]]></content>
</Home>
<Home id=""1176"" parentID=""1191"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""14"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""sub-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1176"" isDoc="""">
<content><![CDATA[]]></content>
</Home>
<Home id=""1176"" parentID=""1192"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""13"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""sub-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1176"" isDoc="""">
<content><![CDATA[]]></content>
</Home>
<Home id=""1176"" parentID=""1193"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""12"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""sub-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1176"" isDoc="""">
<content><![CDATA[]]></content>
</Home>
<Home id=""1176"" parentID=""1194"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""11"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""sub-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1176"" isDoc="""">
<content><![CDATA[]]></content>
</Home>
<Home id=""1176"" parentID=""1195"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""10"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""sub-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1176"" isDoc="""">
<content><![CDATA[]]></content>
</Home>
<Home id=""1176"" parentID=""1196"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""9"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""sub-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1176"" isDoc="""">
<content><![CDATA[]]></content>
</Home>
<Home id=""1176"" parentID=""1197"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""8"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""sub-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1176"" isDoc="""">
<content><![CDATA[]]></content>
</Home>
<Home id=""1176"" parentID=""1198"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""7"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""sub-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1176"" isDoc="""">
<content><![CDATA[]]></content>
</Home>
<Home id=""1176"" parentID=""1199"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""6"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""sub-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1176"" isDoc="""">
<content><![CDATA[]]></content>
</Home>
<Home id=""1176"" parentID=""1200"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""5"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""sub-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1176"" isDoc="""">
<content><![CDATA[]]></content>
</Home>
<Home id=""1176"" parentID=""1201"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""4"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""sub-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1176"" isDoc="""">
<content><![CDATA[]]></content>
</Home>
</Home>
<Home id=""1175"" parentID=""1046"" level=""2"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""1"" createDate=""2012-07-20T18:08:01"" updateDate=""2012-07-20T18:49:32"" nodeName=""Sub 2"" urlName=""sub-2"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1175"" isDoc=""""><content><![CDATA[]]></content>
</Home>
</Home>
<CustomDocument id=""1172"" parentID=""-1"" level=""1"" writerID=""0"" creatorID=""0"" nodeType=""1234"" template=""" + templateId + @""" sortOrder=""1"" createDate=""2012-07-16T15:26:59"" updateDate=""2012-07-18T14:23:35"" nodeName=""Test"" urlName=""test-page"" writerName=""admin"" creatorName=""admin"" path=""-1,1172"" isDoc="""" />
</root>";
}
}
}

View File

@@ -20,6 +20,7 @@ using Umbraco.Core.Serialization;
using Umbraco.Core.Services;
using Umbraco.Tests.TestHelpers;
using Umbraco.Tests.TestHelpers.Entities;
using Umbraco.Tests.TestHelpers.Stubs;
namespace Umbraco.Tests.Models
{

View File

@@ -9,6 +9,7 @@ using Umbraco.Core.Models.EntityBase;
using Umbraco.Core.Serialization;
using Umbraco.Tests.TestHelpers;
using Umbraco.Tests.TestHelpers.Entities;
using Umbraco.Tests.TestHelpers.Stubs;
namespace Umbraco.Tests.Models
{

View File

@@ -14,6 +14,7 @@ using Umbraco.Core.Persistence.SqlSyntax;
using Umbraco.Core.Profiling;
using Umbraco.Core.Services;
using Umbraco.Tests.TestHelpers;
using Umbraco.Tests.TestHelpers.Stubs;
namespace Umbraco.Tests.Persistence
{

View File

@@ -8,6 +8,7 @@ using Umbraco.Core.Persistence;
using Umbraco.Core.Persistence.Mappers;
using Umbraco.Core.Persistence.SqlSyntax;
using Umbraco.Tests.TestHelpers;
using Umbraco.Tests.TestHelpers.Stubs;
namespace Umbraco.Tests.Persistence.FaultHandling
{

View File

@@ -22,6 +22,7 @@ using umbraco.uicontrols;
using Umbraco.Core.Logging;
using Umbraco.Core.Plugins;
using Umbraco.Tests.TestHelpers;
using Umbraco.Tests.TestHelpers.Stubs;
using Umbraco.Web;
using Umbraco.Web.Models.Trees;
using Umbraco.Web.Trees;

View File

@@ -12,6 +12,7 @@ using Umbraco.Core.Logging;
using Umbraco.Core.Persistence;
using Umbraco.Core.Services;
using Umbraco.Tests.TestHelpers;
using Umbraco.Tests.TestHelpers.Stubs;
using UmbracoExamine;
namespace Umbraco.Tests.Runtimes

View File

@@ -13,6 +13,7 @@ using Umbraco.Core.Models.Rdbms;
using Umbraco.Core.Persistence.Repositories;
using Umbraco.Tests.TestHelpers;
using Umbraco.Tests.TestHelpers.Entities;
using Umbraco.Tests.TestHelpers.Stubs;
using Current = Umbraco.Web.Current;
namespace Umbraco.Tests.Services

View File

@@ -19,6 +19,7 @@ using Umbraco.Tests.TestHelpers;
using Umbraco.Tests.TestHelpers.Entities;
using Umbraco.Core.DI;
using Umbraco.Core.Events;
using Umbraco.Tests.TestHelpers.Stubs;
namespace Umbraco.Tests.Services
{

View File

@@ -20,6 +20,7 @@ using Umbraco.Core.Persistence.UnitOfWork;
using Umbraco.Core.Services;
using Umbraco.Tests.TestHelpers;
using Umbraco.Tests.TestHelpers.Entities;
using Umbraco.Tests.TestHelpers.Stubs;
namespace Umbraco.Tests.Services
{

View File

@@ -66,7 +66,7 @@ namespace Umbraco.Tests.TestHelpers
return new FacadeRouter(
TestObjects.GetUmbracoSettings().WebRouting,
contentFinders ?? new ContentFinderCollection(Enumerable.Empty<IContentFinder>()),
new FakeLastChanceFinder(),
new TestLastChanceFinder(),
container?.TryGetInstance<ServiceContext>() ?? new ServiceContext(),
new ProfilingLogger(Mock.Of<ILogger>(), Mock.Of<IProfiler>()));
}

View File

@@ -1,29 +0,0 @@
namespace Umbraco.Tests.TestHelpers
{
/// <summary>
/// The behavior used to control how the database is handled for test fixtures inheriting from BaseDatabaseFactoryTest
/// </summary>
public enum DatabaseBehavior
{
/// <summary>
/// A database is not required whatsoever for the fixture
/// </summary>
NoDatabasePerFixture,
/// <summary>
/// For each test a new database file and schema will be created
/// </summary>
NewDbFileAndSchemaPerTest,
/// <summary>
/// Creates a new database file and schema for the whole fixture, each test will use the pre-existing one
/// </summary>
NewDbFileAndSchemaPerFixture,
/// <summary>
/// For each test a new database file without a schema
/// </summary>
EmptyDbFilePerTest,
}
}

View File

@@ -5,7 +5,6 @@ using System.Reflection;
using System.Web.Mvc;
using System.Web.Routing;
using System.Web.SessionState;
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.Logging;
using Umbraco.Core.Plugins;
@@ -59,7 +58,7 @@ namespace Umbraco.Tests.TestHelpers.Stubs
return null;
}
public System.Web.SessionState.SessionStateBehavior GetControllerSessionBehavior(RequestContext requestContext, string controllerName)
public SessionStateBehavior GetControllerSessionBehavior(RequestContext requestContext, string controllerName)
{
return SessionStateBehavior.Disabled;
}

View File

@@ -1,8 +1,8 @@
using Umbraco.Web.PublishedCache;
namespace Umbraco.Tests.TestHelpers
namespace Umbraco.Tests.TestHelpers.Stubs
{
class TestFacadeAccessor : IFacadeAccessor
public class TestFacadeAccessor : IFacadeAccessor
{
public IFacade Facade { get; set; }
}

View File

@@ -2,16 +2,10 @@ using System.Collections.Generic;
using Examine;
using UmbracoExamine;
namespace Umbraco.Tests.TestHelpers
namespace Umbraco.Tests.TestHelpers.Stubs
{
/// <summary>
/// An empty index collection accessor class for testing
/// </summary>
public class TestIndexCollectionAccessor : IExamineIndexCollectionAccessor
{
public IReadOnlyDictionary<string, IExamineIndexer> Indexes
{
get { return new Dictionary<string, IExamineIndexer>(); }
}
public IReadOnlyDictionary<string, IExamineIndexer> Indexes => new Dictionary<string, IExamineIndexer>();
}
}

View File

@@ -1,12 +1,12 @@
using Umbraco.Web.Routing;
namespace Umbraco.Tests.TestHelpers.Stubs
{
internal class FakeLastChanceFinder : IContentLastChanceFinder
{
public bool TryFindContent(PublishedContentRequest frequest)
{
return false;
}
}
using Umbraco.Web.Routing;
namespace Umbraco.Tests.TestHelpers.Stubs
{
internal class TestLastChanceFinder : IContentLastChanceFinder
{
public bool TryFindContent(PublishedContentRequest frequest)
{
return false;
}
}
}

View File

@@ -3,7 +3,7 @@ using StackExchange.Profiling;
using StackExchange.Profiling.SqlFormatters;
using Umbraco.Core.Logging;
namespace Umbraco.Tests.TestHelpers
namespace Umbraco.Tests.TestHelpers.Stubs
{
public class TestProfiler : IProfiler
{

View File

@@ -0,0 +1,9 @@
using Umbraco.Web;
namespace Umbraco.Tests.TestHelpers.Stubs
{
public class TestUmbracoContextAccessor : IUmbracoContextAccessor
{
public UmbracoContext UmbracoContext { get; set; }
}
}

View File

@@ -0,0 +1,9 @@
using Umbraco.Core.Persistence;
namespace Umbraco.Tests.TestHelpers.Stubs
{
public class TestUmbracoDatabaseAccessor : IUmbracoDatabaseAccessor
{
public UmbracoDatabase UmbracoDatabase { get; set; }
}
}

View File

@@ -9,6 +9,7 @@ using Umbraco.Core.Configuration.UmbracoSettings;
using Umbraco.Core.Logging;
using Umbraco.Core.Persistence;
using Umbraco.Core.Services;
using Umbraco.Tests.TestHelpers.Stubs;
using Umbraco.Web;
using Umbraco.Web.PublishedCache;
using Umbraco.Web.Routing;

View File

@@ -16,6 +16,7 @@ using Umbraco.Core.Persistence.SqlSyntax;
using Umbraco.Core.Persistence.UnitOfWork;
using Umbraco.Core.Services;
using Umbraco.Core.Strings;
using Umbraco.Tests.TestHelpers.Stubs;
using Umbraco.Web.Services;
namespace Umbraco.Tests.TestHelpers

View File

@@ -1,9 +0,0 @@
using Umbraco.Web;
namespace Umbraco.Tests
{
internal class TestUmbracoContextAccessor : IUmbracoContextAccessor
{
public UmbracoContext UmbracoContext { get; set; }
}
}

View File

@@ -1,9 +0,0 @@
using Umbraco.Core.Persistence;
namespace Umbraco.Tests.TestHelpers
{
internal class TestUmbracoDatabaseAccessor : IUmbracoDatabaseAccessor
{
public UmbracoDatabase UmbracoDatabase { get; set; }
}
}

View File

@@ -16,6 +16,7 @@ using Umbraco.Core.Events;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.Plugins;
using Umbraco.Core.Services;
using Umbraco.Tests.TestHelpers.Stubs;
using Umbraco.Web.Services;
using UmbracoExamine;

View File

@@ -31,6 +31,7 @@ using File = System.IO.File;
using Umbraco.Core.DI;
using Umbraco.Core.Events;
using Umbraco.Core.Strings;
using Umbraco.Tests.TestHelpers.Stubs;
namespace Umbraco.Tests.TestHelpers
{

View File

@@ -1,4 +1,5 @@
using NUnit.Framework;
using Umbraco.Tests.TestHelpers.Stubs;
using Current = Umbraco.Web.Current;
namespace Umbraco.Tests.TestHelpers

View File

@@ -1,6 +1,7 @@
using System;
using System.Linq;
using System.Reflection;
using Umbraco.Core;
namespace Umbraco.Tests.TestHelpers
{

View File

@@ -1,103 +1,98 @@
using System;
using System.Linq;
using System.Web;
using System.Web.Security;
using LightInject;
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.Configuration.UmbracoSettings;
using Umbraco.Core.Logging;
using Umbraco.Core.Dictionary;
using Umbraco.Core.Services;
using Moq;
using Umbraco.Core.Cache;
using Umbraco.Core.DI;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Tests.TestHelpers;
using Umbraco.Web;
using Umbraco.Web.PublishedCache;
using Umbraco.Web.Routing;
using Umbraco.Web.Security;
using Current = Umbraco.Web.Current;
namespace Umbraco.Tests
{
[TestFixture]
public class MockTests : UmbracoTestBase
{
public override void SetUp()
{
base.SetUp();
Current.UmbracoContextAccessor = new TestUmbracoContextAccessor();
}
[Test]
public void Can_Mock_Service_Context()
{
// ReSharper disable once UnusedVariable
var serviceContext = TestObjects.GetServiceContextMock();
Assert.Pass();
}
[Test]
public void Can_Mock_Database_Context()
{
var databaseFactory = TestObjects.GetDatabaseFactoryMock();
var logger = Mock.Of<ILogger>();
var runtimeState = Mock.Of<IRuntimeState>();
var migrationEntryService = Mock.Of<IMigrationEntryService>();
// ReSharper disable once UnusedVariable
var databaseContext = new DatabaseContext(databaseFactory, logger, runtimeState, migrationEntryService);
Assert.Pass();
}
[Test]
public void Can_Mock_Umbraco_Context()
{
var umbracoContext = TestObjects.GetUmbracoContextMock(Current.UmbracoContextAccessor);
Assert.AreEqual(umbracoContext, UmbracoContext.Current);
}
[Test]
public void Can_Mock_Umbraco_Helper()
{
var umbracoContext = TestObjects.GetUmbracoContextMock();
// unless we can inject them in MembershipHelper, we need need this
Container.Register(_ => Mock.Of<IMemberService>());
Container.Register(_ => Mock.Of<IMemberTypeService>());
Container.Register(_ => CacheHelper.CreateDisabledCacheHelper());
Container.Register<ServiceContext>();
// ReSharper disable once UnusedVariable
var helper = new UmbracoHelper(umbracoContext,
Mock.Of<IPublishedContent>(),
Mock.Of<IPublishedContentQuery>(),
Mock.Of<ITagQuery>(),
Mock.Of<IDataTypeService>(),
Mock.Of<ICultureDictionary>(),
Mock.Of<IUmbracoComponentRenderer>(),
new MembershipHelper(umbracoContext, Mock.Of<MembershipProvider>(), Mock.Of<RoleProvider>()),
new ServiceContext(),
CacheHelper.CreateDisabledCacheHelper());
Assert.Pass();
}
[Test]
public void Can_Mock_UrlProvider()
{
var umbracoContext = TestObjects.GetUmbracoContextMock();
var urlProviderMock = new Mock<IUrlProvider>();
urlProviderMock.Setup(provider => provider.GetUrl(It.IsAny<UmbracoContext>(), It.IsAny<int>(), It.IsAny<Uri>(), It.IsAny<UrlProviderMode>()))
.Returns("/hello/world/1234");
var urlProvider = urlProviderMock.Object;
var theUrlProvider = new UrlProvider(umbracoContext, new [] { urlProvider });
Assert.AreEqual("/hello/world/1234", theUrlProvider.GetUrl(1234));
}
}
}
using System;
using System.Web.Security;
using Moq;
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.Cache;
using Umbraco.Core.Dictionary;
using Umbraco.Core.Logging;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.Services;
using Umbraco.Tests.TestHelpers;
using Umbraco.Tests.TestHelpers.Stubs;
using Umbraco.Web;
using Umbraco.Web.Routing;
using Umbraco.Web.Security;
using Current = Umbraco.Web.Current;
namespace Umbraco.Tests.Testing
{
[TestFixture]
public class MockTests : UmbracoTestBase
{
public override void SetUp()
{
base.SetUp();
Current.UmbracoContextAccessor = new TestUmbracoContextAccessor();
}
[Test]
public void Can_Mock_Service_Context()
{
// ReSharper disable once UnusedVariable
var serviceContext = TestObjects.GetServiceContextMock();
Assert.Pass();
}
[Test]
public void Can_Mock_Database_Context()
{
var databaseFactory = TestObjects.GetDatabaseFactoryMock();
var logger = Mock.Of<ILogger>();
var runtimeState = Mock.Of<IRuntimeState>();
var migrationEntryService = Mock.Of<IMigrationEntryService>();
// ReSharper disable once UnusedVariable
var databaseContext = new DatabaseContext(databaseFactory, logger, runtimeState, migrationEntryService);
Assert.Pass();
}
[Test]
public void Can_Mock_Umbraco_Context()
{
var umbracoContext = TestObjects.GetUmbracoContextMock(Current.UmbracoContextAccessor);
Assert.AreEqual(umbracoContext, UmbracoContext.Current);
}
[Test]
public void Can_Mock_Umbraco_Helper()
{
var umbracoContext = TestObjects.GetUmbracoContextMock();
// unless we can inject them in MembershipHelper, we need need this
Container.Register(_ => Mock.Of<IMemberService>());
Container.Register(_ => Mock.Of<IMemberTypeService>());
Container.Register(_ => CacheHelper.CreateDisabledCacheHelper());
Container.Register<ServiceContext>();
// ReSharper disable once UnusedVariable
var helper = new UmbracoHelper(umbracoContext,
Mock.Of<IPublishedContent>(),
Mock.Of<IPublishedContentQuery>(),
Mock.Of<ITagQuery>(),
Mock.Of<IDataTypeService>(),
Mock.Of<ICultureDictionary>(),
Mock.Of<IUmbracoComponentRenderer>(),
new MembershipHelper(umbracoContext, Mock.Of<MembershipProvider>(), Mock.Of<RoleProvider>()),
new ServiceContext(),
CacheHelper.CreateDisabledCacheHelper());
Assert.Pass();
}
[Test]
public void Can_Mock_UrlProvider()
{
var umbracoContext = TestObjects.GetUmbracoContextMock();
var urlProviderMock = new Mock<IUrlProvider>();
urlProviderMock.Setup(provider => provider.GetUrl(It.IsAny<UmbracoContext>(), It.IsAny<int>(), It.IsAny<Uri>(), It.IsAny<UrlProviderMode>()))
.Returns("/hello/world/1234");
var urlProvider = urlProviderMock.Object;
var theUrlProvider = new UrlProvider(umbracoContext, new [] { urlProvider });
Assert.AreEqual("/hello/world/1234", theUrlProvider.GetUrl(1234));
}
}
}

View File

@@ -1,6 +1,6 @@
using NUnit.Framework;
namespace Umbraco.Tests
namespace Umbraco.Tests.Testing
{
// these 4 test classes validate that our test class pattern *should* be:
// - test base classes *not* marked as [TestFixture] but having a virtual SetUp

View File

@@ -227,38 +227,36 @@
<ItemGroup>
<Compile Include="Cache\RefresherTests.cs" />
<Compile Include="Cache\SnapDictionaryTests.cs" />
<Compile Include="CallContextTests.cs" />
<Compile Include="CoreThings\CallContextTests.cs" />
<Compile Include="Components\ComponentTests.cs" />
<Compile Include="CoreXml\RenamedRootNavigatorTests.cs" />
<Compile Include="IO\ShadowFileSystemTests.cs" />
<Compile Include="Logging\ConsoleLogger.cs" />
<Compile Include="DependencyInjection\TempTests.cs" />
<Compile Include="Integration\ContentEventsTests.cs" />
<Compile Include="Migrations\MigrationIssuesTests.cs" />
<Compile Include="NUnitTests.cs" />
<Compile Include="Testing\NUnitTests.cs" />
<Compile Include="Persistence\BulkDataReaderTests.cs" />
<Compile Include="Persistence\Migrations\PostMigrationTests.cs" />
<Compile Include="Persistence\NPocoExpressionsTests.cs" />
<Compile Include="Persistence\UnitOfWorkTests.cs" />
<Compile Include="Persistence\Repositories\RedirectUrlRepositoryTests.cs" />
<Compile Include="Scheduling\DeployTest.cs" />
<Compile Include="TestHelpers\Settable.cs" />
<Compile Include="TestHelpers\UmbracoTestAttribute.cs" />
<Compile Include="TestHelpers\UmbracoTestBase.cs" />
<Compile Include="TestHelpers\Entities\MockedPropertyTypes.cs" />
<Compile Include="TestHelpers\UmbracoTestOptions.cs" />
<Compile Include="TryConvertToTests.cs" />
<Compile Include="TestHelpers\TestFacadeAccessor.cs" />
<Compile Include="TestHelpers\TestIndexCollectionAccessor.cs" />
<Compile Include="CoreThings\TryConvertToTests.cs" />
<Compile Include="TestHelpers\Stubs\TestFacadeAccessor.cs" />
<Compile Include="TestHelpers\Stubs\TestIndexCollectionAccessor.cs" />
<Compile Include="TestHelpers\TestObjects-Mocks.cs" />
<Compile Include="TestHelpers\TestObjects.cs" />
<Compile Include="TestHelpers\TestUmbracoDatabaseAccessor.cs" />
<Compile Include="TestHelpers\TestUmbracoContextAccessor.cs" />
<Compile Include="TestHelpers\Stubs\TestUmbracoDatabaseAccessor.cs" />
<Compile Include="TestHelpers\Stubs\TestUmbracoContextAccessor.cs" />
<Compile Include="Web\AngularIntegration\AngularAntiForgeryTests.cs" />
<Compile Include="Web\AngularIntegration\ContentModelSerializationTests.cs" />
<Compile Include="Web\AngularIntegration\JsInitializationTests.cs" />
<Compile Include="Web\AngularIntegration\ServerVariablesParserTests.cs" />
<Compile Include="AttemptTests.cs" />
<Compile Include="CoreThings\AttemptTests.cs" />
<Compile Include="Cache\CacheRefresherTests.cs" />
<Compile Include="Migrations\Stubs\DropForeignKeyMigrationStub.cs" />
<Compile Include="Models\Mapping\ContentTypeModelMappingTests.cs" />
@@ -268,7 +266,7 @@
<Compile Include="Cache\SingleItemsOnlyCachePolicyTests.cs" />
<Compile Include="Collections\DeepCloneableListTests.cs" />
<Compile Include="Web\Controllers\BackOfficeControllerUnitTests.cs" />
<Compile Include="DelegateExtensionsTests.cs" />
<Compile Include="CoreThings\DelegateExtensionsTests.cs" />
<Compile Include="Logging\AsyncRollingFileAppenderTest.cs" />
<Compile Include="Logging\DebugAppender.cs" />
<Compile Include="Logging\ParallelForwarderTest.cs" />
@@ -298,7 +296,7 @@
<Compile Include="Migrations\Stubs\FiveZeroMigration.cs" />
<Compile Include="Migrations\Stubs\FourElevenMigration.cs" />
<Compile Include="Migrations\Stubs\SixZeroMigration2.cs" />
<Compile Include="MockTests.cs" />
<Compile Include="Testing\MockTests.cs" />
<Compile Include="Models\MacroTests.cs" />
<Compile Include="Models\Mapping\AutoMapperTests.cs" />
<Compile Include="Models\Collections\Item.cs" />
@@ -394,7 +392,7 @@
<Compile Include="PublishedContent\StronglyTypedModels\Textpage.cs" />
<Compile Include="PublishedContent\StronglyTypedModels\TypedModelBase.cs" />
<Compile Include="Scheduling\BackgroundTaskRunnerTests.cs" />
<Compile Include="ApplicationUrlHelperTests.cs" />
<Compile Include="Misc\ApplicationUrlHelperTests.cs" />
<Compile Include="Services\FileServiceTests.cs" />
<Compile Include="Services\LocalizedTextServiceTests.cs" />
<Compile Include="Services\TagServiceTests.cs" />
@@ -452,10 +450,10 @@
<Compile Include="PublishedContent\PublishedContentTestElements.cs" />
<Compile Include="PublishedContent\PublishedContentTests.cs" />
<Compile Include="PublishedContent\PublishedMediaTests.cs" />
<Compile Include="HashCodeCombinerTests.cs" />
<Compile Include="Misc\HashCodeCombinerTests.cs" />
<Compile Include="Web\Mvc\HtmlHelperExtensionMethodsTests.cs" />
<Compile Include="IO\IOHelperTest.cs" />
<Compile Include="LibraryTests.cs" />
<Compile Include="Misc\LibraryTests.cs" />
<Compile Include="PropertyEditors\PropertyEditorValueConverterTests.cs" />
<Compile Include="Models\ContentTests.cs" />
<Compile Include="Models\ContentXmlTest.cs" />
@@ -494,7 +492,7 @@
<Compile Include="TestHelpers\Entities\MockedMember.cs" />
<Compile Include="TestHelpers\Entities\MockedUser.cs" />
<Compile Include="TestHelpers\Entities\MockedUserType.cs" />
<Compile Include="TestHelpers\TestProfiler.cs" />
<Compile Include="TestHelpers\Stubs\TestProfiler.cs" />
<Compile Include="TreesAndSections\ResourceFiles.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
@@ -502,7 +500,7 @@
</Compile>
<Compile Include="TreesAndSections\SectionTests.cs" />
<Compile Include="TreesAndSections\ApplicationTreeTest.cs" />
<Compile Include="ObjectExtensionsTests.cs" />
<Compile Include="CoreThings\ObjectExtensionsTests.cs" />
<Compile Include="Cache\PublishedCache\PublishedContentCacheTests.cs" />
<Compile Include="DependencyInjection\LazyCollectionBuilderTests.cs" />
<Compile Include="DependencyInjection\CollectionBuildersTests.cs" />
@@ -530,7 +528,6 @@
<Compile Include="Templates\MasterPageHelperTests.cs" />
<Compile Include="TestHelpers\TestWithDatabaseBase.cs" />
<Compile Include="TestHelpers\TestWithApplicationBase.cs" />
<Compile Include="TestHelpers\DatabaseBehavior.cs" />
<Compile Include="TestHelpers\SettingsForTests.cs" />
<Compile Include="Configurations\GlobalSettingsTests.cs" />
<Compile Include="Routing\ContentFinderByAliasTests.cs" />
@@ -564,14 +561,14 @@
<Compile Include="UI\LegacyDialogTests.cs" />
<Compile Include="UmbracoExamine\ExamineDemoDataMediaService.cs" />
<Compile Include="UmbracoExamine\ExamineDemoDataContentService.cs" />
<Compile Include="UriExtensionsTests.cs" />
<Compile Include="UriUtilityTests.cs" />
<Compile Include="CoreThings\UriExtensionsTests.cs" />
<Compile Include="Misc\UriUtilityTests.cs" />
<Compile Include="DependencyInjection\PackageActionCollectionTests.cs" />
<Compile Include="Plugins\PluginManagerExtensions.cs" />
<Compile Include="Plugins\PluginManagerTests.cs" />
<Compile Include="TestHelpers\Stubs\FakeLastChanceFinder.cs" />
<Compile Include="TestHelpers\Stubs\TestLastChanceFinder.cs" />
<Compile Include="TestHelpers\TestHelper.cs" />
<Compile Include="EnumerableExtensionsTests.cs" />
<Compile Include="CoreThings\EnumerableExtensionsTests.cs" />
<Compile Include="IO\AbstractFileSystemTests.cs" />
<Compile Include="IO\FileSystemProviderManagerTests.cs" />
<Compile Include="IO\PhysicalFileSystemTests.cs" />
@@ -580,10 +577,10 @@
<Compile Include="TestHelpers\FakeHttpContextFactory.cs" />
<Compile Include="Plugins\TypeFinderTests.cs" />
<Compile Include="Routing\UmbracoModuleTests.cs" />
<Compile Include="VersionExtensionTests.cs" />
<Compile Include="CoreThings\VersionExtensionTests.cs" />
<Compile Include="Web\WebExtensionMethodTests.cs" />
<Compile Include="XmlExtensionsTests.cs" />
<Compile Include="XmlHelperTests.cs" />
<Compile Include="CoreThings\XmlExtensionsTests.cs" />
<Compile Include="Misc\XmlHelperTests.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config">

View File

@@ -14,6 +14,7 @@ using Umbraco.Core.Logging;
using Umbraco.Core.Profiling;
using Umbraco.Core.Services;
using Umbraco.Tests.TestHelpers;
using Umbraco.Tests.TestHelpers.Stubs;
using Umbraco.Web;
using Umbraco.Web.Models;
using Umbraco.Web.Mvc;

View File

@@ -7,6 +7,7 @@ using Moq;
using NUnit.Framework;
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Tests.TestHelpers.Stubs;
using Umbraco.Web.Models;
using Umbraco.Web.Mvc;
using Current = Umbraco.Web.Current;

View File

@@ -12,6 +12,7 @@ using Umbraco.Core.Dictionary;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.Services;
using Umbraco.Tests.TestHelpers;
using Umbraco.Tests.TestHelpers.Stubs;
using Umbraco.Web;
using Umbraco.Web.Mvc;
using Umbraco.Web.PublishedCache;

View File

@@ -7,6 +7,7 @@ using Moq;
using NUnit.Framework;
using Umbraco.Core.Configuration.UmbracoSettings;
using Umbraco.Tests.TestHelpers;
using Umbraco.Tests.TestHelpers.Stubs;
using Umbraco.Web;
using Umbraco.Web.Mvc;
using Umbraco.Web.PublishedCache;