Skip to content

Commit

Permalink
Merge pull request #24 from MrDave1999/patch-2
Browse files Browse the repository at this point in the history
test: Use FakeCarrier in the tests
  • Loading branch information
MrDave1999 committed Aug 17, 2024
2 parents daf26ad + da84553 commit 2f12d88
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 4 deletions.
16 changes: 16 additions & 0 deletions tests/Application.Tests/Flags/FakeCarrier.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace CTF.Application.Tests.Flags;

public class FakeCarrier : Player
{
public override bool SetAttachedObject(
int index,
int modelId,
Bone bone,
Vector3 offset,
Vector3 rotation,
Vector3 scale,
Color materialColor1,
Color materialColor2) => true;

public override bool RemoveAttachedObject(int index) => true;
}
45 changes: 41 additions & 4 deletions tests/Application.Tests/Flags/FlagTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ public void IsCaptured_WhenFlagIsCapturedByPlayer_ShouldReturnsTrue()
Name = "Red",
ColorHex = Color.Red
};
Player player = (Player)Activator.CreateInstance(type: typeof(Player), nonPublic: true);
flag.GetType()
.GetProperty(name: nameof(Flag.FlagCarrier))
.SetValue(flag, player);
var fakeCarrier = new FakeCarrier();
flag.SetCarrier(fakeCarrier);

// Act
bool actual = flag.IsCaptured();
Expand Down Expand Up @@ -63,6 +61,25 @@ public void SetCarrier_WhenArgumentIsNull_ShouldThrowArgumentNullException()
.WithParameterName(nameof(player));
}

[Test]
public void SetCarrier_WhenArgumentIsValid_ShouldSetPlayerAsCarrier()
{
// Arrange
var flag = new Flag
{
Model = FlagModel.Red,
Name = "Red",
ColorHex = Color.Red
};
var fakeCarrier = new FakeCarrier();

// Act
flag.SetCarrier(fakeCarrier);

// Assert
flag.FlagCarrier.Should().Be(fakeCarrier);
}

[Test]
public void RemoveCarrier_WhenNoPlayerHasCapturedFlag_ShouldNotThrowNullReferenceException()
{
Expand All @@ -80,4 +97,24 @@ public void RemoveCarrier_WhenNoPlayerHasCapturedFlag_ShouldNotThrowNullReferenc
// Assert
act.Should().NotThrow<NullReferenceException>();
}

[Test]
public void RemoveCarrier_WhenPlayerHasCapturedFlag_ShouldRemoveFlagOfThatPlayer()
{
// Arrange
var flag = new Flag
{
Model = FlagModel.Red,
Name = "Red",
ColorHex = Color.Red
};
var fakeCarrier = new FakeCarrier();
flag.SetCarrier(fakeCarrier);

// Act
flag.RemoveCarrier();

// Assert
flag.FlagCarrier.Should().BeNull();
}
}

0 comments on commit 2f12d88

Please sign in to comment.