fix many to many
continuous-integration/drone/push Build is passing Details

WebAPI
PATRICK 1 year ago
parent d57695c21d
commit 40acb54f79

@ -15,10 +15,7 @@ namespace DbContextLib
public DbSet<VocabularyEntity> Vocabularys { get; set; } public DbSet<VocabularyEntity> Vocabularys { get; set; }
public DbSet<VocabularyListEntity> VocabularyLists { get; set; } public DbSet<VocabularyListEntity> VocabularyLists { get; set; }
public DbSet<VocabularyListEntity> GroupVocabularyList { get; set; }
public DbSet<GroupEntity> VocsGroups { get; set; }
public DbSet<TranslateEntity> Voctranslations { get; set; }
public DbSet<VocabularyEntity> TransVoc { get; set; }
//permet de créer une base de donnée (fichier .db) ici en Sqlite avec le nom Db.Books.db //permet de créer une base de donnée (fichier .db) ici en Sqlite avec le nom Db.Books.db

@ -10,7 +10,7 @@ using StubbedContextLib;
namespace StubbedContextLib.Migrations namespace StubbedContextLib.Migrations
{ {
[DbContext(typeof(StubbedContext))] [DbContext(typeof(StubbedContext))]
[Migration("20240316154336_newMigs")] [Migration("20240330163827_newMigs")]
partial class newMigs partial class newMigs
{ {
/// <inheritdoc /> /// <inheritdoc />
@ -37,7 +37,7 @@ namespace StubbedContextLib.Migrations
b.HasKey("Id"); b.HasKey("Id");
b.ToTable("GroupEntity"); b.ToTable("Groups");
b.HasData( b.HasData(
new new
@ -118,7 +118,7 @@ namespace StubbedContextLib.Migrations
b.HasIndex("VocabularyListVocId"); b.HasIndex("VocabularyListVocId");
b.ToTable("TranslateEntity"); b.ToTable("Translates");
b.HasData( b.HasData(
new new
@ -227,7 +227,7 @@ namespace StubbedContextLib.Migrations
b.HasIndex("LangueName"); b.HasIndex("LangueName");
b.ToTable("VocabularyEntity"); b.ToTable("Vocabularys");
b.HasData( b.HasData(
new new
@ -258,7 +258,7 @@ namespace StubbedContextLib.Migrations
b.HasIndex("UserId"); b.HasIndex("UserId");
b.ToTable("VocabularyListEntity"); b.ToTable("VocabularyLists");
b.HasData( b.HasData(
new new

@ -13,7 +13,7 @@ namespace StubbedContextLib.Migrations
protected override void Up(MigrationBuilder migrationBuilder) protected override void Up(MigrationBuilder migrationBuilder)
{ {
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "GroupEntity", name: "Groups",
columns: table => new columns: table => new
{ {
Id = table.Column<long>(type: "INTEGER", nullable: false) Id = table.Column<long>(type: "INTEGER", nullable: false)
@ -24,7 +24,7 @@ namespace StubbedContextLib.Migrations
}, },
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_GroupEntity", x => x.Id); table.PrimaryKey("PK_Groups", x => x.Id);
}); });
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
@ -52,7 +52,7 @@ namespace StubbedContextLib.Migrations
}); });
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "VocabularyEntity", name: "Vocabularys",
columns: table => new columns: table => new
{ {
word = table.Column<string>(type: "TEXT", nullable: false), word = table.Column<string>(type: "TEXT", nullable: false),
@ -60,9 +60,9 @@ namespace StubbedContextLib.Migrations
}, },
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_VocabularyEntity", x => x.word); table.PrimaryKey("PK_Vocabularys", x => x.word);
table.ForeignKey( table.ForeignKey(
name: "FK_VocabularyEntity_Langues_LangueName", name: "FK_Vocabularys_Langues_LangueName",
column: x => x.LangueName, column: x => x.LangueName,
principalTable: "Langues", principalTable: "Langues",
principalColumn: "name", principalColumn: "name",
@ -89,9 +89,9 @@ namespace StubbedContextLib.Migrations
{ {
table.PrimaryKey("PK_Users", x => x.Id); table.PrimaryKey("PK_Users", x => x.Id);
table.ForeignKey( table.ForeignKey(
name: "FK_Users_GroupEntity_GroupId", name: "FK_Users_Groups_GroupId",
column: x => x.GroupId, column: x => x.GroupId,
principalTable: "GroupEntity", principalTable: "Groups",
principalColumn: "Id", principalColumn: "Id",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
table.ForeignKey( table.ForeignKey(
@ -103,7 +103,7 @@ namespace StubbedContextLib.Migrations
}); });
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "VocabularyListEntity", name: "VocabularyLists",
columns: table => new columns: table => new
{ {
Id = table.Column<long>(type: "INTEGER", nullable: false) Id = table.Column<long>(type: "INTEGER", nullable: false)
@ -114,9 +114,9 @@ namespace StubbedContextLib.Migrations
}, },
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_VocabularyListEntity", x => x.Id); table.PrimaryKey("PK_VocabularyLists", x => x.Id);
table.ForeignKey( table.ForeignKey(
name: "FK_VocabularyListEntity_Users_UserId", name: "FK_VocabularyLists_Users_UserId",
column: x => x.UserId, column: x => x.UserId,
principalTable: "Users", principalTable: "Users",
principalColumn: "Id", principalColumn: "Id",
@ -134,21 +134,21 @@ namespace StubbedContextLib.Migrations
{ {
table.PrimaryKey("PK_GroupEntityVocabularyListEntity", x => new { x.GroupVocabularyListId, x.VocsGroupsId }); table.PrimaryKey("PK_GroupEntityVocabularyListEntity", x => new { x.GroupVocabularyListId, x.VocsGroupsId });
table.ForeignKey( table.ForeignKey(
name: "FK_GroupEntityVocabularyListEntity_GroupEntity_VocsGroupsId", name: "FK_GroupEntityVocabularyListEntity_Groups_VocsGroupsId",
column: x => x.VocsGroupsId, column: x => x.VocsGroupsId,
principalTable: "GroupEntity", principalTable: "Groups",
principalColumn: "Id", principalColumn: "Id",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
table.ForeignKey( table.ForeignKey(
name: "FK_GroupEntityVocabularyListEntity_VocabularyListEntity_GroupVocabularyListId", name: "FK_GroupEntityVocabularyListEntity_VocabularyLists_GroupVocabularyListId",
column: x => x.GroupVocabularyListId, column: x => x.GroupVocabularyListId,
principalTable: "VocabularyListEntity", principalTable: "VocabularyLists",
principalColumn: "Id", principalColumn: "Id",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
}); });
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "TranslateEntity", name: "Translates",
columns: table => new columns: table => new
{ {
Id = table.Column<long>(type: "INTEGER", nullable: false) Id = table.Column<long>(type: "INTEGER", nullable: false)
@ -158,11 +158,11 @@ namespace StubbedContextLib.Migrations
}, },
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_TranslateEntity", x => x.Id); table.PrimaryKey("PK_Translates", x => x.Id);
table.ForeignKey( table.ForeignKey(
name: "FK_TranslateEntity_VocabularyListEntity_VocabularyListVocId", name: "FK_Translates_VocabularyLists_VocabularyListVocId",
column: x => x.VocabularyListVocId, column: x => x.VocabularyListVocId,
principalTable: "VocabularyListEntity", principalTable: "VocabularyLists",
principalColumn: "Id", principalColumn: "Id",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
}); });
@ -178,21 +178,21 @@ namespace StubbedContextLib.Migrations
{ {
table.PrimaryKey("PK_TranslateEntityVocabularyEntity", x => new { x.TransVocword, x.VoctranslationsId }); table.PrimaryKey("PK_TranslateEntityVocabularyEntity", x => new { x.TransVocword, x.VoctranslationsId });
table.ForeignKey( table.ForeignKey(
name: "FK_TranslateEntityVocabularyEntity_TranslateEntity_VoctranslationsId", name: "FK_TranslateEntityVocabularyEntity_Translates_VoctranslationsId",
column: x => x.VoctranslationsId, column: x => x.VoctranslationsId,
principalTable: "TranslateEntity", principalTable: "Translates",
principalColumn: "Id", principalColumn: "Id",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
table.ForeignKey( table.ForeignKey(
name: "FK_TranslateEntityVocabularyEntity_VocabularyEntity_TransVocword", name: "FK_TranslateEntityVocabularyEntity_Vocabularys_TransVocword",
column: x => x.TransVocword, column: x => x.TransVocword,
principalTable: "VocabularyEntity", principalTable: "Vocabularys",
principalColumn: "word", principalColumn: "word",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
}); });
migrationBuilder.InsertData( migrationBuilder.InsertData(
table: "GroupEntity", table: "Groups",
columns: new[] { "Id", "Num", "sector", "year" }, columns: new[] { "Id", "Num", "sector", "year" },
values: new object[] { 1L, 1, "informatics", 1 }); values: new object[] { 1L, 1, "informatics", 1 });
@ -226,17 +226,17 @@ namespace StubbedContextLib.Migrations
}); });
migrationBuilder.InsertData( migrationBuilder.InsertData(
table: "VocabularyEntity", table: "Vocabularys",
columns: new[] { "word", "LangueName" }, columns: new[] { "word", "LangueName" },
values: new object[] { "Bonjour", "French" }); values: new object[] { "Bonjour", "French" });
migrationBuilder.InsertData( migrationBuilder.InsertData(
table: "VocabularyListEntity", table: "VocabularyLists",
columns: new[] { "Id", "Image", "Name", "UserId" }, columns: new[] { "Id", "Image", "Name", "UserId" },
values: new object[] { 1L, "image1", "Liste1", 1L }); values: new object[] { 1L, "image1", "Liste1", 1L });
migrationBuilder.InsertData( migrationBuilder.InsertData(
table: "TranslateEntity", table: "Translates",
columns: new[] { "Id", "VocabularyListVocId", "WordsId" }, columns: new[] { "Id", "VocabularyListVocId", "WordsId" },
values: new object[] { 1L, 1L, "1" }); values: new object[] { 1L, 1L, "1" });
@ -245,16 +245,16 @@ namespace StubbedContextLib.Migrations
table: "GroupEntityVocabularyListEntity", table: "GroupEntityVocabularyListEntity",
column: "VocsGroupsId"); column: "VocsGroupsId");
migrationBuilder.CreateIndex(
name: "IX_TranslateEntity_VocabularyListVocId",
table: "TranslateEntity",
column: "VocabularyListVocId");
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "IX_TranslateEntityVocabularyEntity_VoctranslationsId", name: "IX_TranslateEntityVocabularyEntity_VoctranslationsId",
table: "TranslateEntityVocabularyEntity", table: "TranslateEntityVocabularyEntity",
column: "VoctranslationsId"); column: "VoctranslationsId");
migrationBuilder.CreateIndex(
name: "IX_Translates_VocabularyListVocId",
table: "Translates",
column: "VocabularyListVocId");
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "IX_Users_GroupId", name: "IX_Users_GroupId",
table: "Users", table: "Users",
@ -266,14 +266,14 @@ namespace StubbedContextLib.Migrations
column: "RoleId"); column: "RoleId");
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "IX_VocabularyEntity_LangueName", name: "IX_VocabularyLists_UserId",
table: "VocabularyEntity", table: "VocabularyLists",
column: "LangueName"); column: "UserId");
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "IX_VocabularyListEntity_UserId", name: "IX_Vocabularys_LangueName",
table: "VocabularyListEntity", table: "Vocabularys",
column: "UserId"); column: "LangueName");
} }
/// <inheritdoc /> /// <inheritdoc />
@ -286,13 +286,13 @@ namespace StubbedContextLib.Migrations
name: "TranslateEntityVocabularyEntity"); name: "TranslateEntityVocabularyEntity");
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "TranslateEntity"); name: "Translates");
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "VocabularyEntity"); name: "Vocabularys");
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "VocabularyListEntity"); name: "VocabularyLists");
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "Langues"); name: "Langues");
@ -301,7 +301,7 @@ namespace StubbedContextLib.Migrations
name: "Users"); name: "Users");
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "GroupEntity"); name: "Groups");
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "Roles"); name: "Roles");

@ -34,7 +34,7 @@ namespace StubbedContextLib.Migrations
b.HasKey("Id"); b.HasKey("Id");
b.ToTable("GroupEntity"); b.ToTable("Groups");
b.HasData( b.HasData(
new new
@ -115,7 +115,7 @@ namespace StubbedContextLib.Migrations
b.HasIndex("VocabularyListVocId"); b.HasIndex("VocabularyListVocId");
b.ToTable("TranslateEntity"); b.ToTable("Translates");
b.HasData( b.HasData(
new new
@ -224,7 +224,7 @@ namespace StubbedContextLib.Migrations
b.HasIndex("LangueName"); b.HasIndex("LangueName");
b.ToTable("VocabularyEntity"); b.ToTable("Vocabularys");
b.HasData( b.HasData(
new new
@ -255,7 +255,7 @@ namespace StubbedContextLib.Migrations
b.HasIndex("UserId"); b.HasIndex("UserId");
b.ToTable("VocabularyListEntity"); b.ToTable("VocabularyLists");
b.HasData( b.HasData(
new new

@ -148,37 +148,6 @@ namespace TU
} }
} }
[TestMethod]
public async Task TestAddVocabToTranslate()
{
var connection = new SqliteConnection("DataSource=:memory:");
connection.Open();
var options = new DbContextOptionsBuilder<SAEContext>()
.UseSqlite(connection)
.Options;
using (var context = new StubbedContext(options))
{
context.Database.EnsureCreated();
var mockLogger = new Mock<ILogger<TranslateController>>();
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);
}
}
} }
} }

@ -179,43 +179,6 @@ namespace TU
}
}
[TestMethod]
public async Task TestAddGroupToVocabularyList()
{
var connection = new SqliteConnection("DataSource=:memory:");
connection.Open();
var options = new DbContextOptionsBuilder<SAEContext>()
.UseSqlite(connection)
.Options;
using (var context = new StubbedContext(options))
{
context.Database.EnsureCreated();
var mockLogger = new Mock<ILogger<VocabularyListController>>();
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);
} }
} }
} }

@ -174,43 +174,6 @@ namespace TU
} }
} }
[TestMethod]
public async Task TestAddTranslation()
{
var connection = new SqliteConnection("DataSource=:memory:");
connection.Open();
var options = new DbContextOptionsBuilder<SAEContext>()
.UseSqlite(connection)
.Options;
using (var context = new StubbedContext(options))
{
context.Database.EnsureCreated();
var mockLogger = new Mock<ILogger<VocabularyController>>();
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);
}
}
} }
} }

Loading…
Cancel
Save