Skip to content

Commit 655873f

Browse files
renemadsenclaude
andcommitted
test(user-property-access): migrate InMemory tests to Testcontainers + TestBaseSetup
Moves BackendConfigurationUserPropertyAccessTests from the EF-InMemory-backed .Test project into the Integration.Test project, inheriting TestBaseSetup so the tests run against real MariaDb. Seeds parent Property rows before PropertyWorker to satisfy the FK constraint that the InMemory provider had been silently ignoring; [SetUp] cleans both tables in FK-safe order. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent bb14f0c commit 655873f

2 files changed

Lines changed: 100 additions & 88 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
using BackendConfiguration.Pn.Services.UserPropertyAccess;
2+
using Microting.eForm.Infrastructure.Constants;
3+
using Microting.EformBackendConfigurationBase.Infrastructure.Data.Entities;
4+
5+
namespace BackendConfiguration.Pn.Integration.Test.UserPropertyAccess;
6+
7+
[Parallelizable(ParallelScope.Fixtures)]
8+
[TestFixture]
9+
public class BackendConfigurationUserPropertyAccessTests : TestBaseSetup
10+
{
11+
[SetUp]
12+
public async Task ClearPropertyWorkers()
13+
{
14+
BackendConfigurationPnDbContext!.PropertyWorkers.RemoveRange(
15+
BackendConfigurationPnDbContext.PropertyWorkers);
16+
await BackendConfigurationPnDbContext.SaveChangesAsync();
17+
18+
BackendConfigurationPnDbContext.Properties.RemoveRange(
19+
BackendConfigurationPnDbContext.Properties);
20+
await BackendConfigurationPnDbContext.SaveChangesAsync();
21+
}
22+
23+
[Test]
24+
public async Task GetAccessiblePropertyIdsAsync_returns_only_properties_where_site_has_active_property_worker()
25+
{
26+
BackendConfigurationPnDbContext!.Properties.Add(new Property { Id = 100 });
27+
BackendConfigurationPnDbContext.Properties.Add(new Property { Id = 101 });
28+
BackendConfigurationPnDbContext.Properties.Add(new Property { Id = 102 });
29+
await BackendConfigurationPnDbContext.SaveChangesAsync();
30+
31+
BackendConfigurationPnDbContext.PropertyWorkers.Add(new PropertyWorker { WorkerId = 7, PropertyId = 100, WorkflowState = Constants.WorkflowStates.Created });
32+
BackendConfigurationPnDbContext.PropertyWorkers.Add(new PropertyWorker { WorkerId = 7, PropertyId = 101, WorkflowState = Constants.WorkflowStates.Removed });
33+
BackendConfigurationPnDbContext.PropertyWorkers.Add(new PropertyWorker { WorkerId = 99, PropertyId = 102, WorkflowState = Constants.WorkflowStates.Created });
34+
await BackendConfigurationPnDbContext.SaveChangesAsync();
35+
36+
var sut = new BackendConfigurationUserPropertyAccess(BackendConfigurationPnDbContext);
37+
38+
var ids = await sut.GetAccessiblePropertyIdsAsync(7);
39+
40+
Assert.That(ids, Is.EquivalentTo(new[] { 100 }));
41+
}
42+
43+
[Test]
44+
public async Task GetAccessiblePropertyIdsAsync_returns_empty_for_unknown_site()
45+
{
46+
BackendConfigurationPnDbContext!.Properties.Add(new Property { Id = 100 });
47+
await BackendConfigurationPnDbContext.SaveChangesAsync();
48+
49+
BackendConfigurationPnDbContext.PropertyWorkers.Add(new PropertyWorker { WorkerId = 7, PropertyId = 100, WorkflowState = Constants.WorkflowStates.Created });
50+
await BackendConfigurationPnDbContext.SaveChangesAsync();
51+
52+
var sut = new BackendConfigurationUserPropertyAccess(BackendConfigurationPnDbContext);
53+
54+
var ids = await sut.GetAccessiblePropertyIdsAsync(42);
55+
56+
Assert.That(ids, Is.Empty);
57+
}
58+
59+
[Test]
60+
public async Task HasAccessAsync_true_when_active_property_worker_exists()
61+
{
62+
BackendConfigurationPnDbContext!.Properties.Add(new Property { Id = 100 });
63+
await BackendConfigurationPnDbContext.SaveChangesAsync();
64+
65+
BackendConfigurationPnDbContext.PropertyWorkers.Add(new PropertyWorker { WorkerId = 7, PropertyId = 100, WorkflowState = Constants.WorkflowStates.Created });
66+
await BackendConfigurationPnDbContext.SaveChangesAsync();
67+
68+
var sut = new BackendConfigurationUserPropertyAccess(BackendConfigurationPnDbContext);
69+
70+
Assert.That(await sut.HasAccessAsync(7, 100), Is.True);
71+
}
72+
73+
[Test]
74+
public async Task HasAccessAsync_false_for_removed_property_worker()
75+
{
76+
BackendConfigurationPnDbContext!.Properties.Add(new Property { Id = 100 });
77+
await BackendConfigurationPnDbContext.SaveChangesAsync();
78+
79+
BackendConfigurationPnDbContext.PropertyWorkers.Add(new PropertyWorker { WorkerId = 7, PropertyId = 100, WorkflowState = Constants.WorkflowStates.Removed });
80+
await BackendConfigurationPnDbContext.SaveChangesAsync();
81+
82+
var sut = new BackendConfigurationUserPropertyAccess(BackendConfigurationPnDbContext);
83+
84+
Assert.That(await sut.HasAccessAsync(7, 100), Is.False);
85+
}
86+
87+
[Test]
88+
public async Task HasAccessAsync_false_for_different_property()
89+
{
90+
BackendConfigurationPnDbContext!.Properties.Add(new Property { Id = 100 });
91+
await BackendConfigurationPnDbContext.SaveChangesAsync();
92+
93+
BackendConfigurationPnDbContext.PropertyWorkers.Add(new PropertyWorker { WorkerId = 7, PropertyId = 100, WorkflowState = Constants.WorkflowStates.Created });
94+
await BackendConfigurationPnDbContext.SaveChangesAsync();
95+
96+
var sut = new BackendConfigurationUserPropertyAccess(BackendConfigurationPnDbContext);
97+
98+
Assert.That(await sut.HasAccessAsync(7, 999), Is.False);
99+
}
100+
}

eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Test/UserPropertyAccess/BackendConfigurationUserPropertyAccessTests.cs

Lines changed: 0 additions & 88 deletions
This file was deleted.

0 commit comments

Comments
 (0)