61 lines
2.2 KiB
C#
61 lines
2.2 KiB
C#
using NeonSprawl.Server.Game.Encounters;
|
|
using Xunit;
|
|
|
|
namespace NeonSprawl.Server.Tests.Game.Encounters;
|
|
|
|
public sealed class InMemoryEncounterProgressStoreTests
|
|
{
|
|
private const string PlayerId = "dev-local-1";
|
|
private const string EncounterId = "prototype_combat_pocket";
|
|
private const string MeleeNpc = "prototype_npc_melee";
|
|
private const string RangedNpc = "prototype_npc_ranged";
|
|
|
|
[Fact]
|
|
public void TryActivate_ShouldReturnTrueThenFalse_WhenCalledTwice()
|
|
{
|
|
// Arrange
|
|
var store = new InMemoryEncounterProgressStore();
|
|
// Act
|
|
var first = store.TryActivate(PlayerId, EncounterId);
|
|
var second = store.TryActivate(PlayerId, EncounterId);
|
|
// Assert
|
|
Assert.True(first);
|
|
Assert.False(second);
|
|
Assert.True(store.TryGetProgress(PlayerId, EncounterId, out var progress));
|
|
Assert.True(progress.Started);
|
|
Assert.Empty(progress.DefeatedNpcInstanceIds);
|
|
}
|
|
|
|
[Fact]
|
|
public void TryAddDefeatedTarget_ShouldReturnFalse_WhenEncounterNotActivated()
|
|
{
|
|
// Arrange
|
|
var store = new InMemoryEncounterProgressStore();
|
|
// Act
|
|
var added = store.TryAddDefeatedTarget(PlayerId, EncounterId, MeleeNpc);
|
|
// Assert
|
|
Assert.False(added);
|
|
Assert.False(store.TryGetProgress(PlayerId, EncounterId, out _));
|
|
}
|
|
|
|
[Fact]
|
|
public void TryAddDefeatedTarget_ShouldReturnFalseOnDuplicate_AndTrueForSecondNpc()
|
|
{
|
|
// Arrange
|
|
var store = new InMemoryEncounterProgressStore();
|
|
_ = store.TryActivate(PlayerId, EncounterId);
|
|
// Act
|
|
var firstAdd = store.TryAddDefeatedTarget(PlayerId, EncounterId, MeleeNpc);
|
|
var duplicate = store.TryAddDefeatedTarget(PlayerId, EncounterId, MeleeNpc);
|
|
var secondAdd = store.TryAddDefeatedTarget(PlayerId, EncounterId, RangedNpc);
|
|
// Assert
|
|
Assert.True(firstAdd);
|
|
Assert.False(duplicate);
|
|
Assert.True(secondAdd);
|
|
Assert.True(store.TryGetProgress(PlayerId, EncounterId, out var progress));
|
|
Assert.Equal(2, progress.DefeatedNpcInstanceIds.Count);
|
|
Assert.Contains(MeleeNpc, progress.DefeatedNpcInstanceIds);
|
|
Assert.Contains(RangedNpc, progress.DefeatedNpcInstanceIds);
|
|
}
|
|
}
|