2021-02-01 12:35:59 -08:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
using SabreTools.Core;
|
|
|
|
|
using SabreTools.DatItems;
|
2021-02-02 10:23:43 -08:00
|
|
|
using SabreTools.DatItems.Formats;
|
2021-02-01 14:16:51 -08:00
|
|
|
using SabreTools.Filtering;
|
2021-02-01 12:35:59 -08:00
|
|
|
using Xunit;
|
|
|
|
|
|
2021-02-01 14:16:51 -08:00
|
|
|
namespace SabreTools.Test.Filtering
|
2021-02-01 12:35:59 -08:00
|
|
|
{
|
|
|
|
|
public class ReplacerTests
|
|
|
|
|
{
|
|
|
|
|
[Fact]
|
|
|
|
|
public void ReplaceFieldsDatItemTest()
|
|
|
|
|
{
|
|
|
|
|
var datItem = CreateDatItem();
|
|
|
|
|
var repDatItem = CreateDatItem();
|
|
|
|
|
repDatItem.SetName("bar");
|
2024-03-05 20:07:38 -05:00
|
|
|
var fields = new Dictionary<string, List<string>>
|
|
|
|
|
{
|
|
|
|
|
["item"] = [Models.Metadata.Rom.NameKey]
|
|
|
|
|
};
|
2021-02-01 12:35:59 -08:00
|
|
|
Replacer.ReplaceFields(datItem, repDatItem, fields);
|
|
|
|
|
Assert.Equal("bar", datItem.GetName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void ReplaceFieldsMachineTest()
|
|
|
|
|
{
|
|
|
|
|
var datItem = CreateDatItem();
|
|
|
|
|
var repDatItem = CreateDatItem();
|
|
|
|
|
repDatItem.Machine.Name = "foo";
|
2024-03-05 20:07:38 -05:00
|
|
|
List<string> fields = [Models.Metadata.Machine.NameKey];
|
2021-02-01 12:35:59 -08:00
|
|
|
Replacer.ReplaceFields(datItem.Machine, repDatItem.Machine, fields, false);
|
|
|
|
|
Assert.Equal("foo", datItem.Machine.Name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Generate a consistent DatItem for testing
|
|
|
|
|
/// </summary>
|
2023-04-19 16:39:58 -04:00
|
|
|
private static DatItem CreateDatItem()
|
2021-02-01 12:35:59 -08:00
|
|
|
{
|
|
|
|
|
return new Rom
|
|
|
|
|
{
|
|
|
|
|
Name = "foo",
|
|
|
|
|
Machine = new Machine
|
|
|
|
|
{
|
|
|
|
|
Name = "bar",
|
|
|
|
|
Description = "bar",
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|