diff --git a/WebApi/ServiceManagers/AnswerServiceManager.cs b/WebApi/ServiceManagers/AnswerServiceManager.cs index e4f88e4..49af335 100644 --- a/WebApi/ServiceManagers/AnswerServiceManager.cs +++ b/WebApi/ServiceManagers/AnswerServiceManager.cs @@ -31,17 +31,8 @@ namespace ServiceManagers public async Task<(int nbPages, IEnumerable? answers)> getAnswers(int nb, int count, AnswerOrderCriteria orderCriteria = AnswerOrderCriteria.ById) { - List? tmp = new List(); var res = await manager.getAnswers(nb, count, orderCriteria); - if (res.answers == null) tmp = null; - else - { - foreach (var item in res.answers) - { - tmp.Add(item.ToDto()); - } - } - return (res.nbPages, tmp); + return (res.nbPages, res.answers?.Select(a => a.ToDto())); } public async Task?> getAnswersByIdQuestion(int id) diff --git a/WebApi/TestServiceManagers/Program.cs b/WebApi/TestServiceManagers/Program.cs new file mode 100644 index 0000000..488779f --- /dev/null +++ b/WebApi/TestServiceManagers/Program.cs @@ -0,0 +1,641 @@ +using DataManagers; +using DbConnectionLibrairie; +using DTOs; +using EntityManagers; +using ExtensionsClassLibrairie; +using Microsoft.Data.Sqlite; +using Microsoft.EntityFrameworkCore; +using Model; +using OrderCriterias; +using ServiceManagers; +using StubbedDbContextLibrary; + +// for each test, 'WF' mean 'waiting for' + +/// +/// test of the 'addAnswer' method of an AnswerManager +/// +void TestAddAnswer() +{ + var connection = new SqliteConnection("DataSource=:memory:"); + + connection.Open(); + + var opt = new DbContextOptionsBuilder() + .UseSqlite(connection) + .Options; + using (var context = new MyDbContext(opt)) + { + context.Database.EnsureCreated(); + var manager = new AnswerServiceManager(new AnswerDataManager(new AnswerEntityManager(context))); + var answerToAdd = new AnswerDto { Id = 1, Content = "chateîgne" }; + var a = manager.addAnswer(answerToAdd).Result; + // 1) normal insertion + // WF : a is the same + // as answerToAdd + 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 AnswerServiceManager.addAnswer OK"); + Console.ResetColor(); + } + else + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine("test 1 AnswerServiceManager.addAnswer KO"); + Console.ResetColor(); + Console.WriteLine($"what we have : {a.Id} : {a.Content}"); + Console.WriteLine($"WF : {answerToAdd.Id} : {answerToAdd.Content}"); + } + + answerToAdd = new AnswerDto { Id = 5, Content = "damien" }; + a = manager.addAnswer(answerToAdd).Result; + // 2) with a random id greater than 0 + // WF : 'a' content is equal to the + // 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 && context.Answers.Single(e => e.Id == 2).Content == a.Content) + { + Console.ForegroundColor = ConsoleColor.Green; + Console.WriteLine("test 2 AnswerServiceManager.addAnswer OK"); + Console.ResetColor(); + } + else + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine("test 2 AnswerServiceManager.addAnswer KO"); + Console.ResetColor(); + Console.WriteLine($"what we have : {a.Id} : {a.Content}"); + Console.WriteLine($"WF : 2 : {answerToAdd.Content}"); + } + + answerToAdd = new AnswerDto { Id = 7, Content = "chateîgne" }; + a = manager.addAnswer(answerToAdd).Result; + // 3) with a content that we already have added + // WF : the function return the answer which already + // have the same content so the content of 'a' is "châteigne" + // and his id is 1 + if (a.Content == "chateîgne" && a.Id == 1) + { + Console.ForegroundColor = ConsoleColor.Green; + Console.WriteLine("test 3 AnswerServiceManager.addAnswer OK"); + Console.ResetColor(); + } + else + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine("test 3 AnswerServiceManager.addAnswer KO"); + Console.ResetColor(); + Console.WriteLine($"what we have : {a.Id} : {a.Content}"); + Console.WriteLine($"WF : 1 : {answerToAdd.Content}"); + } + + answerToAdd = new AnswerDto { Id = 7, Content = "CHATEÎGNE" }; + a = manager.addAnswer(answerToAdd).Result; + // 3) with a content that we already have added + // but in upperCase instead of lowerCase + // WF : the function return the answer which + // already have the same content so the content + // of 'a' is "chateîgne" and his id is 1 + if (a.Content == "chateîgne" && a.Id == 1) + { + Console.ForegroundColor = ConsoleColor.Green; + Console.WriteLine("test 4 AnswerServiceManager.addAnswer OK"); + Console.ResetColor(); + } + else + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine("test 4 AnswerServiceManager.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(); + } +} + +/// +/// test of the 'supprimerAnswer' method of an AnswerManager +/// +void TestRemoveAnswerById(MyDbContext context) +{ + var mgr = new AnswerServiceManager(new AnswerDataManager(new AnswerEntityManager(context))); + var a = mgr.removeAnswer(context.Answers.Select(a => a.Id).Max() + 1).Result; + // 1) with an id greater or equal + // to the number of element + // WF : it don't works so 'a' is null, + if (a == null) + { + Console.ForegroundColor = ConsoleColor.Green; + Console.WriteLine("test 1 AnswerServiceManager.removeAnswer OK"); + Console.ResetColor(); + } + else + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine("test 1 AnswerServiceManager.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 == 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 AnswerServiceManager.removeAnswer OK"); + Console.ResetColor(); + } + else + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine("test 2 AnswerServiceManager.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}"); + } +} + +/// +/// test of the 'getNbElement' method of an AnswerManager +/// +void TestGetNbAnswers() +{ + var connection = new SqliteConnection("DataSource=:memory:"); + + connection.Open(); + + var opt = new DbContextOptionsBuilder() + .UseSqlite(connection) + .Options; + using (var context = new MyDbContext(opt)) + { + context.Database.EnsureCreated(); + var mgr = new AnswerServiceManager(new AnswerDataManager(new AnswerEntityManager(context))); + int count = context.Answers.CountAsync().Result; + int nb = 0; + var list = new List() + { + new AnswerDto { Content = "Ajout 1" }, + new AnswerDto { Content = "Ajout 2" }, + new AnswerDto { Content = "Ajout 3" }, + new AnswerDto { Content = "Ajout 4" }, + new AnswerDto { Content = "Ajout 5" }, + new AnswerDto { Content = "Ajout 6" }, + new AnswerDto { Content = "Ajout 7" }, + new AnswerDto { Content = "Ajout 8" }, + new AnswerDto { Content = "Ajout 9" }, + new AnswerDto { Content = "Ajout 10" } + }; + foreach (var answer in list) + { + var tmp = mgr.addAnswer(answer).Result; + count++; + nb++; + if (mgr.getNbAnswers() == count) + { // ok, it's incremented + Console.ForegroundColor = ConsoleColor.Green; + Console.WriteLine($"test {nb} AnswerServiceManager.getNbAnswers OK"); + Console.ResetColor(); + } + else + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine($"test {nb} AnswerServiceManager.getNbAnswers KO"); + Console.ResetColor(); + Console.WriteLine($"what we have : {mgr.getNbAnswers()}"); + Console.WriteLine($"WF : {count}"); + } + } + } +} + +/// +/// member data for the 'TestGetAnswer' test method +/// +/// a set of all inline datas for the test method +(int id, AnswerDto? waiting)[] TestGetAnswer_Datas(MyDbContext context) +{ + var datas = context.Answers; + int max = 0; + (int id, AnswerDto? waiting)[] tmp = new (int id, AnswerDto? waiting)[] { }; + foreach (var item in datas) + { + tmp.Append((item.Id, item.ToDto())); + if (max < item.Id) max = item.Id; + } + tmp.Append((max + 1, null!)); + return tmp; +} + +/// +/// test of the 'getAnswer' method of an AnswerManager +/// +/// identifiant of the answer to get +/// answer expected +/// nothing but a Task +void TestGetAnswer(MyDbContext context, int numTest, int id, AnswerDto? waiting) +{ + context.Database.EnsureCreated(); + var mgr = new AnswerServiceManager(new AnswerDataManager(new AnswerEntityManager(context))); + + var tmp = mgr.getAnswer(id).Result; + if (tmp?.Content == waiting?.Content) + { + Console.ForegroundColor = ConsoleColor.Green; + Console.WriteLine($"test {numTest} AnswerServiceManager.getAnswer OK"); + Console.ResetColor(); + } + else + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine($"test {numTest} AnswerServiceManager.getAnswer KO"); + Console.ResetColor(); + } +} + +/// +/// member data for the 'TestGetAnswer' test method +/// +/// a set of all inline datas for the test method +(int numPage, int count, IEnumerable? waiting, AnswerOrderCriteria? orderCriteria)[] TestGetSomeAnswers_Datas(MyDbContext context) +{ + var tmp = context.Answers; + var datas = new List(); + foreach (var item in tmp) datas.Add(item.ToDto()); + var tmp2 = context.Answers.OrderBy(a => a.Content); + var datas2 = new List(); + foreach (var item in tmp2) datas2.Add(item.ToDto()); + var count = datas.Count(); + // remind that to add answers, we haven't ordered this collection + // but we just have done a foreach + + return [ + // 1/2 : 0 answer from the page 1 then, -1 answer from this page + // WF : count < 1 so we got null + (1, 0, null, null), + (1, -1, null, null), + // 3/4 : 1 answers from the page 0 then, 1 answers from the page -1 + // WF : page < 1 so we got null + (0, 1, null, null), + (-1, 1, null, null), + // 5 : 10 answers from the page 1 + // WF : the first 10 element of datas + (1, 10, datas.Take(10), null), + // 6 : 10 elements from the page 1 order by id + // WF : the first 10 element of datas order by id + (1, 10, datas.OrderBy(e => e.Id).Take(10), AnswerOrderCriteria.ById), + // 7 : 10 elements from the page 1 order by content + // WF : the first 10 element of datas order by content + (1, 10, datas2.Take(10), AnswerOrderCriteria.ByContent), + // 8/9/10 : repeat 3, 4 and 5 with the page 2 + // WF : the 10 next answer from each case + (2, 10, datas.Skip(10).Take(10), null), + (2, 10, datas.OrderBy(e => e.Id).Skip(10).Take(10), AnswerOrderCriteria.ById), + (2, 10, datas2.Skip(10).Take(10), AnswerOrderCriteria.ByContent), + // 11 : count/4 elements from the page 4 + // WF : the lasts count/4 elements of datas + (4, count / 4, datas.Skip(3*count/4).Take(count/4), null), + // 12 : count/4 elements from the page 5 + // WF : null since num (4) >= count / (count/4) + (3, count / 2, null, null), + // 13 : 7 elements from the page 5 + // WF : since there's only 30 elements in fake datas, + // we got the 2 last elements + (5, 7, datas.Skip(28).Take(2), null) + ]; +} + +/// +/// test of the 'getAnswer' method of an AnswerManager +/// +/// the page number +/// page elements number +/// set of answers expected +/// the order criteria +/// nothing but a Task +void TestGetSomeAnswers(MyDbContext context, int numTest, int num, int count, List? waiting, AnswerOrderCriteria? orderCriteria) +{ + var mgr = new AnswerServiceManager(new AnswerDataManager(new AnswerEntityManager(context))); + + float nbPages = count == 0 ? -1 : (float)mgr.getNbAnswers() / count; + if (nbPages != (int)nbPages) nbPages++; + + (int nbPages, IEnumerable? answers) tmp = orderCriteria == null ? mgr.getAnswers(num, count).Result : mgr.getAnswers(num, count, orderCriteria.Value).Result; + if (tmp.nbPages == (int)nbPages) + { + Console.ForegroundColor = ConsoleColor.Green; + Console.WriteLine($"test {2 * numTest} AnswerServiceManager.getSomeAnswers OK"); + Console.ResetColor(); + } + else + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine($"test {2 * numTest} AnswerServiceManager.getSomeAnswers KO"); + Console.ResetColor(); + } + + if (waiting == null && tmp.answers == null) + { + Console.ForegroundColor = ConsoleColor.Green; + Console.WriteLine($"test {2 * numTest + 1} AnswerServiceManager.getSomeAnswers OK"); + Console.ResetColor(); + } + else if (waiting != null && tmp.answers != null) + { + if (waiting.Count() == 0 && tmp.answers.Count() == 0) + { + Console.ForegroundColor = ConsoleColor.Green; + Console.WriteLine($"test {2 * numTest + 1} AnswerServiceManager.getSomeAnswers OK"); + Console.ResetColor(); + } + else if (waiting.Count() != 0 && tmp.answers.Count() != 0) + { + var nbFautes = 0; + for (var i = 0; i < waiting.Count(); i++) + { + var e1 = waiting!.ElementAt(i); + var e2 = tmp.answers!.ElementAt(i); + if (e2.Content != e1.Content || e2.IdQuestion != e1.IdQuestion) nbFautes++; + } + if (nbFautes == 0) + { + Console.ForegroundColor = ConsoleColor.Green; + Console.WriteLine($"test {2 * numTest + 1} AnswerServiceManager.getSomeAnswers OK"); + Console.ResetColor(); + } + else + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine($"test {2 * numTest + 1} AnswerServiceManager.getSomeAnswers KO"); + Console.ResetColor(); + Console.WriteLine($"numPage : {num}, count : {count}"); + Console.Write("what we have : "); + if (tmp.answers == null) Console.WriteLine("null"); + else + { + Console.Write("{ "); + tmp.answers.ToList().ForEach(a => Console.Write("{" + $"{a.Id}" + "}, ")); // I know that I use sames collections + 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 : "); + if (waiting == null) Console.WriteLine("null"); + else + { + Console.Write("{ "); + waiting.ForEach(a => Console.Write("{" + $"{a.Id}" + "}, ")); + Console.WriteLine("}"); + Console.WriteLine($"([{waiting.Select(a => a.Id).Min()}, {waiting.Select(a => a.Id).Max()}], {waiting.Count()})"); + } + } + } + else + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine($"test {2 * numTest + 1} AnswerServiceManager.getSomeAnswers KO"); + Console.ResetColor(); + Console.WriteLine($"numPage : {num}, count : {count}, nbEl : {mgr.getNbAnswers()}"); + Console.Write("what we have : "); + if (tmp.answers == null) Console.WriteLine("null"); + else + { + Console.Write("{ "); + tmp.answers.ToList().ForEach(a => Console.Write("{" + $"{a.Id}" + "}, ")); + 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 : "); + if (waiting == null) Console.WriteLine("null"); + else + { + Console.Write("{ "); + waiting.ForEach(a => Console.Write("{" + $"{a.Id}" + "}, ")); + Console.WriteLine("}"); + if(waiting.Count() != 0) Console.WriteLine($"([{waiting.Select(a => a.Id).Min()}, {waiting.Select(a => a.Id).Max()}], {waiting.Count()})"); + } + } + } + else + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine($"test {2 * numTest + 1} AnswerServiceManager.getSomeAnswers KO"); + Console.ResetColor(); + Console.WriteLine($"numPage : {num}, count : {count}"); + Console.Write("what we have : "); + if (tmp.answers == null) Console.WriteLine("null"); + else + { + Console.Write("{ "); + tmp.answers.ToList().ForEach(a => Console.Write("{" + $"{a.Id}" + "}, ")); + 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 : "); + if (waiting == null) Console.WriteLine("null"); + else + { + Console.Write("{ "); + waiting.ForEach(a => Console.Write("{" + $"{a.Id}" + "}, ")); + Console.WriteLine("}"); + Console.WriteLine($"([{waiting.Select(a => a.Id).Min()}, {waiting.Select(a => a.Id).Max()}], {waiting.Count()})"); + } + } +} + +/// +/// test of the 'supprimerAnswer' method of an AnswerManager +/// +void TestRemoveAnswer(MyDbContext context) +{ + var mgr = new AnswerServiceManager(new AnswerDataManager(new AnswerEntityManager(context))); + var a = mgr.removeAnswer(new AnswerDto { Content = "test remove answer" }).Result; + // 1) with an id greater or equal + // to the number of element + // WF : it don't works so 'a' is null, + if (a == null) + { + Console.ForegroundColor = ConsoleColor.Green; + Console.WriteLine("test 1 AnswerServiceManager.removeAnswer OK"); + Console.ResetColor(); + } + else + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine("test 1 AnswerServiceManager.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(answer.ToDto()).Result; + // 1) with a content that correspond 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 == 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 AnswerServiceManager.removeAnswer OK"); + Console.ResetColor(); + } + else + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine("test 2 AnswerServiceManager.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}"); + } +} + +(int id, AnswerDto modified, AnswerDto? waiting)[] TestUpdateAnswer_Datas(MyDbContext context) +{ + return new (int, AnswerDto, AnswerDto?)[] + { + // 1) with an id that is not allowed + // WF : since no answer match with this id, + // the function return null + ( + context.Answers.Select(a => a.Id).Max() + 1, + new AnswerDto + { + Id = 3, + Content = "we don't care about" + }, + null + ), + // 2) with a content that correspond to the content of another answer + // WF : since some answers can each have same content, it work + // and the id of the answer we got is the one we give (content.Answers.Select.(a => a.id.Min()) + // and his content is the one we want + ( + context.Answers.Select(a => a.Id).Min(), + new AnswerDto + { + Id = 5, + Content = context.Answers.Single(a => a.Id == context.Answers.Select(a => a.Id).Min()).Content, + }, + new AnswerDto + { + Id = context.Answers.Select(a => a.Id).Min(), + Content = context.Answers.Single(a => a.Id == context.Answers.Select(a => a.Id).Min()).Content, + } + ), + // 3) normal insertion + // WF : the id of the answer we got is the one we + // give (content.Answers.Select.(a => a.id.Min()) + // and his content is the one we want + ( + context.Answers.Select(a => a.Id).Max(), + new AnswerDto + { + Id = context.Answers.Select(a => a.Id).Min(), + Content = context.Answers.First().Content + }, + new AnswerDto + { + Id = context.Answers.Select(a => a.Id).Max(), + Content = context.Answers.First().Content + } + ) + }; +} + +void TestUpdateAnswer(MyDbContext context, int numTest, int id, AnswerDto modified, AnswerDto? waiting) +{ + var mgr = new AnswerServiceManager(new AnswerDataManager(new AnswerEntityManager(context))); + var response = mgr.updateAnswer(id, modified).Result; + if ((waiting == null && response == null) || (waiting != null && response != null && response.Id == id && response.Content == waiting.Content)) + { + Console.ForegroundColor = ConsoleColor.Green; + Console.WriteLine($"test {numTest} AnswerServiceManager.updateAnswer OK"); + Console.ResetColor(); + } + else + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine("test 2 AnswerServiceManager.removeAnswer KO"); + Console.ResetColor(); + Console.WriteLine("what we have : " + response == null ? "null" : $"{id} : {response!.Content}"); + Console.WriteLine("WF : " + waiting == null ? "null" : $"{waiting!.Id} : {waiting.Content}"); + } +} + +// Tests of an answer +void TestAnswer(MyDbContext context) +{ + TestAddAnswer(); + TestRemoveAnswerById(context); + TestGetNbAnswers(); + { + var tmp = TestGetAnswer_Datas(context); + for (int i = 0; i < tmp.Count(); i++) + { + TestGetAnswer( + context, + i + 1, + tmp.ElementAt(i).id, + tmp.ElementAt(i).waiting + ); + } + } + { + var tmp = TestGetSomeAnswers_Datas(context); + for (int i = 0; i < tmp.Count(); i++) + { + TestGetSomeAnswers( + context, + i + 1, + tmp.ElementAt(i).numPage, + tmp.ElementAt(i).count, + tmp.ElementAt(i).waiting?.ToList(), + tmp.ElementAt(i).orderCriteria + ); + } + } + TestRemoveAnswer(context); + { + var tmp = TestUpdateAnswer_Datas(context); + for (int i = 0; i < tmp.Count(); i++) + { + TestUpdateAnswer( + context, + i + 1, + tmp.ElementAt(i).id, + tmp.ElementAt(i).modified, + tmp.ElementAt(i).waiting + ); + } + } +} + +void Test(MyDbContext context) +{ + TestAnswer(context); +} + +var connection = new SqliteConnection("DataSource=:memory:"); + +connection.Open(); + +var opt = new DbContextOptionsBuilder() + .UseSqlite(connection) + .Options; +using var context = new StubbedDbContext(opt); +context.Database.EnsureCreated(); +Test(context); \ No newline at end of file diff --git a/WebApi/TestServiceManagers/TestServiceManagers.csproj b/WebApi/TestServiceManagers/TestServiceManagers.csproj new file mode 100644 index 0000000..efbe93f --- /dev/null +++ b/WebApi/TestServiceManagers/TestServiceManagers.csproj @@ -0,0 +1,24 @@ + + + + Exe + net8.0 + enable + enable + + + + + + + + + + + + + + + + + diff --git a/WebApi/WebApi.sln b/WebApi/WebApi.sln index 5ad8e61..7ef6916 100644 --- a/WebApi/WebApi.sln +++ b/WebApi/WebApi.sln @@ -31,7 +31,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FakeDatas", "FakeDatas\Fake EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StubbedDbContextLibrary", "StubbedDbContextLibrary\StubbedDbContextLibrary.csproj", "{6A0D9093-EAA4-45A0-8813-ED5BB4E1EA3E}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestEntityManagers", "TestEntityManagers\TestEntityManagers.csproj", "{F0758B69-FD20-4BC4-BE0F-5868DB8BF74E}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestEntityManagers", "TestEntityManagers\TestEntityManagers.csproj", "{F0758B69-FD20-4BC4-BE0F-5868DB8BF74E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestServiceManagers", "TestServiceManagers\TestServiceManagers.csproj", "{0C04BD99-636A-48CA-ACFE-D2BF544E2C05}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestDataManagers", "TestDataManagers\TestDataManagers.csproj", "{F47BB104-98B0-473F-A75C-64A1A399ED56}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -99,6 +103,14 @@ Global {F0758B69-FD20-4BC4-BE0F-5868DB8BF74E}.Debug|Any CPU.Build.0 = Debug|Any CPU {F0758B69-FD20-4BC4-BE0F-5868DB8BF74E}.Release|Any CPU.ActiveCfg = Release|Any CPU {F0758B69-FD20-4BC4-BE0F-5868DB8BF74E}.Release|Any CPU.Build.0 = Release|Any CPU + {0C04BD99-636A-48CA-ACFE-D2BF544E2C05}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0C04BD99-636A-48CA-ACFE-D2BF544E2C05}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0C04BD99-636A-48CA-ACFE-D2BF544E2C05}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0C04BD99-636A-48CA-ACFE-D2BF544E2C05}.Release|Any CPU.Build.0 = Release|Any CPU + {F47BB104-98B0-473F-A75C-64A1A399ED56}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F47BB104-98B0-473F-A75C-64A1A399ED56}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F47BB104-98B0-473F-A75C-64A1A399ED56}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F47BB104-98B0-473F-A75C-64A1A399ED56}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE