2021-02-01 12:35:59 -08:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using SabreTools.DatItems;
|
2021-02-02 10:23:43 -08:00
|
|
|
using SabreTools.DatItems.Formats;
|
2021-02-01 12:35:59 -08:00
|
|
|
using Xunit;
|
|
|
|
|
|
2025-02-12 12:36:42 -05:00
|
|
|
namespace SabreTools.DatFiles.Test
|
2021-02-01 12:35:59 -08:00
|
|
|
{
|
|
|
|
|
public class ReplacerTests
|
|
|
|
|
{
|
2025-02-12 13:06:56 -05:00
|
|
|
#region ReplaceFields
|
|
|
|
|
|
2021-02-01 12:35:59 -08:00
|
|
|
[Fact]
|
2025-02-12 13:06:56 -05:00
|
|
|
public void ReplaceFields_Machine()
|
2021-02-01 12:35:59 -08:00
|
|
|
{
|
2025-02-12 13:06:56 -05:00
|
|
|
var machine = new Machine();
|
|
|
|
|
machine.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, "bar");
|
|
|
|
|
machine.SetFieldValue<string?>(Models.Metadata.Machine.DescriptionKey, "bar");
|
|
|
|
|
|
|
|
|
|
var repMachine = new Machine();
|
|
|
|
|
machine.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, "foo");
|
|
|
|
|
machine.SetFieldValue<string?>(Models.Metadata.Machine.DescriptionKey, "bar");
|
|
|
|
|
|
|
|
|
|
List<string> fields = [Models.Metadata.Machine.NameKey];
|
|
|
|
|
|
|
|
|
|
Replacer.ReplaceFields(machine, repMachine, fields, false);
|
|
|
|
|
|
|
|
|
|
Assert.Equal("foo", machine.GetStringFieldValue(Models.Metadata.Machine.NameKey));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: Check more fields for replacement
|
|
|
|
|
[Fact]
|
|
|
|
|
public void ReplaceFields_Disk()
|
|
|
|
|
{
|
|
|
|
|
var datItem = new Disk();
|
|
|
|
|
datItem.SetName("foo");
|
|
|
|
|
|
|
|
|
|
var repDatItem = new Disk();
|
2021-02-01 12:35:59 -08:00
|
|
|
repDatItem.SetName("bar");
|
2025-02-12 13:06:56 -05:00
|
|
|
|
|
|
|
|
var fields = new Dictionary<string, List<string>>
|
|
|
|
|
{
|
|
|
|
|
["item"] = [Models.Metadata.Disk.NameKey]
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Replacer.ReplaceFields(datItem, repDatItem, fields);
|
|
|
|
|
|
|
|
|
|
Assert.Equal("bar", datItem.GetName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: Check more fields for replacement
|
|
|
|
|
[Fact]
|
|
|
|
|
public void ReplaceFields_File()
|
|
|
|
|
{
|
|
|
|
|
var datItem = new DatItems.Formats.File();
|
|
|
|
|
datItem.SetName("foo");
|
|
|
|
|
|
|
|
|
|
var repDatItem = new DatItems.Formats.File();
|
|
|
|
|
repDatItem.SetName("bar");
|
|
|
|
|
|
2024-03-05 20:07:38 -05:00
|
|
|
var fields = new Dictionary<string, List<string>>
|
|
|
|
|
{
|
|
|
|
|
["item"] = [Models.Metadata.Rom.NameKey]
|
|
|
|
|
};
|
2025-02-12 12:36:42 -05:00
|
|
|
|
2021-02-01 12:35:59 -08:00
|
|
|
Replacer.ReplaceFields(datItem, repDatItem, fields);
|
2025-02-12 12:36:42 -05:00
|
|
|
|
2025-02-12 13:06:56 -05:00
|
|
|
// TODO: There is no name field for File type
|
|
|
|
|
//Assert.Equal("bar", datItem.GetName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: Check more fields for replacement
|
|
|
|
|
[Fact]
|
|
|
|
|
public void ReplaceFields_Media()
|
|
|
|
|
{
|
|
|
|
|
var datItem = new Media();
|
|
|
|
|
datItem.SetName("foo");
|
|
|
|
|
|
|
|
|
|
var repDatItem = new Media();
|
|
|
|
|
repDatItem.SetName("bar");
|
|
|
|
|
|
|
|
|
|
var fields = new Dictionary<string, List<string>>
|
|
|
|
|
{
|
|
|
|
|
["item"] = [Models.Metadata.Media.NameKey]
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Replacer.ReplaceFields(datItem, repDatItem, fields);
|
|
|
|
|
|
2021-02-01 12:35:59 -08:00
|
|
|
Assert.Equal("bar", datItem.GetName());
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-12 13:06:56 -05:00
|
|
|
// TODO: Check more fields for replacement
|
2021-02-01 12:35:59 -08:00
|
|
|
[Fact]
|
2025-02-12 13:06:56 -05:00
|
|
|
public void ReplaceFields_Rom()
|
2021-02-01 12:35:59 -08:00
|
|
|
{
|
2025-02-12 13:06:56 -05:00
|
|
|
var datItem = new Rom();
|
|
|
|
|
datItem.SetName("foo");
|
2025-02-12 12:36:42 -05:00
|
|
|
|
2025-02-12 13:06:56 -05:00
|
|
|
var repDatItem = new Rom();
|
|
|
|
|
repDatItem.SetName("bar");
|
2025-02-12 12:36:42 -05:00
|
|
|
|
2025-02-12 13:06:56 -05:00
|
|
|
var fields = new Dictionary<string, List<string>>
|
|
|
|
|
{
|
|
|
|
|
["item"] = [Models.Metadata.Rom.NameKey]
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Replacer.ReplaceFields(datItem, repDatItem, fields);
|
|
|
|
|
|
|
|
|
|
Assert.Equal("bar", datItem.GetName());
|
2021-02-01 12:35:59 -08:00
|
|
|
}
|
|
|
|
|
|
2025-02-12 13:06:56 -05:00
|
|
|
[Fact]
|
|
|
|
|
public void ReplaceFields_Sample()
|
2021-02-01 12:35:59 -08:00
|
|
|
{
|
2025-02-12 13:06:56 -05:00
|
|
|
var datItem = new Sample();
|
|
|
|
|
datItem.SetName("foo");
|
|
|
|
|
|
|
|
|
|
var repDatItem = new Sample();
|
|
|
|
|
repDatItem.SetName("bar");
|
2024-03-09 23:43:43 -05:00
|
|
|
|
2025-02-12 13:06:56 -05:00
|
|
|
var fields = new Dictionary<string, List<string>>
|
|
|
|
|
{
|
|
|
|
|
["item"] = [Models.Metadata.Rom.NameKey]
|
|
|
|
|
};
|
2024-03-09 23:43:43 -05:00
|
|
|
|
2025-02-12 13:06:56 -05:00
|
|
|
Replacer.ReplaceFields(datItem, repDatItem, fields);
|
|
|
|
|
|
|
|
|
|
Assert.Equal("bar", datItem.GetName());
|
2021-02-01 12:35:59 -08:00
|
|
|
}
|
2025-02-12 13:06:56 -05:00
|
|
|
|
|
|
|
|
#endregion
|
2021-02-01 12:35:59 -08:00
|
|
|
}
|
|
|
|
|
}
|