change all test based on new DiceGroup Class
continuous-integration/drone/push Build is failing Details

test_dice_group_manager
mzjeeawody 2 years ago
parent 13f45645fe
commit 69821cea42

@ -17,186 +17,184 @@ using Xunit;
namespace Tests.Data_UTs.Dice namespace Tests.Data_UTs.Dice
{ {
public class DiceGroupManagerTest public class DiceGroupManagerTest
{ {
private readonly MasterOfCeremonies stubGameRunner = new Stub().LoadApp(); private static readonly Task<MasterOfCeremonies> stubGameRunner = new Stub().LoadApp();
[Fact] [Fact]
public void TestConstructorReturnsEmptyEnumerable() public void TestConstructorReturnsEmptyEnumerable()
{ {
// Arrange // Arrange
DiceGroupManager diceGroupManager = new(); DiceGroupManager diceGroupManager = new();
Dictionary<string, IEnumerable<Die>> expected;
Dictionary<string, IEnumerable<Die>> actual; List<DiceGroup> expected;
Task<ReadOnlyCollection<DiceGroup>> actual;
// Act
expected = new Dictionary<string, IEnumerable<Die>>(); // Act
actual = (Dictionary<string, IEnumerable<Die>>)diceGroupManager.GetAll(); expected = new List<DiceGroup>();
actual = diceGroupManager.GetAll();
// Assert
Xunit.Assert.Equal(expected, actual); // Assert
Xunit.Assert.Equal(expected, actual.Result);
}
}
[Fact]
[Fact]
public void TestAddWhenDiceGroupThenDoAddAndReturnDiceGroup()
{ public async Task TestAddWhenDiceGroupThenDoAddAndReturnDiceGroup()
// Arrange {
// Arrange
DiceGroupManager dgm = new(); DiceGroupManager dgm = new();
KeyValuePair<string, IEnumerable<Die>> group1 = stubGameRunner.DiceGroupManager.GetAll().First(); DiceGroup group1 = new("Monopoly", new List<NumberDie> { new NumberDie(new NumberFace(5), new NumberFace(7)), new NumberDie(new NumberFace(5), new NumberFace(7)) });
KeyValuePair<string, IEnumerable<Die>> group2 = stubGameRunner.DiceGroupManager.GetAll().Last(); DiceGroup group2 = new("Scrabble", new List<NumberDie> { new NumberDie(new NumberFace(5), new NumberFace(7)), new NumberDie(new NumberFace(5), new NumberFace(7)) });
// Act //...storing the results of DiceGroupManager.Add() in variables
Collection<DiceGroup> expected = new() {group1,group2 };
//...adding keys and values to some dictionary for future comparison Collection<DiceGroup> actual = new()
Dictionary<string, IEnumerable<Die>> expected = new()
{ {
{ group1.Key, group1.Value }, await dgm.Add(group1),
{ group2.Key, group2.Value } await dgm.Add(group2)
}; };
//...storing the results of DiceGroupManager.Add() in variables
KeyValuePair<string, IEnumerable<Die>> resultFromAdd1 = dgm.Add(group1);
KeyValuePair<string, IEnumerable<Die>> resultFromAdd2 = dgm.Add(group2);
//...using those variables to fill a second dictionary for comparison
Dictionary<string, IEnumerable<Die>> actual = new()
{
{ resultFromAdd1.Key, resultFromAdd1.Value },
{ resultFromAdd2.Key, resultFromAdd2.Value }
};
// Assert // Assert
Xunit.Assert.Equal(expected, actual); Xunit.Assert.Equal(expected, actual);
} Xunit.Assert.Equal(expected, actual);
}
[Fact]
[Fact] public async Task TestAddIfNullThrowsException()
public void TestAddIfNullThrowsException() {
{ DiceGroupManager dgm = new();
DiceGroupManager dgm = new(); DiceGroup expected;
KeyValuePair<string, IEnumerable<Die>> group1 = stubGameRunner.DiceGroupManager.GetAll().First(); expected = null;
KeyValuePair<string, IEnumerable<Die>> group2 = stubGameRunner.DiceGroupManager.GetAll().Last(); async Task actionAsync() => await dgm.Add(expected);// Add() returns the added element if succesful
NumberFace[] d6Faces = new NumberFace[] { new(1), new(2), new(3), new(4), new(5), new(6) };
// Assert
Xunit.Assert.Null(expected);
Dictionary<string, IEnumerable<Die>> expected = new() await Xunit.Assert.ThrowsAsync<ArgumentNullException>(actionAsync);
{ Xunit.Assert.DoesNotContain(expected, await dgm.GetAll());
{ "", new List<NumberDie>{ new NumberDie(d6Faces[0], d6Faces[1..]), new NumberDie(d6Faces[0], d6Faces[3..]) } } }
}; [Fact]
Dictionary<string, IEnumerable<Die>> toAdd = new(); public async Task TestAddIfAlreadyExistsThrowsException()
/* void action() => toAdd.Add("", new List<NumberDie>{ new NumberDie(d6Faces[0], d6Faces[1..]), {
new NumberDie(d6Faces[0], d6Faces[3..])}); */ DiceGroupManager dgm = new();
// Xunit.Assert.Empty(expected.Keys);
foreach (KeyValuePair<string, IEnumerable<Die>> entry in expected) await dgm.Add(new("Monopoly", new List<NumberDie> { new NumberDie(new NumberFace(5), new NumberFace(7)), new NumberDie(new NumberFace(5), new NumberFace(7)) }));
{ DiceGroup group1 = new("Monopoly", new List<NumberDie> { new NumberDie(new NumberFace(5), new NumberFace(7)), new NumberDie(new NumberFace(5), new NumberFace(7)) });
Xunit.Assert.Empty(entry.Key);
// do something with entry.Value or entry.Key async Task actionAsync() => await dgm.Add(group1);
}
} // Assert
await Xunit.Assert.ThrowsAsync<Exception>(actionAsync);
[Fact] }
public void TestAddIfAlreadyExistsThrowsException()
{ /*
DiceGroupManager dgm = new();
[Fact]
// Act public void TestAddIfAlreadyExistsThrowsException()
KeyValuePair<string, IEnumerable<Die>> toAdd = new("Monopoly", new List<NumberDie> { new NumberDie(new NumberFace(5), new NumberFace(7)), new NumberDie(new NumberFace(5), new NumberFace(7))}); {
dgm.Add(toAdd); DiceGroupManager dgm = new();
void action() => dgm.Add(toAdd); // Act
KeyValuePair<string, IEnumerable<Die>> toAdd = new("Monopoly", new List<NumberDie> { new NumberDie(new NumberFace(5), new NumberFace(7)), new NumberDie(new NumberFace(5), new NumberFace(7)) });
// Assert DiceGroup diceGroup = new DiceGroup("Monopoly", new List<NumberDie> { new NumberDie(new NumberFace(5), new NumberFace(7)), new NumberDie(new NumberFace(5), new NumberFace(7)) });
Xunit.Assert.Throws<ArgumentException>(action);
dgm.Add(diceGroup);
}
[Fact] void action() => dgm.Add(diceGroup);
public void TestGetOneByIdThrowsException()
{ // Assert
// Arrange Xunit.Assert.Throws<ArgumentException>(action);
DiceGroupManager dgm = new();
}
// Act [Fact]
public void TestGetOneByIdThrowsException()
void action() => dgm.GetOneByID(new("9657b6f0-9431-458e-a2bd-4bb0c7d4a6ed")); {
// Arrange
// Assert DiceGroupManager dgm = new();
Xunit.Assert.Throws<NotImplementedException>(action);
} // Act
[Theory] void action() => dgm.GetOneByID(new("9657b6f0-9431-458e-a2bd-4bb0c7d4a6ed"));
[InlineData("")]
[InlineData(null)] // Assert
[InlineData(" ")] Xunit.Assert.Throws<NotImplementedException>(action);
public void TestGetOneByNameIfInvalidThrowsException(string name) }
{
// Arrange [Theory]
DiceGroupManager dgm = new(); [InlineData("")]
KeyValuePair<string, IEnumerable<Die>> toAdd = new("Monopoly", new List<NumberDie> { new NumberDie(new NumberFace(5), new NumberFace(7)), new NumberDie(new NumberFace(5), new NumberFace(7)) }); [InlineData(null)]
dgm.Add(toAdd); [InlineData(" ")]
void action() => dgm.GetOneByName(name); public void TestGetOneByNameIfInvalidThrowsException(string name)
{
// Assert // Arrange
Xunit.Assert.Throws<ArgumentNullException>(action); DiceGroupManager dgm = new();
} KeyValuePair<string, IEnumerable<Die>> toAdd = new("Monopoly", new List<NumberDie> { new NumberDie(new NumberFace(5), new NumberFace(7)), new NumberDie(new NumberFace(5), new NumberFace(7)) });
DiceGroup diceGroup = new DiceGroup("Monopoly", new List<NumberDie> { new NumberDie(new NumberFace(5), new NumberFace(7)), new NumberDie(new NumberFace(5), new NumberFace(7)) });
[Fact]
public void TestRemoveWorksIfExists() dgm.Add(diceGroup);
{ void action() => dgm.GetOneByName(name);
// Arrange
DiceGroupManager dgm = new(); // Assert
KeyValuePair<string, IEnumerable<Die>> toAdd = new("Monopoly", new List<NumberDie> { new NumberDie(new NumberFace(5), new NumberFace(7)), new NumberDie(new NumberFace(5), new NumberFace(7)) }); Xunit.Assert.Throws<ArgumentNullException>(action);
dgm.Add(toAdd); }
dgm.Remove(toAdd);
[Fact]
Xunit.Assert.DoesNotContain(toAdd, dgm.GetAll()); public void TestRemoveWorksIfExists()
} {
// Arrange
[Fact] DiceGroupManager dgm = new();
public void TestRemoveFailsSilentlyIfGivenNonExistent() // KeyValuePair<string, IEnumerable<Die>> toAdd = new("Monopoly", new List<NumberDie> { new NumberDie(new NumberFace(5), new NumberFace(7)), new NumberDie(new NumberFace(5), new NumberFace(7)) });
{ DiceGroup diceGroup = new DiceGroup("Monopoly", new List<NumberDie> { new NumberDie(new NumberFace(5), new NumberFace(7)), new NumberDie(new NumberFace(5), new NumberFace(7)) });
DiceGroupManager dgm = new();
KeyValuePair<string, IEnumerable<Die>> toAdd = new("Monopoly", new List<NumberDie> { new NumberDie(new NumberFace(5), new NumberFace(7)), new NumberDie(new NumberFace(5), new NumberFace(7)) }); dgm.Add(diceGroup);
dgm.Add(toAdd); dgm.Remove(diceGroup);
KeyValuePair<string, IEnumerable<Die>> toAdd2 = new("Scrabble", new List<NumberDie> { new NumberDie(new NumberFace(5), new NumberFace(7)), new NumberDie(new NumberFace(5), new NumberFace(7)) }); Xunit.Assert.DoesNotContain(diceGroup, (IEnumerable<DiceGroup>)dgm.GetAll());
}
// Act
dgm.Remove(toAdd2); [Fact]
public void TestRemoveFailsSilentlyIfGivenNonExistent()
// Assert {
Xunit.Assert.DoesNotContain(toAdd2, dgm.GetAll()); DiceGroupManager dgm = new();
} KeyValuePair<string, IEnumerable<Die>> toAdd = new("Monopoly", new List<NumberDie> { new NumberDie(new NumberFace(5), new NumberFace(7)), new NumberDie(new NumberFace(5), new NumberFace(7)) });
dgm.Add(toAdd);
[Fact]
public void TestUpdateWorksIfValid() KeyValuePair<string, IEnumerable<Die>> toAdd2 = new("Scrabble", new List<NumberDie> { new NumberDie(new NumberFace(5), new NumberFace(7)), new NumberDie(new NumberFace(5), new NumberFace(7)) });
{
// Arrange // Act
DiceGroupManager dgm = new(); dgm.Remove(toAdd2);
KeyValuePair<string, IEnumerable<Die>> toAdd = new("Monopoly", new List<NumberDie> { new NumberDie(new NumberFace(5), new NumberFace(7)), new NumberDie(new NumberFace(5), new NumberFace(7)) });
dgm.Add(toAdd); // Assert
KeyValuePair<string, IEnumerable<Die>> toAdd2 = new("Scrabble", new List<NumberDie> { new NumberDie(new NumberFace(5), new NumberFace(7)), new NumberDie(new NumberFace(5), new NumberFace(7)) }); Xunit.Assert.DoesNotContain(toAdd2, dgm.GetAll());
dgm.Update(toAdd, toAdd2); }
Xunit.Assert.DoesNotContain(toAdd, dgm.GetAll()); [Fact]
Xunit.Assert.Contains(toAdd2, dgm.GetAll()); public void TestUpdateWorksIfValid()
Xunit.Assert.True(dgm.GetAll().Count() == 1); {
} // Arrange
DiceGroupManager dgm = new();
KeyValuePair<string, IEnumerable<Die>> toAdd = new("Monopoly", new List<NumberDie> { new NumberDie(new NumberFace(5), new NumberFace(7)), new NumberDie(new NumberFace(5), new NumberFace(7)) });
dgm.Add(toAdd);
KeyValuePair<string, IEnumerable<Die>> toAdd2 = new("Scrabble", new List<NumberDie> { new NumberDie(new NumberFace(5), new NumberFace(7)), new NumberDie(new NumberFace(5), new NumberFace(7)) });
dgm.Update(toAdd, toAdd2);
Xunit.Assert.DoesNotContain(toAdd, dgm.GetAll());
Xunit.Assert.Contains(toAdd2, dgm.GetAll());
Xunit.Assert.True(dgm.GetAll().Count() == 1);
}
*/
} }
} }

Loading…
Cancel
Save