Skip to content

Commit 1001eb6

Browse files
committed
Add tests for Issue #2506 fix
1 parent caf6158 commit 1001eb6

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Collections.Generic;
2+
using System.IO;
3+
using Xunit;
4+
5+
namespace LiteDB.Tests.Issues;
6+
7+
public class Issue2506_Tests
8+
{
9+
[Fact]
10+
public void Test()
11+
{
12+
// Open database connection
13+
using LiteDatabase dataBase = new("demo.db");
14+
15+
// Get the file metadata/chunks storage
16+
ILiteStorage<string> fileStorage = dataBase.GetStorage<string>("myFiles", "myChunks");
17+
18+
// Upload empty test file to file storage
19+
using MemoryStream emptyStream = new();
20+
fileStorage.Upload("photos/2014/picture-01.jpg", "picture-01.jpg", emptyStream);
21+
22+
// Find file reference by its ID (returns null if not found)
23+
LiteFileInfo<string> file = fileStorage.FindById("photos/2014/picture-01.jpg");
24+
Assert.NotNull(file);
25+
26+
// Load and save file bytes to hard drive
27+
file.SaveAs(Path.Combine(Path.GetTempPath(), "new-picture.jpg"));
28+
29+
// Find all files matching pattern
30+
IEnumerable<LiteFileInfo<string>> files = fileStorage.Find("_id LIKE 'photos/2014/%'");
31+
Assert.Single(files);
32+
// Find all files matching pattern using parameters
33+
IEnumerable<LiteFileInfo<string>> files2 = fileStorage.Find("_id LIKE @0", "photos/2014/%");
34+
Assert.Single(files2);
35+
}
36+
}

LiteDB.Tests/LiteDB.Tests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
</ItemGroup>
3030

3131
<ItemGroup>
32-
<PackageReference Include="FluentAssertions" Version="6.12.1" />
33-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
32+
<PackageReference Include="FluentAssertions" Version="6.12.2" />
33+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
3434
<PackageReference Include="xunit" Version="2.9.2" />
3535
<PackageReference Include="xunit.runner.console" Version="2.9.2">
3636
<PrivateAssets>all</PrivateAssets>

0 commit comments

Comments
 (0)