Skip to content

Commit

Permalink
mock ProjectContext for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hahn-kev committed May 24, 2024
1 parent baaa8cb commit 5074b9a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 6 additions & 2 deletions backend/LcmCrdt.Tests/LexboxApiTests.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
using Crdt;
using Crdt.Db;
using LcmCrdt.Tests.Mocks;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using MiniLcm;
using Entry = MiniLcm.Entry;
using ExampleSentence = MiniLcm.ExampleSentence;
using Sense = MiniLcm.Sense;

namespace LcmCrdt.Tests;

public class BasicApiTests: IAsyncLifetime
public class BasicApiTests : IAsyncLifetime
{
private CrdtLexboxApi _api = null!;
private Guid _entry1Id = new Guid("a3f5aa5a-578f-4181-8f38-eaaf27f01f1c");
Expand All @@ -24,9 +26,11 @@ public BasicApiTests()
{
var services = new ServiceCollection()
.AddLcmCrdtClient()
.RemoveAll(typeof(ProjectContext))
.AddSingleton<ProjectContext>(new MockProjectContext(new CrdtProject("sena-3", ":memory:")))
.BuildServiceProvider();
_projectsService = services.GetRequiredService<ProjectsService>();
_services = _projectsService.CreateProjectScope(new CrdtProject("sena-3", ":memory:"));
_services = services.CreateScope();
_crdtDbContext = _services.ServiceProvider.GetRequiredService<CrdtDbContext>();
}

Expand Down
6 changes: 6 additions & 0 deletions backend/LcmCrdt.Tests/Mocks/MockProjectContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace LcmCrdt.Tests.Mocks;

public class MockProjectContext(CrdtProject project) : ProjectContext
{
public override CrdtProject? Project { get; set; } = project;
}

0 comments on commit 5074b9a

Please sign in to comment.