Files
Umbraco-CMS/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Collections/OrderedHashSetTests.cs
Nikolaj Geisle 7aeb400fce V10: fix build warnings in test projects (#12509)
* Run code cleanup

* Dotnet format benchmarks project

* Fix up Test.Common

* Run dotnet format + manual cleanup

* Run code cleanup for unit tests

* Run dotnet format

* Fix up errors

* Manual cleanup of Unit test project

* Update tests/Umbraco.Tests.Benchmarks/HexStringBenchmarks.cs

Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>

* Update tests/Umbraco.Tests.Integration/Testing/TestDbMeta.cs

Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>

* Update tests/Umbraco.Tests.Benchmarks/TypeFinderBenchmarks.cs

Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>

* Update tests/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs

Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>

* Update tests/Umbraco.Tests.Integration/Umbraco.Core/Events/EventAggregatorTests.cs

Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>

* Fix according to review

* Fix after merge

* Fix errors

Co-authored-by: Nikolaj Geisle <niko737@edu.ucl.dk>
Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>
Co-authored-by: Zeegaan <nge@umbraco.dk>
2022-06-21 08:09:38 +02:00

96 lines
2.2 KiB
C#

// Copyright (c) Umbraco.
// See LICENSE for more details.
using System;
using NUnit.Framework;
using Umbraco.Cms.Core.Collections;
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Collections;
[TestFixture]
public class OrderedHashSetTests
{
[Test]
public void Keeps_Last()
{
var list = new OrderedHashSet<MyClass>(false);
MyClass[] items = { new MyClass("test"), new MyClass("test"), new MyClass("test") };
foreach (var item in items)
{
list.Add(item);
}
Assert.AreEqual(1, list.Count);
Assert.AreEqual(items[2].Id, list[0].Id);
Assert.AreNotEqual(items[0].Id, list[0].Id);
}
[Test]
public void Keeps_First()
{
var list = new OrderedHashSet<MyClass>();
MyClass[] items = { new MyClass("test"), new MyClass("test"), new MyClass("test") };
foreach (var item in items)
{
list.Add(item);
}
Assert.AreEqual(1, list.Count);
Assert.AreEqual(items[0].Id, list[0].Id);
}
private class MyClass : IEquatable<MyClass>
{
public MyClass(string name)
{
Name = name;
Id = Guid.NewGuid();
}
public string Name { get; }
public Guid Id { get; }
public bool Equals(MyClass other)
{
if (other is null)
{
return false;
}
if (ReferenceEquals(this, other))
{
return true;
}
return string.Equals(Name, other.Name);
}
public override bool Equals(object obj)
{
if (obj is null)
{
return false;
}
if (ReferenceEquals(this, obj))
{
return true;
}
if (obj.GetType() != GetType())
{
return false;
}
return Equals((MyClass)obj);
}
public override int GetHashCode() => Name.GetHashCode();
public static bool operator ==(MyClass left, MyClass right) => Equals(left, right);
public static bool operator !=(MyClass left, MyClass right) => Equals(left, right) == false;
}
}