|
|
@ -173,74 +173,103 @@ namespace Tests.Model_UTs
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
[Fact]
|
|
|
|
public void TestUpdateWorksIfValid()
|
|
|
|
public void TestUpdateWhenValidThenSucceeds()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Arrange
|
|
|
|
// Arrange
|
|
|
|
|
|
|
|
string oldName = "blargh";
|
|
|
|
|
|
|
|
string newName = "blargh2.0";
|
|
|
|
|
|
|
|
GameRunner gameRunner = new(new PlayerManager(), new DieManager());
|
|
|
|
|
|
|
|
Game game = new(oldName, new PlayerManager(), stubGameRunner.GetAll().First().Dice);
|
|
|
|
|
|
|
|
game.PlayerManager.Add(new("Alice"));
|
|
|
|
|
|
|
|
gameRunner.Add(game);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Game oldGame = gameRunner.GetAll().First();
|
|
|
|
|
|
|
|
Game newGame = new(newName, oldGame.PlayerManager, oldGame.Dice);
|
|
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
// Act
|
|
|
|
|
|
|
|
int oldSize = gameRunner.GetAll().Count();
|
|
|
|
|
|
|
|
gameRunner.Update(oldGame, newGame);
|
|
|
|
|
|
|
|
int newSize = gameRunner.GetAll().Count();
|
|
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
// Assert
|
|
|
|
|
|
|
|
Assert.NotEqual(oldName, newName);
|
|
|
|
|
|
|
|
Assert.DoesNotContain(oldGame, gameRunner.GetAll());
|
|
|
|
|
|
|
|
Assert.Contains(newGame, gameRunner.GetAll());
|
|
|
|
|
|
|
|
Assert.Equal(oldSize, newSize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Theory]
|
|
|
|
[Theory]
|
|
|
|
[InlineData("")]
|
|
|
|
[InlineData("")]
|
|
|
|
[InlineData(" ")]
|
|
|
|
[InlineData(" ")]
|
|
|
|
[InlineData(null)]
|
|
|
|
[InlineData(null)]
|
|
|
|
public void TestUpdateDoesNotGoWithValidBeforeAndInvalidAfter(string badName)
|
|
|
|
public void TestUpdateWhenValidBeforeAndInvalidAfterThenDoesNotGo(string badName)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Arrange
|
|
|
|
// Arrange
|
|
|
|
|
|
|
|
int expectedSize = stubGameRunner.GetAll().Count();
|
|
|
|
|
|
|
|
Game oldGame = stubGameRunner.GetAll().First();
|
|
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
// Act
|
|
|
|
|
|
|
|
void action() => stubGameRunner.Update(oldGame, new(badName, oldGame.PlayerManager, oldGame.Dice));
|
|
|
|
|
|
|
|
int actualSize = stubGameRunner.GetAll().Count();
|
|
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
// Assert
|
|
|
|
|
|
|
|
Assert.Throws<ArgumentException>(action); // thrown by constructor
|
|
|
|
|
|
|
|
Assert.Contains(oldGame, stubGameRunner.GetAll()); // still there
|
|
|
|
|
|
|
|
Assert.True(expectedSize == actualSize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
[Fact]
|
|
|
|
public void TestUpdateDoesNotGoWithValidBeforeAndNullAfter()
|
|
|
|
public void TestUpdateWhenValidBeforeAndNullAfterThenDoesNotGo()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Arrange
|
|
|
|
// Arrange
|
|
|
|
|
|
|
|
int expectedSize = stubGameRunner.GetAll().Count();
|
|
|
|
|
|
|
|
Game oldGame = stubGameRunner.GetAll().First();
|
|
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
// Act
|
|
|
|
|
|
|
|
void action() => stubGameRunner.Update(oldGame, null);
|
|
|
|
|
|
|
|
int actualSize = stubGameRunner.GetAll().Count();
|
|
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
// Assert
|
|
|
|
|
|
|
|
Assert.Throws<ArgumentNullException>(action); // thrown by constructor
|
|
|
|
|
|
|
|
Assert.Contains(oldGame, stubGameRunner.GetAll()); // still there
|
|
|
|
|
|
|
|
Assert.True(expectedSize == actualSize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
[Fact]
|
|
|
|
public void TestUpdateDoesNotGoWithValidAfterAndNullBefore()
|
|
|
|
public void TestUpdateDoesNotGoWithValidAfterAndNullBefore()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Arrange
|
|
|
|
// Arrange
|
|
|
|
|
|
|
|
int expectedSize = stubGameRunner.GetAll().Count();
|
|
|
|
|
|
|
|
Game oldGame = stubGameRunner.GetAll().First();
|
|
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
// Act
|
|
|
|
|
|
|
|
void action() => stubGameRunner.Update(null, new("newgamename", oldGame.PlayerManager, oldGame.Dice));
|
|
|
|
|
|
|
|
int actualSize = stubGameRunner.GetAll().Count();
|
|
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
// Assert
|
|
|
|
|
|
|
|
Assert.Throws<ArgumentNullException>(action); // thrown by constructor
|
|
|
|
|
|
|
|
Assert.Contains(oldGame, stubGameRunner.GetAll()); // still there
|
|
|
|
|
|
|
|
Assert.True(expectedSize == actualSize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Theory]
|
|
|
|
[Theory]
|
|
|
|
[InlineData("")]
|
|
|
|
[InlineData("")]
|
|
|
|
[InlineData(" ")]
|
|
|
|
[InlineData(" ")]
|
|
|
|
[InlineData(null)]
|
|
|
|
[InlineData(null)]
|
|
|
|
public void TestUpdateDoesNotGoWithValidAfterAndInvalidBefore(string name)
|
|
|
|
public void TestUpdateWhenInvalidBeforeAndValidAfterThenDoesNotGo(string badName)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Arrange
|
|
|
|
// Arrange
|
|
|
|
|
|
|
|
int expectedSize = stubGameRunner.GetAll().Count();
|
|
|
|
|
|
|
|
Game oldGame = stubGameRunner.GetAll().First();
|
|
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
// Act
|
|
|
|
|
|
|
|
void action() => stubGameRunner.Update(new(badName, oldGame.PlayerManager, oldGame.Dice), new("valid", oldGame.PlayerManager, oldGame.Dice));
|
|
|
|
|
|
|
|
int actualSize = stubGameRunner.GetAll().Count();
|
|
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
// Assert
|
|
|
|
|
|
|
|
Assert.Throws<ArgumentException>(action); // thrown by constructor
|
|
|
|
|
|
|
|
Assert.Contains(oldGame, stubGameRunner.GetAll()); // still there
|
|
|
|
|
|
|
|
Assert.True(expectedSize == actualSize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|