Skip to content

Commit 3f94643

Browse files
Merge pull request #3 from ReneSchwarzer/develop
Version 0.0.7-alpha
2 parents 9a6968c + 72d5c36 commit 3f94643

219 files changed

Lines changed: 22169 additions & 3326 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ bld/
3232
[Ll]og/
3333
[Ll]ogs/
3434

35+
# Visual Studi Code
36+
.vscode
37+
3538
# Visual Studio 2015/2017 cache/options directory
3639
.vs/
3740
# Uncomment if you have tasks that create the project's static files in wwwroot

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ WebExpress.WebIndex is part of the WebExpress family. The project provides a rev
2323
to enable a quick and efficient search for data. The index can be filtered using the
2424
wql (webexpress query language). Even though the reverse index is part of the WebExpress
2525
family, it can also be used in other projects (outside of WebExpress).
26+
For detailed information about WebIndex, see [concept](https://github.com/ReneSchwarzer/WebExpress.WebIndex/blob/main/doc/concept.md).
2627

2728
# Download
2829
The current binaries are available for download [here](https://github.com/ReneSchwarzer/WebExpress/releases).

doc/concept.md

Lines changed: 989 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using Xunit.Abstractions;
2+
3+
namespace WebExpress.WebIndex.Test.DocumentStore
4+
{
5+
/// <summary>
6+
/// Test class for testing the document store.
7+
/// </summary>
8+
/// <param name="fixture">The log.</param>
9+
/// <param name="output">The test context.</param>
10+
public abstract class UnitTestDocumentStore<T>(T fixture, ITestOutputHelper output) : IClassFixture<T> where T : class
11+
{
12+
/// <summary>
13+
/// Returns the log.
14+
/// </summary>
15+
protected ITestOutputHelper Output { get; private set; } = output;
16+
17+
/// <summary>
18+
/// Returns the test context.
19+
/// </summary>
20+
protected T Fixture { get; private set; } = fixture;
21+
22+
/// <summary>
23+
/// Returns the context.
24+
/// </summary>
25+
protected IIndexDocumemntContext Context { get; private set; }
26+
27+
/// <summary>
28+
/// It sets up the preconditions for a unit test.
29+
/// </summary>
30+
protected void Preconditions()
31+
{
32+
var context = new IndexContext();
33+
34+
context.IndexDirectory = Path.Combine(context.IndexDirectory, Path.GetFileNameWithoutExtension(Path.GetRandomFileName()));
35+
Context = new IndexDocumemntContext(context, new Term.IndexTokenAnalyzer(context));
36+
}
37+
38+
/// <summary>
39+
/// It performs cleanup tasks after a unit test.
40+
/// </summary>
41+
protected void Postconditions()
42+
{
43+
Context.TokenAnalyzer.Dispose();
44+
Directory.Delete(Context.IndexDirectory, true);
45+
}
46+
}
47+
}
Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
using WebExpress.WebIndex.Memory;
2+
using WebExpress.WebIndex.Test.Document;
3+
using WebExpress.WebIndex.Test.Fixture;
4+
using Xunit.Abstractions;
5+
6+
namespace WebExpress.WebIndex.Test.DocumentStore
7+
{
8+
/// <summary>
9+
/// Test class for testing the memory-based document store.
10+
/// </summary>
11+
public class UnitTestDocumentStoreMemoryA : UnitTestDocumentStore<UnitTestIndexFixtureIndexA>
12+
{
13+
/// <summary>
14+
/// Constructor
15+
/// </summary>
16+
/// <param name="fixture">The log.</param>
17+
/// <param name="output">The test context.</param>
18+
public UnitTestDocumentStoreMemoryA(UnitTestIndexFixtureIndexA fixture, ITestOutputHelper output)
19+
: base(fixture, output)
20+
{
21+
}
22+
23+
/// <summary>
24+
/// Creates a document store.
25+
/// </summary>
26+
[Fact]
27+
public void Create()
28+
{
29+
// preconditions
30+
var context = new IndexContext();
31+
32+
// test execution
33+
var documentStore = new IndexMemoryDocumentStore<UnitTestIndexTestDocumentA>(context, 5);
34+
35+
// postconditions
36+
documentStore.Dispose();
37+
}
38+
39+
/// <summary>
40+
/// Adds items to a document store.
41+
/// </summary>
42+
[Fact]
43+
public void Add()
44+
{
45+
// preconditions
46+
Preconditions();
47+
var documentStore = new IndexMemoryDocumentStore<UnitTestIndexTestDocumentA>(Context, 5);
48+
49+
documentStore.Clear();
50+
51+
// test execution
52+
documentStore.Add(Fixture.TestData[0]);
53+
documentStore.Add(Fixture.TestData[1]);
54+
55+
var i = documentStore.GetItem(Fixture.TestData[0].Id);
56+
57+
Assert.True(i != null && i.Id == Fixture.TestData[0].Id);
58+
59+
// postconditions
60+
documentStore.Dispose();
61+
Postconditions();
62+
}
63+
64+
/// <summary>
65+
/// Update an entry in the reverse index where the item has a first name change.
66+
/// </summary>
67+
[Fact]
68+
public void UpdateWithChange()
69+
{
70+
// preconditions
71+
Preconditions();
72+
var documentStore = new IndexMemoryDocumentStore<UnitTestIndexTestDocumentA>(Context, 5);
73+
74+
documentStore.Clear();
75+
documentStore.Add(Fixture.TestData[0]);
76+
documentStore.Add(Fixture.TestData[1]);
77+
78+
var name = "Update_" + Fixture.TestData[0].Text;
79+
var changed = new UnitTestIndexTestDocumentA
80+
{
81+
Id = Fixture.TestData[0].Id,
82+
Text = name,
83+
};
84+
85+
// test execution
86+
documentStore.Update(changed);
87+
88+
var all = documentStore.All;
89+
90+
Assert.Equal(all.Select(x => x.Id).OrderBy(x => x), Fixture.TestData.Take(2).Select(x => x.Id).OrderBy(x => x));
91+
Assert.True(all.Where(x => x.Text == name).Any());
92+
93+
// postconditions
94+
documentStore.Dispose();
95+
Postconditions();
96+
}
97+
98+
/// <summary>
99+
/// Changes an entry in the reverse index without the element to be changed having any changes.
100+
/// </summary>
101+
[Fact]
102+
public void UpdateWithoutChanges()
103+
{
104+
// preconditions
105+
Preconditions();
106+
var documentStore = new IndexMemoryDocumentStore<UnitTestIndexTestDocumentA>(Context, 5);
107+
108+
documentStore.Clear();
109+
documentStore.Add(Fixture.TestData[0]);
110+
documentStore.Add(Fixture.TestData[1]);
111+
112+
// test execution
113+
documentStore.Update(Fixture.TestData[0]);
114+
var all = documentStore.All;
115+
116+
Assert.Equal(all.Select(x => x.Id).OrderBy(x => x), Fixture.TestData.Take(2).Select(x => x.Id).OrderBy(x => x));
117+
Assert.True(all.Where(x => x.Text == Fixture.TestData[0].Text).Any());
118+
119+
// postconditions
120+
documentStore.Dispose();
121+
Postconditions();
122+
}
123+
124+
/// <summary>
125+
/// Removes an entry from the document store.
126+
/// </summary>
127+
[Fact]
128+
public void Remove()
129+
{
130+
// preconditions
131+
Preconditions();
132+
var documentStore = new IndexMemoryDocumentStore<UnitTestIndexTestDocumentA>(Context, 5);
133+
134+
documentStore.Clear();
135+
documentStore.Add(Fixture.TestData[0]);
136+
documentStore.Add(Fixture.TestData[1]);
137+
138+
// test execution
139+
documentStore.Delete(Fixture.TestData[0]);
140+
var all = documentStore.All;
141+
142+
Assert.Equal(all.Select(x => x.Id).OrderBy(x => x), Fixture.TestData.Where(x => x.Id == Fixture.TestData[1].Id).Select(x => x.Id));
143+
144+
// postconditions
145+
documentStore.Dispose();
146+
Postconditions();
147+
}
148+
149+
/// <summary>
150+
/// Retrieve a entry of the reverse index.
151+
/// </summary>
152+
[Fact]
153+
public void Retrieve()
154+
{
155+
// preconditions
156+
Preconditions();
157+
var documentStore = new IndexMemoryDocumentStore<UnitTestIndexTestDocumentA>(Context, 5);
158+
159+
documentStore.Clear();
160+
documentStore.Add(Fixture.TestData[0]);
161+
documentStore.Add(Fixture.TestData[1]);
162+
163+
// test execution
164+
var item = documentStore.GetItem(Fixture.TestData[0].Id);
165+
166+
Assert.NotNull(documentStore);
167+
Assert.NotNull(item);
168+
169+
// postconditions
170+
documentStore.Dispose();
171+
Postconditions();
172+
}
173+
174+
/// <summary>
175+
/// Return all entries of the document store.
176+
/// </summary>
177+
[Fact]
178+
public void All()
179+
{
180+
// preconditions
181+
Preconditions();
182+
var documentStore = new IndexMemoryDocumentStore<UnitTestIndexTestDocumentA>(Context, 5);
183+
184+
documentStore.Clear();
185+
foreach (var item in Fixture.TestData)
186+
{
187+
documentStore.Add(item);
188+
}
189+
190+
// test execution
191+
var all = documentStore.All;
192+
193+
Assert.True(all.Select(x => x.Id).OrderBy(x => x).SequenceEqual(Fixture.TestData.Select(x => x.Id).OrderBy(x => x)));
194+
195+
// postconditions
196+
documentStore.Dispose();
197+
Postconditions();
198+
}
199+
}
200+
}

0 commit comments

Comments
 (0)