-
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathStubContentControlProvider.cs
More file actions
118 lines (106 loc) · 4.35 KB
/
StubContentControlProvider.cs
File metadata and controls
118 lines (106 loc) · 4.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// Copyright (c) 2016-2026 SIL International
// This software is licensed under the LGPL, version 2.1 or later
// (http://www.gnu.org/licenses/lgpl-2.1.html)using System;
using System;
using System.Xml;
using NUnit.Framework;
using SIL.FieldWorks.Common.FwUtils;
using static SIL.FieldWorks.Common.FwUtils.FwUtils;
using XCore;
namespace SIL.FieldWorks.XWorks.DictionaryConfigurationMigrators
{
/// <summary>
/// This class is for use in unit tests that need to use the ActivateClerk functionality. For instance to imitate switching
/// tools for testing export functionality.
/// </summary>
/// <remarks>To use add the following to your TestFixtureSetup: m_mediator.AddColleague(new StubContentControlProvider());</remarks>
internal class StubContentControlProvider : IxCoreColleague, IDisposable
{
private const string m_contentControlDictionary =
@"<control>
<parameters PaneBarGroupId='PaneBar-Dictionary'>
<control>
<parameters area='lexicon' clerk='entries' />
</control>
<!-- The following configureLayouts node is only required to help migrate old configurations to the new format -->
<configureLayouts>
<layoutType label='Lexeme-based (complex forms as main entries)' layout='publishStem'>
<configure class='LexEntry' label='Main Entry' layout='publishStemEntry' />
<configure class='LexEntry' label='Minor Entry' layout='publishStemMinorEntry' hideConfig='true' />
</layoutType>
<layoutType label='Root-based (complex forms as subentries)' layout='publishRoot'>
<configure class='LexEntry' label='Main Entry' layout='publishRootEntry' />
<configure class='LexEntry' label='Minor Entry' layout='publishRootMinorEntry' hideConfig='true' />
</layoutType>
</configureLayouts>
</parameters>
</control>";
private readonly XmlNode m_testControlDictNode;
private const string m_contentControlReversal =
@"<control>
<parameters id='reversalIndexEntryList' PaneBarGroupId='PaneBar-ReversalIndicesMenu'>
<control>
<parameters area='lexicon' clerk='AllReversalEntries' />
</control>
<configureLayouts>
<layoutType label='All Reversal Indexes' layout='publishReversal'>
<configure class='ReversalIndexEntry' label='Reversal Entry' layout='publishReversalIndexEntry' />
</layoutType>
<layoutType label='$wsName' layout='publishReversal-$ws'>
<configure class='ReversalIndexEntry' label='Reversal Entry' layout='publishReversalIndexEntry-$ws' />
</layoutType>
</configureLayouts>
</parameters>
</control>";
private readonly XmlNode m_testControlRevNode;
public StubContentControlProvider()
{
var doc = new XmlDocument();
doc.LoadXml(m_contentControlDictionary);
m_testControlDictNode = doc.DocumentElement;
var reversalDoc = new XmlDocument();
reversalDoc.LoadXml(m_contentControlReversal);
m_testControlRevNode = reversalDoc.DocumentElement;
Subscriber.Subscribe(EventConstants.GetContentControlParameters, GetContentControlParameters);
}
public void Init(Mediator mediator, PropertyTable propertyTable, XmlNode configurationParameters)
{
}
public IxCoreColleague[] GetMessageTargets()
{
return new IxCoreColleague[] { this };
}
/// <summary>
/// This is called by reflection through the mediator. We need so that we can migrate through the PreHistoricMigrator.
/// </summary>
// ReSharper disable once UnusedMember.Local
private void GetContentControlParameters(object parameterObj)
{
var param = parameterObj as Tuple<string, string, XmlNode[]>;
if (param == null)
return;
var result = param.Item3;
Assert.That(param.Item2 == "lexiconDictionary" || param.Item2 == "reversalToolEditComplete", "No params for tool: " + param.Item2);
result[0] = param.Item2 == "lexiconDictionary" ? m_testControlDictNode : m_testControlRevNode;
}
public bool ShouldNotCall => false;
public int Priority => 1;
public void Dispose()
{
GC.SuppressFinalize(this);
Dispose(true);
}
public void Dispose(bool disposeCalled)
{
System.Diagnostics.Debug.WriteLineIf(!disposeCalled, "****** Missing Dispose() call for " + GetType().Name + ". ****** ");
if (disposeCalled)
{
Subscriber.Unsubscribe(EventConstants.GetContentControlParameters, GetContentControlParameters);
}
}
~StubContentControlProvider()
{
Dispose(false);
}
}
}