From 40acb54f79403d1608f2a2f7e7e72bb36b8330ad Mon Sep 17 00:00:00 2001 From: PATRICK Date: Sat, 30 Mar 2024 17:47:03 +0100 Subject: [PATCH] fix many to many --- .../API/Db.in_english_please.db | Bin 106496 -> 106496 bytes .../API/Db.in_english_please.db-shm | Bin 0 -> 32768 bytes .../API/Db.in_english_please.db-wal | 0 .../EntityFramework/DbContext/SAEContext.cs | 5 +- ....cs => 20240330163827_newMigs.Designer.cs} | 10 +-- ...6_newMigs.cs => 20240330163827_newMigs.cs} | 82 +++++++++--------- .../Migrations/StubbedContextModelSnapshot.cs | 8 +- Project/EntityFramework/TU/TranslateTU.cs | 33 +------ .../EntityFramework/TU/VocabularyListTU.cs | 37 -------- Project/EntityFramework/TU/VocabularyTU.cs | 37 -------- 10 files changed, 52 insertions(+), 160 deletions(-) create mode 100644 Project/EntityFramework/API/Db.in_english_please.db-shm create mode 100644 Project/EntityFramework/API/Db.in_english_please.db-wal rename Project/EntityFramework/StubbedContext/Migrations/{20240316154336_newMigs.Designer.cs => 20240330163827_newMigs.Designer.cs} (98%) rename Project/EntityFramework/StubbedContext/Migrations/{20240316154336_newMigs.cs => 20240330163827_newMigs.cs} (85%) diff --git a/Project/EntityFramework/API/Db.in_english_please.db b/Project/EntityFramework/API/Db.in_english_please.db index 867cda464484e9b5daaaa5d48fa524f7dbba6b35..d85099670d0640e3c9b9834c3729d8eabd21dc62 100644 GIT binary patch delta 1568 zcmeHHPfXKb6z8>FySCdpP*(;5T{jpEkRegLj6cd^77!FcNsNpk4G@u$eGnwkFc4I3 z#wOGo(Ss(6Ca}a^FxkOGqmhI0po!7DdNU@(sQ9hJl#pn+aP#u=zOV1S-+O((?-x(e z@f3XnIqzD*I&K-@SxdEffvKPx=vTy3LLrnyw*4KbZy@ZRp0F{Z%LTK6(Ma!*(h-Xc zqoK&Cf(%dXA#&BYrAl2SSU~D9<5oWqz1b*yDta!`J2n)FO|%T6QKWTy!J#cwK%LrP zF63r83nMl+!yKP@PeuV}o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?ZL>vP-uVfRA^(Wf`An&S7(-3a_h1pLh%@RYK8fdV+JDHAVB7}K_!{A zLCCzdl$DP Vocabularys { get; set; } public DbSet VocabularyLists { get; set; } - public DbSet GroupVocabularyList { get; set; } - public DbSet VocsGroups { get; set; } - public DbSet Voctranslations { get; set; } - public DbSet TransVoc { get; set; } + //permet de créer une base de donnée (fichier .db) ici en Sqlite avec le nom Db.Books.db diff --git a/Project/EntityFramework/StubbedContext/Migrations/20240316154336_newMigs.Designer.cs b/Project/EntityFramework/StubbedContext/Migrations/20240330163827_newMigs.Designer.cs similarity index 98% rename from Project/EntityFramework/StubbedContext/Migrations/20240316154336_newMigs.Designer.cs rename to Project/EntityFramework/StubbedContext/Migrations/20240330163827_newMigs.Designer.cs index 0cf189d..b550929 100644 --- a/Project/EntityFramework/StubbedContext/Migrations/20240316154336_newMigs.Designer.cs +++ b/Project/EntityFramework/StubbedContext/Migrations/20240330163827_newMigs.Designer.cs @@ -10,7 +10,7 @@ using StubbedContextLib; namespace StubbedContextLib.Migrations { [DbContext(typeof(StubbedContext))] - [Migration("20240316154336_newMigs")] + [Migration("20240330163827_newMigs")] partial class newMigs { /// @@ -37,7 +37,7 @@ namespace StubbedContextLib.Migrations b.HasKey("Id"); - b.ToTable("GroupEntity"); + b.ToTable("Groups"); b.HasData( new @@ -118,7 +118,7 @@ namespace StubbedContextLib.Migrations b.HasIndex("VocabularyListVocId"); - b.ToTable("TranslateEntity"); + b.ToTable("Translates"); b.HasData( new @@ -227,7 +227,7 @@ namespace StubbedContextLib.Migrations b.HasIndex("LangueName"); - b.ToTable("VocabularyEntity"); + b.ToTable("Vocabularys"); b.HasData( new @@ -258,7 +258,7 @@ namespace StubbedContextLib.Migrations b.HasIndex("UserId"); - b.ToTable("VocabularyListEntity"); + b.ToTable("VocabularyLists"); b.HasData( new diff --git a/Project/EntityFramework/StubbedContext/Migrations/20240316154336_newMigs.cs b/Project/EntityFramework/StubbedContext/Migrations/20240330163827_newMigs.cs similarity index 85% rename from Project/EntityFramework/StubbedContext/Migrations/20240316154336_newMigs.cs rename to Project/EntityFramework/StubbedContext/Migrations/20240330163827_newMigs.cs index c81fcd3..6377dc5 100644 --- a/Project/EntityFramework/StubbedContext/Migrations/20240316154336_newMigs.cs +++ b/Project/EntityFramework/StubbedContext/Migrations/20240330163827_newMigs.cs @@ -13,7 +13,7 @@ namespace StubbedContextLib.Migrations protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( - name: "GroupEntity", + name: "Groups", columns: table => new { Id = table.Column(type: "INTEGER", nullable: false) @@ -24,7 +24,7 @@ namespace StubbedContextLib.Migrations }, constraints: table => { - table.PrimaryKey("PK_GroupEntity", x => x.Id); + table.PrimaryKey("PK_Groups", x => x.Id); }); migrationBuilder.CreateTable( @@ -52,7 +52,7 @@ namespace StubbedContextLib.Migrations }); migrationBuilder.CreateTable( - name: "VocabularyEntity", + name: "Vocabularys", columns: table => new { word = table.Column(type: "TEXT", nullable: false), @@ -60,9 +60,9 @@ namespace StubbedContextLib.Migrations }, constraints: table => { - table.PrimaryKey("PK_VocabularyEntity", x => x.word); + table.PrimaryKey("PK_Vocabularys", x => x.word); table.ForeignKey( - name: "FK_VocabularyEntity_Langues_LangueName", + name: "FK_Vocabularys_Langues_LangueName", column: x => x.LangueName, principalTable: "Langues", principalColumn: "name", @@ -89,9 +89,9 @@ namespace StubbedContextLib.Migrations { table.PrimaryKey("PK_Users", x => x.Id); table.ForeignKey( - name: "FK_Users_GroupEntity_GroupId", + name: "FK_Users_Groups_GroupId", column: x => x.GroupId, - principalTable: "GroupEntity", + principalTable: "Groups", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( @@ -103,7 +103,7 @@ namespace StubbedContextLib.Migrations }); migrationBuilder.CreateTable( - name: "VocabularyListEntity", + name: "VocabularyLists", columns: table => new { Id = table.Column(type: "INTEGER", nullable: false) @@ -114,9 +114,9 @@ namespace StubbedContextLib.Migrations }, constraints: table => { - table.PrimaryKey("PK_VocabularyListEntity", x => x.Id); + table.PrimaryKey("PK_VocabularyLists", x => x.Id); table.ForeignKey( - name: "FK_VocabularyListEntity_Users_UserId", + name: "FK_VocabularyLists_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", @@ -134,21 +134,21 @@ namespace StubbedContextLib.Migrations { table.PrimaryKey("PK_GroupEntityVocabularyListEntity", x => new { x.GroupVocabularyListId, x.VocsGroupsId }); table.ForeignKey( - name: "FK_GroupEntityVocabularyListEntity_GroupEntity_VocsGroupsId", + name: "FK_GroupEntityVocabularyListEntity_Groups_VocsGroupsId", column: x => x.VocsGroupsId, - principalTable: "GroupEntity", + principalTable: "Groups", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( - name: "FK_GroupEntityVocabularyListEntity_VocabularyListEntity_GroupVocabularyListId", + name: "FK_GroupEntityVocabularyListEntity_VocabularyLists_GroupVocabularyListId", column: x => x.GroupVocabularyListId, - principalTable: "VocabularyListEntity", + principalTable: "VocabularyLists", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( - name: "TranslateEntity", + name: "Translates", columns: table => new { Id = table.Column(type: "INTEGER", nullable: false) @@ -158,11 +158,11 @@ namespace StubbedContextLib.Migrations }, constraints: table => { - table.PrimaryKey("PK_TranslateEntity", x => x.Id); + table.PrimaryKey("PK_Translates", x => x.Id); table.ForeignKey( - name: "FK_TranslateEntity_VocabularyListEntity_VocabularyListVocId", + name: "FK_Translates_VocabularyLists_VocabularyListVocId", column: x => x.VocabularyListVocId, - principalTable: "VocabularyListEntity", + principalTable: "VocabularyLists", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); @@ -178,21 +178,21 @@ namespace StubbedContextLib.Migrations { table.PrimaryKey("PK_TranslateEntityVocabularyEntity", x => new { x.TransVocword, x.VoctranslationsId }); table.ForeignKey( - name: "FK_TranslateEntityVocabularyEntity_TranslateEntity_VoctranslationsId", + name: "FK_TranslateEntityVocabularyEntity_Translates_VoctranslationsId", column: x => x.VoctranslationsId, - principalTable: "TranslateEntity", + principalTable: "Translates", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( - name: "FK_TranslateEntityVocabularyEntity_VocabularyEntity_TransVocword", + name: "FK_TranslateEntityVocabularyEntity_Vocabularys_TransVocword", column: x => x.TransVocword, - principalTable: "VocabularyEntity", + principalTable: "Vocabularys", principalColumn: "word", onDelete: ReferentialAction.Cascade); }); migrationBuilder.InsertData( - table: "GroupEntity", + table: "Groups", columns: new[] { "Id", "Num", "sector", "year" }, values: new object[] { 1L, 1, "informatics", 1 }); @@ -226,17 +226,17 @@ namespace StubbedContextLib.Migrations }); migrationBuilder.InsertData( - table: "VocabularyEntity", + table: "Vocabularys", columns: new[] { "word", "LangueName" }, values: new object[] { "Bonjour", "French" }); migrationBuilder.InsertData( - table: "VocabularyListEntity", + table: "VocabularyLists", columns: new[] { "Id", "Image", "Name", "UserId" }, values: new object[] { 1L, "image1", "Liste1", 1L }); migrationBuilder.InsertData( - table: "TranslateEntity", + table: "Translates", columns: new[] { "Id", "VocabularyListVocId", "WordsId" }, values: new object[] { 1L, 1L, "1" }); @@ -245,16 +245,16 @@ namespace StubbedContextLib.Migrations table: "GroupEntityVocabularyListEntity", column: "VocsGroupsId"); - migrationBuilder.CreateIndex( - name: "IX_TranslateEntity_VocabularyListVocId", - table: "TranslateEntity", - column: "VocabularyListVocId"); - migrationBuilder.CreateIndex( name: "IX_TranslateEntityVocabularyEntity_VoctranslationsId", table: "TranslateEntityVocabularyEntity", column: "VoctranslationsId"); + migrationBuilder.CreateIndex( + name: "IX_Translates_VocabularyListVocId", + table: "Translates", + column: "VocabularyListVocId"); + migrationBuilder.CreateIndex( name: "IX_Users_GroupId", table: "Users", @@ -266,14 +266,14 @@ namespace StubbedContextLib.Migrations column: "RoleId"); migrationBuilder.CreateIndex( - name: "IX_VocabularyEntity_LangueName", - table: "VocabularyEntity", - column: "LangueName"); + name: "IX_VocabularyLists_UserId", + table: "VocabularyLists", + column: "UserId"); migrationBuilder.CreateIndex( - name: "IX_VocabularyListEntity_UserId", - table: "VocabularyListEntity", - column: "UserId"); + name: "IX_Vocabularys_LangueName", + table: "Vocabularys", + column: "LangueName"); } /// @@ -286,13 +286,13 @@ namespace StubbedContextLib.Migrations name: "TranslateEntityVocabularyEntity"); migrationBuilder.DropTable( - name: "TranslateEntity"); + name: "Translates"); migrationBuilder.DropTable( - name: "VocabularyEntity"); + name: "Vocabularys"); migrationBuilder.DropTable( - name: "VocabularyListEntity"); + name: "VocabularyLists"); migrationBuilder.DropTable( name: "Langues"); @@ -301,7 +301,7 @@ namespace StubbedContextLib.Migrations name: "Users"); migrationBuilder.DropTable( - name: "GroupEntity"); + name: "Groups"); migrationBuilder.DropTable( name: "Roles"); diff --git a/Project/EntityFramework/StubbedContext/Migrations/StubbedContextModelSnapshot.cs b/Project/EntityFramework/StubbedContext/Migrations/StubbedContextModelSnapshot.cs index 4177cc3..6347fe3 100644 --- a/Project/EntityFramework/StubbedContext/Migrations/StubbedContextModelSnapshot.cs +++ b/Project/EntityFramework/StubbedContext/Migrations/StubbedContextModelSnapshot.cs @@ -34,7 +34,7 @@ namespace StubbedContextLib.Migrations b.HasKey("Id"); - b.ToTable("GroupEntity"); + b.ToTable("Groups"); b.HasData( new @@ -115,7 +115,7 @@ namespace StubbedContextLib.Migrations b.HasIndex("VocabularyListVocId"); - b.ToTable("TranslateEntity"); + b.ToTable("Translates"); b.HasData( new @@ -224,7 +224,7 @@ namespace StubbedContextLib.Migrations b.HasIndex("LangueName"); - b.ToTable("VocabularyEntity"); + b.ToTable("Vocabularys"); b.HasData( new @@ -255,7 +255,7 @@ namespace StubbedContextLib.Migrations b.HasIndex("UserId"); - b.ToTable("VocabularyListEntity"); + b.ToTable("VocabularyLists"); b.HasData( new diff --git a/Project/EntityFramework/TU/TranslateTU.cs b/Project/EntityFramework/TU/TranslateTU.cs index 8d3906a..7783bdf 100644 --- a/Project/EntityFramework/TU/TranslateTU.cs +++ b/Project/EntityFramework/TU/TranslateTU.cs @@ -148,37 +148,6 @@ namespace TU } } - [TestMethod] - public async Task TestAddVocabToTranslate() - { - var connection = new SqliteConnection("DataSource=:memory:"); - connection.Open(); - var options = new DbContextOptionsBuilder() - .UseSqlite(connection) - .Options; - - using (var context = new StubbedContext(options)) - { - context.Database.EnsureCreated(); - - var mockLogger = new Mock>(); - - var controller = new TranslateController(new TranslateService(context), mockLogger.Object); - var result = await controller.AddVocab("Bonjour", 1); - Assert.IsNotNull(result.Value); - Assert.AreEqual("Bonjour", result.Value.word); - - var res = await context.Translates.FirstOrDefaultAsync(v => v.Id == 1); - Assert.IsNotNull(res); - var test = res.TransVoc.FirstOrDefault(t => t.word == "Bonjour"); - Assert.IsNotNull(test); - Assert.AreEqual("Bonjour", test.word); - - var test2 = await context.TransVoc.FirstOrDefaultAsync(t => t.word == "Bonjour"); - Assert.IsNotNull(test2); - Assert.AreEqual("Bonjour", test2.word); - - } - } + } } diff --git a/Project/EntityFramework/TU/VocabularyListTU.cs b/Project/EntityFramework/TU/VocabularyListTU.cs index 3ad2793..443ed30 100644 --- a/Project/EntityFramework/TU/VocabularyListTU.cs +++ b/Project/EntityFramework/TU/VocabularyListTU.cs @@ -179,43 +179,6 @@ namespace TU - } - } - - [TestMethod] - public async Task TestAddGroupToVocabularyList() - { - var connection = new SqliteConnection("DataSource=:memory:"); - connection.Open(); - var options = new DbContextOptionsBuilder() - .UseSqlite(connection) - .Options; - - using (var context = new StubbedContext(options)) - { - context.Database.EnsureCreated(); - - var mockLogger = new Mock>(); - - var controller = new VocabularyListController(new VocabularyListService(context), mockLogger.Object); - - var result = await controller.AddGroupToVocabularyList(1, 1); - Assert.IsNotNull(result.Value); - Assert.AreEqual("informatics", result.Value.sector); - Assert.AreEqual(1, result.Value.Id); - - var res = await context.VocabularyLists.FirstOrDefaultAsync(v => v.Id == 1); - Assert.IsNotNull(res); - var test = res.VocsGroups.FirstOrDefault(g => g.Id == 1); - Assert.IsNotNull(test); - Assert.AreEqual("informatics", test.sector); - Assert.AreEqual(1, test.Id); - var test2 = await context.VocsGroups.FirstOrDefaultAsync(g => g.Id == 1); - Assert.IsNotNull(test2); - Assert.AreEqual("informatics", test2.sector); - Assert.AreEqual(1, test2.Id); - - } } } diff --git a/Project/EntityFramework/TU/VocabularyTU.cs b/Project/EntityFramework/TU/VocabularyTU.cs index 22dea5a..847d2d3 100644 --- a/Project/EntityFramework/TU/VocabularyTU.cs +++ b/Project/EntityFramework/TU/VocabularyTU.cs @@ -174,43 +174,6 @@ namespace TU } } - [TestMethod] - public async Task TestAddTranslation() - { - - var connection = new SqliteConnection("DataSource=:memory:"); - connection.Open(); - var options = new DbContextOptionsBuilder() - .UseSqlite(connection) - .Options; - - using (var context = new StubbedContext(options)) - { - context.Database.EnsureCreated(); - - var mockLogger = new Mock>(); - - var controller = new VocabularyController(new VocabularyService(context), mockLogger.Object); - var result3 = await controller.AddTranslation("Bonjour",1); - Assert.IsNotNull(result3.Value); - Assert.AreEqual(1, result3.Value.Id); - - - var res = await context.Vocabularys.FirstOrDefaultAsync(v => v.word == "Bonjour"); - Assert.IsNotNull(res); - var test = res.Voctranslations.FirstOrDefault(t => t.Id == 1); - Assert.IsNotNull(test); - Assert.AreEqual(1, test.Id); - - - var test2 = await context.Voctranslations.FirstOrDefaultAsync(t => t.Id == 1); - Assert.IsNotNull(test2); - Assert.AreEqual(1, test2.Id); - - - } - } - } }