From 672ef9db67e9b2f36436e8c576021e345cc2b0be Mon Sep 17 00:00:00 2001 From: Damien Nortier Date: Fri, 8 Mar 2024 08:21:46 +0100 Subject: [PATCH] =?UTF-8?q?error=20;=20ne=20compile=20pas.=20v=C3=A9rifica?= =?UTF-8?q?tion=20par=20le=20prof?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Migrations/20240307151226_m1.Designer.cs | 263 ++++++++++++++++++ .../Migrations/20240307151226_m1.cs | 236 ++++++++++++++++ .../Migrations/MyDbContextModelSnapshot.cs | 260 +++++++++++++++++ WebApi/DbConnectionLibrairie/database.db | Bin 81920 -> 81920 bytes WebApi/Entities/AnswerEntity.cs | 1 - WebApi/EntityManagers/AnswerEntityManager.cs | 15 +- .../AdministratorExtensionMethods.cs | 64 ----- .../AnswerExtensionMethods.cs | 64 ----- .../ChapterExtensionMethods.cs | 64 ----- .../LobbyExtensionMethods.cs | 86 ++---- .../PlayerExtensionMethods.cs | 64 ----- .../QuestionExtensionMethods.cs | 64 ----- .../AdministratorServiceManager.cs | 2 +- .../ServiceManagers/QuestionServiceManager.cs | 5 +- .../AbstractUnitTestEM.cs | 98 +++---- .../UnitTestAnswerManager.cs | 61 ++-- .../Controllers/AdministratorController.cs | 64 +++++ WebApi/WebApi/Controllers/AnswerController.cs | 6 + .../WebApi/Controllers/ChapterController.cs | 6 + WebApi/WebApi/Controllers/LobbyController.cs | 6 + WebApi/WebApi/Controllers/PlayerController.cs | 6 + .../WebApi/Controllers/QuestionController.cs | 6 + .../Controllers/WeatherForecastController.cs | 33 --- WebApi/WebApi/WeatherForecast.cs | 13 - WebApi/WebApi/WebApi.csproj | 8 + 25 files changed, 975 insertions(+), 520 deletions(-) create mode 100644 WebApi/DbConnectionLibrairie/Migrations/20240307151226_m1.Designer.cs create mode 100644 WebApi/DbConnectionLibrairie/Migrations/20240307151226_m1.cs create mode 100644 WebApi/DbConnectionLibrairie/Migrations/MyDbContextModelSnapshot.cs create mode 100644 WebApi/WebApi/Controllers/AdministratorController.cs create mode 100644 WebApi/WebApi/Controllers/AnswerController.cs create mode 100644 WebApi/WebApi/Controllers/ChapterController.cs create mode 100644 WebApi/WebApi/Controllers/LobbyController.cs create mode 100644 WebApi/WebApi/Controllers/PlayerController.cs create mode 100644 WebApi/WebApi/Controllers/QuestionController.cs delete mode 100644 WebApi/WebApi/Controllers/WeatherForecastController.cs delete mode 100644 WebApi/WebApi/WeatherForecast.cs diff --git a/WebApi/DbConnectionLibrairie/Migrations/20240307151226_m1.Designer.cs b/WebApi/DbConnectionLibrairie/Migrations/20240307151226_m1.Designer.cs new file mode 100644 index 0000000..525f696 --- /dev/null +++ b/WebApi/DbConnectionLibrairie/Migrations/20240307151226_m1.Designer.cs @@ -0,0 +1,263 @@ +// +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("20240307151226_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"); + + 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/20240307151226_m1.cs b/WebApi/DbConnectionLibrairie/Migrations/20240307151226_m1.cs new file mode 100644 index 0000000..911f582 --- /dev/null +++ b/WebApi/DbConnectionLibrairie/Migrations/20240307151226_m1.cs @@ -0,0 +1,236 @@ +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: true) + }, + 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"); + } + + /// + 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 new file mode 100644 index 0000000..af4491f --- /dev/null +++ b/WebApi/DbConnectionLibrairie/Migrations/MyDbContextModelSnapshot.cs @@ -0,0 +1,260 @@ +// +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"); + + 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/database.db b/WebApi/DbConnectionLibrairie/database.db index 0d5ba66a99f1e0f01ab7b1c3c4260fad77e43d15..35ca7ad23f04612af5c4d52db4a96c6de3e267ea 100644 GIT binary patch delta 123 zcmZo@U~On%osgvw!@zfme=YAD-dQ|fd9=9>bKK;b#m>mFiS;7$apoANFHAF;6c{%! z#!MCzIJMc0v5bXNmxosEt7Y%a7{kR%|Ce>TiE7*Y#${!jSb8VO%08V W%r^g!|HF^qHviS%{#T!oSpWc#;U`)E delta 126 zcmZo@U~On%osgyB#=v)pe=YAD-dQ|fd9=9>bKK;b#m>mFiFG&gMrJprdrZwtT#U0A z-6k&FvN?vajD^#ghh1D+nz1Ez@@>{Fljm^rP5#TmKY0aP*yL6&(antP?<6>ljLZxy ZP0S5UH~*0T!;j!L|JC3ASD%qt008#RC*1%5 diff --git a/WebApi/Entities/AnswerEntity.cs b/WebApi/Entities/AnswerEntity.cs index 605d3a9..0d06dc3 100644 --- a/WebApi/Entities/AnswerEntity.cs +++ b/WebApi/Entities/AnswerEntity.cs @@ -20,7 +20,6 @@ namespace Entities [Required] public string Content { get; set; } = null!; - [Required] [ForeignKey(nameof(Question))] public uint? IdQuestion { get; set; } diff --git a/WebApi/EntityManagers/AnswerEntityManager.cs b/WebApi/EntityManagers/AnswerEntityManager.cs index 19124cb..ab706be 100644 --- a/WebApi/EntityManagers/AnswerEntityManager.cs +++ b/WebApi/EntityManagers/AnswerEntityManager.cs @@ -12,20 +12,25 @@ using System.Threading.Tasks; namespace EntityManagers { - public class AnswerEntityManager(MyDbContext dbContext) : IAnswerManager + public class AnswerEntityManager : IAnswerManager { - private MyDbContext dbContext = dbContext; + private MyDbContext dbContext; + + public AnswerEntityManager(MyDbContext dbContext) + { + this.dbContext = dbContext; + } public async Task addAnswer(AnswerEntity answer) { - var tmp = await dbContext.Answers.Where(a => a.Equals(answer)).FirstOrDefaultAsync(); + var tmp = await dbContext.Answers.Where(a => a.Content == answer.Content.ToLower() && a.IdQuestion == answer.IdQuestion).FirstOrDefaultAsync(); if (tmp != null) // <=> he already exist { return tmp!; } - await dbContext.Answers.AddAsync(answer); + await dbContext.Answers.AddAsync(new AnswerEntity { Content = answer.Content.ToLower(), IdQuestion = answer.IdQuestion }); await dbContext.SaveChangesAsync(); - return await dbContext.Answers.Where(a => a.Equals(answer)).FirstAsync(); + return await dbContext.Answers.Where(a => a.Content == answer.Content && a.IdQuestion == answer.IdQuestion).FirstAsync(); } public async Task getAnswer(uint id) diff --git a/WebApi/ExtensionsClassLibrairie/AdministratorExtensionMethods.cs b/WebApi/ExtensionsClassLibrairie/AdministratorExtensionMethods.cs index 410e359..fb74830 100644 --- a/WebApi/ExtensionsClassLibrairie/AdministratorExtensionMethods.cs +++ b/WebApi/ExtensionsClassLibrairie/AdministratorExtensionMethods.cs @@ -31,69 +31,5 @@ namespace ExtensionsClassLibrairie => a.ToModel().ToDto(); public static AdministratorEntity ToEntity(this AdministratorDto a) => a.ToModel().ToEntity(); - - // equality protocols - public static bool Equals(Administrator a1, Administrator a2) - => a1.Username == a2.Username; - - // reuse other methods - public static bool Equals(Administrator a1, AdministratorDto a2) - => Equals(a1, a2.ToModel()); - public static bool Equals(Administrator a1, AdministratorEntity a2) - => Equals(a1, a2.ToModel()); - public static bool Equals(AdministratorDto a1, Administrator a2) - => Equals(a1.ToModel(), a2); - public static bool Equals(AdministratorDto a1, AdministratorDto a2) - => Equals(a1.ToModel(), a2.ToModel()); - public static bool Equals(AdministratorDto a1, AdministratorEntity a2) - => Equals(a1.ToModel(), a2.ToModel()); - public static bool Equals(AdministratorEntity a1, Administrator a2) - => Equals(a1.ToModel(), a2); - public static bool Equals(AdministratorEntity a1, AdministratorDto a2) - => Equals(a1.ToModel(), a2.ToModel()); - public static bool Equals(AdministratorEntity a1, AdministratorEntity a2) - => Equals(a1.ToModel(), a2.ToModel()); - /// - /// equality protocol for an administrator - /// - /// the administrator - /// an object - /// true if the administrator and the object are sames, false otherwise - public static bool Equals(this Administrator a, object? o) - { - if (o == null) return false; - if (o.GetType() == typeof(Administrator)) return Equals(a, (Administrator)o); - else if (o.GetType() == typeof(AdministratorEntity)) return Equals(a, ((AdministratorEntity)o)); - else if (o.GetType() == typeof(AdministratorDto)) return Equals(a, (AdministratorDto)o); - return false; - } - /// - /// equality protocol for an administrator entity - /// - /// the administrator entity - /// an object - /// true if the administrator entity and the object are sames, false otherwise - public static bool Equals(this AdministratorEntity a, object? o) - { - if (o == null) return false; - if (o.GetType() == typeof(Administrator)) return Equals(a, (Administrator)o); - else if (o.GetType() == typeof(AdministratorEntity)) return Equals(a, ((AdministratorEntity)o)); - else if (o.GetType() == typeof(AdministratorDto)) return Equals(a, (AdministratorDto)o); - return false; - } - /// - /// equality protocol for an administrator dto - /// - /// the administrator dto - /// an object - /// true if the administrator dto and the object are sames, false otherwise - public static bool Equals(this AdministratorDto a, object? o) - { - if (o == null) return false; - if (o.GetType() == typeof(Administrator)) return Equals(a, (Administrator)o); - else if (o.GetType() == typeof(AdministratorEntity)) return Equals(a, ((AdministratorEntity)o)); - else if (o.GetType() == typeof(AdministratorDto)) return Equals(a, (AdministratorDto)o); - return false; - } } } diff --git a/WebApi/ExtensionsClassLibrairie/AnswerExtensionMethods.cs b/WebApi/ExtensionsClassLibrairie/AnswerExtensionMethods.cs index 9508dc1..753634f 100644 --- a/WebApi/ExtensionsClassLibrairie/AnswerExtensionMethods.cs +++ b/WebApi/ExtensionsClassLibrairie/AnswerExtensionMethods.cs @@ -31,69 +31,5 @@ namespace ExtensionsClassLibrairie => a.ToModel().ToDto(); public static AnswerEntity ToEntity(this AnswerDto a) => a.ToModel().ToEntity(); - - // equality protocols - public static bool Equals(this Answer a1, Answer a2) - => a1.Content == a2.Content && a1.IdQuestion == a2.IdQuestion; - - // reuse other methods - public static bool Equals(this Answer a1, AnswerDto a2) - => a1.Equals(a2.ToModel()); - public static bool Equals(this Answer a1, AnswerEntity a2) - => a1.Equals(a2.ToModel()); - public static bool Equals(this AnswerDto a1, Answer a2) - => a1.ToModel().Equals(a2); - public static bool Equals(this AnswerDto a1, AnswerDto a2) - => a1.ToModel().Equals(a2.ToModel()); - public static bool Equals(this AnswerDto a1, AnswerEntity a2) - => a1.ToModel().Equals(a2.ToModel()); - public static bool Equals(this AnswerEntity a1, Answer a2) - => a1.ToModel().Equals(a2); - public static bool Equals(this AnswerEntity a1, AnswerDto a2) - => a1.ToModel().Equals(a2.ToModel()); - public static bool Equals(this AnswerEntity a1, AnswerEntity a2) - => a1.ToModel().Equals(a2.ToModel()); - /// - /// equality protocol for an answer - /// - /// the answer - /// an object - /// true if the answer and the object are sames, false otherwise - public static bool Equals(this Answer a, object? o) - { - if (o == null) return false; - if (o.GetType() == typeof(Answer)) return Equals(a, (Answer)o); - else if (o.GetType() == typeof(AnswerEntity)) return Equals(a, ((AnswerEntity)o)); - else if (o.GetType() == typeof(AnswerDto)) return Equals(a, (AnswerDto)o); - return false; - } - /// - /// equality protocol for an answer entity - /// - /// the answer entity - /// an object - /// true if the answer entity and the object are sames, false otherwise - public static bool Equals(this AnswerEntity a, object? o) - { - if (o == null) return false; - if (o.GetType() == typeof(Answer)) return Equals(a, (Answer)o); - else if (o.GetType() == typeof(AnswerEntity)) return Equals(a, ((AnswerEntity)o)); - else if (o.GetType() == typeof(AnswerDto)) return Equals(a, (AnswerDto)o); - return false; - } - /// - /// equality protocol for an answer dto - /// - /// the answer dto - /// an object - /// true if the answer dto and the object are sames, false otherwise - public static bool Equals(this AnswerDto a, object? o) - { - if (o == null) return false; - if (o.GetType() == typeof(Answer)) return Equals(a, (Answer)o); - else if (o.GetType() == typeof(AnswerEntity)) return Equals(a, ((AnswerEntity)o)); - else if (o.GetType() == typeof(AnswerDto)) return Equals(a, (AnswerDto)o); - return false; - } } } diff --git a/WebApi/ExtensionsClassLibrairie/ChapterExtensionMethods.cs b/WebApi/ExtensionsClassLibrairie/ChapterExtensionMethods.cs index f71ff98..b23d3af 100644 --- a/WebApi/ExtensionsClassLibrairie/ChapterExtensionMethods.cs +++ b/WebApi/ExtensionsClassLibrairie/ChapterExtensionMethods.cs @@ -31,69 +31,5 @@ namespace ExtensionsClassLibrairie => c.ToModel().ToDto(); public static ChapterEntity ToEntity(this ChapterDto c) => c.ToModel().ToEntity(); - - // equality protocols - public static bool Equals(this Chapter c1, Chapter c2) - => c1.Name == c2.Name; - - // reuse other methods - public static bool Equals(this Chapter c1, ChapterDto c2) - => c1.Equals(c2.ToModel()); - public static bool Equals(this Chapter c1, ChapterEntity c2) - => c1.Equals(c2.ToModel()); - public static bool Equals(this ChapterDto c1, Chapter c2) - => c1.ToModel().Equals(c2); - public static bool Equals(this ChapterDto c1, ChapterDto c2) - => c1.ToModel().Equals(c2.ToModel()); - public static bool Equals(this ChapterDto c1, ChapterEntity c2) - => c1.ToModel().Equals(c2.ToModel()); - public static bool Equals(this ChapterEntity c1, Chapter c2) - => c1.ToModel().Equals(c2); - public static bool Equals(this ChapterEntity c1, ChapterDto c2) - => c1.ToModel().Equals(c2.ToModel()); - public static bool Equals(this ChapterEntity c1, ChapterEntity c2) - => c1.ToModel().Equals(c2.ToModel()); - /// - /// equality protocol for a chapter - /// - /// the chapter - /// an object - /// true if the chapter and the object are sames, false otherwise - public static bool Equals(this Chapter c, object? o) - { - if (o == null) return false; - if (o.GetType() == typeof(Chapter)) return Equals(c, (Chapter)o); - else if (o.GetType() == typeof(ChapterEntity)) return Equals(c, ((ChapterEntity)o)); - else if (o.GetType() == typeof(ChapterDto)) return Equals(c, (ChapterDto)o); - return false; - } - /// - /// equality protocol for a chapter entity - /// - /// the chapter entity - /// an object - /// true if the chapter entity and the object are sames, false otherwise - public static bool Equals(this ChapterEntity c, object? o) - { - if (o == null) return false; - if (o.GetType() == typeof(Chapter)) return Equals(c, (Chapter)o); - else if (o.GetType() == typeof(ChapterEntity)) return Equals(c, ((ChapterEntity)o)); - else if (o.GetType() == typeof(ChapterDto)) return Equals(c, (ChapterDto)o); - return false; - } - /// - /// equality protocol for a chapter dto - /// - /// the chapter dto - /// an object - /// true if the chapter dto and the object are sames, false otherwise - public static bool Equals(this ChapterDto c, object? o) - { - if (o == null) return false; - if (o.GetType() == typeof(Chapter)) return Equals(c, (Chapter)o); - else if (o.GetType() == typeof(ChapterEntity)) return Equals(c, ((ChapterEntity)o)); - else if (o.GetType() == typeof(ChapterDto)) return Equals(c, (ChapterDto)o); - return false; - } } } diff --git a/WebApi/ExtensionsClassLibrairie/LobbyExtensionMethods.cs b/WebApi/ExtensionsClassLibrairie/LobbyExtensionMethods.cs index 17f1f8b..f781848 100644 --- a/WebApi/ExtensionsClassLibrairie/LobbyExtensionMethods.cs +++ b/WebApi/ExtensionsClassLibrairie/LobbyExtensionMethods.cs @@ -21,80 +21,30 @@ namespace ExtensionsClassLibrairie public static Lobby ToModel(this LobbyDto l) => new Lobby(l.Name, l.Creator.ToModel(), l.Password, l.NbPlayers, l.Id); public static LobbyDto ToDto(this Lobby l) - => new LobbyDto { Id = l.Id, Creator = l.Creator.ToDto(), IdCreator = l.IdCreator, - Name = l.Name, Password = l.Password, NbPlayers = l.NbPlayers}; + => new LobbyDto + { + Id = l.Id, + Creator = l.Creator.ToDto(), + IdCreator = l.IdCreator, + Name = l.Name, + Password = l.Password, + NbPlayers = l.NbPlayers + }; public static LobbyEntity ToEntity(this Lobby l) - => new LobbyEntity { Id = l.Id, Creator = l.Creator.ToEntity(), IdCreator = l.IdCreator, - Name = l.Name, Password = l.Password, NbPlayers = l.NbPlayers}; + => new LobbyEntity + { + Id = l.Id, + Creator = l.Creator.ToEntity(), + IdCreator = l.IdCreator, + Name = l.Name, + Password = l.Password, + NbPlayers = l.NbPlayers + }; // reuse other methods public static LobbyDto ToDto(this LobbyEntity l) => l.ToModel().ToDto(); public static LobbyEntity ToEntity(this LobbyDto l) => l.ToModel().ToEntity(); - - // equality protocols - public static bool Equals(this Lobby l1, Lobby l2) - => l1.Name == l2.Name && l1.IdCreator == l2.IdCreator; - - // reuse other methods - public static bool Equals(this Lobby l1, LobbyDto l2) - => l1.Equals(l2.ToModel()); - public static bool Equals(this Lobby l1, LobbyEntity l2) - => l1.Equals(l2.ToModel()); - public static bool Equals(this LobbyDto l1, Lobby l2) - => l1.ToModel().Equals(l2); - public static bool Equals(this LobbyDto l1, LobbyDto l2) - => l1.ToModel().Equals(l2.ToModel()); - public static bool Equals(this LobbyDto l1, LobbyEntity l2) - => l1.ToModel().Equals(l2.ToModel()); - public static bool Equals(this LobbyEntity l1, Lobby l2) - => l1.ToModel().Equals(l2); - public static bool Equals(this LobbyEntity l1, LobbyDto l2) - => l1.ToModel().Equals(l2.ToModel()); - public static bool Equals(this LobbyEntity l1, LobbyEntity l2) - => l1.ToModel().Equals(l2.ToModel()); - /// - /// equality protocol for a lobby - /// - /// the lobby - /// an object - /// true if the lobby and the object are sames, false otherwise - public static bool Equals(this Lobby l, object? o) - { - if (o == null) return false; - if (o.GetType() == typeof(Lobby)) return Equals(l, (Lobby)o); - else if (o.GetType() == typeof(LobbyEntity)) return Equals(l, ((LobbyEntity)o)); - else if (o.GetType() == typeof(LobbyDto)) return Equals(l, (LobbyDto)o); - return false; - } - /// - /// equality protocol for a lobby entity - /// - /// the lobby entity - /// an object - /// true if the lobby entity and the object are sames, false otherwise - public static bool Equals(this LobbyEntity l, object? o) - { - if (o == null) return false; - if (o.GetType() == typeof(Lobby)) return Equals(l, (Lobby)o); - else if (o.GetType() == typeof(LobbyEntity)) return Equals(l, ((LobbyEntity)o)); - else if (o.GetType() == typeof(LobbyDto)) return Equals(l, (LobbyDto)o); - return false; - } - /// - /// equality protocol for a lobby dto - /// - /// the lobby dto - /// an object - /// true if the lobby dto and the object are sames, false otherwise - public static bool Equals(this LobbyDto l, object? o) - { - if (o == null) return false; - if (o.GetType() == typeof(Lobby)) return Equals(l, (Lobby)o); - else if (o.GetType() == typeof(LobbyEntity)) return Equals(l, ((LobbyEntity)o)); - else if (o.GetType() == typeof(LobbyDto)) return Equals(l, (LobbyDto)o); - return false; - } } } diff --git a/WebApi/ExtensionsClassLibrairie/PlayerExtensionMethods.cs b/WebApi/ExtensionsClassLibrairie/PlayerExtensionMethods.cs index 3f16cc6..3267011 100644 --- a/WebApi/ExtensionsClassLibrairie/PlayerExtensionMethods.cs +++ b/WebApi/ExtensionsClassLibrairie/PlayerExtensionMethods.cs @@ -31,69 +31,5 @@ namespace ExtensionsClassLibrairie => p.ToModel().ToDto(); public static PlayerEntity ToEntity(this PlayerDto p) => p.ToModel().ToEntity(); - - // equality protocols - public static bool Equals(this Player p1, Player p2) - => p1.Nickname == p2.Nickname; - - // reuse other methods - public static bool Equals(this Player p1, PlayerDto p2) - => p1.Equals(p2.ToModel()); - public static bool Equals(this Player p1, PlayerEntity p2) - => p1.Equals(p2.ToModel()); - public static bool Equals(this PlayerDto p1, Player p2) - => p1.ToModel().Equals(p2); - public static bool Equals(this PlayerDto p1, PlayerDto p2) - => p1.ToModel().Equals(p2.ToModel()); - public static bool Equals(this PlayerDto p1, PlayerEntity p2) - => p1.ToModel().Equals(p2.ToModel()); - public static bool Equals(this PlayerEntity p1, Player p2) - => p1.ToModel().Equals(p2); - public static bool Equals(this PlayerEntity p1, PlayerDto p2) - => p1.ToModel().Equals(p2.ToModel()); - public static bool Equals(this PlayerEntity p1, PlayerEntity p2) - => p1.ToModel().Equals(p2.ToModel()); - /// - /// equality protocol for a player - /// - /// the player - /// an object - /// true if the player and the object are sames, false otherwise - public static bool Equals(this Player p, object? o) - { - if (o == null) return false; - if (o.GetType() == typeof(Player)) return Equals(p, (Player)o); - else if (o.GetType() == typeof(PlayerEntity)) return Equals(p, ((PlayerEntity)o)); - else if (o.GetType() == typeof(PlayerDto)) return Equals(p, (PlayerDto)o); - return false; - } - /// - /// equality protocol for a player entity - /// - /// the player entity - /// an object - /// true if the player entity and the object are sames, false otherwise - public static bool Equals(this PlayerEntity p, object? o) - { - if (o == null) return false; - if (o.GetType() == typeof(Player)) return Equals(p, (Player)o); - else if (o.GetType() == typeof(PlayerEntity)) return Equals(p, ((PlayerEntity)o)); - else if (o.GetType() == typeof(PlayerDto)) return Equals(p, (PlayerDto)o); - return false; - } - /// - /// equality protocol for a player dto - /// - /// the player dto - /// an object - /// true if the player dto and the object are sames, false otherwise - public static bool Equals(this PlayerDto p, object? o) - { - if (o == null) return false; - if (o.GetType() == typeof(Player)) return Equals(p, (Player)o); - else if (o.GetType() == typeof(PlayerEntity)) return Equals(p, ((PlayerEntity)o)); - else if (o.GetType() == typeof(PlayerDto)) return Equals(p, (PlayerDto)o); - return false; - } } } diff --git a/WebApi/ExtensionsClassLibrairie/QuestionExtensionMethods.cs b/WebApi/ExtensionsClassLibrairie/QuestionExtensionMethods.cs index 8d8a8b4..b34308f 100644 --- a/WebApi/ExtensionsClassLibrairie/QuestionExtensionMethods.cs +++ b/WebApi/ExtensionsClassLibrairie/QuestionExtensionMethods.cs @@ -43,69 +43,5 @@ namespace ExtensionsClassLibrairie => q.ToModel().ToDto(); public static QuestionEntity ToEntity(this QuestionDto q) => q.ToModel().ToEntity(); - - // equality protocols - public static bool Equals(this Question q1, Question q2) - => q1.Content == q2.Content; - - // reuse other methods - public static bool Equals(this Question q1, QuestionDto q2) - => q1.Equals(q2.ToModel()); - public static bool Equals(this Question q1, QuestionEntity q2) - => q1.Equals(q2.ToModel()); - public static bool Equals(this QuestionDto q1, Question q2) - => q1.ToModel().Equals(q2); - public static bool Equals(this QuestionDto q1, QuestionDto q2) - => q1.ToModel().Equals(q2.ToModel()); - public static bool Equals(this QuestionDto q1, QuestionEntity q2) - => q1.ToModel().Equals(q2.ToModel()); - public static bool Equals(this QuestionEntity q1, Question q2) - => q1.ToModel().Equals(q2); - public static bool Equals(this QuestionEntity q1, QuestionDto q2) - => q1.ToModel().Equals(q2.ToModel()); - public static bool Equals(this QuestionEntity q1, QuestionEntity q2) - => q1.ToModel().Equals(q2.ToModel()); - /// - /// equality protocol for a question - /// - /// the question - /// an object - /// true if the question and the object are sames, false otherwise - public static bool Equals(this Question q, object? o) - { - if (o == null) return false; - if (o.GetType() == typeof(Question)) return Equals(q, (Question)o); - else if (o.GetType() == typeof(QuestionEntity)) return Equals(q, ((QuestionEntity)o)); - else if (o.GetType() == typeof(QuestionDto)) return Equals(q, (QuestionDto)o); - return false; - } - /// - /// equality protocol for a question entity - /// - /// the question entity - /// an object - /// true if the question entity and the object are sames, false otherwise - public static bool Equals(this QuestionEntity q, object? o) - { - if (o == null) return false; - if (o.GetType() == typeof(Question)) return Equals(q, (Question)o); - else if (o.GetType() == typeof(QuestionEntity)) return Equals(q, ((QuestionEntity)o)); - else if (o.GetType() == typeof(QuestionDto)) return Equals(q, (QuestionDto)o); - return false; - } - /// - /// equality protocol for a question dto - /// - /// the question dto - /// an object - /// true if the question dto and the object are sames, false otherwise - public static bool Equals(this QuestionDto q, object? o) - { - if (o == null) return false; - if (o.GetType() == typeof(Question)) return Equals(q, (Question)o); - else if (o.GetType() == typeof(QuestionEntity)) return Equals(q, ((QuestionEntity)o)); - else if (o.GetType() == typeof(QuestionDto)) return Equals(q, (QuestionDto)o); - return false; - } } } \ No newline at end of file diff --git a/WebApi/ServiceManagers/AdministratorServiceManager.cs b/WebApi/ServiceManagers/AdministratorServiceManager.cs index dd2295e..834b644 100644 --- a/WebApi/ServiceManagers/AdministratorServiceManager.cs +++ b/WebApi/ServiceManagers/AdministratorServiceManager.cs @@ -11,7 +11,7 @@ using System.Text; using System.Threading.Tasks; using DTOs; -namespace ToModel +namespace ServiceManagers { public class AdministratorServiceManager(MyDbContext dbContext) : IAdministratorManager { diff --git a/WebApi/ServiceManagers/QuestionServiceManager.cs b/WebApi/ServiceManagers/QuestionServiceManager.cs index 65a49ac..a76af1e 100644 --- a/WebApi/ServiceManagers/QuestionServiceManager.cs +++ b/WebApi/ServiceManagers/QuestionServiceManager.cs @@ -1,4 +1,5 @@ -using DbConnectionLibrairie; +using DataManagers; +using DbConnectionLibrairie; using DTOs; using Entities; using EntityManagers; @@ -12,7 +13,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace DataManagers +namespace ServiceManagers { public class QuestionServiceManager(MyDbContext dbContext) : IQuestionManager { diff --git a/WebApi/UnitTestsEntityManagers/AbstractUnitTestEM.cs b/WebApi/UnitTestsEntityManagers/AbstractUnitTestEM.cs index 5019272..9464ec5 100644 --- a/WebApi/UnitTestsEntityManagers/AbstractUnitTestEM.cs +++ b/WebApi/UnitTestsEntityManagers/AbstractUnitTestEM.cs @@ -1,50 +1,50 @@ -using DbConnectionLibrairie; -using Microsoft.Data.Sqlite; -using Microsoft.EntityFrameworkCore; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace UnitTestsEntityManagers -{ - /// - /// an abstract class to init the dbContext - /// (every unit tests need to implement it) - /// - public abstract class AbstractUnitTestEM - { - protected MyDbContext dbContext; - protected HttpClient httpClient; - - /// - /// constructor of the class : - /// initialise the database context - /// - public AbstractUnitTestEM() - { +using DbConnectionLibrairie; +using Microsoft.Data.Sqlite; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UnitTestsEntityManagers +{ + /// + /// an abstract class to init the dbContext + /// (every unit tests need to implement it) + /// + public abstract class AbstractUnitTestEM + { + public MyDbContext dbContext; + public HttpClient httpClient; + + /// + /// constructor of the class : + /// initialise the database context + /// + public AbstractUnitTestEM() + { var connection = new SqliteConnection("DataSource=:memory:"); - connection.Open(); - - var opt = new DbContextOptionsBuilder() - .UseSqlite(connection) - .Options; - - dbContext = new MyDbContext(opt); - - dbContext.Database.EnsureCreated(); - - httpClient = new HttpClient(); - } - - /// - /// destructor of the class : - /// dispose the database context - /// - ~AbstractUnitTestEM() - { - dbContext.Dispose(); - } - } -} + connection.Open(); + + var opt = new DbContextOptionsBuilder() + .UseSqlite(connection) + .Options; + + dbContext = new MyDbContext(opt); + + dbContext.Database.EnsureCreated(); + + httpClient = new HttpClient(); + } + + /// + /// destructor of the class : + /// dispose the database context + /// + ~AbstractUnitTestEM() + { + dbContext.Dispose(); + } + } +} diff --git a/WebApi/UnitTestsEntityManagers/UnitTestAnswerManager.cs b/WebApi/UnitTestsEntityManagers/UnitTestAnswerManager.cs index 5a81efa..697793d 100644 --- a/WebApi/UnitTestsEntityManagers/UnitTestAnswerManager.cs +++ b/WebApi/UnitTestsEntityManagers/UnitTestAnswerManager.cs @@ -7,7 +7,7 @@ namespace UnitTestsEntityManagers public class UnitTestAnswerManager : AbstractUnitTestEM { - AnswerEntityManager mgr; + private AnswerEntityManager mgr; public UnitTestAnswerManager() : base() { @@ -20,39 +20,42 @@ namespace UnitTestsEntityManagers [Fact] public async void TestAddAnswer() { - var answerToAdd = new AnswerEntity { Id = 0, Content = "damien" }; + var answerToAdd = new AnswerEntity { Id = 1, Content = "chateîgne" }; var a = await mgr.addAnswer(answerToAdd); // 1) normal insertion - // WF : it work perfectally - // and a is the same as answerToAdd - Assert.NotNull(a); + // WF : a is the same + // as answerToAdd 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 + // WF : 'a' 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); + // that we add, his id equal 2 Assert.Equal(answerToAdd.Content, a.Content); - Assert.NotEqual((uint)1, a.Id); + Assert.Equal((uint)2, a.Id); - answerToAdd = new AnswerEntity { Id = 7, Content = "châteîgne" }; + answerToAdd = new AnswerEntity { Id = 7, Content = "chateî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); + // WF : the function return the answer which already + // have the same content so the content of 'a' is "châteigne" + // and his id is 1 + Assert.Equal("chateîgne", a.Content); + Assert.Equal((uint)1, a.Id); - answerToAdd = new AnswerEntity { Id = 7, Content = "CHÂTEÎGNE" }; + answerToAdd = new AnswerEntity { Id = 7, Content = "CHATEÎ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); + // WF : the function return the answer which + // already have the same content so the content + // of 'a' is "chateîgne" and his id is 1 + Assert.Equal("chateîgne", a.Content); + Assert.Equal((uint)1, a.Id); } /// @@ -62,38 +65,38 @@ namespace UnitTestsEntityManagers 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) (1, "châteigne") + // 2) (2, "damien") + var a = await mgr.removeAnswer(3); // 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); + a = await mgr.removeAnswer(1); // 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" + // the id 1, the content is "châteigne" Assert.NotNull(a); - Assert.Equal((uint)0, a.Id); + Assert.Equal((uint)1, a.Id); Assert.Equal("châteigne", a.Content); - a = await mgr.removeAnswer(1); + a = await mgr.removeAnswer(2); // 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" + // the id 2, the content is "damien" Assert.NotNull(a); - Assert.Equal((uint)0, a.Id); + Assert.Equal((uint)2, 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) + // id index while now start at 3 (even though we've delete those) /// /// test of the 'getNbElement' method of an AnswerManager @@ -116,8 +119,9 @@ namespace UnitTestsEntityManagers public static IEnumerable TestGetAnswer_Datas() { + var datas = fakeAnswers.datas; uint max = 0; - foreach (var item in fakeAnswers.datas) + foreach (var item in datas) { yield return new Object[] { item.Id, item }; if(max < item.Id) max = item.Id; @@ -128,7 +132,8 @@ namespace UnitTestsEntityManagers [MemberData(nameof(TestGetAnswer_Datas))] public async Task TestGetAnswer(uint id, AnswerEntity? waiting) { - Assert.Equal(waiting, await mgr.getAnswer(id)); + var tmp = await mgr.getAnswer(id + 2); + Assert.Equal(waiting?.Content, tmp?.Content); } // modifierAnswer diff --git a/WebApi/WebApi/Controllers/AdministratorController.cs b/WebApi/WebApi/Controllers/AdministratorController.cs new file mode 100644 index 0000000..e7803ff --- /dev/null +++ b/WebApi/WebApi/Controllers/AdministratorController.cs @@ -0,0 +1,64 @@ +using DataManagers; +using DbConnectionLibrairie; +using DTOs; +using ManagerInterfaces; +using Microsoft.AspNetCore.Mvc; +using ServiceManagers; +using Microsoft.Extensions.Logging; +using OrderCriterias; +using Microsoft.AspNetCore.Http.HttpResults; + +namespace WebApi.Controllers +{ + [ApiController] + [Route("api/[controller]")] + public class AdministratorController + { + private IAdministratorManager mgr; + + private readonly Logger logger; + + public AdministratorController(MyDbContext dbContext, Logger logger) + { + mgr = new AdministratorServiceManager(dbContext); + this.logger = logger; + } + + [HttpPost("add/administrator/")] + public async Task PostAdministrator([FromBody] AdministratorDto administrator) + { + int count = mgr.getNbElements(); + var tmp = await mgr.addAdmin(administrator); + if (mgr.getNbElements() == count) // <=> not added + { + return StatusCode(208) ; + } + logger.LogInformation(message: $"administrator added : {administrator.ToString()}"); + return StatusCode(202); + } + + [HttpGet("administrators")] + public async Task GetSomeAdministrators(int page, int count = 10, AdministratorOrderCriteria orderCriteria = AdministratorOrderCriteria.ById) + { + var tmp = await mgr.getAdministrators(page, count, orderCriteria); + if (tmp.administrators == null) + { + return BadRequest(tmp); + } + else return Ok(tmp); + } + + [HttpDelete()] + public async Task DeleteAdministrator(int id) + { + if (id < 0) + { + return BadRequest(); + } + var tmp = await mgr.removeAdmin(id); + if (tmp == null) return StatusCode(403); + logger.LogInformation(message: $"administrator removed : ${tmp}"); + return Ok(tmp); + } + } +} diff --git a/WebApi/WebApi/Controllers/AnswerController.cs b/WebApi/WebApi/Controllers/AnswerController.cs new file mode 100644 index 0000000..ea55e11 --- /dev/null +++ b/WebApi/WebApi/Controllers/AnswerController.cs @@ -0,0 +1,6 @@ +namespace WebApi.Controllers +{ + public class AnswerController + { + } +} diff --git a/WebApi/WebApi/Controllers/ChapterController.cs b/WebApi/WebApi/Controllers/ChapterController.cs new file mode 100644 index 0000000..ed02709 --- /dev/null +++ b/WebApi/WebApi/Controllers/ChapterController.cs @@ -0,0 +1,6 @@ +namespace WebApi.Controllers +{ + public class ChapterController + { + } +} diff --git a/WebApi/WebApi/Controllers/LobbyController.cs b/WebApi/WebApi/Controllers/LobbyController.cs new file mode 100644 index 0000000..5058257 --- /dev/null +++ b/WebApi/WebApi/Controllers/LobbyController.cs @@ -0,0 +1,6 @@ +namespace WebApi.Controllers +{ + public class LobbyController + { + } +} diff --git a/WebApi/WebApi/Controllers/PlayerController.cs b/WebApi/WebApi/Controllers/PlayerController.cs new file mode 100644 index 0000000..696c6a9 --- /dev/null +++ b/WebApi/WebApi/Controllers/PlayerController.cs @@ -0,0 +1,6 @@ +namespace WebApi.Controllers +{ + public class PlayerController + { + } +} diff --git a/WebApi/WebApi/Controllers/QuestionController.cs b/WebApi/WebApi/Controllers/QuestionController.cs new file mode 100644 index 0000000..58b51cd --- /dev/null +++ b/WebApi/WebApi/Controllers/QuestionController.cs @@ -0,0 +1,6 @@ +namespace WebApi.Controllers +{ + public class QuestionController + { + } +} diff --git a/WebApi/WebApi/Controllers/WeatherForecastController.cs b/WebApi/WebApi/Controllers/WeatherForecastController.cs deleted file mode 100644 index e08016f..0000000 --- a/WebApi/WebApi/Controllers/WeatherForecastController.cs +++ /dev/null @@ -1,33 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -namespace WebApi.Controllers -{ - [ApiController] - [Route("[controller]")] - public class WeatherForecastController : ControllerBase - { - private static readonly string[] Summaries = new[] - { - "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" - }; - - private readonly ILogger _logger; - - public WeatherForecastController(ILogger logger) - { - _logger = logger; - } - - [HttpGet(Name = "GetWeatherForecast")] - public IEnumerable Get() - { - return Enumerable.Range(1, 5).Select(index => new WeatherForecast - { - Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)), - TemperatureC = Random.Shared.Next(-20, 55), - Summary = Summaries[Random.Shared.Next(Summaries.Length)] - }) - .ToArray(); - } - } -} diff --git a/WebApi/WebApi/WeatherForecast.cs b/WebApi/WebApi/WeatherForecast.cs deleted file mode 100644 index 7b55bf8..0000000 --- a/WebApi/WebApi/WeatherForecast.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace WebApi -{ - public class WeatherForecast - { - public DateOnly Date { get; set; } - - public int TemperatureC { get; set; } - - public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); - - public string? Summary { get; set; } - } -} diff --git a/WebApi/WebApi/WebApi.csproj b/WebApi/WebApi/WebApi.csproj index 9daa180..80534f9 100644 --- a/WebApi/WebApi/WebApi.csproj +++ b/WebApi/WebApi/WebApi.csproj @@ -10,4 +10,12 @@ + + + + + + + +