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<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

@ -10,7 +10,7 @@ using StubbedContextLib;
namespace StubbedContextLib.Migrations
{
[DbContext(typeof(StubbedContext))]
[Migration("20240316154336_newMigs")]
[Migration("20240330163827_newMigs")]
partial class newMigs
{
/// <inheritdoc />
@ -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

@ -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<long>(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<string>(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<long>(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<long>(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");
}
/// <inheritdoc />
@ -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");

@ -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

@ -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