From e3df3d8d79d9ce8221a57bdd31a0798f7fb3b7b5 Mon Sep 17 00:00:00 2001 From: Louis LABORIE Date: Sat, 16 Mar 2024 14:27:21 +0100 Subject: [PATCH 1/6] =?UTF-8?q?Tests=20FormEntity=20=F0=9F=8D=BB?= =?UTF-8?q?=F0=9F=8D=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../API/Entity_FrameWork.Article.db-shm | Bin 32768 -> 0 bytes .../API/Entity_FrameWork.Article.db-wal | 0 .../Unit_Test_EF/TestsFormEntity.cs | 200 ++++++++++++++++++ .../Unit_Test_EF/Unit_Test_EF.csproj | 2 +- 4 files changed, 201 insertions(+), 1 deletion(-) delete mode 100644 Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db-shm delete mode 100644 Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db-wal create mode 100644 Verax_API_EF/Verax_API_EF/Unit_Test_EF/TestsFormEntity.cs diff --git a/Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db-shm b/Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db-shm deleted file mode 100644 index fe9ac2845eca6fe6da8a63cd096d9cf9e24ece10..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 32768 zcmeIuAr62r3() + .UseSqlite(connection) + .Options; + + using (var context = new LibraryContext(options)) + { + context.Database.EnsureCreated(); + UserEntity u1 = new UserEntity + { + Pseudo = "Blizzard", + Prenom = "Louis", + Nom = "Laborie", + Mail = "he@gmail.com", + Mdp = "1234", + Role = "Admin" + }; + FormEntity f1 = new FormEntity + { + Id = 1, + Theme = "theme", + DatePublication = "date", + Link = "link", + UserEntityPseudo = "Blizzard", + User = u1 + }; + FormEntity f2 = new FormEntity + { + Id = 2, + Theme = "theme", + DatePublication = "date", + Link = "link", + UserEntityPseudo = "Blizzard", + User = u1 + }; + FormEntity f3 = new FormEntity + { + Id = 3, + Theme = "theme", + DatePublication = "date", + Link = "link", + UserEntityPseudo = "Blizzard", + User = u1 + }; + context.UserSet.Add(u1); + context.FormSet.Add(f1); + context.FormSet.Add(f2); + context.FormSet.Add(f3); + context.SaveChanges(); + + Assert.Equal(3, context.FormSet.Count()); + Assert.Equal("Blizzard", context.FormSet.First().UserEntityPseudo); + connection.Close(); + } + } + + [Fact] + public void Modify_Test() + { + var connection = new SqliteConnection("DataSource=:memory:"); + connection.Open(); + + var options = new DbContextOptionsBuilder() + .UseSqlite(connection) + .Options; + using (var context = new LibraryContext(options)) + { + context.Database.EnsureCreated(); + UserEntity u1 = new UserEntity + { + Pseudo = "Blizzard", + Prenom = "Louis", + Nom = "Laborie", + Mail = "he@gmail.com", + Mdp = "1234", + Role = "Admin" + }; + FormEntity f1 = new FormEntity + { + Id = 1, + Theme = "theme", + DatePublication = "date", + Link = "link", + UserEntityPseudo = "Blizzard", + User = u1 + }; + FormEntity f2 = new FormEntity + { + Id = 2, + Theme = "theme2", + DatePublication = "date", + Link = "link", + UserEntityPseudo = "Blizzard", + User = u1 + }; + FormEntity f3 = new FormEntity + { + Id = 3, + Theme = "theme3", + DatePublication = "date", + Link = "link", + UserEntityPseudo = "Blizzard", + User = u1 + }; + context.UserSet.Add(u1); + context.FormSet.Add(f1); + context.FormSet.Add(f2); + context.FormSet.Add(f3); + context.SaveChanges(); + + var form = context.FormSet.First(f => f.Id == 1); + form.Theme = "Politique"; + context.SaveChanges(); + string formRemove = "theme"; + string formNew = "Politique"; + Assert.Equal(1, context.FormSet.Count(f => f.Theme == formNew)); + Assert.Equal(0, context.FormSet.Count(f => f.Theme == formRemove)); + connection.Close(); + + } + } + + [Fact] + public void Remove_Test() + { + var connection = new SqliteConnection("DataSource=:memory:"); + connection.Open(); + + var options = new DbContextOptionsBuilder() + .UseSqlite(connection) + .Options; + using (var context = new LibraryContext(options)) + { + context.Database.EnsureCreated(); + UserEntity u1 = new UserEntity + { + Pseudo = "Blizzard", + Prenom = "Louis", + Nom = "Laborie", + Mail = "he@gmail.com", + Mdp = "1234", + Role = "Admin" + }; + FormEntity f1 = new FormEntity + { + Id = 1, + Theme = "theme", + DatePublication = "date", + Link = "link", + UserEntityPseudo = "Blizzard", + User = u1 + }; + FormEntity f2 = new FormEntity + { + Id = 2, + Theme = "theme2", + DatePublication = "date", + Link = "link", + UserEntityPseudo = "Blizzard", + User = u1 + }; + FormEntity f3 = new FormEntity + { + Id = 3, + Theme = "theme3", + DatePublication = "date", + Link = "link", + UserEntityPseudo = "Blizzard", + User = u1 + }; + context.UserSet.Add(u1); + context.FormSet.Add(f1); + context.FormSet.Add(f2); + context.FormSet.Add(f3); + context.SaveChanges(); + + Assert.Equal(3, context.FormSet.Count()); + var form = context.FormSet.First(f => f.Theme == "theme2"); + context.Remove(form); + context.SaveChanges(); + Assert.Equal(2, context.FormSet.Count()); + Assert.Equal(0, context.FormSet.Count(f => f.Theme == "theme2")); + connection.Close(); + } + } +} \ No newline at end of file diff --git a/Verax_API_EF/Verax_API_EF/Unit_Test_EF/Unit_Test_EF.csproj b/Verax_API_EF/Verax_API_EF/Unit_Test_EF/Unit_Test_EF.csproj index 8cbb5d2..2e0344d 100644 --- a/Verax_API_EF/Verax_API_EF/Unit_Test_EF/Unit_Test_EF.csproj +++ b/Verax_API_EF/Verax_API_EF/Unit_Test_EF/Unit_Test_EF.csproj @@ -1,4 +1,4 @@ - + net8.0 From f0d875a60ba101c1179d181a424d866af45279fb Mon Sep 17 00:00:00 2001 From: Louis LABORIE Date: Sat, 16 Mar 2024 14:50:44 +0100 Subject: [PATCH 2/6] =?UTF-8?q?Tests=20ArticleUserEntity=20=F0=9F=8D=BB?= =?UTF-8?q?=F0=9F=8D=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Unit_Test_EF/TestsArticleUserEntity.cs | 219 ++++++++++++++++++ 1 file changed, 219 insertions(+) create mode 100644 Verax_API_EF/Verax_API_EF/Unit_Test_EF/TestsArticleUserEntity.cs diff --git a/Verax_API_EF/Verax_API_EF/Unit_Test_EF/TestsArticleUserEntity.cs b/Verax_API_EF/Verax_API_EF/Unit_Test_EF/TestsArticleUserEntity.cs new file mode 100644 index 0000000..02f7526 --- /dev/null +++ b/Verax_API_EF/Verax_API_EF/Unit_Test_EF/TestsArticleUserEntity.cs @@ -0,0 +1,219 @@ +using DbContextLib; +using Entities; +using Microsoft.Data.Sqlite; +using Microsoft.EntityFrameworkCore; + +namespace TestsUnitaires; + +public class TestsArticleUserEntity +{ + [Fact] + public void Add_Test() + { + var connection = new SqliteConnection("DataSource=:memory:"); + connection.Open(); + + var options = new DbContextOptionsBuilder() + .UseSqlite(connection) + .Options; + + using (var context = new LibraryContext(options)) + { + context.Database.EnsureCreated(); + ArticleEntity a1 = new ArticleEntity { Title = "Breaking News Elisabeth 2 Died", Description = "The queen of England died today at the age of 95", DatePublished = "2022-02-06", LectureTime = 2, Author = "Tom Smith" }; + ArticleEntity a2 = new ArticleEntity { Title = "The new iPhone 15", Description = "The new iPhone 15 is out and it's the best phone ever", DatePublished = "2022-02-06", LectureTime = 3, Author = "Tom Smith" }; + ArticleEntity a3 = new ArticleEntity { Title = "M&M's new recipe", Description = "M&M's new recipe is out and it's the best chocolate ever", DatePublished = "2022-02-06", LectureTime = 1, Author = "M&M's Red" }; + + UserEntity u1 = new UserEntity + { + Pseudo = "Blizzard", + Prenom = "Louis", + Nom = "Laborie", + Mail = "he@gmail.com", + Mdp = "1234", + Role = "Admin" + }; + + ArticleUserEntity au1 = new ArticleUserEntity + { + UserEntityPseudo = "Blizzard", + ArticleEntityId = 1 + }; + + ArticleUserEntity au2 = new ArticleUserEntity + { + UserEntityPseudo = "Blizzard", + ArticleEntityId = 2 + }; + + ArticleUserEntity au3 = new ArticleUserEntity + { + UserEntityPseudo = "Blizzard", + ArticleEntityId = 3 + }; + + context.ArticleSet.Add(a1); + context.ArticleSet.Add(a2); + context.ArticleSet.Add(a3); + context.UserSet.Add(u1); + context.ArticleUserSet.Add(au1); + context.ArticleUserSet.Add(au2); + context.ArticleUserSet.Add(au3); + context.SaveChanges(); + + Assert.Equal(3, context.ArticleSet.Count()); + Assert.Equal(1, context.ArticleUserSet.First().ArticleEntityId); + connection.Close(); + } + } + + [Fact] + public void Modify_Test() + { + var connection = new SqliteConnection("DataSource=:memory:"); + connection.Open(); + + var options = new DbContextOptionsBuilder() + .UseSqlite(connection) + .Options; + using (var context = new LibraryContext(options)) + { + context.Database.EnsureCreated(); + ArticleEntity a1 = new ArticleEntity { Title = "Breaking News Elisabeth 2 Died", Description = "The queen of England died today at the age of 95", DatePublished = "2022-02-06", LectureTime = 2, Author = "Tom Smith" }; + ArticleEntity a2 = new ArticleEntity { Title = "The new iPhone 15", Description = "The new iPhone 15 is out and it's the best phone ever", DatePublished = "2022-02-06", LectureTime = 3, Author = "Tom Smith" }; + ArticleEntity a3 = new ArticleEntity { Title = "M&M's new recipe", Description = "M&M's new recipe is out and it's the best chocolate ever", DatePublished = "2022-02-06", LectureTime = 1, Author = "M&M's Red" }; + + UserEntity u1 = new UserEntity + { + Pseudo = "Blizzard", + Prenom = "Louis", + Nom = "Laborie", + Mail = "he@gmail.com", + Mdp = "1234", + Role = "Admin" + }; + + UserEntity u2 = new UserEntity + { + Pseudo = "Tofgasy", + Prenom = "Tony", + Nom = "Fages", + Mail = "he@gmail.com", + Mdp = "1234", + Role = "Admin" + }; + + ArticleUserEntity au1 = new ArticleUserEntity + { + UserEntityPseudo = "Blizzard", + ArticleEntityId = 1 + }; + + ArticleUserEntity au2 = new ArticleUserEntity + { + UserEntityPseudo = "Blizzard", + ArticleEntityId = 2 + }; + + ArticleUserEntity au3 = new ArticleUserEntity + { + UserEntityPseudo = "Blizzard", + ArticleEntityId = 3 + }; + + context.ArticleSet.Add(a1); + context.ArticleSet.Add(a2); + context.ArticleSet.Add(a3); + context.UserSet.Add(u1); + context.UserSet.Add(u2); + context.ArticleUserSet.Add(au1); + context.ArticleUserSet.Add(au2); + context.ArticleUserSet.Add(au3); + context.SaveChanges(); + + var article = context.ArticleUserSet.First(a => a.UserEntityPseudo == "Blizzard"); + article.UserEntityPseudo = "Tofgasy"; + context.SaveChanges(); + string persRemove = "Blizzard"; + string persNew = "Tofgasy"; + Assert.Equal(2, context.ArticleUserSet.Count(a => a.UserEntityPseudo == persRemove)); + Assert.Equal(1, context.ArticleUserSet.Count(a => a.UserEntityPseudo == persNew)); + connection.Close(); + } + } + + [Fact] + public void Remove_Test() + { + var connection = new SqliteConnection("DataSource=:memory:"); + connection.Open(); + + var options = new DbContextOptionsBuilder() + .UseSqlite(connection) + .Options; + using (var context = new LibraryContext(options)) + { + context.Database.EnsureCreated(); + ArticleEntity a1 = new ArticleEntity { Title = "Breaking News Elisabeth 2 Died", Description = "The queen of England died today at the age of 95", DatePublished = "2022-02-06", LectureTime = 2, Author = "Tom Smith" }; + ArticleEntity a2 = new ArticleEntity { Title = "The new iPhone 15", Description = "The new iPhone 15 is out and it's the best phone ever", DatePublished = "2022-02-06", LectureTime = 3, Author = "Tom Smith" }; + ArticleEntity a3 = new ArticleEntity { Title = "M&M's new recipe", Description = "M&M's new recipe is out and it's the best chocolate ever", DatePublished = "2022-02-06", LectureTime = 1, Author = "M&M's Red" }; + + UserEntity u1 = new UserEntity + { + Pseudo = "Blizzard", + Prenom = "Louis", + Nom = "Laborie", + Mail = "he@gmail.com", + Mdp = "1234", + Role = "Admin" + }; + + UserEntity u2 = new UserEntity + { + Pseudo = "Tofgasy", + Prenom = "Tony", + Nom = "Fages", + Mail = "he@gmail.com", + Mdp = "1234", + Role = "Admin" + }; + + ArticleUserEntity au1 = new ArticleUserEntity + { + UserEntityPseudo = "Blizzard", + ArticleEntityId = 1 + }; + + ArticleUserEntity au2 = new ArticleUserEntity + { + UserEntityPseudo = "Blizzard", + ArticleEntityId = 2 + }; + + ArticleUserEntity au3 = new ArticleUserEntity + { + UserEntityPseudo = "Blizzard", + ArticleEntityId = 3 + }; + + context.ArticleSet.Add(a1); + context.ArticleSet.Add(a2); + context.ArticleSet.Add(a3); + context.UserSet.Add(u1); + context.UserSet.Add(u2); + context.ArticleUserSet.Add(au1); + context.ArticleUserSet.Add(au2); + context.ArticleUserSet.Add(au3); + + context.SaveChanges(); + + var article = context.ArticleUserSet.First(a => a.UserEntityPseudo == "Blizzard"); + context.Remove(article); + context.SaveChanges(); + Assert.Equal(2, context.ArticleSet.Count()); + Assert.Equal(2, context.ArticleUserSet.Count(a => a.UserEntityPseudo == "Blizzard")); + connection.Close(); + } + } + +} \ No newline at end of file From 892398e914c7e2de25f47bfef9906b9828d310cc Mon Sep 17 00:00:00 2001 From: Louis LABORIE Date: Sat, 16 Mar 2024 14:53:37 +0100 Subject: [PATCH 3/6] =?UTF-8?q?Tests=20ArticleUserEntity=20=F0=9F=8D=BB?= =?UTF-8?q?=F0=9F=8D=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Unit_Test_EF/TestsFormEntity.cs | 129 ------------------ 1 file changed, 129 deletions(-) diff --git a/Verax_API_EF/Verax_API_EF/Unit_Test_EF/TestsFormEntity.cs b/Verax_API_EF/Verax_API_EF/Unit_Test_EF/TestsFormEntity.cs index a7cd1f8..cf68efb 100644 --- a/Verax_API_EF/Verax_API_EF/Unit_Test_EF/TestsFormEntity.cs +++ b/Verax_API_EF/Verax_API_EF/Unit_Test_EF/TestsFormEntity.cs @@ -68,133 +68,4 @@ public class TestsFormEntity } } - [Fact] - public void Modify_Test() - { - var connection = new SqliteConnection("DataSource=:memory:"); - connection.Open(); - - var options = new DbContextOptionsBuilder() - .UseSqlite(connection) - .Options; - using (var context = new LibraryContext(options)) - { - context.Database.EnsureCreated(); - UserEntity u1 = new UserEntity - { - Pseudo = "Blizzard", - Prenom = "Louis", - Nom = "Laborie", - Mail = "he@gmail.com", - Mdp = "1234", - Role = "Admin" - }; - FormEntity f1 = new FormEntity - { - Id = 1, - Theme = "theme", - DatePublication = "date", - Link = "link", - UserEntityPseudo = "Blizzard", - User = u1 - }; - FormEntity f2 = new FormEntity - { - Id = 2, - Theme = "theme2", - DatePublication = "date", - Link = "link", - UserEntityPseudo = "Blizzard", - User = u1 - }; - FormEntity f3 = new FormEntity - { - Id = 3, - Theme = "theme3", - DatePublication = "date", - Link = "link", - UserEntityPseudo = "Blizzard", - User = u1 - }; - context.UserSet.Add(u1); - context.FormSet.Add(f1); - context.FormSet.Add(f2); - context.FormSet.Add(f3); - context.SaveChanges(); - - var form = context.FormSet.First(f => f.Id == 1); - form.Theme = "Politique"; - context.SaveChanges(); - string formRemove = "theme"; - string formNew = "Politique"; - Assert.Equal(1, context.FormSet.Count(f => f.Theme == formNew)); - Assert.Equal(0, context.FormSet.Count(f => f.Theme == formRemove)); - connection.Close(); - - } - } - - [Fact] - public void Remove_Test() - { - var connection = new SqliteConnection("DataSource=:memory:"); - connection.Open(); - - var options = new DbContextOptionsBuilder() - .UseSqlite(connection) - .Options; - using (var context = new LibraryContext(options)) - { - context.Database.EnsureCreated(); - UserEntity u1 = new UserEntity - { - Pseudo = "Blizzard", - Prenom = "Louis", - Nom = "Laborie", - Mail = "he@gmail.com", - Mdp = "1234", - Role = "Admin" - }; - FormEntity f1 = new FormEntity - { - Id = 1, - Theme = "theme", - DatePublication = "date", - Link = "link", - UserEntityPseudo = "Blizzard", - User = u1 - }; - FormEntity f2 = new FormEntity - { - Id = 2, - Theme = "theme2", - DatePublication = "date", - Link = "link", - UserEntityPseudo = "Blizzard", - User = u1 - }; - FormEntity f3 = new FormEntity - { - Id = 3, - Theme = "theme3", - DatePublication = "date", - Link = "link", - UserEntityPseudo = "Blizzard", - User = u1 - }; - context.UserSet.Add(u1); - context.FormSet.Add(f1); - context.FormSet.Add(f2); - context.FormSet.Add(f3); - context.SaveChanges(); - - Assert.Equal(3, context.FormSet.Count()); - var form = context.FormSet.First(f => f.Theme == "theme2"); - context.Remove(form); - context.SaveChanges(); - Assert.Equal(2, context.FormSet.Count()); - Assert.Equal(0, context.FormSet.Count(f => f.Theme == "theme2")); - connection.Close(); - } - } } \ No newline at end of file From 141cbc2532455d859094a0daad9086bec40bbedc Mon Sep 17 00:00:00 2001 From: Louis LABORIE Date: Sat, 16 Mar 2024 14:57:34 +0100 Subject: [PATCH 4/6] =?UTF-8?q?Tests=20ArticleUserEntity=20=F0=9F=8D=BB?= =?UTF-8?q?=F0=9F=8D=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Unit_Test_EF/TestsArticleUserEntity.cs | 149 ------------------ .../Unit_Test_EF/TestsFormEntity.cs | 129 +++++++++++++++ 2 files changed, 129 insertions(+), 149 deletions(-) diff --git a/Verax_API_EF/Verax_API_EF/Unit_Test_EF/TestsArticleUserEntity.cs b/Verax_API_EF/Verax_API_EF/Unit_Test_EF/TestsArticleUserEntity.cs index 02f7526..8ed120f 100644 --- a/Verax_API_EF/Verax_API_EF/Unit_Test_EF/TestsArticleUserEntity.cs +++ b/Verax_API_EF/Verax_API_EF/Unit_Test_EF/TestsArticleUserEntity.cs @@ -67,153 +67,4 @@ public class TestsArticleUserEntity } } - [Fact] - public void Modify_Test() - { - var connection = new SqliteConnection("DataSource=:memory:"); - connection.Open(); - - var options = new DbContextOptionsBuilder() - .UseSqlite(connection) - .Options; - using (var context = new LibraryContext(options)) - { - context.Database.EnsureCreated(); - ArticleEntity a1 = new ArticleEntity { Title = "Breaking News Elisabeth 2 Died", Description = "The queen of England died today at the age of 95", DatePublished = "2022-02-06", LectureTime = 2, Author = "Tom Smith" }; - ArticleEntity a2 = new ArticleEntity { Title = "The new iPhone 15", Description = "The new iPhone 15 is out and it's the best phone ever", DatePublished = "2022-02-06", LectureTime = 3, Author = "Tom Smith" }; - ArticleEntity a3 = new ArticleEntity { Title = "M&M's new recipe", Description = "M&M's new recipe is out and it's the best chocolate ever", DatePublished = "2022-02-06", LectureTime = 1, Author = "M&M's Red" }; - - UserEntity u1 = new UserEntity - { - Pseudo = "Blizzard", - Prenom = "Louis", - Nom = "Laborie", - Mail = "he@gmail.com", - Mdp = "1234", - Role = "Admin" - }; - - UserEntity u2 = new UserEntity - { - Pseudo = "Tofgasy", - Prenom = "Tony", - Nom = "Fages", - Mail = "he@gmail.com", - Mdp = "1234", - Role = "Admin" - }; - - ArticleUserEntity au1 = new ArticleUserEntity - { - UserEntityPseudo = "Blizzard", - ArticleEntityId = 1 - }; - - ArticleUserEntity au2 = new ArticleUserEntity - { - UserEntityPseudo = "Blizzard", - ArticleEntityId = 2 - }; - - ArticleUserEntity au3 = new ArticleUserEntity - { - UserEntityPseudo = "Blizzard", - ArticleEntityId = 3 - }; - - context.ArticleSet.Add(a1); - context.ArticleSet.Add(a2); - context.ArticleSet.Add(a3); - context.UserSet.Add(u1); - context.UserSet.Add(u2); - context.ArticleUserSet.Add(au1); - context.ArticleUserSet.Add(au2); - context.ArticleUserSet.Add(au3); - context.SaveChanges(); - - var article = context.ArticleUserSet.First(a => a.UserEntityPseudo == "Blizzard"); - article.UserEntityPseudo = "Tofgasy"; - context.SaveChanges(); - string persRemove = "Blizzard"; - string persNew = "Tofgasy"; - Assert.Equal(2, context.ArticleUserSet.Count(a => a.UserEntityPseudo == persRemove)); - Assert.Equal(1, context.ArticleUserSet.Count(a => a.UserEntityPseudo == persNew)); - connection.Close(); - } - } - - [Fact] - public void Remove_Test() - { - var connection = new SqliteConnection("DataSource=:memory:"); - connection.Open(); - - var options = new DbContextOptionsBuilder() - .UseSqlite(connection) - .Options; - using (var context = new LibraryContext(options)) - { - context.Database.EnsureCreated(); - ArticleEntity a1 = new ArticleEntity { Title = "Breaking News Elisabeth 2 Died", Description = "The queen of England died today at the age of 95", DatePublished = "2022-02-06", LectureTime = 2, Author = "Tom Smith" }; - ArticleEntity a2 = new ArticleEntity { Title = "The new iPhone 15", Description = "The new iPhone 15 is out and it's the best phone ever", DatePublished = "2022-02-06", LectureTime = 3, Author = "Tom Smith" }; - ArticleEntity a3 = new ArticleEntity { Title = "M&M's new recipe", Description = "M&M's new recipe is out and it's the best chocolate ever", DatePublished = "2022-02-06", LectureTime = 1, Author = "M&M's Red" }; - - UserEntity u1 = new UserEntity - { - Pseudo = "Blizzard", - Prenom = "Louis", - Nom = "Laborie", - Mail = "he@gmail.com", - Mdp = "1234", - Role = "Admin" - }; - - UserEntity u2 = new UserEntity - { - Pseudo = "Tofgasy", - Prenom = "Tony", - Nom = "Fages", - Mail = "he@gmail.com", - Mdp = "1234", - Role = "Admin" - }; - - ArticleUserEntity au1 = new ArticleUserEntity - { - UserEntityPseudo = "Blizzard", - ArticleEntityId = 1 - }; - - ArticleUserEntity au2 = new ArticleUserEntity - { - UserEntityPseudo = "Blizzard", - ArticleEntityId = 2 - }; - - ArticleUserEntity au3 = new ArticleUserEntity - { - UserEntityPseudo = "Blizzard", - ArticleEntityId = 3 - }; - - context.ArticleSet.Add(a1); - context.ArticleSet.Add(a2); - context.ArticleSet.Add(a3); - context.UserSet.Add(u1); - context.UserSet.Add(u2); - context.ArticleUserSet.Add(au1); - context.ArticleUserSet.Add(au2); - context.ArticleUserSet.Add(au3); - - context.SaveChanges(); - - var article = context.ArticleUserSet.First(a => a.UserEntityPseudo == "Blizzard"); - context.Remove(article); - context.SaveChanges(); - Assert.Equal(2, context.ArticleSet.Count()); - Assert.Equal(2, context.ArticleUserSet.Count(a => a.UserEntityPseudo == "Blizzard")); - connection.Close(); - } - } - } \ No newline at end of file diff --git a/Verax_API_EF/Verax_API_EF/Unit_Test_EF/TestsFormEntity.cs b/Verax_API_EF/Verax_API_EF/Unit_Test_EF/TestsFormEntity.cs index cf68efb..a7cd1f8 100644 --- a/Verax_API_EF/Verax_API_EF/Unit_Test_EF/TestsFormEntity.cs +++ b/Verax_API_EF/Verax_API_EF/Unit_Test_EF/TestsFormEntity.cs @@ -68,4 +68,133 @@ public class TestsFormEntity } } + [Fact] + public void Modify_Test() + { + var connection = new SqliteConnection("DataSource=:memory:"); + connection.Open(); + + var options = new DbContextOptionsBuilder() + .UseSqlite(connection) + .Options; + using (var context = new LibraryContext(options)) + { + context.Database.EnsureCreated(); + UserEntity u1 = new UserEntity + { + Pseudo = "Blizzard", + Prenom = "Louis", + Nom = "Laborie", + Mail = "he@gmail.com", + Mdp = "1234", + Role = "Admin" + }; + FormEntity f1 = new FormEntity + { + Id = 1, + Theme = "theme", + DatePublication = "date", + Link = "link", + UserEntityPseudo = "Blizzard", + User = u1 + }; + FormEntity f2 = new FormEntity + { + Id = 2, + Theme = "theme2", + DatePublication = "date", + Link = "link", + UserEntityPseudo = "Blizzard", + User = u1 + }; + FormEntity f3 = new FormEntity + { + Id = 3, + Theme = "theme3", + DatePublication = "date", + Link = "link", + UserEntityPseudo = "Blizzard", + User = u1 + }; + context.UserSet.Add(u1); + context.FormSet.Add(f1); + context.FormSet.Add(f2); + context.FormSet.Add(f3); + context.SaveChanges(); + + var form = context.FormSet.First(f => f.Id == 1); + form.Theme = "Politique"; + context.SaveChanges(); + string formRemove = "theme"; + string formNew = "Politique"; + Assert.Equal(1, context.FormSet.Count(f => f.Theme == formNew)); + Assert.Equal(0, context.FormSet.Count(f => f.Theme == formRemove)); + connection.Close(); + + } + } + + [Fact] + public void Remove_Test() + { + var connection = new SqliteConnection("DataSource=:memory:"); + connection.Open(); + + var options = new DbContextOptionsBuilder() + .UseSqlite(connection) + .Options; + using (var context = new LibraryContext(options)) + { + context.Database.EnsureCreated(); + UserEntity u1 = new UserEntity + { + Pseudo = "Blizzard", + Prenom = "Louis", + Nom = "Laborie", + Mail = "he@gmail.com", + Mdp = "1234", + Role = "Admin" + }; + FormEntity f1 = new FormEntity + { + Id = 1, + Theme = "theme", + DatePublication = "date", + Link = "link", + UserEntityPseudo = "Blizzard", + User = u1 + }; + FormEntity f2 = new FormEntity + { + Id = 2, + Theme = "theme2", + DatePublication = "date", + Link = "link", + UserEntityPseudo = "Blizzard", + User = u1 + }; + FormEntity f3 = new FormEntity + { + Id = 3, + Theme = "theme3", + DatePublication = "date", + Link = "link", + UserEntityPseudo = "Blizzard", + User = u1 + }; + context.UserSet.Add(u1); + context.FormSet.Add(f1); + context.FormSet.Add(f2); + context.FormSet.Add(f3); + context.SaveChanges(); + + Assert.Equal(3, context.FormSet.Count()); + var form = context.FormSet.First(f => f.Theme == "theme2"); + context.Remove(form); + context.SaveChanges(); + Assert.Equal(2, context.FormSet.Count()); + Assert.Equal(0, context.FormSet.Count(f => f.Theme == "theme2")); + connection.Close(); + } + } } \ No newline at end of file From eb0eea6a48a36173d64c2bfef831453ac0ef3917 Mon Sep 17 00:00:00 2001 From: Louis LABORIE Date: Sat, 16 Mar 2024 15:07:05 +0100 Subject: [PATCH 5/6] =?UTF-8?q?Fix=20Coverage=20Exclusions=20=F0=9F=8D=BB?= =?UTF-8?q?=F0=9F=8D=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index fb68690..ba7e5b6 100644 --- a/.drone.yml +++ b/.drone.yml @@ -37,7 +37,7 @@ steps: - cd Verax_API_EF/ - cd Verax_API_EF/ - dotnet restore Verax_API_EF.sln - - dotnet sonarscanner begin /k:$${project_key} /d:sonar.host.url=$${sonar_host} /d:sonar.coverageReportPaths="coveragereport/SonarQube.xml" /d:sonar.coverage.exclusions="Unit_Test_EF/**","API_Unit_Test/**","API_Tests_Console/**,"Test_Console_EF/**,"DbContextLib/Migrations/**" /d:sonar.login=$${sonar_token} + - dotnet sonarscanner begin /k:$${project_key} /d:sonar.host.url=$${sonar_host} /d:sonar.coverageReportPaths="coveragereport/SonarQube.xml" /d:sonar.coverage.exclusions="Unit_Test_EF/**","API_Unit_Test/**","API_Tests_Console/**","Test_Console_EF/**,"DbContextLib/Migrations/**","StubbedContextLib/**" /d:sonar.login=$${sonar_token} - dotnet build Verax_API_EF.sln -c Release --no-restore - dotnet test Verax_API_EF.sln --logger trx --no-restore /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura --collect "XPlat Code Coverage" - reportgenerator -reports:"**/coverage.cobertura.xml" -reporttypes:SonarQube -targetdir:"coveragereport" From 87fed48b3e12e7b7d6a019d4072e082e1f8860db Mon Sep 17 00:00:00 2001 From: Louis LABORIE Date: Sat, 16 Mar 2024 15:09:18 +0100 Subject: [PATCH 6/6] =?UTF-8?q?Fix=20Coverage=20Exclusions=20=F0=9F=8D=BB?= =?UTF-8?q?=F0=9F=8D=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index ba7e5b6..6d4fb92 100644 --- a/.drone.yml +++ b/.drone.yml @@ -37,7 +37,7 @@ steps: - cd Verax_API_EF/ - cd Verax_API_EF/ - dotnet restore Verax_API_EF.sln - - dotnet sonarscanner begin /k:$${project_key} /d:sonar.host.url=$${sonar_host} /d:sonar.coverageReportPaths="coveragereport/SonarQube.xml" /d:sonar.coverage.exclusions="Unit_Test_EF/**","API_Unit_Test/**","API_Tests_Console/**","Test_Console_EF/**,"DbContextLib/Migrations/**","StubbedContextLib/**" /d:sonar.login=$${sonar_token} + - dotnet sonarscanner begin /k:$${project_key} /d:sonar.host.url=$${sonar_host} /d:sonar.coverageReportPaths="coveragereport/SonarQube.xml" /d:sonar.coverage.exclusions="Unit_Test_EF/**","API_Unit_Test/**","API_Tests_Console/**","Test_Console_EF/**","DbContextLib/Migrations/**","StubbedContextLib/**" /d:sonar.login=$${sonar_token} - dotnet build Verax_API_EF.sln -c Release --no-restore - dotnet test Verax_API_EF.sln --logger trx --no-restore /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura --collect "XPlat Code Coverage" - reportgenerator -reports:"**/coverage.cobertura.xml" -reporttypes:SonarQube -targetdir:"coveragereport"