77 lines
1.8 KiB
C#
77 lines
1.8 KiB
C#
using AutoFixture;
|
|
using FluentAssertions;
|
|
using FluentAssertions.Execution;
|
|
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket;
|
|
using Gameboard.ShogiUI.Sockets.ServiceModels.Types;
|
|
using Gameboard.ShogiUI.Sockets.Services.RequestValidators;
|
|
using Xunit;
|
|
|
|
namespace Gameboard.ShogiUI.xUnitTests.RequestValidators
|
|
{
|
|
public class MoveRequestValidatorShould
|
|
{
|
|
private readonly Fixture fixture;
|
|
private readonly MoveRequestValidator validator;
|
|
public MoveRequestValidatorShould()
|
|
{
|
|
fixture = new Fixture();
|
|
validator = new MoveRequestValidator();
|
|
}
|
|
|
|
[Fact]
|
|
public void PreventInvalidPropertyCombinations()
|
|
{
|
|
// Arrange
|
|
var request = fixture.Create<MoveRequest>();
|
|
|
|
// Act
|
|
var results = validator.Validate(request);
|
|
|
|
// Assert
|
|
using (new AssertionScope())
|
|
{
|
|
results.IsValid.Should().BeFalse();
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void AllowValidPropertyCombinations()
|
|
{
|
|
// Arrange
|
|
var requestWithoutFrom = new MoveRequest()
|
|
{
|
|
Action = ClientAction.Move,
|
|
GameName = "Some game name",
|
|
Move = new Move()
|
|
{
|
|
IsPromotion = false,
|
|
PieceFromCaptured = WhichPiece.Bishop,
|
|
To = "A4"
|
|
}
|
|
};
|
|
var requestWithoutPieceFromCaptured = new MoveRequest()
|
|
{
|
|
Action = ClientAction.Move,
|
|
GameName = "Some game name",
|
|
Move = new Move()
|
|
{
|
|
From = "A1",
|
|
IsPromotion = false,
|
|
To = "A4"
|
|
}
|
|
};
|
|
|
|
// Act
|
|
var results = validator.Validate(requestWithoutFrom);
|
|
var results2 = validator.Validate(requestWithoutPieceFromCaptured);
|
|
|
|
// Assert
|
|
using (new AssertionScope())
|
|
{
|
|
results.IsValid.Should().BeTrue();
|
|
results2.IsValid.Should().BeTrue();
|
|
}
|
|
}
|
|
}
|
|
}
|