récupération des modifications
continuous-integration/drone/push Build is passing Details

API
Damien NORTIER 1 year ago
parent dbab6e4fc9
commit 665f017e83

@ -1,265 +0,0 @@
// <auto-generated />
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
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "8.0.2");
modelBuilder.Entity("Entities.AdministratorEntity", b =>
{
b.Property<uint?>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("HashedPassword")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Username")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Administrators");
});
modelBuilder.Entity("Entities.AnswerEntity", b =>
{
b.Property<uint?>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Content")
.IsRequired()
.HasColumnType("TEXT");
b.Property<uint>("IdQuestion")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("IdQuestion");
b.ToTable("Answers");
});
modelBuilder.Entity("Entities.ChapterEntity", b =>
{
b.Property<uint?>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Chapters");
});
modelBuilder.Entity("Entities.LobbyEntity", b =>
{
b.Property<uint?>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<uint?>("IdCreator")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<uint>("NbPlayers")
.HasColumnType("INTEGER");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("IdCreator");
b.ToTable("Lobbies");
});
modelBuilder.Entity("Entities.LobbyEntityPlayerEntity", b =>
{
b.Property<uint>("IdLobby")
.HasColumnType("INTEGER");
b.Property<uint>("IdPlayer")
.HasColumnType("INTEGER");
b.Property<uint>("MaxScore")
.HasColumnType("INTEGER");
b.HasKey("IdLobby", "IdPlayer");
b.HasIndex("IdPlayer");
b.ToTable("Use");
});
modelBuilder.Entity("Entities.PlayerEntity", b =>
{
b.Property<uint?>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("HashedPassword")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Nickname")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Players");
});
modelBuilder.Entity("Entities.PlayerEntityChapterEntity", b =>
{
b.Property<uint>("IdPlayer")
.HasColumnType("INTEGER");
b.Property<uint>("IdChapter")
.HasColumnType("INTEGER");
b.Property<uint>("MaxScore")
.HasColumnType("INTEGER");
b.HasKey("IdPlayer", "IdChapter");
b.HasIndex("IdChapter");
b.ToTable("Play");
});
modelBuilder.Entity("Entities.QuestionEntity", b =>
{
b.Property<uint?>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Content")
.IsRequired()
.HasColumnType("TEXT");
b.Property<byte>("Difficulty")
.HasColumnType("INTEGER");
b.Property<uint?>("IdAnswerGood")
.HasColumnType("INTEGER");
b.Property<uint?>("IdChapter")
.HasColumnType("INTEGER");
b.Property<uint>("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
}
}
}

@ -1,237 +0,0 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace DbConnectionLibrairie.Migrations
{
/// <inheritdoc />
public partial class m1 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Administrators",
columns: table => new
{
Id = table.Column<uint>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Username = table.Column<string>(type: "TEXT", nullable: false),
HashedPassword = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Administrators", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Chapters",
columns: table => new
{
Id = table.Column<uint>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Name = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Chapters", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Players",
columns: table => new
{
Id = table.Column<uint>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Nickname = table.Column<string>(type: "TEXT", nullable: false),
HashedPassword = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Players", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Lobbies",
columns: table => new
{
Id = table.Column<uint>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Name = table.Column<string>(type: "TEXT", nullable: false),
Password = table.Column<string>(type: "TEXT", nullable: false),
NbPlayers = table.Column<uint>(type: "INTEGER", nullable: false),
IdCreator = table.Column<uint>(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<uint>(type: "INTEGER", nullable: false),
IdPlayer = table.Column<uint>(type: "INTEGER", nullable: false),
MaxScore = table.Column<uint>(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<uint>(type: "INTEGER", nullable: false),
IdPlayer = table.Column<uint>(type: "INTEGER", nullable: false),
MaxScore = table.Column<uint>(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<uint>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Content = table.Column<string>(type: "TEXT", nullable: false),
IdQuestion = table.Column<uint>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Answers", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Questions",
columns: table => new
{
Id = table.Column<uint>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Content = table.Column<string>(type: "TEXT", nullable: false),
Difficulty = table.Column<byte>(type: "INTEGER", nullable: false),
NbFalls = table.Column<uint>(type: "INTEGER", nullable: false),
IdChapter = table.Column<uint>(type: "INTEGER", nullable: true),
IdAnswerGood = table.Column<uint>(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);
}
/// <inheritdoc />
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");
}
}
}

@ -1,262 +0,0 @@
// <auto-generated />
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<uint?>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("HashedPassword")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Username")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Administrators");
});
modelBuilder.Entity("Entities.AnswerEntity", b =>
{
b.Property<uint?>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Content")
.IsRequired()
.HasColumnType("TEXT");
b.Property<uint>("IdQuestion")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("IdQuestion");
b.ToTable("Answers");
});
modelBuilder.Entity("Entities.ChapterEntity", b =>
{
b.Property<uint?>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Chapters");
});
modelBuilder.Entity("Entities.LobbyEntity", b =>
{
b.Property<uint?>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<uint?>("IdCreator")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<uint>("NbPlayers")
.HasColumnType("INTEGER");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("IdCreator");
b.ToTable("Lobbies");
});
modelBuilder.Entity("Entities.LobbyEntityPlayerEntity", b =>
{
b.Property<uint>("IdLobby")
.HasColumnType("INTEGER");
b.Property<uint>("IdPlayer")
.HasColumnType("INTEGER");
b.Property<uint>("MaxScore")
.HasColumnType("INTEGER");
b.HasKey("IdLobby", "IdPlayer");
b.HasIndex("IdPlayer");
b.ToTable("Use");
});
modelBuilder.Entity("Entities.PlayerEntity", b =>
{
b.Property<uint?>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("HashedPassword")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Nickname")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Players");
});
modelBuilder.Entity("Entities.PlayerEntityChapterEntity", b =>
{
b.Property<uint>("IdPlayer")
.HasColumnType("INTEGER");
b.Property<uint>("IdChapter")
.HasColumnType("INTEGER");
b.Property<uint>("MaxScore")
.HasColumnType("INTEGER");
b.HasKey("IdPlayer", "IdChapter");
b.HasIndex("IdChapter");
b.ToTable("Play");
});
modelBuilder.Entity("Entities.QuestionEntity", b =>
{
b.Property<uint?>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Content")
.IsRequired()
.HasColumnType("TEXT");
b.Property<byte>("Difficulty")
.HasColumnType("INTEGER");
b.Property<uint?>("IdAnswerGood")
.HasColumnType("INTEGER");
b.Property<uint?>("IdChapter")
.HasColumnType("INTEGER");
b.Property<uint>("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
}
}
}

@ -22,7 +22,7 @@ namespace Entities
[Required] [Required]
[ForeignKey(nameof(Question))] [ForeignKey(nameof(Question))]
public uint IdQuestion { get; set; } public uint? IdQuestion { get; set; }
public QuestionEntity? Question { get; set; } public QuestionEntity? Question { get; set; }
} }

@ -27,6 +27,6 @@ namespace Entities
[ForeignKey(nameof(Creator))] [ForeignKey(nameof(Creator))]
public uint? IdCreator { get; set; } public uint? IdCreator { get; set; }
public PlayerEntity Creator { get; set; } = null!; public PlayerEntity? Creator { get; set; }
} }
} }

@ -1,4 +1,5 @@
using DbConnectionLibrairie; using DbConnectionLibrairie;
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -23,12 +24,17 @@ namespace UnitTestsEntityManagers
/// </summary> /// </summary>
public AbstractUnitTestEM() public AbstractUnitTestEM()
{ {
var connection = new SqliteConnection("DataSource=:memory:");
connection.Open();
var opt = new DbContextOptionsBuilder<MyDbContext>() var opt = new DbContextOptionsBuilder<MyDbContext>()
.UseSqlite("DataSource=:memory:") .UseSqlite(connection)
.Options; .Options;
dbContext = new MyDbContext(opt); dbContext = new MyDbContext(opt);
dbContext.Database.EnsureCreated();
httpClient = new HttpClient(); httpClient = new HttpClient();
} }

@ -1,129 +1,140 @@
using DbConnectionLibrairie; using DbConnectionLibrairie;
using Entities; using Entities;
using EntityManagers; using EntityManagers;
using Newtonsoft.Json;
namespace UnitTestsEntityManagers
namespace UnitTestsEntityManagers {
{ public class UnitTestAnswerManager : AbstractUnitTestEM
public class UnitTestAnswerManager : AbstractUnitTestEM {
{
IEnumerable<AnswerEntity> answers = JsonConvert AnswerEntityManager mgr;
.DeserializeObject<List<AnswerEntity>> public UnitTestAnswerManager()
(File.ReadAllTextAsync("../fake-Answers.json").Result)!; // if this is null, we don't want to continue : base()
{
AnswerEntityManager mgr; mgr = new AnswerEntityManager(dbContext);
public UnitTestAnswerManager() }
: base()
{ /// <summary>
mgr = new AnswerEntityManager(dbContext); /// test of the 'ajouterAnswer' method of an AnswerManager
} /// </summary>
[Fact]
/// <summary> public async void TestAddAnswer()
/// test of the 'ajouterAnswer' method of an AnswerManager {
/// </summary> var answerToAdd = new AnswerEntity { Id = 0, Content = "damien" };
[Fact] var a = await mgr.addAnswer(answerToAdd);
public async void TestAjouterAnswer() // 1) normal insertion
{ // WF : it work perfectally
var answerToAdd = new AnswerEntity { Id = 0, Content = "damien" }; // and a is the same as answerToAdd
var a = await mgr.addAnswer(answerToAdd); Assert.NotNull(a);
// 1) normal insertion Assert.Equal(answerToAdd.Content, a.Content);
// WF : it work perfectally Assert.Equal(answerToAdd.Id, a.Id);
// and a is the same as answerToAdd
Assert.NotNull(a); answerToAdd = new AnswerEntity { Id = 5, Content = "damien" };
Assert.Equal(answerToAdd.Content, a.Content); a = await mgr.addAnswer(answerToAdd);
Assert.Equal(answerToAdd.Id, a.Id); // 2) with a random id greater than 0
// WF : it works so 'a' is not null,
answerToAdd = new AnswerEntity { Id = 5, Content = "damien" }; // his content is equal to the
a = await mgr.addAnswer(answerToAdd); // content of 'answerToAdd'
// 2) with a random id greater than 0 // and since it's the second answer
// WF : it works so 'a' is not null, // that we add, his id equal 1
// his content is equal to the Assert.NotNull(a);
// content of 'answerToAdd' Assert.Equal(answerToAdd.Content, a.Content);
// and since it's the second answer Assert.NotEqual((uint)1, a.Id);
// that we add, his id equal 1
Assert.NotNull(a); answerToAdd = new AnswerEntity { Id = 7, Content = "châteîgne" };
Assert.Equal(answerToAdd.Content, a.Content); a = await mgr.addAnswer(answerToAdd);
Assert.NotEqual((uint)1, a.Id); // 3) with a content that we already have added
// WF : it don't works so 'a' is null
answerToAdd = new AnswerEntity { Id = 7, Content = "châteîgne" }; Assert.Null(a);
a = await mgr.addAnswer(answerToAdd);
// 3) with a content that we already have added answerToAdd = new AnswerEntity { Id = 7, Content = "CHÂTEÎGNE" };
// WF : it don't works so 'a' is null a = await mgr.addAnswer(answerToAdd);
Assert.Null(a); // 3) with a content that we already have added
// but in upperCase instead of lowerCase
answerToAdd = new AnswerEntity { Id = 7, Content = "CHÂTEÎGNE" }; // WF : it don't works so 'a' is null
a = await mgr.addAnswer(answerToAdd); Assert.Null(a);
// 3) with a content that we already have added }
// but in upperCase instead of lowerCase
// WF : it don't works so 'a' is null /// <summary>
Assert.Null(a); /// test of the 'supprimerAnswer' method of an AnswerManager
} /// </summary>
[Fact]
/// <summary> public async Task TestRemoveAnswer()
/// test of the 'supprimerAnswer' method of an AnswerManager {
/// </summary> // remember that we have only 2 answers in the database :
[Fact] // 1) (0, "châteigne")
public async Task TestSupprimerAnswer() // 2) (1, "damien")
{ var a = await mgr.removeAnswer(2);
// remember that we have only 2 answers in the database : // 1) with an id greater or equal
// 1) (0, "châteigne") // to the number of element
// 2) (1, "damien") // WF : it don't works so 'a' is null,
var a = await mgr.removeAnswer(2); Assert.Null(a);
// 1) with an id greater or equal
// to the number of element a = await mgr.removeAnswer(0);
// WF : it don't works so 'a' is null, // 1) with an id that belongs to an answer
Assert.Null(a); // WF : it works so 'a' is not null,
// and since we've delete the answer with
a = await mgr.removeAnswer(0); // the id 0, the content is "châteigne"
// 1) with an id that belongs to an answer Assert.NotNull(a);
// WF : it works so 'a' is not null, Assert.Equal((uint)0, a.Id);
// and since we've delete the answer with Assert.Equal("châteigne", a.Content);
// the id 0, the content is "châteigne"
Assert.NotNull(a); a = await mgr.removeAnswer(1);
Assert.Equal((uint)0, a.Id); // 1) same thing with the id 1 just
Assert.Equal("châteigne", a.Content); // to clean the database
// WF : it works so 'a' is not null,
a = await mgr.removeAnswer(1); // and since we've delete the answer with
// 1) same thing with the id 1 just // the id 1, the content is "damien"
// to clean the database Assert.NotNull(a);
// WF : it works so 'a' is not null, Assert.Equal((uint)0, a.Id);
// and since we've delete the answer with Assert.Equal("damien", a.Content);
// the id 1, the content is "damien"
Assert.NotNull(a); // now, the database should be clean
Assert.Equal((uint)0, a.Id); }
Assert.Equal("damien", a.Content);
// /!\ WARNING : since there was 2 answers added to the base,
// now, the database should be clean // id index while now start at 2 (even though we've delete those)
}
/// <summary>
// /!\ WARNING : since there was 2 answers added to the base, /// test of the 'getNbElement' method of an AnswerManager
// id index while now start at 2 (even though we've delete those) /// </summary>
[Fact]
/// <summary> public async Task TestGetNbElement()
/// test of the 'getNbElement' method of an AnswerManager {
/// </summary> Assert.Equal(0, mgr.getNbElements()); // just to be sure
[Fact]
public async Task TestGetNbElement() Assert.NotNull(fakeAnswers.datas); // just to be sure
{
Assert.Equal(0, mgr.getNbElements()); // just to be sure int count = 0;
foreach (var answer in fakeAnswers.datas)
Assert.NotNull(answers); // just to be sure {
await mgr.addAnswer(answer);
int count = 0; count++;
foreach (var answer in answers) Assert.Equal(count, mgr.getNbElements()); // ok, it's incremented
{ }
await mgr.addAnswer(answer); }
count++;
Assert.Equal(count, mgr.getNbElements()); public static IEnumerable<Object?[]> TestGetAnswer_Datas()
} {
} uint max = 0;
foreach (var item in fakeAnswers.datas)
// getAnswers {
yield return new Object[] { item.Id, item };
// modifierAnswer if(max < item.Id) max = item.Id;
}
// supprimerAnswer (les 2) yield return new Object[] { max+1, null };
}
// getAnswersByIdQuestion [Theory]
} [MemberData(nameof(TestGetAnswer_Datas))]
public async Task TestGetAnswer(uint id, AnswerEntity? waiting)
{
Assert.Equal(waiting, await mgr.getAnswer(id));
}
// modifierAnswer
// supprimerAnswer (les 2)
// getAnswersByIdQuestion
}
} }

@ -12,7 +12,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" /> <PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="xunit" Version="2.5.3" /> <PackageReference Include="xunit" Version="2.5.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" /> <PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
</ItemGroup> </ItemGroup>
@ -21,6 +21,7 @@
<ProjectReference Include="..\DbConnectionLibrairie\DbConnectionLibrairie.csproj" /> <ProjectReference Include="..\DbConnectionLibrairie\DbConnectionLibrairie.csproj" />
<ProjectReference Include="..\Entities\Entities.csproj" /> <ProjectReference Include="..\Entities\Entities.csproj" />
<ProjectReference Include="..\EntityManagers\EntityManagers.csproj" /> <ProjectReference Include="..\EntityManagers\EntityManagers.csproj" />
<ProjectReference Include="..\FakeDatas\FakeDatas.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

@ -27,7 +27,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ServiceManagers", "ServiceM
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebApi", "WebApi\WebApi.csproj", "{7A65FECF-F4F5-4D88-853D-F21A3BAA5E39}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebApi", "WebApi\WebApi.csproj", "{7A65FECF-F4F5-4D88-853D-F21A3BAA5E39}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FakeDatas", "FakeDatas\FakeDatas.csproj", "{3C930FB5-2F1E-463E-978B-F0B5C7A58307}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FakeDatas", "FakeDatas\FakeDatas.csproj", "{3C930FB5-2F1E-463E-978B-F0B5C7A58307}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution

Loading…
Cancel
Save