mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Add tests for Machine, implement IEquatable for Machine
This commit is contained in:
87
SabreTools.DatItems.Test/MachineTests.cs
Normal file
87
SabreTools.DatItems.Test/MachineTests.cs
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace SabreTools.DatItems.Test
|
||||||
|
{
|
||||||
|
public class MachineTests
|
||||||
|
{
|
||||||
|
#region Clone
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void CloneTest()
|
||||||
|
{
|
||||||
|
Machine item = new Machine();
|
||||||
|
item.SetFieldValue(Models.Metadata.Machine.NameKey, "name");
|
||||||
|
|
||||||
|
object clone = item.Clone();
|
||||||
|
Machine? actual = clone as Machine;
|
||||||
|
Assert.NotNull(actual);
|
||||||
|
Assert.Equal("name", actual.GetStringFieldValue(Models.Metadata.Machine.NameKey));
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region GetInternalClone
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void GetInternalCloneTest()
|
||||||
|
{
|
||||||
|
Machine item = new Machine();
|
||||||
|
item.SetFieldValue(Models.Metadata.Machine.NameKey, "name");
|
||||||
|
|
||||||
|
Models.Metadata.Machine actual = item.GetInternalClone();
|
||||||
|
Assert.Equal("name", actual[Models.Metadata.Machine.NameKey]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Equals
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Equals_Null_False()
|
||||||
|
{
|
||||||
|
Machine self = new Machine();
|
||||||
|
Machine? other = null;
|
||||||
|
|
||||||
|
bool actual = self.Equals(other);
|
||||||
|
Assert.False(actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Equals_DefaultInternal_True()
|
||||||
|
{
|
||||||
|
Machine self = new Machine();
|
||||||
|
Machine? other = new Machine();
|
||||||
|
|
||||||
|
bool actual = self.Equals(other);
|
||||||
|
Assert.True(actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Equals_MismatchedInternal_False()
|
||||||
|
{
|
||||||
|
Machine self = new Machine();
|
||||||
|
self.SetFieldValue(Models.Metadata.Machine.NameKey, "self");
|
||||||
|
|
||||||
|
Machine? other = new Machine();
|
||||||
|
other.SetFieldValue(Models.Metadata.Machine.NameKey, "other");
|
||||||
|
|
||||||
|
bool actual = self.Equals(other);
|
||||||
|
Assert.False(actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Equals_EqualInternal_True()
|
||||||
|
{
|
||||||
|
Machine self = new Machine();
|
||||||
|
self.SetFieldValue(Models.Metadata.Machine.NameKey, "name");
|
||||||
|
|
||||||
|
Machine? other = new Machine();
|
||||||
|
other.SetFieldValue(Models.Metadata.Machine.NameKey, "name");
|
||||||
|
|
||||||
|
bool actual = self.Equals(other);
|
||||||
|
Assert.True(actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,7 +11,7 @@ namespace SabreTools.DatItems
|
|||||||
/// Represents the information specific to a set/game/machine
|
/// Represents the information specific to a set/game/machine
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonObject("machine"), XmlRoot("machine")]
|
[JsonObject("machine"), XmlRoot("machine")]
|
||||||
public sealed class Machine : ModelBackedItem<Models.Metadata.Machine>, ICloneable
|
public sealed class Machine : ModelBackedItem<Models.Metadata.Machine>, ICloneable, IEquatable<Machine>
|
||||||
{
|
{
|
||||||
#region Constants
|
#region Constants
|
||||||
|
|
||||||
@@ -57,15 +57,6 @@ namespace SabreTools.DatItems
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Accessors
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get a clone of the current internal model
|
|
||||||
/// </summary>
|
|
||||||
public Models.Metadata.Machine GetInternalClone() => (_internal.Clone() as Models.Metadata.Machine)!;
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Cloning methods
|
#region Cloning methods
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -76,10 +67,15 @@ namespace SabreTools.DatItems
|
|||||||
{
|
{
|
||||||
return new Machine()
|
return new Machine()
|
||||||
{
|
{
|
||||||
_internal = this._internal.Clone() as Models.Metadata.Machine ?? [],
|
_internal = _internal.Clone() as Models.Metadata.Machine ?? [],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get a clone of the current internal model
|
||||||
|
/// </summary>
|
||||||
|
public Models.Metadata.Machine GetInternalClone() => (_internal.Clone() as Models.Metadata.Machine)!;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Comparision Methods
|
#region Comparision Methods
|
||||||
@@ -114,6 +110,17 @@ namespace SabreTools.DatItems
|
|||||||
return _internal.EqualTo(otherItem._internal);
|
return _internal.EqualTo(otherItem._internal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public bool Equals(Machine? other)
|
||||||
|
{
|
||||||
|
// If other is null
|
||||||
|
if (other == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Compare internal models
|
||||||
|
return _internal.EqualTo(other._internal);
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Manipulation
|
#region Manipulation
|
||||||
|
|||||||
Reference in New Issue
Block a user