Merge remote-tracking branch 'origin/netcore/dev' into netcore/netcore

This commit is contained in:
Bjarke Berg
2020-06-12 07:13:00 +02:00
17 changed files with 110 additions and 152 deletions

View File

@@ -0,0 +1,77 @@
using System;
using Umbraco.Core.Models;
namespace Umbraco.Tests.Common
{
public class TestClone : IDeepCloneable, IEquatable<TestClone>
{
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);
}
/// <summary>
/// Indicates whether the current object is equal to another object of the same type.
/// </summary>
/// <returns>
/// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
/// </returns>
/// <param name="other">An object to compare with this object.</param>
public bool Equals(TestClone other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return Id.Equals(other.Id);
}
/// <summary>
/// Determines whether the specified object is equal to the current object.
/// </summary>
/// <returns>
/// true if the specified object is equal to the current object; otherwise, false.
/// </returns>
/// <param name="obj">The object to compare with the current object. </param>
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);
}
/// <summary>
/// Serves as the default hash function.
/// </summary>
/// <returns>
/// A hash code for the current object.
/// </returns>
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;
}
}
}

View File

@@ -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()
{

View File

@@ -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
{

View File

@@ -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<TestClone>)list.DeepClone();
var cloned = (DeepCloneableList<TestClone>) 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<TestClone>
{
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);
}
/// <summary>
/// Indicates whether the current object is equal to another object of the same type.
/// </summary>
/// <returns>
/// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
/// </returns>
/// <param name="other">An object to compare with this object.</param>
public bool Equals(TestClone other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return Id.Equals(other.Id);
}
/// <summary>
/// Determines whether the specified object is equal to the current object.
/// </summary>
/// <returns>
/// true if the specified object is equal to the current object; otherwise, false.
/// </returns>
/// <param name="obj">The object to compare with the current object. </param>
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);
}
/// <summary>
/// Serves as the default hash function.
/// </summary>
/// <returns>
/// A hash code for the current object.
/// </returns>
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;
}
}
}
}

View File

@@ -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<MyClass>(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<MyClass>(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()

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -2,7 +2,7 @@
using NUnit.Framework;
using Umbraco.Core;
namespace Umbraco.Tests.CoreThings
namespace Umbraco.Tests.UnitTests.Umbraco.Core
{
public class GuidUtilsTests
{

View File

@@ -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
{

View File

@@ -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
}
}

View File

@@ -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<StaticClass1, Action>("Method");
var method = ReflectionUtilities.EmitMethod<Action>(typeof (StaticClass1), "Method");
method();
}
@@ -205,10 +203,6 @@ namespace Umbraco.Tests.Clr
(var getter3, var setter3) = ReflectionUtilities.EmitPropertyGetterAndSetter<Class1, int>("Value3");
Assert.AreEqual(42, getter3(class1));
setter3(class1, 42);
// this is not supported yet
//var getter4 = ReflectionUtilities.EmitPropertyGetter<Class1, object>("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<Class4, int>(propInt4);
Assert.IsNotNull(getterInt4T);
var valueInt4T = getterInt4T(object4);

View File

@@ -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);

View File

@@ -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

View File

@@ -15,6 +15,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Lucene.Net.Contrib" Version="3.0.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />

View File

@@ -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<DeepCloneableListTests.TestClone>(ListCloneBehavior.Always);
original.Add(new DeepCloneableListTests.TestClone());
original.Add(new DeepCloneableListTests.TestClone());
original.Add(new DeepCloneableListTests.TestClone());
var original = new DeepCloneableList<TestClone>(ListCloneBehavior.Always);
original.Add(new TestClone());
original.Add(new TestClone());
original.Add(new TestClone());
var val = _provider.GetCacheItem<DeepCloneableList<DeepCloneableListTests.TestClone>>("test", () => original);
var val = _provider.GetCacheItem<DeepCloneableList<TestClone>>("test", () => original);
Assert.AreEqual(original.Count, val.Count);
foreach (var item in val)

View File

@@ -117,17 +117,11 @@
<Compile Include="Cache\DistributedCacheBinderTests.cs" />
<Compile Include="Cache\RefresherTests.cs" />
<Compile Include="Cache\SnapDictionaryTests.cs" />
<Compile Include="Clr\ReflectionUtilitiesTests.cs" />
<Compile Include="Collections\OrderedHashSetTests.cs" />
<Compile Include="Composing\CompositionTests.cs" />
<Compile Include="Composing\ContainerConformingTests.cs" />
<Compile Include="Configurations\GlobalSettingsTests.cs" />
<Compile Include="CoreThings\CallContextTests.cs" />
<Compile Include="Components\ComponentTests.cs" />
<Compile Include="CoreThings\ClaimsIdentityExtensionsTests.cs" />
<Compile Include="CoreThings\EnumExtensionsTests.cs" />
<Compile Include="CoreThings\GuidUtilsTests.cs" />
<Compile Include="CoreThings\HexEncoderTests.cs" />
<Compile Include="CoreXml\RenamedRootNavigatorTests.cs" />
<Compile Include="LegacyXmlPublishedCache\ContentXmlDto.cs" />
<Compile Include="LegacyXmlPublishedCache\PreviewXmlDto.cs" />
@@ -243,17 +237,14 @@
<Compile Include="Web\AngularIntegration\ContentModelSerializationTests.cs" />
<Compile Include="Web\AngularIntegration\JsInitializationTests.cs" />
<Compile Include="Web\AngularIntegration\ServerVariablesParserTests.cs" />
<Compile Include="CoreThings\AttemptTests.cs" />
<Compile Include="Migrations\Stubs\DropForeignKeyMigrationStub.cs" />
<Compile Include="Models\Mapping\ContentTypeModelMappingTests.cs" />
<Compile Include="Cache\DeepCloneAppCacheTests.cs" />
<Compile Include="Cache\DefaultCachePolicyTests.cs" />
<Compile Include="Cache\FullDataSetCachePolicyTests.cs" />
<Compile Include="Cache\SingleItemsOnlyCachePolicyTests.cs" />
<Compile Include="Collections\DeepCloneableListTests.cs" />
<Compile Include="Web\Controllers\AuthenticationControllerTests.cs" />
<Compile Include="Web\Controllers\BackOfficeControllerUnitTests.cs" />
<Compile Include="CoreThings\DelegateExtensionsTests.cs" />
<Compile Include="Web\Controllers\ContentControllerTests.cs" />
<Compile Include="Web\Controllers\UserEditorAuthorizationHelperTests.cs" />
<Compile Include="Web\Controllers\UsersControllerTests.cs" />
@@ -301,7 +292,6 @@
<Compile Include="Web\Controllers\FilterAllowedOutgoingContentAttributeTests.cs" />
<Compile Include="Web\Controllers\MediaControllerUnitTests.cs" />
<Compile Include="CoreXml\FrameworkXmlTests.cs" />
<Compile Include="Clr\ReflectionTests.cs" />
<Compile Include="Macros\MacroParserTests.cs" />
<Compile Include="Models\ContentExtensionsTests.cs" />
<Compile Include="Web\Mvc\MergeParentContextViewDataAttributeTests.cs" />
@@ -458,7 +448,6 @@
<Compile Include="Composing\TypeLoaderTests.cs" />
<Compile Include="TestHelpers\Stubs\TestLastChanceFinder.cs" />
<Compile Include="TestHelpers\TestHelper.cs" />
<Compile Include="CoreThings\EnumerableExtensionsTests.cs" />
<Compile Include="IO\AbstractFileSystemTests.cs" />
<Compile Include="IO\FileSystemsTests.cs" />
<Compile Include="IO\PhysicalFileSystemTests.cs" />
@@ -467,10 +456,8 @@
<Compile Include="TestHelpers\FakeHttpContextFactory.cs" />
<Compile Include="Composing\TypeFinderTests.cs" />
<Compile Include="Routing\UmbracoModuleTests.cs" />
<Compile Include="CoreThings\VersionExtensionTests.cs" />
<Compile Include="Web\UrlHelperExtensionTests.cs" />
<Compile Include="Web\WebExtensionMethodTests.cs" />
<Compile Include="CoreThings\XmlExtensionsTests.cs" />
<Compile Include="LegacyXmlPublishedCache\DictionaryPublishedContent.cs" />
<Compile Include="LegacyXmlPublishedCache\DomainCache.cs" />
<Compile Include="LegacyXmlPublishedCache\PreviewContent.cs" />