Fix UT, fix Tests.csproj, move UT file to proper folder
continuous-integration/drone/push Build is passing Details

pull/184/head
Alexis DRAI 2 years ago
parent 2429329049
commit 781d77fda3

@ -1,89 +0,0 @@
using Data.EF;
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Model.Dice;
using Model.Dice.Faces;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;
namespace Tests.Data_UTs.Dice
{
public class DiceGroupManagerTest
{
[Fact]
public void TestConstructorReturnsEmptyEnumerable()
{
// Arrange
DiceGroupManager diceGroupManager = new();
Dictionary<string, IEnumerable<Die>> expected;
Dictionary<string, IEnumerable<Die>> actual;
// Act
expected = new Dictionary<string, IEnumerable<Die>>();
actual = (Dictionary<string, IEnumerable<Die>>)diceGroupManager.GetAll();
// Assert
Xunit.Assert.Equal(expected, actual);
}
[Fact]
public void TestAddIfDieGroupThenDoAddAndDieGroup()
{
List<NumberFace> faces = new ();
faces.Add(new NumberFace(2));
faces.Add(new NumberFace(3));
faces.Add(new NumberFace(7));
NumberFace[] facesArr = faces.ToArray();
faces.Clear();
/* facesArr[0] = new NumberFace(2);
facesArr[1] = new NumberFace(3);
facesArr[2] = new NumberFace(7);*/
faces.Add(new NumberFace(3));
faces.Add(new NumberFace(5));
faces.Add(new NumberFace(6));
NumberFace[] facesArr1 = faces.ToArray();
/*facesArr1[0] = new NumberFace(3);
facesArr1[1] = new NumberFace(5);
facesArr1[2] = new NumberFace(6);
*/
Collection<Die> collectDie = new();
Dictionary<string, IEnumerable<Die>> diceGroupsActuel = new();
NumberDie die = new NumberDie(facesArr[0], facesArr[1..]);
NumberDie die2 = new NumberDie(facesArr1[0], facesArr1[1..]);
collectDie.Add(die);
collectDie.Add(die2);
Collection<Die> ExpectedDie = new();
ExpectedDie.Add(new NumberDie(new NumberFace(2), new NumberFace(3), new NumberFace(7)));
ExpectedDie.Add(new NumberDie(new NumberFace(3), new NumberFace(5), new NumberFace(6)));
Dictionary<string, IEnumerable<Die>> diceGroupExpected = new();//to ask direct initialization why cannot
diceGroupExpected.Add("Monopoly", ExpectedDie);
diceGroupsActuel.Add("Monopoly", collectDie);
CollectionAssert.AreEqual(collectDie, ExpectedDie);
}
}
}

@ -0,0 +1,63 @@
using Data;
using Model.Dice;
using Model.Games;
using System.Collections.Generic;
using System.Linq;
using Xunit;
namespace Tests.Model_UTs.Dice
{
public class DiceGroupManagerTest
{
private readonly MasterOfCeremonies stubGameRunner = new Stub().LoadApp();
[Fact]
public void TestConstructorReturnsEmptyEnumerable()
{
// Arrange
DiceGroupManager diceGroupManager = new();
Dictionary<string, IEnumerable<Die>> expected;
Dictionary<string, IEnumerable<Die>> actual;
// Act
expected = new Dictionary<string, IEnumerable<Die>>();
actual = (Dictionary<string, IEnumerable<Die>>)diceGroupManager.GetAll();
// Assert
Assert.Equal(expected, actual);
}
[Fact]
public void TestAddWhenDiceGroupThenDoAddAndReturnDiceGroup()
{
// Arrange
DiceGroupManager dgm = new();
KeyValuePair<string, IEnumerable<Die>> group1 = stubGameRunner.DiceGroupManager.GetAll().First();
KeyValuePair<string, IEnumerable<Die>> group2 = stubGameRunner.DiceGroupManager.GetAll().Last();
// Act
//...adding keys and values to some dictionary for future comparison
Dictionary<string, IEnumerable<Die>> expected = new()
{
{ group1.Key, group1.Value },
{ group2.Key, group2.Value }
};
//...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.Equal(expected, actual);
}
}
}

@ -8,7 +8,6 @@
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

Loading…
Cancel
Save