Add school dress rules tab in Management with tests.
This commit is contained in:
@@ -54,6 +54,38 @@ public class DressRulesApiTests(AppHostFixture fixture)
|
||||
Assert.Equal(before.Worn.Select(row => row.DefName), after.Worn.Select(row => row.DefName));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UnknownForm_Returns400()
|
||||
{
|
||||
using var client = fixture.App.CreateHttpClient("server");
|
||||
await SchoolApiTests.ResetAsync(client);
|
||||
var school = await SchoolApiTests.CreateAsync(client, "Плохая форма", Start, seed: 35);
|
||||
|
||||
using var response = await client.PostAsJsonAsync(
|
||||
$"/api/schools/{school.Id}/dress-rules",
|
||||
new { students = new { form = "tuxedo", color = "noBright" } },
|
||||
TestContext.Current.CancellationToken);
|
||||
|
||||
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
|
||||
Assert.Equal("unknown-form", await SchoolApiTests.ProblemCodeAsync(response));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UnknownColor_Returns400()
|
||||
{
|
||||
using var client = fixture.App.CreateHttpClient("server");
|
||||
await SchoolApiTests.ResetAsync(client);
|
||||
var school = await SchoolApiTests.CreateAsync(client, "Плохой цвет", Start, seed: 35);
|
||||
|
||||
using var response = await client.PostAsJsonAsync(
|
||||
$"/api/schools/{school.Id}/dress-rules",
|
||||
new { students = new { form = "regular", color = "neon" } },
|
||||
TestContext.Current.CancellationToken);
|
||||
|
||||
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
|
||||
Assert.Equal("unknown-color", await SchoolApiTests.ProblemCodeAsync(response));
|
||||
}
|
||||
|
||||
private sealed record DressRulesDto(DressRulePairDto Students, DressRulePairDto Staff);
|
||||
|
||||
private sealed record DressRulePairDto(string Form, string Color);
|
||||
|
||||
@@ -46,6 +46,17 @@ public class AppropriatenessTests
|
||||
Assert.True(Appropriateness.SkirtLengthFits(context, catalog.Things["ShortSkirt"]));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WhiteTopBlackBottom_RejectsWrongTopOrBottom()
|
||||
{
|
||||
var catalog = LoadCatalog();
|
||||
var rules = new DressRulePair(FormPolicies.Regular, ColorPolicies.WhiteTopBlackBottom);
|
||||
Assert.False(Appropriateness.ColorAllowed(catalog, rules, catalog.Things["Shirt"], "Gray"));
|
||||
Assert.True(Appropriateness.ColorAllowed(catalog, rules, catalog.Things["Shirt"], "White"));
|
||||
Assert.False(Appropriateness.ColorAllowed(catalog, rules, catalog.Things["Jeans"], "Blue"));
|
||||
Assert.True(Appropriateness.ColorAllowed(catalog, rules, catalog.Things["Jeans"], "Black"));
|
||||
}
|
||||
|
||||
private static DefCatalog LoadCatalog()
|
||||
{
|
||||
var root = Path.Combine(AppContext.BaseDirectory, "vanilla");
|
||||
|
||||
@@ -152,6 +152,63 @@ public class AppropriatenessSimulationTests
|
||||
Assert.Equal(0, BrightWornCount(school));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PendingNoBright_AfterMorning_RemovesBrightWornColours()
|
||||
{
|
||||
using var school = Open(TuesdayMorning, seed: 31);
|
||||
MorningDress.Apply(school);
|
||||
school.DressRules = school.DressRules with
|
||||
{
|
||||
PendingStudents = new DressRulePair(FormPolicies.Regular, ColorPolicies.Free),
|
||||
};
|
||||
AdvanceMorning(school);
|
||||
Assert.True(BrightWornCount(school) > 0, "Free colours should allow at least one bright item.");
|
||||
|
||||
school.DressRules = school.DressRules with
|
||||
{
|
||||
PendingStudents = new DressRulePair(FormPolicies.Regular, ColorPolicies.NoBright),
|
||||
};
|
||||
AdvanceMorning(school);
|
||||
Assert.Equal(0, BrightWornCount(school));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WhiteTopBlackBottom_AfterMorning_WhiteShirtsOnStudents()
|
||||
{
|
||||
using var school = Open(TuesdayMorning, seed: 31);
|
||||
MorningDress.Apply(school);
|
||||
school.DressRules = school.DressRules with
|
||||
{
|
||||
PendingStudents = new DressRulePair(FormPolicies.Regular, ColorPolicies.WhiteTopBlackBottom),
|
||||
};
|
||||
AdvanceMorning(school);
|
||||
|
||||
var checkedAny = false;
|
||||
foreach (var pupil in school.Roster!.People.Where(person => person.IsStudent))
|
||||
{
|
||||
foreach (var item in pupil.Items.Where(row => row.Location == ItemLocations.Worn))
|
||||
{
|
||||
if (!school.Catalog!.Things[item.Def].Layers.Any(layer =>
|
||||
layer.Equals(ApparelLayers.Top, StringComparison.Ordinal)))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
checkedAny = true;
|
||||
Assert.Equal("White", item.Color);
|
||||
}
|
||||
}
|
||||
|
||||
Assert.True(checkedAny, "Expected at least one pupil with a top-layer shirt.");
|
||||
}
|
||||
|
||||
private static void AdvanceMorning(School school)
|
||||
{
|
||||
var before = school.Clock.Time;
|
||||
school.Clock.JumpTo(before.Date.AddDays(1).AddHours(6));
|
||||
ApparelWear.Apply(school, gameMinutes: 0, before);
|
||||
}
|
||||
|
||||
private static int BrightWornCount(School school)
|
||||
{
|
||||
var count = 0;
|
||||
|
||||
Reference in New Issue
Block a user