Files
Umbraco-CMS/tests/Umbraco.Tests.Common/TestClone.cs

86 lines
2.1 KiB
C#
Raw Normal View History

// Copyright (c) Umbraco.
// See LICENSE for more details.
using System;
using Umbraco.Cms.Core.Models;
2020-06-11 14:39:10 +01:00
namespace Umbraco.Cms.Tests.Common;
public class TestClone : IDeepCloneable, IEquatable<TestClone>
2020-06-11 14:39:10 +01:00
{
public TestClone(Guid id)
2020-06-11 14:39:10 +01:00
{
Id = id;
IsClone = true;
}
2020-06-11 14:39:10 +01:00
public TestClone() => Id = Guid.NewGuid();
2020-06-11 14:39:10 +01:00
public Guid Id { get; }
public bool IsClone { get; }
2020-06-11 14:39:10 +01:00
public object DeepClone() => new TestClone(Id);
2020-06-11 14:39:10 +01:00
/// <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 (other is null)
2020-06-11 14:39:10 +01:00
{
return false;
}
if (ReferenceEquals(this, other))
{
return true;
2020-06-11 14:39:10 +01:00
}
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 (obj is null)
2020-06-11 14:39:10 +01:00
{
return false;
2020-06-11 14:39:10 +01:00
}
if (ReferenceEquals(this, obj))
{
return true;
}
2020-06-11 14:39:10 +01:00
if (obj.GetType() != GetType())
{
return false;
}
2020-06-11 14:39:10 +01:00
return Equals((TestClone)obj);
2020-06-11 14:39:10 +01:00
}
/// <summary>
/// Serves as the default hash function.
/// </summary>
/// <returns>
/// A hash code for the current object.
/// </returns>
public override int GetHashCode() => Id.GetHashCode();
public static bool operator ==(TestClone left, TestClone right) => Equals(left, right);
public static bool operator !=(TestClone left, TestClone right) => Equals(left, right) == false;
2020-06-11 14:39:10 +01:00
}