From f5f94a3f807598d80bed306a9f4f4ce007010622 Mon Sep 17 00:00:00 2001 From: tonyfages Date: Mon, 11 Mar 2024 15:18:31 +0100 Subject: [PATCH] Add COnsole Tests EF Form + User --- .../API/Controllers/UserController.cs | 45 +-- .../API/Entity_FrameWork.Article.db | Bin 45056 -> 36864 bytes Verax_API_EF/Verax_API_EF/API/Program.cs | 4 +- .../DbContextLib/LibraryContext.cs | 10 + .../20240311132206_mrg1.Designer.cs} | 59 +++- .../Migrations/20240311132206_mrg1.cs} | 32 +- .../LibraryContextModelSnapshot.cs} | 59 +++- .../StubbedContextLib/StubTest.cs | 26 -- .../Entity_FrameWork.Article.db | Bin 0 -> 45056 bytes .../Entity_FrameWork.Article.db-shm | Bin 32768 -> 32768 bytes .../Entity_FrameWork.Article.db-wal | Bin 12392 -> 12392 bytes .../Verax_API_EF/Test_Console_EF/Program.cs | 83 ----- .../Test_Console_EF/Test_Console_Article.cs | 304 ++++++++++++++++++ 13 files changed, 470 insertions(+), 152 deletions(-) rename Verax_API_EF/Verax_API_EF/{StubbedContextLib/Migrations/20240307182411_mrg1.Designer.cs => DbContextLib/Migrations/20240311132206_mrg1.Designer.cs} (80%) rename Verax_API_EF/Verax_API_EF/{StubbedContextLib/Migrations/20240307182411_mrg1.cs => DbContextLib/Migrations/20240311132206_mrg1.cs} (83%) rename Verax_API_EF/Verax_API_EF/{StubbedContextLib/Migrations/StubbedContextModelSnapshot.cs => DbContextLib/Migrations/LibraryContextModelSnapshot.cs} (80%) delete mode 100644 Verax_API_EF/Verax_API_EF/StubbedContextLib/StubTest.cs create mode 100644 Verax_API_EF/Verax_API_EF/Test_Console_EF/Entity_FrameWork.Article.db rename Verax_API_EF/Verax_API_EF/{API => Test_Console_EF}/Entity_FrameWork.Article.db-shm (98%) rename Verax_API_EF/Verax_API_EF/{API => Test_Console_EF}/Entity_FrameWork.Article.db-wal (94%) delete mode 100644 Verax_API_EF/Verax_API_EF/Test_Console_EF/Program.cs create mode 100644 Verax_API_EF/Verax_API_EF/Test_Console_EF/Test_Console_Article.cs diff --git a/Verax_API_EF/Verax_API_EF/API/Controllers/UserController.cs b/Verax_API_EF/Verax_API_EF/API/Controllers/UserController.cs index 3b4a285..c7ed3c2 100644 --- a/Verax_API_EF/Verax_API_EF/API/Controllers/UserController.cs +++ b/Verax_API_EF/Verax_API_EF/API/Controllers/UserController.cs @@ -18,6 +18,28 @@ namespace API.Controllers this._us = us; } + [HttpGet("/users")] + public async Task GetAll([FromQuery] int index = 0, [FromQuery] int count = 10, [FromQuery] UserOrderCriteria orderCriteria = UserOrderCriteria.None) + { + var result = (await _us.GetAll(index, count, orderCriteria)).Select(u => u.ToDTO()); + if (result == null) + { + return NotFound(); + } + return Ok(result); + } + + [HttpGet("/user/{pseudo}")] + public async Task GetByPseudo(string pseudo) + { + var result = (await _us.GetByPseudo(pseudo)).ToDTO(); + if (result == null) + { + return NotFound(); + } + return Ok(result); + } + [HttpPost("/user")] public async Task Create(User user) { @@ -37,27 +59,8 @@ namespace API.Controllers return await _us.Delete(pseudo); } - [HttpGet("/user/{pseudo}")] - public async Task GetByPseudo(string pseudo) - { - var result = (await _us.GetByPseudo(pseudo)).ToDTO(); - if (result == null) - { - return NotFound(); - } - return Ok(result); - } - [HttpGet("/users")] - public async Task GetAll([FromQuery] int index = 0, [FromQuery] int count = 10, [FromQuery] UserOrderCriteria orderCriteria = UserOrderCriteria.None) - { - var result = (await _us.GetAll(index, count, orderCriteria)).Select(u => u.ToDTO()); - if (result == null) - { - return NotFound(); - } - return Ok(result); - - } + + } } diff --git a/Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db b/Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db index 2cd90a9663b869eae1efcea320e2fc466a3588bf..d1afbee0e70fb87729e26f8c4193e01e73c690e4 100644 GIT binary patch delta 257 zcmZp8z|^pSX@ayM69WSSClJE`+e95>StbU(v{$^mp$r@x5e$46`RaLNx&HGCaVB$| z%Qv{$^mp$uH?rVM-+`RaLNx&HGCaVB$| z1}exRtHGF_e>C+}xb8$+ILeDJL~P-qp=FGrcIWBr`v+*dw#JB)_Net3rsQlaH%{5>_=z3L0DrK%fLS(lbR#A;dKzM8VG=h(moQYw`=$ z{CKRk#2d!Pi(v6G_vQ$W>FSKklRxN-a53|jGw@&JU(R2?Sx_O9e{;EgX8;>7D6j=K Q3pU*6pEyC9jSGbf0KimyV*mgE diff --git a/Verax_API_EF/Verax_API_EF/API/Program.cs b/Verax_API_EF/Verax_API_EF/API/Program.cs index 9bf4f16..7ee0854 100644 --- a/Verax_API_EF/Verax_API_EF/API/Program.cs +++ b/Verax_API_EF/Verax_API_EF/API/Program.cs @@ -38,8 +38,8 @@ app.MapControllers(); using var scoped = app.Services.CreateScope(); var libraryContext = scoped.ServiceProvider.GetService(); -//libraryContext.Database.EnsureCreated(); -libraryContext.Database.Migrate(); +libraryContext.Database.EnsureCreated(); +//libraryContext.Database.Migrate(); app.Run(); diff --git a/Verax_API_EF/Verax_API_EF/DbContextLib/LibraryContext.cs b/Verax_API_EF/Verax_API_EF/DbContextLib/LibraryContext.cs index 58c2539..774ded2 100644 --- a/Verax_API_EF/Verax_API_EF/DbContextLib/LibraryContext.cs +++ b/Verax_API_EF/Verax_API_EF/DbContextLib/LibraryContext.cs @@ -19,6 +19,8 @@ public class LibraryContext : DbContext public DbSet UserSet { get; set; } public DbSet FormSet { get; set; } + public DbSet ArticleUserSet { get; set; } + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { if (!optionsBuilder.IsConfigured) @@ -91,6 +93,14 @@ public class LibraryContext : DbContext new UserEntity { Id = 3, Nom = "M&M's", Prenom = "Red", Pseudo = "RedM", Mail = "M&M#mail.com", Mdp = "1234", Role = "Modérator" + }, + new UserEntity + { + Id = 4, Nom = "Cascarra", Prenom = "Cascarra", Pseudo = "Sha", Mail = "ShaCasca@gmail.com", Mdp = "1234", Role = "Admin" + }, + new UserEntity + { + Id = 5, Nom = "Sillard", Prenom = "Noa", Pseudo = "NoaSil", Mail = "", Mdp = "1234", Role = "Admin" } ); diff --git a/Verax_API_EF/Verax_API_EF/StubbedContextLib/Migrations/20240307182411_mrg1.Designer.cs b/Verax_API_EF/Verax_API_EF/DbContextLib/Migrations/20240311132206_mrg1.Designer.cs similarity index 80% rename from Verax_API_EF/Verax_API_EF/StubbedContextLib/Migrations/20240307182411_mrg1.Designer.cs rename to Verax_API_EF/Verax_API_EF/DbContextLib/Migrations/20240311132206_mrg1.Designer.cs index 1340e2b..6c21748 100644 --- a/Verax_API_EF/Verax_API_EF/StubbedContextLib/Migrations/20240307182411_mrg1.Designer.cs +++ b/Verax_API_EF/Verax_API_EF/DbContextLib/Migrations/20240311132206_mrg1.Designer.cs @@ -1,16 +1,16 @@ // +using DbContextLib; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using StubbedContextLib; #nullable disable -namespace StubbedContextLib.Migrations +namespace DbContextLib.Migrations { - [DbContext(typeof(StubbedContext))] - [Migration("20240307182411_mrg1")] + [DbContext(typeof(LibraryContext))] + [Migration("20240311132206_mrg1")] partial class mrg1 { /// @@ -90,7 +90,7 @@ namespace StubbedContextLib.Migrations b.HasIndex("UserEntityId"); - b.ToTable("ArticleUserEntity"); + b.ToTable("ArticleUserSet"); b.HasData( new @@ -150,6 +150,35 @@ namespace StubbedContextLib.Migrations b.HasIndex("UserEntityId"); b.ToTable("FormSet"); + + b.HasData( + new + { + Id = 1L, + DatePublication = "Form 1 Description", + Link = "hhtp://form1.com", + Pseudo = "Form 1", + Theme = "", + UserEntityId = 1L + }, + new + { + Id = 2L, + DatePublication = "Form 2 Description", + Link = "hhtp://form2.com", + Pseudo = "Form 2", + Theme = "", + UserEntityId = 2L + }, + new + { + Id = 3L, + DatePublication = "Form 3 Description", + Link = "hhtp://form3.com", + Pseudo = "Form 3", + Theme = "", + UserEntityId = 3L + }); }); modelBuilder.Entity("Entities.UserEntity", b => @@ -216,6 +245,26 @@ namespace StubbedContextLib.Migrations Prenom = "Red", Pseudo = "RedM", Role = "Modérator" + }, + new + { + Id = 4L, + Mail = "ShaCasca@gmail.com", + Mdp = "1234", + Nom = "Cascarra", + Prenom = "Cascarra", + Pseudo = "Sha", + Role = "Admin" + }, + new + { + Id = 5L, + Mail = "", + Mdp = "1234", + Nom = "Sillard", + Prenom = "Noa", + Pseudo = "NoaSil", + Role = "Admin" }); }); diff --git a/Verax_API_EF/Verax_API_EF/StubbedContextLib/Migrations/20240307182411_mrg1.cs b/Verax_API_EF/Verax_API_EF/DbContextLib/Migrations/20240311132206_mrg1.cs similarity index 83% rename from Verax_API_EF/Verax_API_EF/StubbedContextLib/Migrations/20240307182411_mrg1.cs rename to Verax_API_EF/Verax_API_EF/DbContextLib/Migrations/20240311132206_mrg1.cs index a40c540..b9278d6 100644 --- a/Verax_API_EF/Verax_API_EF/StubbedContextLib/Migrations/20240307182411_mrg1.cs +++ b/Verax_API_EF/Verax_API_EF/DbContextLib/Migrations/20240311132206_mrg1.cs @@ -4,7 +4,7 @@ #pragma warning disable CA1814 // Prefer jagged arrays over multidimensional -namespace StubbedContextLib.Migrations +namespace DbContextLib.Migrations { /// public partial class mrg1 : Migration @@ -48,7 +48,7 @@ namespace StubbedContextLib.Migrations }); migrationBuilder.CreateTable( - name: "ArticleUserEntity", + name: "ArticleUserSet", columns: table => new { UserEntityId = table.Column(type: "INTEGER", nullable: false), @@ -56,15 +56,15 @@ namespace StubbedContextLib.Migrations }, constraints: table => { - table.PrimaryKey("PK_ArticleUserEntity", x => new { x.ArticleEntityId, x.UserEntityId }); + table.PrimaryKey("PK_ArticleUserSet", x => new { x.ArticleEntityId, x.UserEntityId }); table.ForeignKey( - name: "FK_ArticleUserEntity_ArticleSet_ArticleEntityId", + name: "FK_ArticleUserSet_ArticleSet_ArticleEntityId", column: x => x.ArticleEntityId, principalTable: "ArticleSet", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( - name: "FK_ArticleUserEntity_UserSet_UserEntityId", + name: "FK_ArticleUserSet_UserSet_UserEntityId", column: x => x.UserEntityId, principalTable: "UserSet", principalColumn: "Id", @@ -111,11 +111,13 @@ namespace StubbedContextLib.Migrations { { 1L, "tony@gmail.com", "1234", "Fages", "Tony", "TonyF", "Admin" }, { 2L, "tom@mail.com", "1234", "Smith", "Tom", "TomS", "User" }, - { 3L, "M&M#mail.com", "1234", "M&M's", "Red", "RedM", "Modérator" } + { 3L, "M&M#mail.com", "1234", "M&M's", "Red", "RedM", "Modérator" }, + { 4L, "ShaCasca@gmail.com", "1234", "Cascarra", "Cascarra", "Sha", "Admin" }, + { 5L, "", "1234", "Sillard", "Noa", "NoaSil", "Admin" } }); migrationBuilder.InsertData( - table: "ArticleUserEntity", + table: "ArticleUserSet", columns: new[] { "ArticleEntityId", "UserEntityId" }, values: new object[,] { @@ -126,9 +128,19 @@ namespace StubbedContextLib.Migrations { 3L, 3L } }); + migrationBuilder.InsertData( + table: "FormSet", + columns: new[] { "Id", "DatePublication", "Link", "Pseudo", "Theme", "UserEntityId" }, + values: new object[,] + { + { 1L, "Form 1 Description", "hhtp://form1.com", "Form 1", "", 1L }, + { 2L, "Form 2 Description", "hhtp://form2.com", "Form 2", "", 2L }, + { 3L, "Form 3 Description", "hhtp://form3.com", "Form 3", "", 3L } + }); + migrationBuilder.CreateIndex( - name: "IX_ArticleUserEntity_UserEntityId", - table: "ArticleUserEntity", + name: "IX_ArticleUserSet_UserEntityId", + table: "ArticleUserSet", column: "UserEntityId"); migrationBuilder.CreateIndex( @@ -141,7 +153,7 @@ namespace StubbedContextLib.Migrations protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( - name: "ArticleUserEntity"); + name: "ArticleUserSet"); migrationBuilder.DropTable( name: "FormSet"); diff --git a/Verax_API_EF/Verax_API_EF/StubbedContextLib/Migrations/StubbedContextModelSnapshot.cs b/Verax_API_EF/Verax_API_EF/DbContextLib/Migrations/LibraryContextModelSnapshot.cs similarity index 80% rename from Verax_API_EF/Verax_API_EF/StubbedContextLib/Migrations/StubbedContextModelSnapshot.cs rename to Verax_API_EF/Verax_API_EF/DbContextLib/Migrations/LibraryContextModelSnapshot.cs index c4e950b..4e992dc 100644 --- a/Verax_API_EF/Verax_API_EF/StubbedContextLib/Migrations/StubbedContextModelSnapshot.cs +++ b/Verax_API_EF/Verax_API_EF/DbContextLib/Migrations/LibraryContextModelSnapshot.cs @@ -1,15 +1,15 @@ // +using DbContextLib; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using StubbedContextLib; #nullable disable -namespace StubbedContextLib.Migrations +namespace DbContextLib.Migrations { - [DbContext(typeof(StubbedContext))] - partial class StubbedContextModelSnapshot : ModelSnapshot + [DbContext(typeof(LibraryContext))] + partial class LibraryContextModelSnapshot : ModelSnapshot { protected override void BuildModel(ModelBuilder modelBuilder) { @@ -87,7 +87,7 @@ namespace StubbedContextLib.Migrations b.HasIndex("UserEntityId"); - b.ToTable("ArticleUserEntity"); + b.ToTable("ArticleUserSet"); b.HasData( new @@ -147,6 +147,35 @@ namespace StubbedContextLib.Migrations b.HasIndex("UserEntityId"); b.ToTable("FormSet"); + + b.HasData( + new + { + Id = 1L, + DatePublication = "Form 1 Description", + Link = "hhtp://form1.com", + Pseudo = "Form 1", + Theme = "", + UserEntityId = 1L + }, + new + { + Id = 2L, + DatePublication = "Form 2 Description", + Link = "hhtp://form2.com", + Pseudo = "Form 2", + Theme = "", + UserEntityId = 2L + }, + new + { + Id = 3L, + DatePublication = "Form 3 Description", + Link = "hhtp://form3.com", + Pseudo = "Form 3", + Theme = "", + UserEntityId = 3L + }); }); modelBuilder.Entity("Entities.UserEntity", b => @@ -213,6 +242,26 @@ namespace StubbedContextLib.Migrations Prenom = "Red", Pseudo = "RedM", Role = "Modérator" + }, + new + { + Id = 4L, + Mail = "ShaCasca@gmail.com", + Mdp = "1234", + Nom = "Cascarra", + Prenom = "Cascarra", + Pseudo = "Sha", + Role = "Admin" + }, + new + { + Id = 5L, + Mail = "", + Mdp = "1234", + Nom = "Sillard", + Prenom = "Noa", + Pseudo = "NoaSil", + Role = "Admin" }); }); diff --git a/Verax_API_EF/Verax_API_EF/StubbedContextLib/StubTest.cs b/Verax_API_EF/Verax_API_EF/StubbedContextLib/StubTest.cs deleted file mode 100644 index 6e01d1f..0000000 --- a/Verax_API_EF/Verax_API_EF/StubbedContextLib/StubTest.cs +++ /dev/null @@ -1,26 +0,0 @@ -using Entities; -using Model; - -namespace StubbedContextLib; - -public class StubTest -{ - private List
_article; - - public List
StubArticle() - { - _article = new List
- { - new Article - { - Id = 1, - Title = "Test", - Description = "Test", - Author = "Test", - DatePublished = "Test", - LectureTime = 1 - } - }; - return _article; - } -} \ No newline at end of file diff --git a/Verax_API_EF/Verax_API_EF/Test_Console_EF/Entity_FrameWork.Article.db b/Verax_API_EF/Verax_API_EF/Test_Console_EF/Entity_FrameWork.Article.db new file mode 100644 index 0000000000000000000000000000000000000000..16746d575d690983803c342494bc39c7fa82814b GIT binary patch literal 45056 zcmeI*O>g7I83%AuluSvEJp~r3uyBGMDQIFLe$h*^Zkt0^vFTKZB|DO~*gX^mEzMf2 zB~c-%xIVPNZi4m`^w?{Q9{MSI>!C#t?J0)(k;#Wncm|`rG@Bth34|q@}k9v zv~}-qE9~D=QoSp!{)PQ+<<~3CXNrk0mj4;QqyB*cF+l(V5P$##o+JS?sit3DlkcaD zep~#ca_4xTK4KffIlgTROY1v^b5UvgVavO9t=!ajrM9Qt;n@WnXZc}`XZ<8uzMh@V zDVw{$oKVx1oP579F0pJmMyo5_&1MS@MkVLU55@=TJgP=;gZbLLdp)kE*Vg2pCmj8x zEBspfvxHw>v;6vjHr=Eorzu-$XNjVzy`j~4?Xbyfw+{~Z?qRLbtd}XAXOG?-Yi9XT zy;3dL@A5abyS#k6d044Y=2flM+!$rn?1-Mo@}_o&GV(L?qxN)191TypMoV`Lvmd_E zfzdw;k2$i%ux*CN1-fRgF{ARQTeLrEk!L;IU0J?=Sl23V)VyZS_B^j^`&wPA?P?9~ z4GK!`_6RxV+%dDK9cVPVcFT?3@}8E=z5BBzHJ!`Jzu58mCfJq1H8t2%!AL4&WPFv@ zX8p9|p+Dcn^D5NOvn5V<_xfC(8>9A5%E-;O$=vvB5iH zl;E6}^sdvnpfqjX(FcQz!p+Tmann7eZJPZHzOSDO`$SQt&7WoxH>xjGU!;P>Ik!a1 z7>L<*H&=7$c)1x4ZR$`-C&G4kt7EpzF5MZ%#XG{H?2B$O`J1C0>Y}YjRB8J>Bj2Dq z%e)edqmJ1Zyzt6gz~WK{UXox5O4ID|M$d3MhOA1J9u@JrCG<0+f68m(+~!)>u=Nw+ zba;{P8KUi$M|YKoJ~!`it$*5eZQ2yU9kZv!~ncszdKvr#*Vo<5tV;mD@d|pNYk#>#4PCE9si4H;k^EfM#9YYEyu>$<1h7 zx|VwGxk9?p(cSo6-EQfYrH|(n>@Ch@y`{vZR4RS#I~ls7pz0>{t}k#`UZ_4lu0_>s z|Ngi1*h14lxS2*$VxOuKO>P? zM3HGmm5wEn-ueGWGW(4EgMGx_XYYS=+k%=w00Izz00bZa0SG_<0uX=z1RyXkz&?}W zbnYKpipuWEzc-7-6g4Wlr~jk#|Iz*bXA=7p`xQH5>+`uF1OgC%00bZa0SG_<0uX=z z1R(HK3G8lXb~1@QL08-Nd0W`L`=UNP5tq*)>^RQA{{Hs%`T05BL-3B#cJCx`ue%>T zoG?!hCtN9PUiWUy=Ow-;?3QH=9K-B)I?jL+-ZQOU$xYLXQ literal 0 HcmV?d00001 diff --git a/Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db-shm b/Verax_API_EF/Verax_API_EF/Test_Console_EF/Entity_FrameWork.Article.db-shm similarity index 98% rename from Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db-shm rename to Verax_API_EF/Verax_API_EF/Test_Console_EF/Entity_FrameWork.Article.db-shm index 96623946a4b4bc58f4fe04bed83515e2f12f40a0..edfc9f003c66ba865c091c0046b9e5913e6b4f5e 100644 GIT binary patch delta 145 zcmZo@U}|V!N|1P@%K!q55G=q9q`853$DjO^YkP9{AL`-}J5Ufcq1K~F<^8{09a7a# tOwizD1)9eRGI!&|OplEV{;+QT>^EbbLOw3FS%o``Nng9TankOj$ diff --git a/Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db-wal b/Verax_API_EF/Verax_API_EF/Test_Console_EF/Entity_FrameWork.Article.db-wal similarity index 94% rename from Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db-wal rename to Verax_API_EF/Verax_API_EF/Test_Console_EF/Entity_FrameWork.Article.db-wal index f654cc2e62dc58070624013c771c3eb0673de1ce..e170424f429b735762cb9608735f3bf81b8652fe 100644 GIT binary patch literal 12392 zcmeI$ze>YE90%|um!`y6&q)-Q6hWt$e`=wdT6_U@aqFK*gH03CXh*?O5LCp?*;f!0 z6<@%~JV4#rr64#J@lt7V=>wF0e~{$v2j9SbZo12zN@twbn&-G#E~&Tk>ABb7;IjR7 z@nNsWdDcq(?=Szv_gC)Cb%r$wjXBz-pX`Hz00bZa0SG_<0uX=z1Rwwb2tZ(L1QbFR z`5iy>cAZF41UA`kI3b&)XLyq3H^ay+*Bmw%*^=aBS%dq6=hjkNxqaM9?gd0z;^;fQ zqepCjf&c^{009U<00Izz00bZa0SHXCz_y;vW#xk772Ud8aT;oErFdL&%ni-3G|RBo zs!8U-wP$WHQh z5=xHrs!a^xf5IA(u!ads(D}cF-2a0)B4G{_Cfiaac?S0a6~FiJ;yuMvtSQnCM|-qG uziD@}w;rp900bZa0SG_<0uX=z1Rwwb2#mdeNMv405uPU`c?$v|viu9FKzGal literal 12392 zcmeI$y-UMD7zXf56Qoe|1PQT-LlNr-ZJ|}@Ae3~eNXejSS0%Ke2AUpR0^%gN`X9K6 zlXTPBO%YriT-?>Mf+Fbboi$*QIx9RcT$1%|=Y31VT&34qo zZfU*#>h;8y`hEYVXdaxNGh3j3~>}gZx0vcT-^p>8` z9r1yJ00bZa0SG_<0uX=z1Rwwb2tZ)CKt_v`MYMD_>Yz zw$j#IAe*!`<2znE*I>TInwMSfgpAL}zUK8B^KChA`(C&$nvnTsG%tVtvr3#8x}h%^ zHP+d!$kB?^as%0gVwtUIy4>`=j=0c3F2M4= a.Author.Equals("Tony Fages")); - foreach (var article in articles) - { - Console.WriteLine($"{article.Author} - {article.Title} - {article.Description} - {article.DatePublished} - {article.LectureTime}"); - } - } -} - -// Allows to add an article to the db -void addArticle() -{ - using (var context = new LibraryContext()) - { - var article = new ArticleEntity - { - Title = "Louis is not sick anymore", - Description = "Louis is not sick anymore, he is now healthy and happy", - DatePublished = "16-02-2024", - LectureTime = 1, - Author = "Tony Fages" - }; - context.ArticleSet.Add(article); - context.SaveChanges(); - } -} - - -// Allows to modify an article from the db -void modifyArticle() -{ - using (var context = new LibraryContext()) - { - var article = context.ArticleSet.Where(a => a.Author.Equals("Tom Smith")); - - foreach (var articles in article) - { - articles.Title = "Demain des l'aube"; - context.SaveChanges(); - } - } -} - -// Allows to delete an article from the db -void deleteArticle() -{ - using (var context = new LibraryContext()) - { - var article = context.ArticleSet.Where(a => a.Author.Equals("M&M's Red")); - - foreach (var articles in article) - { - context.ArticleSet.Remove(articles); - context.SaveChanges(); - } - } -} \ No newline at end of file diff --git a/Verax_API_EF/Verax_API_EF/Test_Console_EF/Test_Console_Article.cs b/Verax_API_EF/Verax_API_EF/Test_Console_EF/Test_Console_Article.cs new file mode 100644 index 0000000..ae275db --- /dev/null +++ b/Verax_API_EF/Verax_API_EF/Test_Console_EF/Test_Console_Article.cs @@ -0,0 +1,304 @@ +// See https://aka.ms/new-console-template for more information + +using DbContextLib; +using Entities; + +//Article +//addArticle(); +listArticle(); +//modifyArticle(); +//deleteArticle(); +//listArticleByAuthor(); + +//Form +//addForm(); +listForms(); +//updateForm(); +//deleteForm(); + +//User +//listUser(); +//addUser(); +//updateUser(); +//deleteUser(); + +//ArticleUser +//listArticleUser(); +//addArticleUser(); +//updateArticleUser(); +//deleteArticleUser(); + +//FormUser +listFormUser(); +//addFormUser(); + + +// Allows to list all the articles from the db +void listArticle() +{ + using (var context = new LibraryContext()) + { + var articles = context.ArticleSet; + foreach (var article in articles) + { + Console.WriteLine($"{article.Author} - {article.Title} - {article.Description} - {article.DatePublished} - {article.LectureTime}"); + } + } +} + + +// Allows to list all the articles from the db by author +void listArticleByAuthor() +{ + using (var context = new LibraryContext()) + { + var articles = context.ArticleSet.Where(a => a.Author.Equals("Tony Fages")); + foreach (var article in articles) + { + Console.WriteLine($"{article.Author} - {article.Title} - {article.Description} - {article.DatePublished} - {article.LectureTime}"); + } + } +} + +// Allows to add an article to the db +void addArticle() +{ + using (var context = new LibraryContext()) + { + var article = new ArticleEntity + { + Title = "Louis is not sick anymore", + Description = "Louis is not sick anymore, he is now healthy and happy", + DatePublished = "16-02-2024", + LectureTime = 1, + Author = "Tony Fages" + }; + context.ArticleSet.Add(article); + context.SaveChanges(); + } +} + + +// Allows to modify an article from the db +void modifyArticle() +{ + using (var context = new LibraryContext()) + { + var article = context.ArticleSet.Where(a => a.Author.Equals("Tom Smith")); + + foreach (var articles in article) + { + articles.Title = "Demain des l'aube"; + context.SaveChanges(); + } + } +} + +// Allows to delete an article from the db +void deleteArticle() +{ + using (var context = new LibraryContext()) + { + var article = context.ArticleSet.Where(a => a.Author.Equals("M&M's Red")); + + foreach (var articles in article) + { + context.ArticleSet.Remove(articles); + context.SaveChanges(); + } + } +} + +// Allow to get all forms +void listForms() +{ + using (var context = new LibraryContext()) + { + var forms = context.FormSet; + foreach (var form in forms) + { + Console.WriteLine($"{form.Id} - {form.Link} - {form.DatePublication} - {form.Pseudo} - {form.Theme} - {form.UserEntityId}"); + } + } +} + +void addForm() +{ + using (var context = new LibraryContext()) + { + var form = new FormEntity + { + Id = 5, + Theme = "Covid", + DatePublication = "16-02-2024", + Link = "https://www.covid.com", + Pseudo = "Tony Fages", + UserEntityId = 1 + }; + context.FormSet.Add(form); + context.SaveChanges(); + } +} + +void updateForm() +{ + using (var context = new LibraryContext()) + { + var form = context.FormSet.Where(f => f.Id.Equals(5)); + + foreach (var forms in form) + { + forms.Theme = "Demain des l'aube"; + context.SaveChanges(); + } + } +} + +void deleteForm() +{ + using (var context = new LibraryContext()) + { + var form = context.FormSet.Where(f => f.Id.Equals(5)); + + foreach (var forms in form) + { + context.FormSet.Remove(forms); + context.SaveChanges(); + } + } +} + +void listUser() +{ + using (var context = new LibraryContext()) + { + var users = context.UserSet; + foreach (var user in users) + { + Console.WriteLine($"{user.Id} - {user.Pseudo} - {user.Nom} - {user.Prenom} - {user.Mail} - {user.Role}"); + } + } +} + +void addUser() +{ + using (var context = new LibraryContext()) + { + var user = new UserEntity + { + Id = 7, Nom = "Fages", Prenom = "Tony", Pseudo = "TonyF", Mail = "tony@gmail.com", Mdp = "1234", Role = "Admin" + }; + context.UserSet.Add(user); + context.SaveChanges(); + } + listUser(); +} + +void updateUser() +{ + using (var context = new LibraryContext()) + { + var user = context.UserSet.Where(u => u.Id.Equals(7)); + + foreach (var users in user) + { + users.Nom = "Thomas"; + context.SaveChanges(); + } + } + listUser(); +} + +void deleteUser() +{ + using (var context = new LibraryContext()) + { + var user = context.UserSet.Where(u => u.Id.Equals(7)); + + foreach (var users in user) + { + context.UserSet.Remove(users); + context.SaveChanges(); + } + } + listUser(); +} + +void listArticleUser() +{ + using (var context = new LibraryContext()) + { + var articleUsers = context.ArticleUserSet; + foreach (var articleUser in articleUsers) + { + Console.WriteLine($"{articleUser.ArticleEntityId} - {articleUser.UserEntityId}"); + } + } +} + +void addArticleUser() +{ + using (var context = new LibraryContext()) + { + var articleUser = new ArticleUserEntity + { + ArticleEntityId = 2, + UserEntityId = 1 + }; + context.ArticleUserSet.Add(articleUser); + context.SaveChanges(); + } + listArticleUser(); +} + +void updateArticleUser() +{ + using (var context = new LibraryContext()) + { + var articleUser = context.ArticleUserSet.FirstOrDefault(au => au.UserEntityId.Equals(2)); + if (articleUser != null) articleUser.UserEntityId = 3; + context.SaveChanges(); + } + listArticleUser(); +} + +void deleteArticleUser() +{ + using (var context = new LibraryContext()) + { + var articleUser = context.ArticleUserSet.Where(au => au.UserEntityId.Equals(1)).Where(u => u.ArticleEntityId.Equals(1)); + + foreach (var articleUsers in articleUser) + { + context.ArticleUserSet.Remove(articleUsers); + context.SaveChanges(); + } + } + listArticleUser(); +} + +void listFormUser() +{ + using (var context = new LibraryContext()) + { + var formUsers = context.FormSet; + foreach (var formUser in formUsers) + { + Console.WriteLine($"{formUser.UserEntityId}"); + } + } +} + +void addFormUser() +{ + using (var context = new LibraryContext()) + { + var formUser = new FormEntity + { + UserEntityId = 1 + }; + context.FormSet.Add(formUser); + context.SaveChanges(); + } +} +