-
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathTestObjectListPublisher.cs
More file actions
80 lines (70 loc) · 3.51 KB
/
Copy pathTestObjectListPublisher.cs
File metadata and controls
80 lines (70 loc) · 3.51 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
// Copyright (c) 2015 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.Linq;
using NUnit.Framework;
using SIL.LCModel;
using SIL.LCModel.Application;
using SIL.FieldWorks.Common.Controls;
using SIL.LCModel.Infrastructure;
using SIL.LCModel.Infrastructure.Impl;
namespace SIL.FieldWorks.XWorks
{
[TestFixture]
public class TestObjectListPublisher : MemoryOnlyBackendProviderTestBase
{
private const int ObjectListFlid = 89999956;
[Test]
public void SetAndAccessDummyList()
{
ILexDb lexDb = Cache.LangProject.LexDbOA;
ILexEntry entry1 = null;
ICmResource res1 = null;
NonUndoableUnitOfWorkHelper.Do(m_actionHandler, () =>
{
var leFactory = Cache.ServiceLocator.GetInstance<ILexEntryFactory>();
entry1 = leFactory.Create();
ILexEntry entry2 = leFactory.Create();
res1 = Cache.ServiceLocator.GetInstance<ICmResourceFactory>().Create();
lexDb.ResourcesOC.Add(res1);
});
int hvoRoot = 10578;
ObjectListPublisher publisher = new ObjectListPublisher(Cache.MainCacheAccessor as ISilDataAccessManaged, ObjectListFlid);
var values = new int[] {23, 56, 2048};
Notifiee recorder = new Notifiee();
publisher.AddNotification(recorder);
publisher.CacheVecProp(hvoRoot, values, true);
Assert.AreEqual(values.Length, publisher.get_VecSize(hvoRoot, ObjectListFlid), "override of vec size");
//Assert.AreEqual(Cache.LangProject.Texts.Count, publisher.get_VecSize(Cache.LangProject.Hvo, LangProjectTags.kflidTexts), "base vec size");
Assert.AreEqual(23, publisher.get_VecItem(hvoRoot, ObjectListFlid, 0), "override of vec item");
Assert.AreEqual(res1.Hvo, publisher.get_VecItem(lexDb.Hvo, LexDbTags.kflidResources, 0), "base vec item");
Assert.AreEqual(56, publisher.get_VecItem(hvoRoot, ObjectListFlid, 1), "override of vec item, non-zero index");
VerifyCurrentValue(hvoRoot, publisher, values, "original value");
Assert.AreEqual(lexDb.ResourcesOC.Count(), publisher.VecProp(lexDb.Hvo, LexDbTags.kflidResources).Length, "base VecProp");
recorder.CheckChanges(new ChangeInformationTest[] { new ChangeInformationTest(hvoRoot, ObjectListFlid, 0, values.Length, 0) },
"expected PropChanged from caching HVOs");
publisher.RemoveNotification(recorder);
recorder = new Notifiee();
publisher.AddNotification(recorder);
publisher.Replace(hvoRoot, 1, new int[] {97, 98}, 0);
VerifyCurrentValue(hvoRoot, publisher, new int[] {23, 97, 98, 56, 2048}, "after inserting 97, 98" );
recorder.CheckChanges(new ChangeInformationTest[] { new ChangeInformationTest(hvoRoot, ObjectListFlid, 1, 2, 0) },
"expected PropChanged from caching HVOs");
publisher.RemoveNotification(recorder);
recorder = new Notifiee();
publisher.AddNotification(recorder);
publisher.Replace(hvoRoot, 1, new int[0] , 2);
VerifyCurrentValue(hvoRoot, publisher, new int[] { 23, 56, 2048 }, "after deleting 97, 98");
recorder.CheckChanges(new ChangeInformationTest[] { new ChangeInformationTest(hvoRoot, ObjectListFlid, 1, 0, 2) },
"expected PropChanged from caching HVOs");
publisher.RemoveNotification(recorder);
}
private void VerifyCurrentValue(int hvoRoot, ObjectListPublisher publisher, int[] values, string label)
{
int[] newValues = publisher.VecProp(hvoRoot, ObjectListFlid);
Assert.AreEqual(values.Length, newValues.Length, label + "length from VecProp");
for (int i = 0; i < values.Length; i++)
Assert.AreEqual(values[i], newValues[i], label + " item " + i +" from VecProp");
}
}
}