diff --git a/src/LibFLExBridge-ChorusPluginTests/Infrastructure/CustomPropertyCacheTests.cs b/src/LibFLExBridge-ChorusPluginTests/Infrastructure/CustomPropertyCacheTests.cs
index 7cd1c054..db05eeb8 100644
--- a/src/LibFLExBridge-ChorusPluginTests/Infrastructure/CustomPropertyCacheTests.cs
+++ b/src/LibFLExBridge-ChorusPluginTests/Infrastructure/CustomPropertyCacheTests.cs
@@ -2,13 +2,13 @@
// This software is licensed under the MIT License (http://opensource.org/licenses/MIT)
using System;
-using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml.Linq;
using Chorus.merge;
using LibFLExBridgeChorusPlugin.DomainServices;
using LibFLExBridgeChorusPlugin.Infrastructure;
+using LibFLExBridgeChorusPluginTests.Infrastructure.RoundTrip;
using LibTriboroughBridgeChorusPlugin;
using NUnit.Framework;
using SIL.Progress;
@@ -24,8 +24,7 @@ namespace LibFLExBridgeChorusPluginTests.Infrastructure
[TestFixture]
public class CustomPropertyCacheTests
{
- private const string LangProjGuid = "c1ed46ba-e382-11de-8a39-0800200c9a66";
- private const string EntryGuid = "c1ed46bc-e382-11de-8a39-0800200c9a66";
+ private static readonly Guid EntryGuid = new Guid("c1ed46bc-e382-11de-8a39-0800200c9a66");
private TemporaryFolder _projectFolder;
private string _fwdataPathname;
@@ -46,51 +45,12 @@ public void TearDown()
_mdc = MetadataCache.TestOnlyNewCache;
}
- ///
- /// The objects LangProject must own for the splitter and unifier to round trip a project:
- /// (LangProject property, class of the owned object).
- ///
- private static readonly string[,] RequiredLangProjectOwnedObjects =
- {
- { "GenreList", "CmPossibilityList" },
- { "LexDb", "LexDb" },
- { "MorphologicalData", "MoMorphData" },
- { "MsFeatureSystem", "FsFeatureSystem" },
- { "PhFeatureSystem", "FsFeatureSystem" },
- { "PhonologicalData", "PhPhonData" },
- { "ResearchNotebook", "RnResearchNbk" },
- { "TextMarkupTags", "CmPossibilityList" },
- { "TranslationTags", "CmPossibilityList" }
- };
-
private static string FwdataWithIntegerCustomField()
{
- var langProject = new XElement("rt",
- new XAttribute("class", "LangProject"),
- new XAttribute("guid", LangProjGuid),
- new XElement("AnalyzingAgents"),
- new XElement("Styles"));
- var ownedObjects = new List();
- for (var i = 0; i < RequiredLangProjectOwnedObjects.GetLength(0); ++i)
- {
- var guid = Guid.NewGuid().ToString();
- langProject.Add(new XElement(RequiredLangProjectOwnedObjects[i, 0],
- new XElement("objsur", new XAttribute("guid", guid), new XAttribute("t", "o"))));
- ownedObjects.Add(new XElement("rt",
- new XAttribute("class", RequiredLangProjectOwnedObjects[i, 1]),
- new XAttribute("guid", guid),
- new XAttribute("ownerguid", LangProjGuid)));
- }
- var entry = XElement.Parse(string.Format(
- "", EntryGuid));
-
- var root = new XElement("languageproject",
- new XAttribute("version", MetadataCache.MaximumModelVersion),
- XElement.Parse(""),
- langProject,
- ownedObjects,
- entry);
- return new XDocument(new XDeclaration("1.0", "utf-8", null), root).ToString();
+ return new FwdataBuilder()
+ .AddCustomField("LexEntry", "Rank", "Integer")
+ .AddUnownedObject("LexEntry", EntryGuid, new XElement("Custom", new XAttribute("name", "Rank"), new XAttribute("val", "3")))
+ .ToString();
}
private void Split()
diff --git a/src/LibFLExBridge-ChorusPluginTests/Infrastructure/RoundTrip/FwdataAssert.cs b/src/LibFLExBridge-ChorusPluginTests/Infrastructure/RoundTrip/FwdataAssert.cs
new file mode 100644
index 00000000..9e54cb7f
--- /dev/null
+++ b/src/LibFLExBridge-ChorusPluginTests/Infrastructure/RoundTrip/FwdataAssert.cs
@@ -0,0 +1,92 @@
+// Copyright (c) 2026 SIL International
+// This software is licensed under the MIT License (http://opensource.org/licenses/MIT)
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Xml.Linq;
+using LibFLExBridgeChorusPlugin.Infrastructure;
+using NUnit.Framework;
+
+namespace LibFLExBridgeChorusPluginTests.Infrastructure.RoundTrip
+{
+ ///
+ /// Semantic comparisons of two .fwdata documents. Objects are matched by guid, so the order of
+ /// <rt> elements, the order of properties within an object, and whitespace do not matter.
+ ///
+ internal static class FwdataAssert
+ {
+ /// Both documents hold the same objects: same guids, classes and owners.
+ internal static void SameObjects(XDocument expected, XDocument actual)
+ {
+ Assert.That(ObjectSummaries(actual), Is.EqualTo(ObjectSummaries(expected)), "objects (guid, class, owner)");
+ }
+
+ /// Both documents declare the same custom fields with the same attributes.
+ internal static void SameCustomFields(XDocument expected, XDocument actual)
+ {
+ Assert.That(CustomFieldSummaries(actual), Is.EqualTo(CustomFieldSummaries(expected)), "custom fields");
+ }
+
+ ///
+ /// Both documents hold the same objects, each with the same properties and property contents.
+ ///
+ internal static void SameObjectContents(XDocument expected, XDocument actual)
+ {
+ SameObjects(expected, actual);
+ var actualObjects = SplitUnifyHarness.ObjectsByGuid(actual);
+ foreach (var expectedObject in SplitUnifyHarness.ObjectsByGuid(expected))
+ {
+ Assert.That(Normalize(actualObjects[expectedObject.Key]).ToString(),
+ Is.EqualTo(Normalize(expectedObject.Value).ToString()),
+ "contents of " + expectedObject.Key);
+ }
+ }
+
+ private static List ObjectSummaries(XDocument fwdata)
+ {
+ return SplitUnifyHarness.ObjectsByGuid(fwdata)
+ .Select(pair => string.Format("{0} {1} owner={2}",
+ pair.Key,
+ pair.Value.Attribute(FlexBridgeConstants.Class).Value,
+ pair.Value.Attribute(FlexBridgeConstants.OwnerGuid) == null
+ ? "none"
+ : new Guid(pair.Value.Attribute(FlexBridgeConstants.OwnerGuid).Value).ToString()))
+ .OrderBy(summary => summary)
+ .ToList();
+ }
+
+ private static List CustomFieldSummaries(XDocument fwdata)
+ {
+ var additionalFields = fwdata.Root.Element(FlexBridgeConstants.AdditionalFieldsTag);
+ if (additionalFields == null)
+ return new List();
+ return additionalFields.Elements(FlexBridgeConstants.CustomField)
+ .Select(cf => string.Join(" ", cf.Attributes()
+ .OrderBy(attr => attr.Name.LocalName)
+ .Select(attr => attr.Name.LocalName + "=" + attr.Value)))
+ .OrderBy(summary => summary)
+ .ToList();
+ }
+
+ /// A copy of an element with attributes and child elements sorted and whitespace-only text dropped.
+ private static XElement Normalize(XElement element)
+ {
+ var copy = new XElement(element.Name,
+ element.Attributes().OrderBy(attr => attr.Name.LocalName).Select(attr => new XAttribute(attr)));
+ if (element.HasElements)
+ {
+ // Owning and reference sequences keep their order: only the order of an object's properties is free.
+ var children = element.Name.LocalName == FlexBridgeConstants.RtTag
+ ? element.Elements().OrderBy(child => child.Name.LocalName).ThenBy(child => (string)child.Attribute(FlexBridgeConstants.Name))
+ : element.Elements();
+ copy.Add(children.Select(Normalize));
+ }
+ else if (!string.IsNullOrWhiteSpace(element.Value))
+ {
+ copy.Add(new XText(element.Value));
+ }
+ return copy;
+ }
+ }
+}
diff --git a/src/LibFLExBridge-ChorusPluginTests/Infrastructure/RoundTrip/FwdataBuilder.cs b/src/LibFLExBridge-ChorusPluginTests/Infrastructure/RoundTrip/FwdataBuilder.cs
new file mode 100644
index 00000000..122e3e25
--- /dev/null
+++ b/src/LibFLExBridge-ChorusPluginTests/Infrastructure/RoundTrip/FwdataBuilder.cs
@@ -0,0 +1,173 @@
+// Copyright (c) 2026 SIL International
+// This software is licensed under the MIT License (http://opensource.org/licenses/MIT)
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Xml.Linq;
+using LibFLExBridgeChorusPlugin.Infrastructure;
+
+namespace LibFLExBridgeChorusPluginTests.Infrastructure.RoundTrip
+{
+ ///
+ /// Builds a small .fwdata document that the splitter and unifier accept.
+ ///
+ ///
+ /// A new builder already holds the stub objects every project needs: a LangProject that owns a LexDb and
+ /// the other objects listed in . Add what a test cares about:
+ ///
+ /// var fwdata = new FwdataBuilder()
+ /// .AddCustomField("LexEntry", "Rank", "Integer")
+ /// .AddUnownedObject("LexEntry", EntryGuid, new XElement("Custom", new XAttribute("name", "Rank"), new XAttribute("val", "3")))
+ /// .AddOwnedObject(EntryGuid, "Senses", "LexSense", SenseGuid);
+ ///
+ /// Property content is passed as s (or anything else
+ /// takes), so any property the model knows can be added. Use for an object that
+ /// needs full control.
+ ///
+ internal sealed class FwdataBuilder
+ {
+ internal static readonly Guid LangProjectGuid = new Guid("c1ed46ba-e382-11de-8a39-0800200c9a66");
+
+ ///
+ /// The objects LangProject must own for the splitter and unifier to round trip a project:
+ /// (LangProject property, class of the owned object). LangProject must also have an AnalyzingAgents element.
+ ///
+ ///
+ /// Without LexDb, MorphologicalData, MsFeatureSystem, PhFeatureSystem, PhonologicalData or AnalyzingAgents
+ /// the split throws. Every real project has those. Without GenreList, TextMarkupTags, TranslationTags or
+ /// ResearchNotebook the split succeeds but the unify throws, because the unifier expects a list file or notebook that the
+ /// splitter writes only when the object exists.
+ ///
+ internal static readonly IReadOnlyList> RequiredLangProjectOwnedObjects = new[]
+ {
+ new KeyValuePair("GenreList", "CmPossibilityList"),
+ new KeyValuePair("LexDb", "LexDb"),
+ new KeyValuePair("MorphologicalData", "MoMorphData"),
+ new KeyValuePair("MsFeatureSystem", "FsFeatureSystem"),
+ new KeyValuePair("PhFeatureSystem", "FsFeatureSystem"),
+ new KeyValuePair("PhonologicalData", "PhPhonData"),
+ new KeyValuePair("ResearchNotebook", "RnResearchNbk"),
+ new KeyValuePair("TextMarkupTags", "CmPossibilityList"),
+ new KeyValuePair("TranslationTags", "CmPossibilityList")
+ };
+
+ private readonly List _customFields = new List();
+ // The