diff --git a/WebApi/DbConnectionLibrairie/Migrations/20240226094705_m1.Designer.cs b/WebApi/DbConnectionLibrairie/Migrations/20240226094705_m1.Designer.cs
deleted file mode 100644
index 2085c6b..0000000
--- a/WebApi/DbConnectionLibrairie/Migrations/20240226094705_m1.Designer.cs
+++ /dev/null
@@ -1,265 +0,0 @@
-//
-using System;
-using DbConnectionLibrairie;
-using Microsoft.EntityFrameworkCore;
-using Microsoft.EntityFrameworkCore.Infrastructure;
-using Microsoft.EntityFrameworkCore.Migrations;
-using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
-
-#nullable disable
-
-namespace DbConnectionLibrairie.Migrations
-{
- [DbContext(typeof(MyDbContext))]
- [Migration("20240226094705_m1")]
- partial class m1
- {
- ///
- protected override void BuildTargetModel(ModelBuilder modelBuilder)
- {
-#pragma warning disable 612, 618
- modelBuilder.HasAnnotation("ProductVersion", "8.0.2");
-
- modelBuilder.Entity("Entities.AdministratorEntity", b =>
- {
- b.Property("Id")
- .ValueGeneratedOnAdd()
- .HasColumnType("INTEGER");
-
- b.Property("HashedPassword")
- .IsRequired()
- .HasColumnType("TEXT");
-
- b.Property("Username")
- .IsRequired()
- .HasColumnType("TEXT");
-
- b.HasKey("Id");
-
- b.ToTable("Administrators");
- });
-
- modelBuilder.Entity("Entities.AnswerEntity", b =>
- {
- b.Property("Id")
- .ValueGeneratedOnAdd()
- .HasColumnType("INTEGER");
-
- b.Property("Content")
- .IsRequired()
- .HasColumnType("TEXT");
-
- b.Property("IdQuestion")
- .HasColumnType("INTEGER");
-
- b.HasKey("Id");
-
- b.HasIndex("IdQuestion");
-
- b.ToTable("Answers");
- });
-
- modelBuilder.Entity("Entities.ChapterEntity", b =>
- {
- b.Property("Id")
- .ValueGeneratedOnAdd()
- .HasColumnType("INTEGER");
-
- b.Property("Name")
- .IsRequired()
- .HasColumnType("TEXT");
-
- b.HasKey("Id");
-
- b.ToTable("Chapters");
- });
-
- modelBuilder.Entity("Entities.LobbyEntity", b =>
- {
- b.Property("Id")
- .ValueGeneratedOnAdd()
- .HasColumnType("INTEGER");
-
- b.Property("IdCreator")
- .HasColumnType("INTEGER");
-
- b.Property("Name")
- .IsRequired()
- .HasColumnType("TEXT");
-
- b.Property("NbPlayers")
- .HasColumnType("INTEGER");
-
- b.Property("Password")
- .IsRequired()
- .HasColumnType("TEXT");
-
- b.HasKey("Id");
-
- b.HasIndex("IdCreator");
-
- b.ToTable("Lobbies");
- });
-
- modelBuilder.Entity("Entities.LobbyEntityPlayerEntity", b =>
- {
- b.Property("IdLobby")
- .HasColumnType("INTEGER");
-
- b.Property("IdPlayer")
- .HasColumnType("INTEGER");
-
- b.Property("MaxScore")
- .HasColumnType("INTEGER");
-
- b.HasKey("IdLobby", "IdPlayer");
-
- b.HasIndex("IdPlayer");
-
- b.ToTable("Use");
- });
-
- modelBuilder.Entity("Entities.PlayerEntity", b =>
- {
- b.Property("Id")
- .ValueGeneratedOnAdd()
- .HasColumnType("INTEGER");
-
- b.Property("HashedPassword")
- .IsRequired()
- .HasColumnType("TEXT");
-
- b.Property("Nickname")
- .IsRequired()
- .HasColumnType("TEXT");
-
- b.HasKey("Id");
-
- b.ToTable("Players");
- });
-
- modelBuilder.Entity("Entities.PlayerEntityChapterEntity", b =>
- {
- b.Property("IdPlayer")
- .HasColumnType("INTEGER");
-
- b.Property("IdChapter")
- .HasColumnType("INTEGER");
-
- b.Property("MaxScore")
- .HasColumnType("INTEGER");
-
- b.HasKey("IdPlayer", "IdChapter");
-
- b.HasIndex("IdChapter");
-
- b.ToTable("Play");
- });
-
- modelBuilder.Entity("Entities.QuestionEntity", b =>
- {
- b.Property("Id")
- .ValueGeneratedOnAdd()
- .HasColumnType("INTEGER");
-
- b.Property("Content")
- .IsRequired()
- .HasColumnType("TEXT");
-
- b.Property("Difficulty")
- .HasColumnType("INTEGER");
-
- b.Property("IdAnswerGood")
- .HasColumnType("INTEGER");
-
- b.Property("IdChapter")
- .HasColumnType("INTEGER");
-
- b.Property("NbFalls")
- .HasColumnType("INTEGER");
-
- b.HasKey("Id");
-
- b.HasIndex("IdAnswerGood");
-
- b.HasIndex("IdChapter");
-
- b.ToTable("Questions");
- });
-
- modelBuilder.Entity("Entities.AnswerEntity", b =>
- {
- b.HasOne("Entities.QuestionEntity", "Question")
- .WithMany()
- .HasForeignKey("IdQuestion")
- .OnDelete(DeleteBehavior.Cascade)
- .IsRequired();
-
- b.Navigation("Question");
- });
-
- modelBuilder.Entity("Entities.LobbyEntity", b =>
- {
- b.HasOne("Entities.PlayerEntity", "Creator")
- .WithMany()
- .HasForeignKey("IdCreator");
-
- b.Navigation("Creator");
- });
-
- modelBuilder.Entity("Entities.LobbyEntityPlayerEntity", b =>
- {
- b.HasOne("Entities.LobbyEntity", "Lobby")
- .WithMany()
- .HasForeignKey("IdLobby")
- .OnDelete(DeleteBehavior.Cascade)
- .IsRequired();
-
- b.HasOne("Entities.PlayerEntity", "Player")
- .WithMany()
- .HasForeignKey("IdPlayer")
- .OnDelete(DeleteBehavior.Cascade)
- .IsRequired();
-
- b.Navigation("Lobby");
-
- b.Navigation("Player");
- });
-
- modelBuilder.Entity("Entities.PlayerEntityChapterEntity", b =>
- {
- b.HasOne("Entities.ChapterEntity", "Chapter")
- .WithMany()
- .HasForeignKey("IdChapter")
- .OnDelete(DeleteBehavior.Cascade)
- .IsRequired();
-
- b.HasOne("Entities.PlayerEntity", "Player")
- .WithMany()
- .HasForeignKey("IdPlayer")
- .OnDelete(DeleteBehavior.Cascade)
- .IsRequired();
-
- b.Navigation("Chapter");
-
- b.Navigation("Player");
- });
-
- modelBuilder.Entity("Entities.QuestionEntity", b =>
- {
- b.HasOne("Entities.AnswerEntity", "AnswerGood")
- .WithMany()
- .HasForeignKey("IdAnswerGood");
-
- b.HasOne("Entities.ChapterEntity", "Chapter")
- .WithMany()
- .HasForeignKey("IdChapter");
-
- b.Navigation("AnswerGood");
-
- b.Navigation("Chapter");
- });
-#pragma warning restore 612, 618
- }
- }
-}
diff --git a/WebApi/DbConnectionLibrairie/Migrations/20240226094705_m1.cs b/WebApi/DbConnectionLibrairie/Migrations/20240226094705_m1.cs
deleted file mode 100644
index e69c689..0000000
--- a/WebApi/DbConnectionLibrairie/Migrations/20240226094705_m1.cs
+++ /dev/null
@@ -1,237 +0,0 @@
-using Microsoft.EntityFrameworkCore.Migrations;
-
-#nullable disable
-
-namespace DbConnectionLibrairie.Migrations
-{
- ///
- public partial class m1 : Migration
- {
- ///
- protected override void Up(MigrationBuilder migrationBuilder)
- {
- migrationBuilder.CreateTable(
- name: "Administrators",
- columns: table => new
- {
- Id = table.Column(type: "INTEGER", nullable: false)
- .Annotation("Sqlite:Autoincrement", true),
- Username = table.Column(type: "TEXT", nullable: false),
- HashedPassword = table.Column(type: "TEXT", nullable: false)
- },
- constraints: table =>
- {
- table.PrimaryKey("PK_Administrators", x => x.Id);
- });
-
- migrationBuilder.CreateTable(
- name: "Chapters",
- columns: table => new
- {
- Id = table.Column(type: "INTEGER", nullable: false)
- .Annotation("Sqlite:Autoincrement", true),
- Name = table.Column(type: "TEXT", nullable: false)
- },
- constraints: table =>
- {
- table.PrimaryKey("PK_Chapters", x => x.Id);
- });
-
- migrationBuilder.CreateTable(
- name: "Players",
- columns: table => new
- {
- Id = table.Column(type: "INTEGER", nullable: false)
- .Annotation("Sqlite:Autoincrement", true),
- Nickname = table.Column(type: "TEXT", nullable: false),
- HashedPassword = table.Column(type: "TEXT", nullable: false)
- },
- constraints: table =>
- {
- table.PrimaryKey("PK_Players", x => x.Id);
- });
-
- migrationBuilder.CreateTable(
- name: "Lobbies",
- columns: table => new
- {
- Id = table.Column(type: "INTEGER", nullable: false)
- .Annotation("Sqlite:Autoincrement", true),
- Name = table.Column(type: "TEXT", nullable: false),
- Password = table.Column(type: "TEXT", nullable: false),
- NbPlayers = table.Column(type: "INTEGER", nullable: false),
- IdCreator = table.Column(type: "INTEGER", nullable: true)
- },
- constraints: table =>
- {
- table.PrimaryKey("PK_Lobbies", x => x.Id);
- table.ForeignKey(
- name: "FK_Lobbies_Players_IdCreator",
- column: x => x.IdCreator,
- principalTable: "Players",
- principalColumn: "Id");
- });
-
- migrationBuilder.CreateTable(
- name: "Play",
- columns: table => new
- {
- IdChapter = table.Column(type: "INTEGER", nullable: false),
- IdPlayer = table.Column(type: "INTEGER", nullable: false),
- MaxScore = table.Column(type: "INTEGER", nullable: false)
- },
- constraints: table =>
- {
- table.PrimaryKey("PK_Play", x => new { x.IdPlayer, x.IdChapter });
- table.ForeignKey(
- name: "FK_Play_Chapters_IdChapter",
- column: x => x.IdChapter,
- principalTable: "Chapters",
- principalColumn: "Id",
- onDelete: ReferentialAction.Cascade);
- table.ForeignKey(
- name: "FK_Play_Players_IdPlayer",
- column: x => x.IdPlayer,
- principalTable: "Players",
- principalColumn: "Id",
- onDelete: ReferentialAction.Cascade);
- });
-
- migrationBuilder.CreateTable(
- name: "Use",
- columns: table => new
- {
- IdLobby = table.Column(type: "INTEGER", nullable: false),
- IdPlayer = table.Column(type: "INTEGER", nullable: false),
- MaxScore = table.Column(type: "INTEGER", nullable: false)
- },
- constraints: table =>
- {
- table.PrimaryKey("PK_Use", x => new { x.IdLobby, x.IdPlayer });
- table.ForeignKey(
- name: "FK_Use_Lobbies_IdLobby",
- column: x => x.IdLobby,
- principalTable: "Lobbies",
- principalColumn: "Id",
- onDelete: ReferentialAction.Cascade);
- table.ForeignKey(
- name: "FK_Use_Players_IdPlayer",
- column: x => x.IdPlayer,
- principalTable: "Players",
- principalColumn: "Id",
- onDelete: ReferentialAction.Cascade);
- });
-
- migrationBuilder.CreateTable(
- name: "Answers",
- columns: table => new
- {
- Id = table.Column(type: "INTEGER", nullable: false)
- .Annotation("Sqlite:Autoincrement", true),
- Content = table.Column(type: "TEXT", nullable: false),
- IdQuestion = table.Column(type: "INTEGER", nullable: false)
- },
- constraints: table =>
- {
- table.PrimaryKey("PK_Answers", x => x.Id);
- });
-
- migrationBuilder.CreateTable(
- name: "Questions",
- columns: table => new
- {
- Id = table.Column(type: "INTEGER", nullable: false)
- .Annotation("Sqlite:Autoincrement", true),
- Content = table.Column(type: "TEXT", nullable: false),
- Difficulty = table.Column(type: "INTEGER", nullable: false),
- NbFalls = table.Column(type: "INTEGER", nullable: false),
- IdChapter = table.Column(type: "INTEGER", nullable: true),
- IdAnswerGood = table.Column(type: "INTEGER", nullable: true)
- },
- constraints: table =>
- {
- table.PrimaryKey("PK_Questions", x => x.Id);
- table.ForeignKey(
- name: "FK_Questions_Answers_IdAnswerGood",
- column: x => x.IdAnswerGood,
- principalTable: "Answers",
- principalColumn: "Id");
- table.ForeignKey(
- name: "FK_Questions_Chapters_IdChapter",
- column: x => x.IdChapter,
- principalTable: "Chapters",
- principalColumn: "Id");
- });
-
- migrationBuilder.CreateIndex(
- name: "IX_Answers_IdQuestion",
- table: "Answers",
- column: "IdQuestion");
-
- migrationBuilder.CreateIndex(
- name: "IX_Lobbies_IdCreator",
- table: "Lobbies",
- column: "IdCreator");
-
- migrationBuilder.CreateIndex(
- name: "IX_Play_IdChapter",
- table: "Play",
- column: "IdChapter");
-
- migrationBuilder.CreateIndex(
- name: "IX_Questions_IdAnswerGood",
- table: "Questions",
- column: "IdAnswerGood");
-
- migrationBuilder.CreateIndex(
- name: "IX_Questions_IdChapter",
- table: "Questions",
- column: "IdChapter");
-
- migrationBuilder.CreateIndex(
- name: "IX_Use_IdPlayer",
- table: "Use",
- column: "IdPlayer");
-
- migrationBuilder.AddForeignKey(
- name: "FK_Answers_Questions_IdQuestion",
- table: "Answers",
- column: "IdQuestion",
- principalTable: "Questions",
- principalColumn: "Id",
- onDelete: ReferentialAction.Cascade);
- }
-
- ///
- protected override void Down(MigrationBuilder migrationBuilder)
- {
- migrationBuilder.DropForeignKey(
- name: "FK_Answers_Questions_IdQuestion",
- table: "Answers");
-
- migrationBuilder.DropTable(
- name: "Administrators");
-
- migrationBuilder.DropTable(
- name: "Play");
-
- migrationBuilder.DropTable(
- name: "Use");
-
- migrationBuilder.DropTable(
- name: "Lobbies");
-
- migrationBuilder.DropTable(
- name: "Players");
-
- migrationBuilder.DropTable(
- name: "Questions");
-
- migrationBuilder.DropTable(
- name: "Answers");
-
- migrationBuilder.DropTable(
- name: "Chapters");
- }
- }
-}
diff --git a/WebApi/DbConnectionLibrairie/Migrations/MyDbContextModelSnapshot.cs b/WebApi/DbConnectionLibrairie/Migrations/MyDbContextModelSnapshot.cs
deleted file mode 100644
index a361ff4..0000000
--- a/WebApi/DbConnectionLibrairie/Migrations/MyDbContextModelSnapshot.cs
+++ /dev/null
@@ -1,262 +0,0 @@
-//
-using System;
-using DbConnectionLibrairie;
-using Microsoft.EntityFrameworkCore;
-using Microsoft.EntityFrameworkCore.Infrastructure;
-using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
-
-#nullable disable
-
-namespace DbConnectionLibrairie.Migrations
-{
- [DbContext(typeof(MyDbContext))]
- partial class MyDbContextModelSnapshot : ModelSnapshot
- {
- protected override void BuildModel(ModelBuilder modelBuilder)
- {
-#pragma warning disable 612, 618
- modelBuilder.HasAnnotation("ProductVersion", "8.0.2");
-
- modelBuilder.Entity("Entities.AdministratorEntity", b =>
- {
- b.Property("Id")
- .ValueGeneratedOnAdd()
- .HasColumnType("INTEGER");
-
- b.Property("HashedPassword")
- .IsRequired()
- .HasColumnType("TEXT");
-
- b.Property("Username")
- .IsRequired()
- .HasColumnType("TEXT");
-
- b.HasKey("Id");
-
- b.ToTable("Administrators");
- });
-
- modelBuilder.Entity("Entities.AnswerEntity", b =>
- {
- b.Property("Id")
- .ValueGeneratedOnAdd()
- .HasColumnType("INTEGER");
-
- b.Property("Content")
- .IsRequired()
- .HasColumnType("TEXT");
-
- b.Property("IdQuestion")
- .HasColumnType("INTEGER");
-
- b.HasKey("Id");
-
- b.HasIndex("IdQuestion");
-
- b.ToTable("Answers");
- });
-
- modelBuilder.Entity("Entities.ChapterEntity", b =>
- {
- b.Property("Id")
- .ValueGeneratedOnAdd()
- .HasColumnType("INTEGER");
-
- b.Property("Name")
- .IsRequired()
- .HasColumnType("TEXT");
-
- b.HasKey("Id");
-
- b.ToTable("Chapters");
- });
-
- modelBuilder.Entity("Entities.LobbyEntity", b =>
- {
- b.Property("Id")
- .ValueGeneratedOnAdd()
- .HasColumnType("INTEGER");
-
- b.Property("IdCreator")
- .HasColumnType("INTEGER");
-
- b.Property("Name")
- .IsRequired()
- .HasColumnType("TEXT");
-
- b.Property("NbPlayers")
- .HasColumnType("INTEGER");
-
- b.Property("Password")
- .IsRequired()
- .HasColumnType("TEXT");
-
- b.HasKey("Id");
-
- b.HasIndex("IdCreator");
-
- b.ToTable("Lobbies");
- });
-
- modelBuilder.Entity("Entities.LobbyEntityPlayerEntity", b =>
- {
- b.Property("IdLobby")
- .HasColumnType("INTEGER");
-
- b.Property("IdPlayer")
- .HasColumnType("INTEGER");
-
- b.Property("MaxScore")
- .HasColumnType("INTEGER");
-
- b.HasKey("IdLobby", "IdPlayer");
-
- b.HasIndex("IdPlayer");
-
- b.ToTable("Use");
- });
-
- modelBuilder.Entity("Entities.PlayerEntity", b =>
- {
- b.Property("Id")
- .ValueGeneratedOnAdd()
- .HasColumnType("INTEGER");
-
- b.Property("HashedPassword")
- .IsRequired()
- .HasColumnType("TEXT");
-
- b.Property("Nickname")
- .IsRequired()
- .HasColumnType("TEXT");
-
- b.HasKey("Id");
-
- b.ToTable("Players");
- });
-
- modelBuilder.Entity("Entities.PlayerEntityChapterEntity", b =>
- {
- b.Property("IdPlayer")
- .HasColumnType("INTEGER");
-
- b.Property("IdChapter")
- .HasColumnType("INTEGER");
-
- b.Property("MaxScore")
- .HasColumnType("INTEGER");
-
- b.HasKey("IdPlayer", "IdChapter");
-
- b.HasIndex("IdChapter");
-
- b.ToTable("Play");
- });
-
- modelBuilder.Entity("Entities.QuestionEntity", b =>
- {
- b.Property("Id")
- .ValueGeneratedOnAdd()
- .HasColumnType("INTEGER");
-
- b.Property("Content")
- .IsRequired()
- .HasColumnType("TEXT");
-
- b.Property("Difficulty")
- .HasColumnType("INTEGER");
-
- b.Property("IdAnswerGood")
- .HasColumnType("INTEGER");
-
- b.Property("IdChapter")
- .HasColumnType("INTEGER");
-
- b.Property("NbFalls")
- .HasColumnType("INTEGER");
-
- b.HasKey("Id");
-
- b.HasIndex("IdAnswerGood");
-
- b.HasIndex("IdChapter");
-
- b.ToTable("Questions");
- });
-
- modelBuilder.Entity("Entities.AnswerEntity", b =>
- {
- b.HasOne("Entities.QuestionEntity", "Question")
- .WithMany()
- .HasForeignKey("IdQuestion")
- .OnDelete(DeleteBehavior.Cascade)
- .IsRequired();
-
- b.Navigation("Question");
- });
-
- modelBuilder.Entity("Entities.LobbyEntity", b =>
- {
- b.HasOne("Entities.PlayerEntity", "Creator")
- .WithMany()
- .HasForeignKey("IdCreator");
-
- b.Navigation("Creator");
- });
-
- modelBuilder.Entity("Entities.LobbyEntityPlayerEntity", b =>
- {
- b.HasOne("Entities.LobbyEntity", "Lobby")
- .WithMany()
- .HasForeignKey("IdLobby")
- .OnDelete(DeleteBehavior.Cascade)
- .IsRequired();
-
- b.HasOne("Entities.PlayerEntity", "Player")
- .WithMany()
- .HasForeignKey("IdPlayer")
- .OnDelete(DeleteBehavior.Cascade)
- .IsRequired();
-
- b.Navigation("Lobby");
-
- b.Navigation("Player");
- });
-
- modelBuilder.Entity("Entities.PlayerEntityChapterEntity", b =>
- {
- b.HasOne("Entities.ChapterEntity", "Chapter")
- .WithMany()
- .HasForeignKey("IdChapter")
- .OnDelete(DeleteBehavior.Cascade)
- .IsRequired();
-
- b.HasOne("Entities.PlayerEntity", "Player")
- .WithMany()
- .HasForeignKey("IdPlayer")
- .OnDelete(DeleteBehavior.Cascade)
- .IsRequired();
-
- b.Navigation("Chapter");
-
- b.Navigation("Player");
- });
-
- modelBuilder.Entity("Entities.QuestionEntity", b =>
- {
- b.HasOne("Entities.AnswerEntity", "AnswerGood")
- .WithMany()
- .HasForeignKey("IdAnswerGood");
-
- b.HasOne("Entities.ChapterEntity", "Chapter")
- .WithMany()
- .HasForeignKey("IdChapter");
-
- b.Navigation("AnswerGood");
-
- b.Navigation("Chapter");
- });
-#pragma warning restore 612, 618
- }
- }
-}
diff --git a/WebApi/Entities/AnswerEntity.cs b/WebApi/Entities/AnswerEntity.cs
index fefe6de..605d3a9 100644
--- a/WebApi/Entities/AnswerEntity.cs
+++ b/WebApi/Entities/AnswerEntity.cs
@@ -22,7 +22,7 @@ namespace Entities
[Required]
[ForeignKey(nameof(Question))]
- public uint IdQuestion { get; set; }
+ public uint? IdQuestion { get; set; }
public QuestionEntity? Question { get; set; }
}
diff --git a/WebApi/Entities/LobbyEntity.cs b/WebApi/Entities/LobbyEntity.cs
index 8badbd9..159d05b 100644
--- a/WebApi/Entities/LobbyEntity.cs
+++ b/WebApi/Entities/LobbyEntity.cs
@@ -27,6 +27,6 @@ namespace Entities
[ForeignKey(nameof(Creator))]
public uint? IdCreator { get; set; }
- public PlayerEntity Creator { get; set; } = null!;
+ public PlayerEntity? Creator { get; set; }
}
}
diff --git a/WebApi/FakeDatas/FakeDatas.csproj b/WebApi/FakeDatas/FakeDatas.csproj
old mode 100644
new mode 100755
diff --git a/WebApi/FakeDatas/JsonFiles/fake-Questions.json b/WebApi/FakeDatas/JsonFiles/fake-Questions.json
old mode 100644
new mode 100755
diff --git a/WebApi/FakeDatas/convertirJson.sh b/WebApi/FakeDatas/convertirJson.sh
old mode 100644
new mode 100755
diff --git a/WebApi/FakeDatas/fake-Administrators.cs b/WebApi/FakeDatas/fake-Administrators.cs
old mode 100644
new mode 100755
diff --git a/WebApi/FakeDatas/fake-Answers.cs b/WebApi/FakeDatas/fake-Answers.cs
old mode 100644
new mode 100755
diff --git a/WebApi/FakeDatas/fake-Chapters.cs b/WebApi/FakeDatas/fake-Chapters.cs
old mode 100644
new mode 100755
diff --git a/WebApi/FakeDatas/fake-Lobbies.cs b/WebApi/FakeDatas/fake-Lobbies.cs
old mode 100644
new mode 100755
diff --git a/WebApi/FakeDatas/fake-Players.cs b/WebApi/FakeDatas/fake-Players.cs
old mode 100644
new mode 100755
diff --git a/WebApi/FakeDatas/fake-Questions.cs b/WebApi/FakeDatas/fake-Questions.cs
old mode 100644
new mode 100755
diff --git a/WebApi/UnitTestsEntityManagers/AbstractUnitTestEM.cs b/WebApi/UnitTestsEntityManagers/AbstractUnitTestEM.cs
index c2a9f24..5019272 100644
--- a/WebApi/UnitTestsEntityManagers/AbstractUnitTestEM.cs
+++ b/WebApi/UnitTestsEntityManagers/AbstractUnitTestEM.cs
@@ -1,4 +1,5 @@
using DbConnectionLibrairie;
+using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
@@ -23,12 +24,17 @@ namespace UnitTestsEntityManagers
///
public AbstractUnitTestEM()
{
+ var connection = new SqliteConnection("DataSource=:memory:");
+ connection.Open();
+
var opt = new DbContextOptionsBuilder()
- .UseSqlite("DataSource=:memory:")
+ .UseSqlite(connection)
.Options;
dbContext = new MyDbContext(opt);
+ dbContext.Database.EnsureCreated();
+
httpClient = new HttpClient();
}
diff --git a/WebApi/UnitTestsEntityManagers/UnitTestAnswerManager.cs b/WebApi/UnitTestsEntityManagers/UnitTestAnswerManager.cs
index 68cde03..5a81efa 100644
--- a/WebApi/UnitTestsEntityManagers/UnitTestAnswerManager.cs
+++ b/WebApi/UnitTestsEntityManagers/UnitTestAnswerManager.cs
@@ -1,129 +1,140 @@
-using DbConnectionLibrairie;
-using Entities;
-using EntityManagers;
-using Newtonsoft.Json;
-
-namespace UnitTestsEntityManagers
-{
- public class UnitTestAnswerManager : AbstractUnitTestEM
- {
- IEnumerable answers = JsonConvert
- .DeserializeObject>
- (File.ReadAllTextAsync("../fake-Answers.json").Result)!; // if this is null, we don't want to continue
-
- AnswerEntityManager mgr;
- public UnitTestAnswerManager()
- : base()
- {
- mgr = new AnswerEntityManager(dbContext);
- }
-
- ///
- /// test of the 'ajouterAnswer' method of an AnswerManager
- ///
- [Fact]
- public async void TestAjouterAnswer()
- {
- var answerToAdd = new AnswerEntity { Id = 0, Content = "damien" };
- var a = await mgr.addAnswer(answerToAdd);
- // 1) normal insertion
- // WF : it work perfectally
- // and a is the same as answerToAdd
- Assert.NotNull(a);
- Assert.Equal(answerToAdd.Content, a.Content);
- Assert.Equal(answerToAdd.Id, a.Id);
-
- answerToAdd = new AnswerEntity { Id = 5, Content = "damien" };
- a = await mgr.addAnswer(answerToAdd);
- // 2) with a random id greater than 0
- // WF : it works so 'a' is not null,
- // his content is equal to the
- // content of 'answerToAdd'
- // and since it's the second answer
- // that we add, his id equal 1
- Assert.NotNull(a);
- Assert.Equal(answerToAdd.Content, a.Content);
- Assert.NotEqual((uint)1, a.Id);
-
- answerToAdd = new AnswerEntity { Id = 7, Content = "châteîgne" };
- a = await mgr.addAnswer(answerToAdd);
- // 3) with a content that we already have added
- // WF : it don't works so 'a' is null
- Assert.Null(a);
-
- answerToAdd = new AnswerEntity { Id = 7, Content = "CHÂTEÎGNE" };
- a = await mgr.addAnswer(answerToAdd);
- // 3) with a content that we already have added
- // but in upperCase instead of lowerCase
- // WF : it don't works so 'a' is null
- Assert.Null(a);
- }
-
- ///
- /// test of the 'supprimerAnswer' method of an AnswerManager
- ///
- [Fact]
- public async Task TestSupprimerAnswer()
- {
- // remember that we have only 2 answers in the database :
- // 1) (0, "châteigne")
- // 2) (1, "damien")
- var a = await mgr.removeAnswer(2);
- // 1) with an id greater or equal
- // to the number of element
- // WF : it don't works so 'a' is null,
- Assert.Null(a);
-
- a = await mgr.removeAnswer(0);
- // 1) with an id that belongs to an answer
- // WF : it works so 'a' is not null,
- // and since we've delete the answer with
- // the id 0, the content is "châteigne"
- Assert.NotNull(a);
- Assert.Equal((uint)0, a.Id);
- Assert.Equal("châteigne", a.Content);
-
- a = await mgr.removeAnswer(1);
- // 1) same thing with the id 1 just
- // to clean the database
- // WF : it works so 'a' is not null,
- // and since we've delete the answer with
- // the id 1, the content is "damien"
- Assert.NotNull(a);
- Assert.Equal((uint)0, a.Id);
- Assert.Equal("damien", a.Content);
-
- // now, the database should be clean
- }
-
- // /!\ WARNING : since there was 2 answers added to the base,
- // id index while now start at 2 (even though we've delete those)
-
- ///
- /// test of the 'getNbElement' method of an AnswerManager
- ///
- [Fact]
- public async Task TestGetNbElement()
- {
- Assert.Equal(0, mgr.getNbElements()); // just to be sure
-
- Assert.NotNull(answers); // just to be sure
-
- int count = 0;
- foreach (var answer in answers)
- {
- await mgr.addAnswer(answer);
- count++;
- Assert.Equal(count, mgr.getNbElements());
- }
- }
-
- // getAnswers
-
- // modifierAnswer
-
- // supprimerAnswer (les 2)
-
- // getAnswersByIdQuestion
- }
+using DbConnectionLibrairie;
+using Entities;
+using EntityManagers;
+
+namespace UnitTestsEntityManagers
+{
+ public class UnitTestAnswerManager : AbstractUnitTestEM
+ {
+
+ AnswerEntityManager mgr;
+ public UnitTestAnswerManager()
+ : base()
+ {
+ mgr = new AnswerEntityManager(dbContext);
+ }
+
+ ///
+ /// test of the 'ajouterAnswer' method of an AnswerManager
+ ///
+ [Fact]
+ public async void TestAddAnswer()
+ {
+ var answerToAdd = new AnswerEntity { Id = 0, Content = "damien" };
+ var a = await mgr.addAnswer(answerToAdd);
+ // 1) normal insertion
+ // WF : it work perfectally
+ // and a is the same as answerToAdd
+ Assert.NotNull(a);
+ Assert.Equal(answerToAdd.Content, a.Content);
+ Assert.Equal(answerToAdd.Id, a.Id);
+
+ answerToAdd = new AnswerEntity { Id = 5, Content = "damien" };
+ a = await mgr.addAnswer(answerToAdd);
+ // 2) with a random id greater than 0
+ // WF : it works so 'a' is not null,
+ // his content is equal to the
+ // content of 'answerToAdd'
+ // and since it's the second answer
+ // that we add, his id equal 1
+ Assert.NotNull(a);
+ Assert.Equal(answerToAdd.Content, a.Content);
+ Assert.NotEqual((uint)1, a.Id);
+
+ answerToAdd = new AnswerEntity { Id = 7, Content = "châteîgne" };
+ a = await mgr.addAnswer(answerToAdd);
+ // 3) with a content that we already have added
+ // WF : it don't works so 'a' is null
+ Assert.Null(a);
+
+ answerToAdd = new AnswerEntity { Id = 7, Content = "CHÂTEÎGNE" };
+ a = await mgr.addAnswer(answerToAdd);
+ // 3) with a content that we already have added
+ // but in upperCase instead of lowerCase
+ // WF : it don't works so 'a' is null
+ Assert.Null(a);
+ }
+
+ ///
+ /// test of the 'supprimerAnswer' method of an AnswerManager
+ ///
+ [Fact]
+ public async Task TestRemoveAnswer()
+ {
+ // remember that we have only 2 answers in the database :
+ // 1) (0, "châteigne")
+ // 2) (1, "damien")
+ var a = await mgr.removeAnswer(2);
+ // 1) with an id greater or equal
+ // to the number of element
+ // WF : it don't works so 'a' is null,
+ Assert.Null(a);
+
+ a = await mgr.removeAnswer(0);
+ // 1) with an id that belongs to an answer
+ // WF : it works so 'a' is not null,
+ // and since we've delete the answer with
+ // the id 0, the content is "châteigne"
+ Assert.NotNull(a);
+ Assert.Equal((uint)0, a.Id);
+ Assert.Equal("châteigne", a.Content);
+
+ a = await mgr.removeAnswer(1);
+ // 1) same thing with the id 1 just
+ // to clean the database
+ // WF : it works so 'a' is not null,
+ // and since we've delete the answer with
+ // the id 1, the content is "damien"
+ Assert.NotNull(a);
+ Assert.Equal((uint)0, a.Id);
+ Assert.Equal("damien", a.Content);
+
+ // now, the database should be clean
+ }
+
+ // /!\ WARNING : since there was 2 answers added to the base,
+ // id index while now start at 2 (even though we've delete those)
+
+ ///
+ /// test of the 'getNbElement' method of an AnswerManager
+ ///
+ [Fact]
+ public async Task TestGetNbElement()
+ {
+ Assert.Equal(0, mgr.getNbElements()); // just to be sure
+
+ Assert.NotNull(fakeAnswers.datas); // just to be sure
+
+ int count = 0;
+ foreach (var answer in fakeAnswers.datas)
+ {
+ await mgr.addAnswer(answer);
+ count++;
+ Assert.Equal(count, mgr.getNbElements()); // ok, it's incremented
+ }
+ }
+
+ public static IEnumerable