Skip to content

Commit

Permalink
Fixed shared data issue in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pkirilin committed Oct 5, 2024
1 parent b602393 commit 3d85928
Showing 1 changed file with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand All @@ -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]));
}
}

0 comments on commit 3d85928

Please sign in to comment.