|
|
|
@ -22,22 +22,19 @@ namespace UnitTestsEntityManagers
|
|
|
|
|
/// test of the 'ajouterAnswer' method of an AnswerManager
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Fact]
|
|
|
|
|
public void TestAjouterAnswer()
|
|
|
|
|
public async void TestAjouterAnswer()
|
|
|
|
|
{
|
|
|
|
|
var answerToAdd = new AnswerEntity { Id = -1, Content = "châteîgne" };
|
|
|
|
|
var a = mgr.ajouterAnswer(answerToAdd);
|
|
|
|
|
// 1) with an id less than 0
|
|
|
|
|
// WF : it works so 'a' is not null,
|
|
|
|
|
// his content is equal to the
|
|
|
|
|
// content of 'answerToAdd'
|
|
|
|
|
// and since it's the first answer
|
|
|
|
|
// that we add, his id equal 0
|
|
|
|
|
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.NotEqual(0, a.Id);
|
|
|
|
|
Assert.Equal(answerToAdd.Id, a.Id);
|
|
|
|
|
|
|
|
|
|
answerToAdd = new AnswerEntity { Id = 5, Content = "damien" };
|
|
|
|
|
a = mgr.ajouterAnswer(answerToAdd);
|
|
|
|
|
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
|
|
|
|
@ -46,16 +43,16 @@ namespace UnitTestsEntityManagers
|
|
|
|
|
// that we add, his id equal 1
|
|
|
|
|
Assert.NotNull(a);
|
|
|
|
|
Assert.Equal(answerToAdd.Content, a.Content);
|
|
|
|
|
Assert.NotEqual(1, a.Id);
|
|
|
|
|
Assert.NotEqual((uint)1, a.Id);
|
|
|
|
|
|
|
|
|
|
answerToAdd = new AnswerEntity { Id = 7, Content = "châteîgne" };
|
|
|
|
|
a = mgr.ajouterAnswer(answerToAdd);
|
|
|
|
|
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 = mgr.ajouterAnswer(answerToAdd);
|
|
|
|
|
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
|
|
|
|
@ -66,40 +63,34 @@ namespace UnitTestsEntityManagers
|
|
|
|
|
/// test of the 'supprimerAnswer' method of an AnswerManager
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Fact]
|
|
|
|
|
public void TestSupprimerAnswer()
|
|
|
|
|
public async Task TestSupprimerAnswer()
|
|
|
|
|
{
|
|
|
|
|
// remember that we have only 2 answers in the database :
|
|
|
|
|
// 1) (0, "châteigne")
|
|
|
|
|
// 2) (1, "damien")
|
|
|
|
|
var a = mgr.supprimerAnswer(-3);
|
|
|
|
|
// 1) with an id less than 0
|
|
|
|
|
// WF : it don't work because there's no
|
|
|
|
|
// negative id so 'a' is null
|
|
|
|
|
Assert.Null(a);
|
|
|
|
|
|
|
|
|
|
a = mgr.supprimerAnswer(3);
|
|
|
|
|
// 2) with an id greater or equal
|
|
|
|
|
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 = mgr.supprimerAnswer(0);
|
|
|
|
|
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(0, a.Id);
|
|
|
|
|
Assert.Equal((uint)0, a.Id);
|
|
|
|
|
Assert.Equal("châteigne", a.Content);
|
|
|
|
|
|
|
|
|
|
a = mgr.supprimerAnswer(0);
|
|
|
|
|
a = await mgr.removeAnswer(1);
|
|
|
|
|
// 1) same thing with the id 1 just
|
|
|
|
|
// for cleaning the database
|
|
|
|
|
// 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(0, a.Id);
|
|
|
|
|
Assert.Equal((uint)0, a.Id);
|
|
|
|
|
Assert.Equal("damien", a.Content);
|
|
|
|
|
|
|
|
|
|
// now, the database should be clean
|
|
|
|
@ -112,18 +103,18 @@ namespace UnitTestsEntityManagers
|
|
|
|
|
/// test of the 'getNbElement' method of an AnswerManager
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Fact]
|
|
|
|
|
public void TestGetNbElement()
|
|
|
|
|
public async Task TestGetNbElement()
|
|
|
|
|
{
|
|
|
|
|
Assert.Equal(0, mgr.getNbElement()); // just to be sure
|
|
|
|
|
Assert.Equal(0, mgr.getNbElements()); // just to be sure
|
|
|
|
|
|
|
|
|
|
Assert.NotNull(answers); // just to be sure
|
|
|
|
|
|
|
|
|
|
int count = 0;
|
|
|
|
|
foreach (var answer in answers)
|
|
|
|
|
{
|
|
|
|
|
mgr.ajouterAnswer(answer);
|
|
|
|
|
await mgr.addAnswer(answer);
|
|
|
|
|
count++;
|
|
|
|
|
Assert.Equal(count, mgr.getNbElement());
|
|
|
|
|
Assert.Equal(count, mgr.getNbElements());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|