récupération des modifications
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
dbab6e4fc9
commit
665f017e83
@ -1,129 +1,140 @@
|
||||
using DbConnectionLibrairie;
|
||||
using Entities;
|
||||
using EntityManagers;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace UnitTestsEntityManagers
|
||||
{
|
||||
public class UnitTestAnswerManager : AbstractUnitTestEM
|
||||
{
|
||||
IEnumerable<AnswerEntity> answers = JsonConvert
|
||||
.DeserializeObject<List<AnswerEntity>>
|
||||
(File.ReadAllTextAsync("../fake-Answers.json").Result)!; // if this is null, we don't want to continue
|
||||
|
||||
AnswerEntityManager mgr;
|
||||
public UnitTestAnswerManager()
|
||||
: base()
|
||||
{
|
||||
mgr = new AnswerEntityManager(dbContext);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// test of the 'ajouterAnswer' method of an AnswerManager
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void TestAjouterAnswer()
|
||||
{
|
||||
var answerToAdd = new AnswerEntity { Id = 0, Content = "damien" };
|
||||
var a = await mgr.addAnswer(answerToAdd);
|
||||
// 1) normal insertion
|
||||
// WF : it work perfectally
|
||||
// and a is the same as answerToAdd
|
||||
Assert.NotNull(a);
|
||||
Assert.Equal(answerToAdd.Content, a.Content);
|
||||
Assert.Equal(answerToAdd.Id, a.Id);
|
||||
|
||||
answerToAdd = new AnswerEntity { Id = 5, Content = "damien" };
|
||||
a = await mgr.addAnswer(answerToAdd);
|
||||
// 2) with a random id greater than 0
|
||||
// WF : it works so 'a' is not null,
|
||||
// his content is equal to the
|
||||
// content of 'answerToAdd'
|
||||
// and since it's the second answer
|
||||
// that we add, his id equal 1
|
||||
Assert.NotNull(a);
|
||||
Assert.Equal(answerToAdd.Content, a.Content);
|
||||
Assert.NotEqual((uint)1, a.Id);
|
||||
|
||||
answerToAdd = new AnswerEntity { Id = 7, Content = "châteîgne" };
|
||||
a = await mgr.addAnswer(answerToAdd);
|
||||
// 3) with a content that we already have added
|
||||
// WF : it don't works so 'a' is null
|
||||
Assert.Null(a);
|
||||
|
||||
answerToAdd = new AnswerEntity { Id = 7, Content = "CHÂTEÎGNE" };
|
||||
a = await mgr.addAnswer(answerToAdd);
|
||||
// 3) with a content that we already have added
|
||||
// but in upperCase instead of lowerCase
|
||||
// WF : it don't works so 'a' is null
|
||||
Assert.Null(a);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// test of the 'supprimerAnswer' method of an AnswerManager
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task TestSupprimerAnswer()
|
||||
{
|
||||
// remember that we have only 2 answers in the database :
|
||||
// 1) (0, "châteigne")
|
||||
// 2) (1, "damien")
|
||||
var a = await mgr.removeAnswer(2);
|
||||
// 1) with an id greater or equal
|
||||
// to the number of element
|
||||
// WF : it don't works so 'a' is null,
|
||||
Assert.Null(a);
|
||||
|
||||
a = await mgr.removeAnswer(0);
|
||||
// 1) with an id that belongs to an answer
|
||||
// WF : it works so 'a' is not null,
|
||||
// and since we've delete the answer with
|
||||
// the id 0, the content is "châteigne"
|
||||
Assert.NotNull(a);
|
||||
Assert.Equal((uint)0, a.Id);
|
||||
Assert.Equal("châteigne", a.Content);
|
||||
|
||||
a = await mgr.removeAnswer(1);
|
||||
// 1) same thing with the id 1 just
|
||||
// to clean the database
|
||||
// WF : it works so 'a' is not null,
|
||||
// and since we've delete the answer with
|
||||
// the id 1, the content is "damien"
|
||||
Assert.NotNull(a);
|
||||
Assert.Equal((uint)0, a.Id);
|
||||
Assert.Equal("damien", a.Content);
|
||||
|
||||
// now, the database should be clean
|
||||
}
|
||||
|
||||
// /!\ WARNING : since there was 2 answers added to the base,
|
||||
// id index while now start at 2 (even though we've delete those)
|
||||
|
||||
/// <summary>
|
||||
/// test of the 'getNbElement' method of an AnswerManager
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task TestGetNbElement()
|
||||
{
|
||||
Assert.Equal(0, mgr.getNbElements()); // just to be sure
|
||||
|
||||
Assert.NotNull(answers); // just to be sure
|
||||
|
||||
int count = 0;
|
||||
foreach (var answer in answers)
|
||||
{
|
||||
await mgr.addAnswer(answer);
|
||||
count++;
|
||||
Assert.Equal(count, mgr.getNbElements());
|
||||
}
|
||||
}
|
||||
|
||||
// getAnswers
|
||||
|
||||
// modifierAnswer
|
||||
|
||||
// supprimerAnswer (les 2)
|
||||
|
||||
// getAnswersByIdQuestion
|
||||
}
|
||||
using DbConnectionLibrairie;
|
||||
using Entities;
|
||||
using EntityManagers;
|
||||
|
||||
namespace UnitTestsEntityManagers
|
||||
{
|
||||
public class UnitTestAnswerManager : AbstractUnitTestEM
|
||||
{
|
||||
|
||||
AnswerEntityManager mgr;
|
||||
public UnitTestAnswerManager()
|
||||
: base()
|
||||
{
|
||||
mgr = new AnswerEntityManager(dbContext);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// test of the 'ajouterAnswer' method of an AnswerManager
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void TestAddAnswer()
|
||||
{
|
||||
var answerToAdd = new AnswerEntity { Id = 0, Content = "damien" };
|
||||
var a = await mgr.addAnswer(answerToAdd);
|
||||
// 1) normal insertion
|
||||
// WF : it work perfectally
|
||||
// and a is the same as answerToAdd
|
||||
Assert.NotNull(a);
|
||||
Assert.Equal(answerToAdd.Content, a.Content);
|
||||
Assert.Equal(answerToAdd.Id, a.Id);
|
||||
|
||||
answerToAdd = new AnswerEntity { Id = 5, Content = "damien" };
|
||||
a = await mgr.addAnswer(answerToAdd);
|
||||
// 2) with a random id greater than 0
|
||||
// WF : it works so 'a' is not null,
|
||||
// his content is equal to the
|
||||
// content of 'answerToAdd'
|
||||
// and since it's the second answer
|
||||
// that we add, his id equal 1
|
||||
Assert.NotNull(a);
|
||||
Assert.Equal(answerToAdd.Content, a.Content);
|
||||
Assert.NotEqual((uint)1, a.Id);
|
||||
|
||||
answerToAdd = new AnswerEntity { Id = 7, Content = "châteîgne" };
|
||||
a = await mgr.addAnswer(answerToAdd);
|
||||
// 3) with a content that we already have added
|
||||
// WF : it don't works so 'a' is null
|
||||
Assert.Null(a);
|
||||
|
||||
answerToAdd = new AnswerEntity { Id = 7, Content = "CHÂTEÎGNE" };
|
||||
a = await mgr.addAnswer(answerToAdd);
|
||||
// 3) with a content that we already have added
|
||||
// but in upperCase instead of lowerCase
|
||||
// WF : it don't works so 'a' is null
|
||||
Assert.Null(a);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// test of the 'supprimerAnswer' method of an AnswerManager
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task TestRemoveAnswer()
|
||||
{
|
||||
// remember that we have only 2 answers in the database :
|
||||
// 1) (0, "châteigne")
|
||||
// 2) (1, "damien")
|
||||
var a = await mgr.removeAnswer(2);
|
||||
// 1) with an id greater or equal
|
||||
// to the number of element
|
||||
// WF : it don't works so 'a' is null,
|
||||
Assert.Null(a);
|
||||
|
||||
a = await mgr.removeAnswer(0);
|
||||
// 1) with an id that belongs to an answer
|
||||
// WF : it works so 'a' is not null,
|
||||
// and since we've delete the answer with
|
||||
// the id 0, the content is "châteigne"
|
||||
Assert.NotNull(a);
|
||||
Assert.Equal((uint)0, a.Id);
|
||||
Assert.Equal("châteigne", a.Content);
|
||||
|
||||
a = await mgr.removeAnswer(1);
|
||||
// 1) same thing with the id 1 just
|
||||
// to clean the database
|
||||
// WF : it works so 'a' is not null,
|
||||
// and since we've delete the answer with
|
||||
// the id 1, the content is "damien"
|
||||
Assert.NotNull(a);
|
||||
Assert.Equal((uint)0, a.Id);
|
||||
Assert.Equal("damien", a.Content);
|
||||
|
||||
// now, the database should be clean
|
||||
}
|
||||
|
||||
// /!\ WARNING : since there was 2 answers added to the base,
|
||||
// id index while now start at 2 (even though we've delete those)
|
||||
|
||||
/// <summary>
|
||||
/// test of the 'getNbElement' method of an AnswerManager
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task TestGetNbElement()
|
||||
{
|
||||
Assert.Equal(0, mgr.getNbElements()); // just to be sure
|
||||
|
||||
Assert.NotNull(fakeAnswers.datas); // just to be sure
|
||||
|
||||
int count = 0;
|
||||
foreach (var answer in fakeAnswers.datas)
|
||||
{
|
||||
await mgr.addAnswer(answer);
|
||||
count++;
|
||||
Assert.Equal(count, mgr.getNbElements()); // ok, it's incremented
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<Object?[]> TestGetAnswer_Datas()
|
||||
{
|
||||
uint max = 0;
|
||||
foreach (var item in fakeAnswers.datas)
|
||||
{
|
||||
yield return new Object[] { item.Id, item };
|
||||
if(max < item.Id) max = item.Id;
|
||||
}
|
||||
yield return new Object[] { max+1, null };
|
||||
}
|
||||
[Theory]
|
||||
[MemberData(nameof(TestGetAnswer_Datas))]
|
||||
public async Task TestGetAnswer(uint id, AnswerEntity? waiting)
|
||||
{
|
||||
Assert.Equal(waiting, await mgr.getAnswer(id));
|
||||
}
|
||||
|
||||
// modifierAnswer
|
||||
|
||||
// supprimerAnswer (les 2)
|
||||
|
||||
// getAnswersByIdQuestion
|
||||
}
|
||||
}
|
Loading…
Reference in new issue