Extract shared XLIFF test-document builders to remove ~130 duplicated lines
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 3
- Forks
- 10
- Avg merge
- 4d 12h
- Merged PRs (30d)
- 9
Description
Background
Raised by @tombogle while reviewing #147. That PR only adds tests, so the extraction was
deferred to keep it focused. The duplication itself predates #147.
Problem
L10NSharp.Windows.Forms.Tests.XliffLocalizationManagerTests is a standalone class rather
than a subclass of LocalizationManagerTestsBase<T>, because it needs
LocalizationManagerWinforms / XliffLocalizationManagerWinforms and WinForms-only hooks
such as ChooseFallbackLanguageWinforms, which the generic base knows nothing about. That
is a legitimate reason for a separate class — but it does not require duplicating the
document-building helpers, and today it does:
| Method | Lines | Duplicated verbatim? |
|---|---|---|
CreateNewDocument |
14 | body identical; signature differs only in formatting |
CreateTransUnit |
23 | body identical; signature differs only in formatting |
CreateTransUnitVariant |
4 | body identical |
AddEnglishTranslation |
20 | byte-for-byte identical |
AddChineseOfChinaTranslation |
22 | byte-for-byte identical |
AddChineseOfTaiwanTranslation |
22 | byte-for-byte identical |
AddChineseBareTranslation |
22 | byte-for-byte identical |
That is 126 lines, plus the six duplicated const fields (AppId, AppName,
AppVersion, HigherVersion, LowerVersion, LiteralNewline). The practical cost is that
test data has two sources of truth: adding a language variant (as #147 did with
AddChineseBareTranslation) means pasting the same 22 lines into both projects, and the two
copies can silently drift.
Proposal
Extract the builders into a shared static class in L10NSharp.Tests, e.g.
XLiffTestDocumentBuilder, taking folderPath and appId as parameters instead of reading
instance state. Have both
L10NSharp.Tests.XLiffLocalizationManagerTests (via LocalizationManagerTestsBase<T>) and
L10NSharp.Windows.Forms.Tests.XliffLocalizationManagerTests call into it.
This is mechanically feasible today:
L10NSharp.Windows.Forms.Testsalready has aProjectReferencetoL10NSharp.Tests, and
already reaches across it forL10NSharp.Tests.TempFolder.- There is no competing
XLiffDocumentinL10NSharp.Windows.Forms.XLiffUtils(it holds
onlyXliffLocalizationManagerWinformsandXliffLocalizedStringCacheWinforms), so both
classes are already building the sameL10NSharp.XLiffUtils.XLiffDocument.
Also worth folding in
LocalizationManagerTestsBase<T> has exactly one subclass, XLiffLocalizationManagerTests.
The protected abstract CreateNewDocument / CreateTransUnit / CreateTransUnitVariant
indirection therefore has no second implementation to abstract over — the generic T plus
abstract-factory machinery is currently paying for flexibility nothing uses. Routing both
classes through a concrete XLIFF builder removes those three abstract members and leaves less
machinery than there is now, not more.
If a non-XLIFF document format is added later, reintroducing the abstraction against two real
implementations will be easier than guessing at it from one.
Out of scope
The base class's AddArabicTranslation / AddFrenchTranslation / AddSpanishTranslation /
AddRandomTranslation are not duplicated and can move or stay as convenient.
Acceptance
- One definition of each XLIFF test-document builder.
L10NSharp.TestsandL10NSharp.Windows.Forms.Testspass with no change in test behaviour.- Adding a new language variant requires editing one place.
Drafted with Claude Code, model Claude Opus 5 (1M context) / claude-opus-5[1m].
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with LocalizationManagerTestsBase, XLiffLocalizationManagerTests, and XliffLocalizationManagerWinforms in the L10NSharp.Tests and L10NSharp.Windows.Forms.Tests projects. Compare the duplicated builder methods and constants, then run both projects' test suites. Done means one shared XLIFF builder definition, no unnecessary abstract factory members, unchanged test behavior, and both projects passing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- testing
- Issue type
- Refactor
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 72/100