|
|
@ -264,46 +264,47 @@ void TestGetAnswer(MyDbContext context, int numTest, int id, AnswerEntity? waiti
|
|
|
|
/// member data for the 'TestGetAnswer' test method
|
|
|
|
/// member data for the 'TestGetAnswer' test method
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>a set of all inline datas for the test method</returns>
|
|
|
|
/// <returns>a set of all inline datas for the test method</returns>
|
|
|
|
(int numPage, int count, IEnumerable<AnswerEntity>? waiting, AnswerOrderCriteria? orderCriteria)[] TestGetSomeAnswers_Datas()
|
|
|
|
(int numPage, int count, IEnumerable<AnswerEntity>? waiting, AnswerOrderCriteria? orderCriteria)[] TestGetSomeAnswers_Datas(MyDbContext context)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var datas = fakeAnswers.datas;
|
|
|
|
var datas = context.Answers;
|
|
|
|
|
|
|
|
var datas2 = context.Answers.OrderBy(a => a.Content);
|
|
|
|
var count = datas.Count();
|
|
|
|
var count = datas.Count();
|
|
|
|
// remind that to add answers, we haven't ordered this collection
|
|
|
|
// remind that to add answers, we haven't ordered this collection
|
|
|
|
// but we just have done a foreach
|
|
|
|
// but we just have done a foreach
|
|
|
|
|
|
|
|
|
|
|
|
return [
|
|
|
|
return [
|
|
|
|
// 1 : 0 answer from the page 1 then, -1 answer from this page
|
|
|
|
// 1/2 : 0 answer from the page 1 then, -1 answer from this page
|
|
|
|
// WF : count < 1 so we got null
|
|
|
|
// WF : count < 1 so we got null
|
|
|
|
(1, 0, null, null),
|
|
|
|
(1, 0, null, null),
|
|
|
|
(1, -1, null, null),
|
|
|
|
(1, -1, null, null),
|
|
|
|
// 2 : 1 answers from the page 0 then, 1 answers from the page -1
|
|
|
|
// 3/4 : 1 answers from the page 0 then, 1 answers from the page -1
|
|
|
|
// WF : page < 1 so we got null
|
|
|
|
// WF : page < 1 so we got null
|
|
|
|
(0, 1, null, null),
|
|
|
|
(0, 1, null, null),
|
|
|
|
(-1, 1, null, null),
|
|
|
|
(-1, 1, null, null),
|
|
|
|
// 3 : 10 answers from the page 1
|
|
|
|
// 5 : 10 answers from the page 1
|
|
|
|
// WF : the first 10 element of datas
|
|
|
|
// WF : the first 10 element of datas
|
|
|
|
(1, 10, datas.Take(10), null),
|
|
|
|
(1, 10, datas.Take(10), null),
|
|
|
|
// 4 : 10 elements from the page 1 order by id
|
|
|
|
// 6 : 10 elements from the page 1 order by id
|
|
|
|
// WF : the first 10 element of datas order by id
|
|
|
|
// WF : the first 10 element of datas order by id
|
|
|
|
(1, 10, datas.OrderBy(e => e.Id).Take(10), AnswerOrderCriteria.ById),
|
|
|
|
(1, 10, datas.OrderBy(e => e.Id).Take(10), AnswerOrderCriteria.ById),
|
|
|
|
// 5 : 10 elements from the page 1 order by content
|
|
|
|
// 7 : 10 elements from the page 1 order by content
|
|
|
|
// WF : the first 10 element of datas order by content
|
|
|
|
// WF : the first 10 element of datas order by content
|
|
|
|
(1, 10, datas.OrderBy(e => e.Content).Take(10), AnswerOrderCriteria.ById),
|
|
|
|
(1, 10, datas2.Take(10), AnswerOrderCriteria.ByContent),
|
|
|
|
// 6 : repeat 3, 4 and 5 with the page 2
|
|
|
|
// 8/9/10 : repeat 3, 4 and 5 with the page 2
|
|
|
|
// WF : the 10 next answer from each case
|
|
|
|
// WF : the 10 next answer from each case
|
|
|
|
(2, 10, datas.Skip(10).Take(10), null),
|
|
|
|
(2, 10, datas.Skip(10).Take(10), null),
|
|
|
|
(1, 10, datas.OrderBy(e => e.Id).Skip(10).Take(10), AnswerOrderCriteria.ById),
|
|
|
|
(2, 10, datas.OrderBy(e => e.Id).Skip(10).Take(10), AnswerOrderCriteria.ById),
|
|
|
|
(1, 10, datas.OrderBy(e => e.Content).Skip(10).Take(10), AnswerOrderCriteria.ByContent),
|
|
|
|
(2, 10, datas2.Skip(10).Take(10), AnswerOrderCriteria.ByContent),
|
|
|
|
// 7 : count/4 elements from the page 4
|
|
|
|
// 11 : count/4 elements from the page 4
|
|
|
|
// WF : the lasts count/4 elements of datas
|
|
|
|
// WF : the lasts count/4 elements of datas
|
|
|
|
(4, count / 4, datas.TakeLast(count / 4), null),
|
|
|
|
(4, count / 4, datas.Skip(3*count/4).Take(count/4), null),
|
|
|
|
// 8 : count/4 elements from the page 5
|
|
|
|
// 12 : count/4 elements from the page 5
|
|
|
|
// WF : null since num (4) >= count / (count/4)
|
|
|
|
// WF : null since num (4) >= count / (count/4)
|
|
|
|
(5, count / 4, null, null),
|
|
|
|
(3, count / 2, null, null),
|
|
|
|
// 9 : 10 elements from the page 4
|
|
|
|
// 13 : 7 elements from the page 5
|
|
|
|
// WF : since there's only 31 elements in fake datas,
|
|
|
|
// WF : since there's only 30 elements in fake datas,
|
|
|
|
// we got the last element
|
|
|
|
// we got the 2 last elements
|
|
|
|
(4, 10, datas.TakeLast(1), null)
|
|
|
|
(5, 7, datas.Skip(28).Take(2), null)
|
|
|
|
];
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -317,12 +318,13 @@ void TestGetAnswer(MyDbContext context, int numTest, int id, AnswerEntity? waiti
|
|
|
|
/// <returns>nothing but a Task</returns>
|
|
|
|
/// <returns>nothing but a Task</returns>
|
|
|
|
void TestGetSomeAnswers(MyDbContext context, int numTest, int num, int count, List<AnswerEntity>? waiting, AnswerOrderCriteria? orderCriteria)
|
|
|
|
void TestGetSomeAnswers(MyDbContext context, int numTest, int num, int count, List<AnswerEntity>? waiting, AnswerOrderCriteria? orderCriteria)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
context.Database.EnsureCreated();
|
|
|
|
|
|
|
|
var mgr = new AnswerEntityManager(context);
|
|
|
|
var mgr = new AnswerEntityManager(context);
|
|
|
|
|
|
|
|
|
|
|
|
var nbPages = count == 0 ? -1 : mgr.getNbAnswers() / count;
|
|
|
|
float nbPages = count == 0 ? -1 : (float)mgr.getNbAnswers() / count;
|
|
|
|
|
|
|
|
if (nbPages != (int)nbPages) nbPages++;
|
|
|
|
|
|
|
|
|
|
|
|
(int nbPages, IEnumerable<AnswerEntity>? answers) tmp = orderCriteria == null ? mgr.getAnswers(num, count).Result : mgr.getAnswers(num, count, orderCriteria.Value).Result;
|
|
|
|
(int nbPages, IEnumerable<AnswerEntity>? answers) tmp = orderCriteria == null ? mgr.getAnswers(num, count).Result : mgr.getAnswers(num, count, orderCriteria.Value).Result;
|
|
|
|
if(tmp.nbPages == nbPages){
|
|
|
|
if(tmp.nbPages == (int) nbPages){
|
|
|
|
Console.ForegroundColor = ConsoleColor.Green;
|
|
|
|
Console.ForegroundColor = ConsoleColor.Green;
|
|
|
|
Console.WriteLine($"test {2*numTest} AnswerEntityManager.getSomeAnswers OK");
|
|
|
|
Console.WriteLine($"test {2*numTest} AnswerEntityManager.getSomeAnswers OK");
|
|
|
|
Console.ResetColor();
|
|
|
|
Console.ResetColor();
|
|
|
@ -348,10 +350,10 @@ void TestGetSomeAnswers(MyDbContext context, int numTest, int num, int count, Li
|
|
|
|
Console.WriteLine($"test {2*numTest + 1} AnswerEntityManager.getSomeAnswers OK");
|
|
|
|
Console.WriteLine($"test {2*numTest + 1} AnswerEntityManager.getSomeAnswers OK");
|
|
|
|
Console.ResetColor();
|
|
|
|
Console.ResetColor();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(waiting.Count() != 0 && tmp.answers.Count() == 0)
|
|
|
|
else if(waiting.Count() != 0 && tmp.answers.Count() != 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var nbFautes = 0;
|
|
|
|
var nbFautes = 0;
|
|
|
|
for (var i = 0; i < count; i++)
|
|
|
|
for (var i = 0; i < waiting.Count(); i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var e1 = waiting!.ElementAt(i);
|
|
|
|
var e1 = waiting!.ElementAt(i);
|
|
|
|
var e2 = tmp.answers!.ElementAt(i);
|
|
|
|
var e2 = tmp.answers!.ElementAt(i);
|
|
|
@ -374,16 +376,19 @@ void TestGetSomeAnswers(MyDbContext context, int numTest, int num, int count, Li
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Console.Write("{ ");
|
|
|
|
Console.Write("{ ");
|
|
|
|
tmp.answers.ToList().ForEach(a => Console.Write("{" + $"id : {a.Id}, content : {a.Content}" + "}, "));
|
|
|
|
tmp.answers.ToList().ForEach(a => Console.Write("{" + $"{a.Id}" + "}, ")); // I know that I use sames collections
|
|
|
|
Console.WriteLine("}");
|
|
|
|
Console.WriteLine("}");
|
|
|
|
|
|
|
|
Console.WriteLine($"([{tmp.answers.Select(a => a.Id).Min()}, {tmp.answers.Select(a => a.Id).Max()}], {tmp.answers.Count()})");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Console.WriteLine();
|
|
|
|
Console.Write("WF : ");
|
|
|
|
Console.Write("WF : ");
|
|
|
|
if (waiting == null) Console.WriteLine("null");
|
|
|
|
if (waiting == null) Console.WriteLine("null");
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Console.Write("{ ");
|
|
|
|
Console.Write("{ ");
|
|
|
|
waiting.ForEach(a => Console.Write("{" + $"id : {a.Id}, content : {a.Content}" + "}, "));
|
|
|
|
waiting.ForEach(a => Console.Write("{" + $"{a.Id}" + "}, "));
|
|
|
|
Console.WriteLine("}");
|
|
|
|
Console.WriteLine("}");
|
|
|
|
|
|
|
|
Console.WriteLine($"([{waiting.Select(a => a.Id).Min()}, {waiting.Select(a => a.Id).Max()}], {waiting.Count()})");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -398,16 +403,19 @@ void TestGetSomeAnswers(MyDbContext context, int numTest, int num, int count, Li
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Console.Write("{ ");
|
|
|
|
Console.Write("{ ");
|
|
|
|
tmp.answers.ToList().ForEach(a => Console.Write("{" + $"id : {a.Id}, content : {a.Content}" + "}, "));
|
|
|
|
tmp.answers.ToList().ForEach(a => Console.Write("{" + $"{a.Id}" + "}, "));
|
|
|
|
Console.WriteLine("}");
|
|
|
|
Console.WriteLine("}");
|
|
|
|
|
|
|
|
Console.WriteLine($"([{tmp.answers.Select(a => a.Id).Min()}, {tmp.answers.Select(a => a.Id).Max()}], {tmp.answers.Count()})");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Console.WriteLine();
|
|
|
|
Console.Write("WF : ");
|
|
|
|
Console.Write("WF : ");
|
|
|
|
if (waiting == null) Console.WriteLine("null");
|
|
|
|
if (waiting == null) Console.WriteLine("null");
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Console.Write("{ ");
|
|
|
|
Console.Write("{ ");
|
|
|
|
waiting.ForEach(a => Console.Write("{" + $"id : {a.Id}, content : {a.Content}" + "}, "));
|
|
|
|
waiting.ForEach(a => Console.Write("{" + $"{a.Id}" + "}, "));
|
|
|
|
Console.WriteLine("}");
|
|
|
|
Console.WriteLine("}");
|
|
|
|
|
|
|
|
Console.WriteLine($"([{waiting.Select(a => a.Id).Min()}, {waiting.Select(a => a.Id).Max()}], {waiting.Count()})");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -422,16 +430,19 @@ void TestGetSomeAnswers(MyDbContext context, int numTest, int num, int count, Li
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Console.Write("{ ");
|
|
|
|
Console.Write("{ ");
|
|
|
|
tmp.answers.ToList().ForEach(a => Console.Write("{" + $"id : {a.Id}, content : {a.Content}" + "}, "));
|
|
|
|
tmp.answers.ToList().ForEach(a => Console.Write("{" + $"{a.Id}" + "}, "));
|
|
|
|
Console.WriteLine("}");
|
|
|
|
Console.WriteLine("}");
|
|
|
|
|
|
|
|
Console.WriteLine($"([{tmp.answers.Select(a => a.Id).Min()}, {tmp.answers.Select(a => a.Id).Max()}], {tmp.answers.Count()})");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Console.WriteLine();
|
|
|
|
Console.Write("WF : ");
|
|
|
|
Console.Write("WF : ");
|
|
|
|
if (waiting == null) Console.WriteLine("null");
|
|
|
|
if (waiting == null) Console.WriteLine("null");
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Console.Write("{ ");
|
|
|
|
Console.Write("{ ");
|
|
|
|
waiting.ForEach(a => Console.Write("{" + $"id : {a.Id}, content : {a.Content}" + "}, "));
|
|
|
|
waiting.ForEach(a => Console.Write("{" + $"{a.Id}" + "}, "));
|
|
|
|
Console.WriteLine("}");
|
|
|
|
Console.WriteLine("}");
|
|
|
|
|
|
|
|
Console.WriteLine($"([{waiting.Select(a => a.Id).Min()}, {waiting.Select(a => a.Id).Max()}], {waiting.Count()})");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -576,7 +587,7 @@ void TestAnswer(MyDbContext context)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var tmp = TestGetSomeAnswers_Datas();
|
|
|
|
var tmp = TestGetSomeAnswers_Datas(context);
|
|
|
|
for (int i = 0; i < tmp.Count(); i++)
|
|
|
|
for (int i = 0; i < tmp.Count(); i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
TestGetSomeAnswers(
|
|
|
|
TestGetSomeAnswers(
|
|
|
|