From 3d859280a427911ef92b80c794cd289a8a2514ce Mon Sep 17 00:00:00 2001 From: Pavel Kirilin Date: Sat, 5 Oct 2024 23:05:29 +0300 Subject: [PATCH] Fixed shared data issue in tests --- .../WeightTracking/WeightLogsApiTests.cs | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/backend/tests/FoodDiary.ComponentTests/Scenarios/WeightTracking/WeightLogsApiTests.cs b/src/backend/tests/FoodDiary.ComponentTests/Scenarios/WeightTracking/WeightLogsApiTests.cs index cc3eb75ae..3eabba9dd 100644 --- a/src/backend/tests/FoodDiary.ComponentTests/Scenarios/WeightTracking/WeightLogsApiTests.cs +++ b/src/backend/tests/FoodDiary.ComponentTests/Scenarios/WeightTracking/WeightLogsApiTests.cs @@ -10,7 +10,7 @@ protected override WeightLogsApiContext CreateContext( FoodDiaryWebApplicationFactory factory, InfrastructureFixture infrastructure) => new(factory, infrastructure); - private static WeightLog[] WeightLogs => + private static WeightLog[] GivenWeightLogs() => [ new() { Date = DateOnly.Parse("2024-10-01"), Weight = 75.6m }, new() { Date = DateOnly.Parse("2024-10-02"), Weight = 76.5m }, @@ -19,23 +19,29 @@ protected override WeightLogsApiContext CreateContext( ]; [Scenario] - public Task I_can_get_weight_logs() => Run( - c => c.Given_authenticated_user(), - c => c.Given_existing_weightLogs(WeightLogs), - c => c.When_user_gets_weightLogs("2024-10-02", "2024-10-03"), - c => c.Then_response_contains_weightLogs(WeightLogs[2], WeightLogs[1])); + public Task I_can_get_weight_logs() + { + var weightLogs = GivenWeightLogs(); + + return Run( + c => c.Given_authenticated_user(), + c => c.Given_existing_weightLogs(GivenWeightLogs()), + c => c.When_user_gets_weightLogs("2024-10-02", "2024-10-03"), + c => c.Then_response_contains_weightLogs(weightLogs[2], weightLogs[1])); + } [Scenario] public Task I_can_log_my_weight() { + var weightLogs = GivenWeightLogs(); var newWeightLog = new WeightLog { Date = DateOnly.Parse("2024-10-05"), Weight = 76.3m }; return Run( c => c.Given_authenticated_user(), - c => c.Given_existing_weightLogs(WeightLogs), + c => c.Given_existing_weightLogs(), c => c.When_user_adds_weightLog(newWeightLog), c => c.Then_weight_is_successfully_saved(), c => c.When_user_gets_weightLogs("2024-10-03", "2024-10-05"), - c => c.Then_response_contains_weightLogs(newWeightLog, WeightLogs[3], WeightLogs[2])); + c => c.Then_response_contains_weightLogs(newWeightLog, weightLogs[3], weightLogs[2])); } } \ No newline at end of file