NEO-135: apply standing deltas from clamped effective value
Compute newStanding from previousStanding + deltaAmount so stale out-of-band persisted values match TryGetStanding before mutation.pull/174/head
parent
2ac804ed6c
commit
94acf57e5b
|
|
@ -118,6 +118,22 @@ public sealed class InMemoryFactionStandingStoreTests
|
||||||
Assert.Equal(0, store.TryGetStanding(PlayerId, GridFactionId).Standing);
|
Assert.Equal(0, store.TryGetStanding(PlayerId, GridFactionId).Standing);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TryApplyStandingDelta_ShouldApplyToClampedEffectiveStanding_WhenRawStoredValueExceedsMax()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var store = CreateStore();
|
||||||
|
store.SeedRawStandingForTests(PlayerId, GridFactionId, 999);
|
||||||
|
Assert.Equal(100, store.TryGetStanding(PlayerId, GridFactionId).Standing);
|
||||||
|
// Act
|
||||||
|
var outcome = store.TryApplyStandingDelta(PlayerId, GridFactionId, -15);
|
||||||
|
// Assert
|
||||||
|
Assert.True(outcome.Success);
|
||||||
|
Assert.Equal(100, outcome.PreviousStanding);
|
||||||
|
Assert.Equal(85, outcome.NewStanding);
|
||||||
|
Assert.Equal(85, store.TryGetStanding(PlayerId, GridFactionId).Standing);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void TryGetStanding_ShouldPreferUnknownFaction_WhenPlayerNotWritableAndFactionUnknown()
|
public void TryGetStanding_ShouldPreferUnknownFaction_WhenPlayerNotWritableAndFactionUnknown()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,7 @@ public sealed class InMemoryFactionStandingStore(
|
||||||
{
|
{
|
||||||
var raw = standingByKey.GetValueOrDefault(key, 0);
|
var raw = standingByKey.GetValueOrDefault(key, 0);
|
||||||
var previousStanding = FactionStandingIds.ClampStanding(raw, definition);
|
var previousStanding = FactionStandingIds.ClampStanding(raw, definition);
|
||||||
var newStanding = FactionStandingIds.ClampStanding(raw + deltaAmount, definition);
|
var newStanding = FactionStandingIds.ClampStanding(previousStanding + deltaAmount, definition);
|
||||||
standingByKey[key] = newStanding;
|
standingByKey[key] = newStanding;
|
||||||
return new FactionStandingMutationOutcome(true, null, previousStanding, newStanding);
|
return new FactionStandingMutationOutcome(true, null, previousStanding, newStanding);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -117,7 +117,7 @@ public sealed class PostgresFactionStandingStore(
|
||||||
}
|
}
|
||||||
|
|
||||||
var previousStanding = FactionStandingIds.ClampStanding(raw, definition);
|
var previousStanding = FactionStandingIds.ClampStanding(raw, definition);
|
||||||
var newStanding = FactionStandingIds.ClampStanding(raw + deltaAmount, definition);
|
var newStanding = FactionStandingIds.ClampStanding(previousStanding + deltaAmount, definition);
|
||||||
|
|
||||||
using var upsert = new Npgsql.NpgsqlCommand(
|
using var upsert = new Npgsql.NpgsqlCommand(
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue