|
|
@ -7,7 +7,7 @@ namespace UnitTestsEntityManagers
|
|
|
|
public class UnitTestAnswerManager : AbstractUnitTestEM
|
|
|
|
public class UnitTestAnswerManager : AbstractUnitTestEM
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
AnswerEntityManager mgr;
|
|
|
|
private AnswerEntityManager mgr;
|
|
|
|
public UnitTestAnswerManager()
|
|
|
|
public UnitTestAnswerManager()
|
|
|
|
: base()
|
|
|
|
: base()
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -20,39 +20,42 @@ namespace UnitTestsEntityManagers
|
|
|
|
[Fact]
|
|
|
|
[Fact]
|
|
|
|
public async void TestAddAnswer()
|
|
|
|
public async void TestAddAnswer()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var answerToAdd = new AnswerEntity { Id = 0, Content = "damien" };
|
|
|
|
var answerToAdd = new AnswerEntity { Id = 1, Content = "chateîgne" };
|
|
|
|
var a = await mgr.addAnswer(answerToAdd);
|
|
|
|
var a = await mgr.addAnswer(answerToAdd);
|
|
|
|
// 1) normal insertion
|
|
|
|
// 1) normal insertion
|
|
|
|
// WF : it work perfectally
|
|
|
|
// WF : a is the same
|
|
|
|
// and a is the same as answerToAdd
|
|
|
|
// as answerToAdd
|
|
|
|
Assert.NotNull(a);
|
|
|
|
|
|
|
|
Assert.Equal(answerToAdd.Content, a.Content);
|
|
|
|
Assert.Equal(answerToAdd.Content, a.Content);
|
|
|
|
Assert.Equal(answerToAdd.Id, a.Id);
|
|
|
|
Assert.Equal(answerToAdd.Id, a.Id);
|
|
|
|
|
|
|
|
|
|
|
|
answerToAdd = new AnswerEntity { Id = 5, Content = "damien" };
|
|
|
|
answerToAdd = new AnswerEntity { Id = 5, Content = "damien" };
|
|
|
|
a = await mgr.addAnswer(answerToAdd);
|
|
|
|
a = await mgr.addAnswer(answerToAdd);
|
|
|
|
// 2) with a random id greater than 0
|
|
|
|
// 2) with a random id greater than 0
|
|
|
|
// WF : it works so 'a' is not null,
|
|
|
|
// WF : 'a' content is equal to the
|
|
|
|
// his content is equal to the
|
|
|
|
|
|
|
|
// content of 'answerToAdd'
|
|
|
|
// content of 'answerToAdd'
|
|
|
|
// and since it's the second answer
|
|
|
|
// and since it's the second answer
|
|
|
|
// that we add, his id equal 1
|
|
|
|
// that we add, his id equal 2
|
|
|
|
Assert.NotNull(a);
|
|
|
|
|
|
|
|
Assert.Equal(answerToAdd.Content, a.Content);
|
|
|
|
Assert.Equal(answerToAdd.Content, a.Content);
|
|
|
|
Assert.NotEqual((uint)1, a.Id);
|
|
|
|
Assert.Equal((uint)2, a.Id);
|
|
|
|
|
|
|
|
|
|
|
|
answerToAdd = new AnswerEntity { Id = 7, Content = "châteîgne" };
|
|
|
|
answerToAdd = new AnswerEntity { Id = 7, Content = "chateîgne" };
|
|
|
|
a = await mgr.addAnswer(answerToAdd);
|
|
|
|
a = await mgr.addAnswer(answerToAdd);
|
|
|
|
// 3) with a content that we already have added
|
|
|
|
// 3) with a content that we already have added
|
|
|
|
// WF : it don't works so 'a' is null
|
|
|
|
// WF : the function return the answer which already
|
|
|
|
Assert.Null(a);
|
|
|
|
// have the same content so the content of 'a' is "châteigne"
|
|
|
|
|
|
|
|
// and his id is 1
|
|
|
|
|
|
|
|
Assert.Equal("chateîgne", a.Content);
|
|
|
|
|
|
|
|
Assert.Equal((uint)1, a.Id);
|
|
|
|
|
|
|
|
|
|
|
|
answerToAdd = new AnswerEntity { Id = 7, Content = "CHÂTEÎGNE" };
|
|
|
|
answerToAdd = new AnswerEntity { Id = 7, Content = "CHATEÎGNE" };
|
|
|
|
a = await mgr.addAnswer(answerToAdd);
|
|
|
|
a = await mgr.addAnswer(answerToAdd);
|
|
|
|
// 3) with a content that we already have added
|
|
|
|
// 3) with a content that we already have added
|
|
|
|
// but in upperCase instead of lowerCase
|
|
|
|
// but in upperCase instead of lowerCase
|
|
|
|
// WF : it don't works so 'a' is null
|
|
|
|
// WF : the function return the answer which
|
|
|
|
Assert.Null(a);
|
|
|
|
// already have the same content so the content
|
|
|
|
|
|
|
|
// of 'a' is "chateîgne" and his id is 1
|
|
|
|
|
|
|
|
Assert.Equal("chateîgne", a.Content);
|
|
|
|
|
|
|
|
Assert.Equal((uint)1, a.Id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
@ -62,38 +65,38 @@ namespace UnitTestsEntityManagers
|
|
|
|
public async Task TestRemoveAnswer()
|
|
|
|
public async Task TestRemoveAnswer()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// remember that we have only 2 answers in the database :
|
|
|
|
// remember that we have only 2 answers in the database :
|
|
|
|
// 1) (0, "châteigne")
|
|
|
|
// 1) (1, "châteigne")
|
|
|
|
// 2) (1, "damien")
|
|
|
|
// 2) (2, "damien")
|
|
|
|
var a = await mgr.removeAnswer(2);
|
|
|
|
var a = await mgr.removeAnswer(3);
|
|
|
|
// 1) with an id greater or equal
|
|
|
|
// 1) with an id greater or equal
|
|
|
|
// to the number of element
|
|
|
|
// to the number of element
|
|
|
|
// WF : it don't works so 'a' is null,
|
|
|
|
// WF : it don't works so 'a' is null,
|
|
|
|
Assert.Null(a);
|
|
|
|
Assert.Null(a);
|
|
|
|
|
|
|
|
|
|
|
|
a = await mgr.removeAnswer(0);
|
|
|
|
a = await mgr.removeAnswer(1);
|
|
|
|
// 1) with an id that belongs to an answer
|
|
|
|
// 1) with an id that belongs to an answer
|
|
|
|
// WF : it works so 'a' is not null,
|
|
|
|
// WF : it works so 'a' is not null,
|
|
|
|
// and since we've delete the answer with
|
|
|
|
// and since we've delete the answer with
|
|
|
|
// the id 0, the content is "châteigne"
|
|
|
|
// the id 1, the content is "châteigne"
|
|
|
|
Assert.NotNull(a);
|
|
|
|
Assert.NotNull(a);
|
|
|
|
Assert.Equal((uint)0, a.Id);
|
|
|
|
Assert.Equal((uint)1, a.Id);
|
|
|
|
Assert.Equal("châteigne", a.Content);
|
|
|
|
Assert.Equal("châteigne", a.Content);
|
|
|
|
|
|
|
|
|
|
|
|
a = await mgr.removeAnswer(1);
|
|
|
|
a = await mgr.removeAnswer(2);
|
|
|
|
// 1) same thing with the id 1 just
|
|
|
|
// 1) same thing with the id 1 just
|
|
|
|
// to clean the database
|
|
|
|
// to clean the database
|
|
|
|
// WF : it works so 'a' is not null,
|
|
|
|
// WF : it works so 'a' is not null,
|
|
|
|
// and since we've delete the answer with
|
|
|
|
// and since we've delete the answer with
|
|
|
|
// the id 1, the content is "damien"
|
|
|
|
// the id 2, the content is "damien"
|
|
|
|
Assert.NotNull(a);
|
|
|
|
Assert.NotNull(a);
|
|
|
|
Assert.Equal((uint)0, a.Id);
|
|
|
|
Assert.Equal((uint)2, a.Id);
|
|
|
|
Assert.Equal("damien", a.Content);
|
|
|
|
Assert.Equal("damien", a.Content);
|
|
|
|
|
|
|
|
|
|
|
|
// now, the database should be clean
|
|
|
|
// now, the database should be clean
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// /!\ WARNING : since there was 2 answers added to the base,
|
|
|
|
// /!\ WARNING : since there was 2 answers added to the base,
|
|
|
|
// id index while now start at 2 (even though we've delete those)
|
|
|
|
// id index while now start at 3 (even though we've delete those)
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// test of the 'getNbElement' method of an AnswerManager
|
|
|
|
/// test of the 'getNbElement' method of an AnswerManager
|
|
|
@ -116,8 +119,9 @@ namespace UnitTestsEntityManagers
|
|
|
|
|
|
|
|
|
|
|
|
public static IEnumerable<Object?[]> TestGetAnswer_Datas()
|
|
|
|
public static IEnumerable<Object?[]> TestGetAnswer_Datas()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
var datas = fakeAnswers.datas;
|
|
|
|
uint max = 0;
|
|
|
|
uint max = 0;
|
|
|
|
foreach (var item in fakeAnswers.datas)
|
|
|
|
foreach (var item in datas)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
yield return new Object[] { item.Id, item };
|
|
|
|
yield return new Object[] { item.Id, item };
|
|
|
|
if(max < item.Id) max = item.Id;
|
|
|
|
if(max < item.Id) max = item.Id;
|
|
|
@ -128,7 +132,8 @@ namespace UnitTestsEntityManagers
|
|
|
|
[MemberData(nameof(TestGetAnswer_Datas))]
|
|
|
|
[MemberData(nameof(TestGetAnswer_Datas))]
|
|
|
|
public async Task TestGetAnswer(uint id, AnswerEntity? waiting)
|
|
|
|
public async Task TestGetAnswer(uint id, AnswerEntity? waiting)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Assert.Equal(waiting, await mgr.getAnswer(id));
|
|
|
|
var tmp = await mgr.getAnswer(id + 2);
|
|
|
|
|
|
|
|
Assert.Equal(waiting?.Content, tmp?.Content);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// modifierAnswer
|
|
|
|
// modifierAnswer
|
|
|
|