Skip to content

Commit d4bf221

Browse files
Call order tests
1 parent e41e13c commit d4bf221

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

Px.Search.Lucene/LuceneIndex.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,8 @@ private static Document GetDocument(TableInformation tbl, PXMeta meta)
243243
{
244244
if (_indexSearcher is null)
245245
{
246-
return null;
246+
throw new InvalidOperationException(
247+
"IndexSearcher is not initialized. Call BeginWrite or BeginUpdate before modifying the index.");
247248
}
248249

249250
string[] field = new[] { SearchConstants.SEARCH_FIELD_SEARCHID };

PxWeb.UnitTests/Search/LuceneIndexTests.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,43 @@ public void NewLucenIndex_NoPath_ShouldThrowExcpetion()
9797
Assert.ThrowsExactly<ArgumentNullException>(() => { var index = new LuceneIndex(""); });
9898
}
9999

100+
101+
[TestMethod]
102+
public void UsageWithoutOpening_ShouldThrowExcpetion()
103+
{
104+
105+
// Arrange
106+
107+
var tableInformation = new TableInformation(
108+
"TAB001",
109+
"Population in the world",
110+
"Population",
111+
"2000",
112+
"2005",
113+
new string[] { "TIME" });
114+
tableInformation.Description = "Test";
115+
tableInformation.SortCode = "001";
116+
tableInformation.Paths.Add(new Level[] { new Level("A", "Test", "A") });
117+
118+
var meta = new PXMeta();
119+
meta.Matrix = "TAB001";
120+
meta.Variables.Add(ModelStore.CreateTimeVariable("", PlacementType.Stub, 2000, 2005));
121+
122+
123+
//
124+
Assert.ThrowsExactly<InvalidOperationException>(() => _luceneIndex.AddEntry(tableInformation, meta));
125+
Assert.ThrowsExactly<InvalidOperationException>(() => _luceneIndex.RemoveEntry("removable"));
126+
127+
//update with path
128+
Assert.ThrowsExactly<InvalidOperationException>(() => _luceneIndex.UpdateEntry(tableInformation, meta));
129+
130+
//update withOut path
131+
tableInformation.Paths.Clear();
132+
Assert.ThrowsExactly<InvalidOperationException>(() => _luceneIndex.UpdateEntry(tableInformation, meta));
133+
134+
135+
}
136+
100137
}
101138

102139
}

0 commit comments

Comments
 (0)