Add tests for Machine, implement IEquatable for Machine

This commit is contained in:
Matt Nadareski
2025-01-08 14:16:54 -05:00
parent 1c16529e8e
commit ef77d3c4da
2 changed files with 105 additions and 11 deletions

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