Skip to content

Commit

Permalink
Merge pull request litedb-org#2552 from Joy-less/fix-2534
Browse files Browse the repository at this point in the history
  • Loading branch information
pictos authored Oct 9, 2024
2 parents 391cc93 + f982a3a commit c4db4ab
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 160 deletions.
61 changes: 61 additions & 0 deletions LiteDB.Tests/Engine/Recursion_Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System;
using Xunit;

namespace LiteDB.Tests.Engine;

public class Recursion_Tests
{
[Fact]
public void UpdateInFindAll()
{
Test(collection =>
{
foreach (BsonDocument document in collection.FindAll())
{
collection.Update(document);
}
});
}
[Fact]
public void InsertDeleteInFindAll()
{
Test(collection =>
{
foreach (BsonDocument document in collection.FindAll())
{
BsonValue id = collection.Insert(new BsonDocument());
collection.Delete(id);
}
});
}
[Fact]
public void QueryInFindAll()
{
Test(collection =>
{
foreach (BsonDocument document in collection.FindAll())
{
collection.Query().Count();
}
});
}

private void Test(Action<ILiteCollection<BsonDocument>> action)
{
using LiteDatabase database = new(new ConnectionString()
{
Filename = "Demo.db",
Connection = ConnectionType.Shared,
});

ILiteCollection<BsonDocument> accounts = database.GetCollection("Recursion");

if (accounts.Count() < 3)
{
accounts.Insert(new BsonDocument());
accounts.Insert(new BsonDocument());
accounts.Insert(new BsonDocument());
}
action(accounts);
}
}
30 changes: 30 additions & 0 deletions LiteDB.Tests/Issues/Issue2534_Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Xunit;

namespace LiteDB.Tests.Issues;

public class Issue2534_Tests
{
[Fact]
public void Test()
{
using LiteDatabase database = new(new ConnectionString()
{
Filename = "Demo.db",
Connection = ConnectionType.Shared,
});

ILiteCollection<BsonDocument> accounts = database.GetCollection("Issue2534");

if (accounts.Count() < 3)
{
accounts.Insert(new BsonDocument());
accounts.Insert(new BsonDocument());
accounts.Insert(new BsonDocument());
}

foreach (BsonDocument document in accounts.FindAll())
{
accounts.Update(document);
}
}
}
12 changes: 6 additions & 6 deletions LiteDB.Tests/LiteDB.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="5.10.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.console" Version="2.4.2">
<PackageReference Include="FluentAssertions" Version="6.12.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.console" Version="2.9.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit.runner.reporters" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PackageReference Include="xunit.runner.reporters" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Loading

0 comments on commit c4db4ab

Please sign in to comment.