fix : modification de manière à ce que les tests (avant l'exception) marchent
continuous-integration/drone/push Build is passing Details

API
Damien NORTIER 1 year ago
parent eb2e2154c9
commit 90cb29b943

@ -3,6 +3,7 @@ using Entities;
using EntityManagers;
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using Model;
using OrderCriterias;
using StubbedDbContextLibrary;
@ -37,7 +38,7 @@ void TestAddAnswer()
// 1) normal insertion
// WF : a is the same
// as answerToAdd
if (a.Content == answerToAdd.Content && a.Id == answerToAdd.Id)
if (a.Content == answerToAdd.Content && a.Id == answerToAdd.Id && context.Answers.Single(e => e.Id == a.Id).Content == a.Content)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("test 1 AnswerEntityManager.addAnswer OK");
@ -48,6 +49,8 @@ void TestAddAnswer()
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("test 1 AnswerEntityManager.addAnswer KO");
Console.ResetColor();
Console.WriteLine($"what we have : {a.Id} : {a.Content}");
Console.WriteLine($"WF : {answerToAdd.Id} : {answerToAdd.Content}");
}
answerToAdd = new AnswerEntity { Id = 5, Content = "damien" };
@ -57,7 +60,7 @@ void TestAddAnswer()
// content of 'answerToAdd'
// and since it's the second answer
// that we add, his id equal 2
if (a.Content == answerToAdd.Content && a.Id == 2)
if (a.Content == answerToAdd.Content && a.Id == 2 && context.Answers.Single(e => e.Id == 2).Content == a.Content)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("test 2 AnswerEntityManager.addAnswer OK");
@ -68,6 +71,8 @@ void TestAddAnswer()
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("test 2 AnswerEntityManager.addAnswer KO");
Console.ResetColor();
Console.WriteLine($"what we have : {a.Id} : {a.Content}");
Console.WriteLine($"WF : 2 : {answerToAdd.Content}");
}
answerToAdd = new AnswerEntity { Id = 7, Content = "chateîgne" };
@ -87,6 +92,8 @@ void TestAddAnswer()
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("test 3 AnswerEntityManager.addAnswer KO");
Console.ResetColor();
Console.WriteLine($"what we have : {a.Id} : {a.Content}");
Console.WriteLine($"WF : 1 : {answerToAdd.Content}");
}
answerToAdd = new AnswerEntity { Id = 7, Content = "CHATEÎGNE" };
@ -107,6 +114,8 @@ void TestAddAnswer()
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("test 4 AnswerEntityManager.addAnswer KO");
Console.ResetColor();
Console.WriteLine($"what we have : {a.Id} : {a.Content}");
Console.WriteLine($"WF : 1 : {answerToAdd.Content.ToLower()}");
}
foreach (var item in context.Answers) context.Answers.Remove(item); // we remove all database answers
context.SaveChanges();
@ -134,15 +143,18 @@ void TestRemoveAnswerById(MyDbContext context)
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("test 1 AnswerEntityManager.RemoveAnswer KO");
Console.ResetColor();
Console.WriteLine("what we have : " + a == null ? "null" : $"{a.Id} : {a.Content}");
Console.WriteLine("WF : null");
}
var answer = context.Answers.Single(a => a.Id == context.Answers.Select(a => a.Id).Min());
a = mgr.removeAnswer(context.Answers.Select(a => a.Id).Min()).Result;
// 1) with an id that is allowed to an answer
// WF : it works so 'a' is not null,
// and since we've delete the answer with
// the id 1, the content is "châteigne"
if (a != null && a.Content == context.Answers.Single(a => a.Id == context.Answers.Select(a => a.Id).Min()).Content
&& a.Id == context.Answers.Select(a => a.Id).Min())
if (a != null && a.Content == answer.Content
&& a.Id == answer.Id && a.Id != context.Answers.Select(a => a.Id).Min() /* <=> he is removed */)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("test 2 AnswerEntityManager.RemoveAnswer OK");
@ -153,6 +165,8 @@ void TestRemoveAnswerById(MyDbContext context)
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("test 2 AnswerEntityManager.RemoveAnswer KO");
Console.ResetColor();
Console.WriteLine("what we have : " + a == null ? "null" : $"{a.Id} : {a.Content}");
Console.WriteLine("WF : " + answer == null ? "null" : $"{answer.Id} : {answer.Content}");
}
}
@ -164,7 +178,20 @@ void TestGetNbAnswers(MyDbContext context)
var mgr = new AnswerEntityManager(context);
int count = context.Answers.CountAsync().Result;
int nb = 0;
foreach (var answer in fakeAnswers.datas)
var list = new List<AnswerEntity>()
{
new AnswerEntity { Content = "Ajout 1" },
new AnswerEntity { Content = "Ajout 2" },
new AnswerEntity { Content = "Ajout 3" },
new AnswerEntity { Content = "Ajout 4" },
new AnswerEntity { Content = "Ajout 5" },
new AnswerEntity { Content = "Ajout 6" },
new AnswerEntity { Content = "Ajout 7" },
new AnswerEntity { Content = "Ajout 8" },
new AnswerEntity { Content = "Ajout 9" },
new AnswerEntity { Content = "Ajout 10" }
};
foreach (var answer in list)
{
var tmp = mgr.addAnswer(answer).Result;
count++;
@ -180,6 +207,8 @@ void TestGetNbAnswers(MyDbContext context)
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"test {nb} AnswerEntityManager.getNbAnswers KO");
Console.ResetColor();
Console.WriteLine($"what we have : {mgr.getNbAnswers()}");
Console.WriteLine($"WF : {count}");
}
}
}

Loading…
Cancel
Save