diff --git a/src/Umbraco.Tests.Common/TestClone.cs b/src/Umbraco.Tests.Common/TestClone.cs new file mode 100644 index 0000000000..5fd0aa30e2 --- /dev/null +++ b/src/Umbraco.Tests.Common/TestClone.cs @@ -0,0 +1,77 @@ +using System; +using Umbraco.Core.Models; + +namespace Umbraco.Tests.Common +{ + public class TestClone : IDeepCloneable, IEquatable + { + public TestClone(Guid id) + { + Id = id; + IsClone = true; + } + + public TestClone() + { + Id = Guid.NewGuid(); + } + + public Guid Id { get; } + public bool IsClone { get; } + + public object DeepClone() + { + return new TestClone(Id); + } + + /// + /// Indicates whether the current object is equal to another object of the same type. + /// + /// + /// true if the current object is equal to the parameter; otherwise, false. + /// + /// An object to compare with this object. + public bool Equals(TestClone other) + { + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; + return Id.Equals(other.Id); + } + + /// + /// Determines whether the specified object is equal to the current object. + /// + /// + /// true if the specified object is equal to the current object; otherwise, false. + /// + /// The object to compare with the current object. + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + if (obj.GetType() != this.GetType()) return false; + return Equals((TestClone)obj); + } + + /// + /// Serves as the default hash function. + /// + /// + /// A hash code for the current object. + /// + public override int GetHashCode() + { + return Id.GetHashCode(); + } + + public static bool operator ==(TestClone left, TestClone right) + { + return Equals(left, right); + } + + public static bool operator !=(TestClone left, TestClone right) + { + return Equals(left, right) == false; + } + } +} diff --git a/src/Umbraco.Tests/CoreThings/AttemptTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/AttemptTests.cs similarity index 92% rename from src/Umbraco.Tests/CoreThings/AttemptTests.cs rename to src/Umbraco.Tests.UnitTests/Umbraco.Core/AttemptTests.cs index a004095243..9a16c5b10f 100644 --- a/src/Umbraco.Tests/CoreThings/AttemptTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/AttemptTests.cs @@ -1,12 +1,11 @@ using NUnit.Framework; using Umbraco.Core; -namespace Umbraco.Tests.CoreThings +namespace Umbraco.Tests.UnitTests.Umbraco.Core { [TestFixture] public class AttemptTests { - [Test] public void AttemptIf() { diff --git a/src/Umbraco.Tests/CoreThings/ClaimsIdentityExtensionsTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/ClaimsIdentityExtensionsTests.cs similarity index 96% rename from src/Umbraco.Tests/CoreThings/ClaimsIdentityExtensionsTests.cs rename to src/Umbraco.Tests.UnitTests/Umbraco.Core/ClaimsIdentityExtensionsTests.cs index 4f728c3861..76f928ca46 100644 --- a/src/Umbraco.Tests/CoreThings/ClaimsIdentityExtensionsTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/ClaimsIdentityExtensionsTests.cs @@ -3,9 +3,8 @@ using System.Collections.Generic; using System.Security.Claims; using NUnit.Framework; using Umbraco.Core; -using Umbraco.Web; -namespace Umbraco.Tests.CoreThings +namespace Umbraco.Tests.UnitTests.Umbraco.Core { public class ClaimsIdentityExtensionsTests { diff --git a/src/Umbraco.Tests/Collections/DeepCloneableListTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Collections/DeepCloneableListTests.cs similarity index 53% rename from src/Umbraco.Tests/Collections/DeepCloneableListTests.cs rename to src/Umbraco.Tests.UnitTests/Umbraco.Core/Collections/DeepCloneableListTests.cs index 37e5b2081d..bcfe142d8d 100644 --- a/src/Umbraco.Tests/Collections/DeepCloneableListTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Collections/DeepCloneableListTests.cs @@ -1,13 +1,9 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Linq; using NUnit.Framework; using Umbraco.Core.Collections; -using Umbraco.Core.Models; +using Umbraco.Tests.Common; -namespace Umbraco.Tests.Collections +namespace Umbraco.Tests.UnitTests.Umbraco.Core.Collections { [TestFixture] public class DeepCloneableListTests @@ -85,7 +81,7 @@ namespace Umbraco.Tests.Collections list.Add(new TestClone()); list.Add(new TestClone()); - var cloned = (DeepCloneableList)list.DeepClone(); + var cloned = (DeepCloneableList) list.DeepClone(); //Test that each item in the sequence is equal - based on the equality comparer of TestClone (i.e. it's ID) Assert.IsTrue(list.SequenceEqual(cloned)); @@ -97,77 +93,5 @@ namespace Umbraco.Tests.Collections Assert.AreNotSame(item, clone); } } - - public class TestClone : IDeepCloneable, IEquatable - { - public TestClone(Guid id) - { - Id = id; - IsClone = true; - } - - public TestClone() - { - Id = Guid.NewGuid(); - } - - public Guid Id { get; private set; } - public bool IsClone { get; private set; } - - public object DeepClone() - { - return new TestClone(Id); - } - - /// - /// Indicates whether the current object is equal to another object of the same type. - /// - /// - /// true if the current object is equal to the parameter; otherwise, false. - /// - /// An object to compare with this object. - public bool Equals(TestClone other) - { - if (ReferenceEquals(null, other)) return false; - if (ReferenceEquals(this, other)) return true; - return Id.Equals(other.Id); - } - - /// - /// Determines whether the specified object is equal to the current object. - /// - /// - /// true if the specified object is equal to the current object; otherwise, false. - /// - /// The object to compare with the current object. - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - if (ReferenceEquals(this, obj)) return true; - if (obj.GetType() != this.GetType()) return false; - return Equals((TestClone)obj); - } - - /// - /// Serves as the default hash function. - /// - /// - /// A hash code for the current object. - /// - public override int GetHashCode() - { - return Id.GetHashCode(); - } - - public static bool operator ==(TestClone left, TestClone right) - { - return Equals(left, right); - } - - public static bool operator !=(TestClone left, TestClone right) - { - return Equals(left, right) == false; - } - } } } diff --git a/src/Umbraco.Tests/Collections/OrderedHashSetTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Collections/OrderedHashSetTests.cs similarity index 87% rename from src/Umbraco.Tests/Collections/OrderedHashSetTests.cs rename to src/Umbraco.Tests.UnitTests/Umbraco.Core/Collections/OrderedHashSetTests.cs index a98348751b..df7f004884 100644 --- a/src/Umbraco.Tests/Collections/OrderedHashSetTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Collections/OrderedHashSetTests.cs @@ -1,9 +1,8 @@ using System; using NUnit.Framework; -using Umbraco.Core; using Umbraco.Core.Collections; -namespace Umbraco.Tests.Collections +namespace Umbraco.Tests.UnitTests.Umbraco.Core.Collections { [TestFixture] public class OrderedHashSetTests @@ -12,7 +11,7 @@ namespace Umbraco.Tests.Collections public void Keeps_Last() { var list = new OrderedHashSet(keepOldest: false); - var items = new[] { new MyClass("test"), new MyClass("test"), new MyClass("test") }; + var items = new[] {new MyClass("test"), new MyClass("test"), new MyClass("test")}; foreach (var item in items) { list.Add(item); @@ -27,7 +26,7 @@ namespace Umbraco.Tests.Collections public void Keeps_First() { var list = new OrderedHashSet(keepOldest: true); - var items = new[] { new MyClass("test"), new MyClass("test"), new MyClass("test") }; + var items = new[] {new MyClass("test"), new MyClass("test"), new MyClass("test")}; foreach (var item in items) { list.Add(item); @@ -60,7 +59,7 @@ namespace Umbraco.Tests.Collections if (ReferenceEquals(null, obj)) return false; if (ReferenceEquals(this, obj)) return true; if (obj.GetType() != this.GetType()) return false; - return Equals((MyClass)obj); + return Equals((MyClass) obj); } public override int GetHashCode() diff --git a/src/Umbraco.Tests/CoreThings/DelegateExtensionsTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/DelegateExtensionsTests.cs similarity index 95% rename from src/Umbraco.Tests/CoreThings/DelegateExtensionsTests.cs rename to src/Umbraco.Tests.UnitTests/Umbraco.Core/DelegateExtensionsTests.cs index 87b2f4c03b..a3e36c8ae6 100644 --- a/src/Umbraco.Tests/CoreThings/DelegateExtensionsTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/DelegateExtensionsTests.cs @@ -3,7 +3,7 @@ using Lucene.Net.Index; using NUnit.Framework; using Umbraco.Core; -namespace Umbraco.Tests.CoreThings +namespace Umbraco.Tests.UnitTests.Umbraco.Core { [TestFixture] public class DelegateExtensionsTests diff --git a/src/Umbraco.Tests/CoreThings/EnumExtensionsTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/EnumExtensionsTests.cs similarity index 97% rename from src/Umbraco.Tests/CoreThings/EnumExtensionsTests.cs rename to src/Umbraco.Tests.UnitTests/Umbraco.Core/EnumExtensionsTests.cs index faa15b0077..d5ea4d2677 100644 --- a/src/Umbraco.Tests/CoreThings/EnumExtensionsTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/EnumExtensionsTests.cs @@ -3,7 +3,7 @@ using NUnit.Framework; using Umbraco.Core; using Umbraco.Web.Trees; -namespace Umbraco.Tests.CoreThings +namespace Umbraco.Tests.UnitTests.Umbraco.Core { [TestFixture] public class EnumExtensionsTests diff --git a/src/Umbraco.Tests/CoreThings/EnumerableExtensionsTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/EnumerableExtensionsTests.cs similarity index 98% rename from src/Umbraco.Tests/CoreThings/EnumerableExtensionsTests.cs rename to src/Umbraco.Tests.UnitTests/Umbraco.Core/EnumerableExtensionsTests.cs index e734713c76..32e039f26a 100644 --- a/src/Umbraco.Tests/CoreThings/EnumerableExtensionsTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/EnumerableExtensionsTests.cs @@ -1,10 +1,9 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using NUnit.Framework; using Umbraco.Core; -namespace Umbraco.Tests.CoreThings +namespace Umbraco.Tests.UnitTests.Umbraco.Core { [TestFixture] public class EnumerableExtensionsTests diff --git a/src/Umbraco.Tests/CoreThings/GuidUtilsTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/GuidUtilsTests.cs similarity index 95% rename from src/Umbraco.Tests/CoreThings/GuidUtilsTests.cs rename to src/Umbraco.Tests.UnitTests/Umbraco.Core/GuidUtilsTests.cs index 639d85b4ff..62e0955d78 100644 --- a/src/Umbraco.Tests/CoreThings/GuidUtilsTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/GuidUtilsTests.cs @@ -2,7 +2,7 @@ using NUnit.Framework; using Umbraco.Core; -namespace Umbraco.Tests.CoreThings +namespace Umbraco.Tests.UnitTests.Umbraco.Core { public class GuidUtilsTests { diff --git a/src/Umbraco.Tests/CoreThings/HexEncoderTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/HexEncoderTests.cs similarity index 97% rename from src/Umbraco.Tests/CoreThings/HexEncoderTests.cs rename to src/Umbraco.Tests.UnitTests/Umbraco.Core/HexEncoderTests.cs index 588fff83e8..f22c3f2ac1 100644 --- a/src/Umbraco.Tests/CoreThings/HexEncoderTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/HexEncoderTests.cs @@ -3,7 +3,7 @@ using System.Text; using NUnit.Framework; using Umbraco.Core; -namespace Umbraco.Tests.CoreThings +namespace Umbraco.Tests.UnitTests.Umbraco.Core { public class HexEncoderTests { diff --git a/src/Umbraco.Tests/Clr/ReflectionTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/ReflectionTests.cs similarity index 54% rename from src/Umbraco.Tests/Clr/ReflectionTests.cs rename to src/Umbraco.Tests.UnitTests/Umbraco.Core/ReflectionTests.cs index f3704c8552..063a8c2621 100644 --- a/src/Umbraco.Tests/Clr/ReflectionTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/ReflectionTests.cs @@ -2,7 +2,7 @@ using NUnit.Framework; using Umbraco.Core; -namespace Umbraco.Tests.Clr +namespace Umbraco.Tests.UnitTests.Umbraco.Core { [TestFixture] public class ReflectionTests @@ -25,37 +25,16 @@ namespace Umbraco.Tests.Clr Assert.Contains(typeof(object), types); } - [Test] - public void GetInterfacesIsOk() - { - // tests that GetInterfaces gets _all_ interfaces - // so the AllInterfaces extension method is useless - - var type = typeof(Class2); - var interfaces = type.GetInterfaces(); - Assert.AreEqual(2, interfaces.Length); - Assert.Contains(typeof(IInterface1), interfaces); - Assert.Contains(typeof(IInterface2), interfaces); - } - #region Test Objects - interface IInterface1 - { } - - interface IInterface2 : IInterface1 + private class Class1 { - void Method(); } - class Class1 : IInterface2 + private class Class2 : Class1 { - public void Method() { } } - class Class2 : Class1 - { } - #endregion } } diff --git a/src/Umbraco.Tests/Clr/ReflectionUtilitiesTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/ReflectionUtilitiesTests.cs similarity index 98% rename from src/Umbraco.Tests/Clr/ReflectionUtilitiesTests.cs rename to src/Umbraco.Tests.UnitTests/Umbraco.Core/ReflectionUtilitiesTests.cs index c885f364dc..0f48f2cea2 100644 --- a/src/Umbraco.Tests/Clr/ReflectionUtilitiesTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/ReflectionUtilitiesTests.cs @@ -1,12 +1,12 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Reflection; +using Newtonsoft.Json; using NUnit.Framework; using Umbraco.Core; -using System.Linq; -using Newtonsoft.Json; -namespace Umbraco.Tests.Clr +namespace Umbraco.Tests.UnitTests.Umbraco.Core { [TestFixture] public class ReflectionUtilitiesTests @@ -104,8 +104,6 @@ namespace Umbraco.Tests.Clr [Test] public void EmitMethodEmitsStaticStatic() { - // static types cannot be used as type arguments - //var method = ReflectionUtilities.EmitMethod("Method"); var method = ReflectionUtilities.EmitMethod(typeof (StaticClass1), "Method"); method(); } @@ -205,10 +203,6 @@ namespace Umbraco.Tests.Clr (var getter3, var setter3) = ReflectionUtilities.EmitPropertyGetterAndSetter("Value3"); Assert.AreEqual(42, getter3(class1)); setter3(class1, 42); - - // this is not supported yet - //var getter4 = ReflectionUtilities.EmitPropertyGetter("Value1", returned: typeof(int)); - //Assert.AreEqual(42, getter1(class1)); } [Test] @@ -448,7 +442,7 @@ namespace Umbraco.Tests.Clr var propInt4 = type4.GetProperty("IntValue"); Assert.IsNotNull(propInt4); - // ... if explicitely getting a value type + // ... if explicitly getting a value type var getterInt4T = ReflectionUtilities.EmitPropertyGetter(propInt4); Assert.IsNotNull(getterInt4T); var valueInt4T = getterInt4T(object4); diff --git a/src/Umbraco.Tests/CoreThings/VersionExtensionTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/VersionExtensionTests.cs similarity index 86% rename from src/Umbraco.Tests/CoreThings/VersionExtensionTests.cs rename to src/Umbraco.Tests.UnitTests/Umbraco.Core/VersionExtensionTests.cs index 5799e28b87..a4ab15afe7 100644 --- a/src/Umbraco.Tests/CoreThings/VersionExtensionTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/VersionExtensionTests.cs @@ -2,7 +2,7 @@ using NUnit.Framework; using Umbraco.Core; -namespace Umbraco.Tests.CoreThings +namespace Umbraco.Tests.UnitTests.Umbraco.Core { [TestFixture] public class VersionExtensionTests @@ -18,7 +18,7 @@ namespace Umbraco.Tests.CoreThings [TestCase(0, 0, 1, 1, "0.0.1.0")] [TestCase(0, 0, 0, 1, "0.0.0.0")] [TestCase(7, 3, 0, 0, "7.2.2147483647.2147483647")] - public void Subract_Revision(int major, int minor, int build, int rev, string outcome) + public void Subtract_Revision(int major, int minor, int build, int rev, string outcome) { var version = new Version(major, minor, build, rev); diff --git a/src/Umbraco.Tests/CoreThings/XmlExtensionsTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/XmlExtensionsTests.cs similarity index 96% rename from src/Umbraco.Tests/CoreThings/XmlExtensionsTests.cs rename to src/Umbraco.Tests.UnitTests/Umbraco.Core/XmlExtensionsTests.cs index 62e385beff..ae3762ef57 100644 --- a/src/Umbraco.Tests/CoreThings/XmlExtensionsTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/XmlExtensionsTests.cs @@ -3,7 +3,7 @@ using System.Xml.Linq; using NUnit.Framework; using Umbraco.Core; -namespace Umbraco.Tests.CoreThings +namespace Umbraco.Tests.UnitTests.Umbraco.Core { [TestFixture] public class XmlExtensionsTests diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Tests.UnitTests.csproj b/src/Umbraco.Tests.UnitTests/Umbraco.Tests.UnitTests.csproj index 20c05ca201..c358eabf27 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Tests.UnitTests.csproj +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Tests.UnitTests.csproj @@ -15,6 +15,7 @@ + diff --git a/src/Umbraco.Tests/Cache/DeepCloneAppCacheTests.cs b/src/Umbraco.Tests/Cache/DeepCloneAppCacheTests.cs index 63e481e9a5..f7b39590f2 100644 --- a/src/Umbraco.Tests/Cache/DeepCloneAppCacheTests.cs +++ b/src/Umbraco.Tests/Cache/DeepCloneAppCacheTests.cs @@ -12,7 +12,7 @@ using Umbraco.Core.Composing; using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.Models.Entities; -using Umbraco.Tests.Collections; +using Umbraco.Tests.Common; using Umbraco.Tests.TestHelpers; using Umbraco.Web.Cache; @@ -41,12 +41,12 @@ namespace Umbraco.Tests.Cache [Test] public void Clones_List() { - var original = new DeepCloneableList(ListCloneBehavior.Always); - original.Add(new DeepCloneableListTests.TestClone()); - original.Add(new DeepCloneableListTests.TestClone()); - original.Add(new DeepCloneableListTests.TestClone()); + var original = new DeepCloneableList(ListCloneBehavior.Always); + original.Add(new TestClone()); + original.Add(new TestClone()); + original.Add(new TestClone()); - var val = _provider.GetCacheItem>("test", () => original); + var val = _provider.GetCacheItem>("test", () => original); Assert.AreEqual(original.Count, val.Count); foreach (var item in val) diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index 5acdd4078d..5959898a87 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -117,17 +117,11 @@ - - - - - - @@ -243,17 +237,14 @@ - - - @@ -301,7 +292,6 @@ - @@ -458,7 +448,6 @@ - @@ -467,10 +456,8 @@ - -