Compare commits

..

2 Commits

Author SHA1 Message Date
Maxence LANONE a63b866b27 🚧 mise en place liaison bdd et api
continuous-integration/drone/push Build is failing Details
2 years ago
Maxence LANONE 10979b13e8 🔨 add CRUD operation for rune, champion and skin
continuous-integration/drone/push Build is failing Details
2 years ago

@ -12,28 +12,28 @@ steps:
image: mcr.microsoft.com/dotnet/sdk:7.0
commands:
- cd Sources/
- dotnet restore LeagueOfLegends_CI.sln
- dotnet build LeagueOfLegends_CI.sln -c Release --no-restore
- dotnet publish LeagueOfLegends_CI.sln -c Release --no-restore -o CI_PROJECT_DIR/build/release
- dotnet restore LeagueOfLegends.sln
- dotnet build LeagueOfLegends.sln -c Release --no-restore
- dotnet publish LeagueOfLegends.sln -c Release --no-restore -o CI_PROJECT_DIR/build/release
- name: tests
image: mcr.microsoft.com/dotnet/sdk:7.0
commands:
- cd Sources/
- dotnet restore LeagueOfLegends_CI.sln
- dotnet test LeagueOfLegends_CI.sln --no-restore
- dotnet restore LeagueOfLegends.sln
- dotnet test LeagueOfLegends.sln --no-restore
depends_on: [build]
- name: code-analysis
image: hub.codefirst.iut.uca.fr/marc.chevaldonne/codefirst-dronesonarplugin-dotnet7
commands:
- cd Sources/
- dotnet restore LeagueOfLegends_CI.sln
- dotnet restore LeagueOfLegends.sln
- dotnet sonarscanner begin /k:EfCore_Lol_S4 /d:sonar.host.url="https://codefirst.iut.uca.fr/sonar" /d:sonar.coverage.exclusions="Tests/**" /d:sonar.coverageReportPaths="coveragereport/SonarQube.xml" /d:sonar.login=$${PLUGIN_SONAR_TOKEN}
- dotnet build LeagueOfLegends_CI.sln -c Release --no-restore
- dotnet test LeagueOfLegends_CI.sln --logger trx --no-restore /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura --collect "XPlat Code Coverage"
- dotnet build LeagueOfLegends.sln -c Release --no-restore
- dotnet test LeagueOfLegends.sln --logger trx --no-restore /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura --collect "XPlat Code Coverage"
- reportgenerator -reports:"**/coverage.cobertura.xml" -reporttypes:SonarQube -targetdir:"coveragereport"
- dotnet publish LeagueOfLegends_CI.sln -c Release --no-restore -o $CI_PROJECT_DIR/build/release
- dotnet publish LeagueOfLegends.sln -c Release --no-restore -o $CI_PROJECT_DIR/build/release
- dotnet sonarscanner end /d:sonar.login=$${PLUGIN_SONAR_TOKEN}
secrets: [ SECRET_SONAR_LOGIN ]
settings:

Binary file not shown.

Before

Width:  |  Height:  |  Size: 136 KiB

@ -18,42 +18,6 @@ Ce dépot réuni plusieurs choses :
- Une documentation de l'api avec les différentes requetes possible.
- Plusieurs schémas dont l'architechture de l'ORM et le lien entre les différents éléments (ORM, API, Application mobile).
## Avancement des projets
# :zap: Consommation et Développement de services
> * :white_check_mark: La mise en place de toutes les opérations CRUD est terminée.
> * :white_check_mark: Une API RESTful a été mise en place en respectant les règles de routage et en utilisant les bons codes de statut.
> * :construction: La version de l'API a été gérée de manière appropriée.
> * :white_check_mark: Les logs ont été implémentés.
> * :construction: Les tests unitaires sont en cours de réalisation.
> * :construction: La création du client MAUI et sa liaison avec l'API sont en cours de réalisation.
> * :construction: La liaison avec la base de données est opérationnelle.
> * :construction: Le filtrage et la pagination des données ont été implémentés.
> * :white_check_mark: Le code est de qualité grâce à l'utilisation de SonarQube.
> * :white_check_mark: L'API a été dockerisée et hébergée sur CodeFirst.
> * :construction: Sécurité
`Note : Le client MAUI a été mis en place mais il n'utilise que le stub actuellement et n'est pas relié à l'api.`
---
# :zap: Entity Framework :
Voici l'état des différentes tâches liées à Entity Framework :
> * :white_check_mark: **Exercice 1** : Une base de données a été créée avec une table pour les champions, et des requêtes CRUD ont été implémentées, ainsi que du filtrage et de la pagination. Le client console n'a pas été réalisé pour cet exercice par manque de temps.
> * :white_check_mark: **Exercice 2** : Des tests unitaires ont été écrits et une base de données a été simulée à l'aide de SQLiteInMemory.
> * :white_check_mark: **Exercice 3** : Entity Framework a été déployé et les tests ont été effectués via Code#0.
> * :white_check_mark: **Exercice 4**: Les tables pour les runes et les skins ont été implémentées (sans les relations).
> * :white_check_mark: **Exercice 5** : Une relation OneToMany a été établie entre les champions et les skins.
> * :white_check_mark: **Exercice 6** : Une relation ManyToMany a été établie entre les champions, les rune pages et les runes.
> * :construction: **Exercice 7** : Le mapping entre le modèle et l'entité a été réalisé pour améliorer la qualité du code.
> * :construction: **Exercice 8** : La mise en place du pattern UnitOfWork n'a pas pu être implémentée par manque de temps.
---
# Lancer le projet
@ -64,28 +28,9 @@ Cette partie est réalisé avec un mac, toutes les manipulations qui vont suivre
:construction:
## IOS
### 1 - Cloner le dépot
Ouvrer Visual Studio Pour Mac, cloner le depot a l'aide du lien suivant:
https://codefirst.iut.uca.fr/git/maxence.lanone/EfCore_LoL_S4.git
### 3 - Configurer le démarrage du projet
> clique droit sur le projet dans l'explorateur de solution > Set Startup Projects
Et selectionner soit LolApp + WebApiLol, soit ConsoleTests + WebApiLol.
### 4 - Lancement du projet
Vous pouvez alors lancer le projet grâce à la flèche verte, bonne navigation !
:construction:
# Documention
Rendez vous sur la partie wiki du projet pour accéder aux différents diagrammes ainsi qu'à la documention de l'api.
# Réalisation
Projet réalisé par Maxence Lanone, élève en PM3.
Rendez vous sur la partie wiki du projet pour accéder aux différents diagrammes ainsi qu'à la documention de l'api.

@ -61,11 +61,7 @@ namespace DbDatamanager
throw new NotImplementedException();
}
public async Task<int> GetNbItems()
{
var nbItems = lolContext.Champions.Count();
return nbItems;
}
public async Task<int> GetNbItems() => lolContext.Champions.Count();
private Func<Champion, string, bool> filterByName = (champ, substring) => champ.Name.Contains(substring, StringComparison.InvariantCultureIgnoreCase);

@ -1,5 +1,4 @@
using System;
using System.Collections.ObjectModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Shared;
@ -12,24 +11,10 @@ namespace EntityFrameWorkLib
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int UniqueId { get; set; }
public string? Name { get; set; }
//[Required]
[MaxLength(256)]
public string? Bio { get; set; }
public string? Icon { get; set; }
//[Required]
public ChampionClass Class { get; set; }
public Collection<SkinEntity>? Skins { get; set; }
public LargeImageEntity? LargeImage { get; set; }
public HashSet<SkillEntity> skills = new HashSet<SkillEntity>();
public Collection<RunePageEntity>? ListRunePages { get; set; }
}
public string Name { get; set; }
public string Bio { get; set; }
public string Icon { get; set; }
public ChampionClass championClass { get; set; }
}
}

@ -1,21 +0,0 @@
using System;
using System.ComponentModel.DataAnnotations;
namespace EntityFrameWorkLib
{
public class LargeImageEntity
{
[Key]
public Guid Id { get; set; }
//[Required]
public string? Base64 { get; set; }
//[Required]
public int championId { get; set; }
//[Required]
public ChampionEntity? champion { get; set; }
}
}

@ -6,52 +6,32 @@ namespace EntityFrameWorkLib
{
public class LolContext : DbContext
{
public DbSet<ChampionEntity> Champions { get; set; }
public DbSet<SkillEntity> Skill { get; set; }
public DbSet<LargeImageEntity> LargeImage { get; set; }
public DbSet<RuneEntity> Runes { get; set; }
public DbSet<RunePageEntity> RunesPage { get; set; }
public DbSet<SkinEntity> Skins { get; set; }
public LolContext() { }
public LolContext(DbContextOptions<LolContext> options)
: base(options)
{ }
protected override void OnConfiguring(DbContextOptionsBuilder options)
{
if (!options.IsConfigured)
{
public DbSet<ChampionEntity> Champions { get; set; }
public LolContext() { }
public LolContext(DbContextOptions<LolContext> options)
:base(options)
{ }
protected override void OnConfiguring(DbContextOptionsBuilder options)
{
if (!options.IsConfigured)
{
base.OnConfiguring(options.UseSqlite($"DataSource=projet.Champions.db"));
}
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
//Définition de la clé primaire de ChampionEntity
modelBuilder.Entity<ChampionEntity>().HasKey(n => n.UniqueId);
//Définition du mode de generation de la clé : génération à l'insertion
modelBuilder.Entity<ChampionEntity>().Property(n => n.UniqueId).ValueGeneratedOnAdd();
modelBuilder.Entity<ChampionEntity>()
.HasOne(c => c.LargeImage)
.WithOne(li => li.champion)
.HasForeignKey<LargeImageEntity>(li => li.championId);
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
//Définition de la clé primaire de ChampionEntity
modelBuilder.Entity<ChampionEntity>().HasKey(n => n.UniqueId);
//Définition du mode de generation de la clé : génération à l'insertion
modelBuilder.Entity<ChampionEntity>().Property(n => n.UniqueId).ValueGeneratedOnAdd();
modelBuilder.Entity<SkinEntity>()
.Property(s => s.Name)
.ValueGeneratedOnAdd();
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<RunePageEntity>()
.Property(s => s.Id)
.ValueGeneratedOnAdd();
modelBuilder.Entity<RuneEntity>()
.Property(s => s.Name)
.ValueGeneratedOnAdd();
}
}
}
}

@ -0,0 +1,50 @@
// <auto-generated />
using EntityFrameWorkLib;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace EntityFrameWorkLib.Migrations
{
[DbContext(typeof(LolContext))]
[Migration("20230308120111_MyMigration")]
partial class MyMigration
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "7.0.3");
modelBuilder.Entity("EntityFrameWorkLib.ChampionEntity", b =>
{
b.Property<int>("UniqueId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Bio")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Icon")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("championClass")
.HasColumnType("INTEGER");
b.HasKey("UniqueId");
b.ToTable("Champions");
});
#pragma warning restore 612, 618
}
}
}

@ -0,0 +1,37 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace EntityFrameWorkLib.Migrations
{
/// <inheritdoc />
public partial class MyMigration : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Champions",
columns: table => new
{
UniqueId = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Name = table.Column<string>(type: "TEXT", nullable: false),
Bio = table.Column<string>(type: "TEXT", nullable: false),
Icon = table.Column<string>(type: "TEXT", nullable: false),
championClass = table.Column<int>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Champions", x => x.UniqueId);
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Champions");
}
}
}

@ -1,225 +0,0 @@
// <auto-generated />
using System;
using EntityFrameWorkLib;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace EntityFrameWorkLib.Migrations
{
[DbContext(typeof(LolContext))]
[Migration("20230326210027_MyMigration")]
partial class MyMigration
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "7.0.4");
modelBuilder.Entity("EntityFrameWorkLib.ChampionEntity", b =>
{
b.Property<int>("UniqueId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Bio")
.IsRequired()
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<int>("Class")
.HasColumnType("INTEGER");
b.Property<string>("Icon")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("SkillEntityName")
.HasColumnType("TEXT");
b.HasKey("UniqueId");
b.HasIndex("SkillEntityName");
b.ToTable("Champions");
});
modelBuilder.Entity("EntityFrameWorkLib.LargeImageEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("Base64")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("championId")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("championId")
.IsUnique();
b.ToTable("LargeImage");
});
modelBuilder.Entity("EntityFrameWorkLib.RuneEntity", b =>
{
b.Property<string>("Name")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("Description")
.IsRequired()
.HasMaxLength(500)
.HasColumnType("TEXT");
b.Property<int>("RuneFamily")
.HasColumnType("INTEGER");
b.HasKey("Name");
b.ToTable("Runes");
});
modelBuilder.Entity("EntityFrameWorkLib.RunePageEntity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int?>("ChampionEntityUniqueId")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("RuneEntityName")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("ChampionEntityUniqueId");
b.HasIndex("RuneEntityName");
b.ToTable("RunesPage");
});
modelBuilder.Entity("EntityFrameWorkLib.SkillEntity", b =>
{
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<string>("Description")
.IsRequired()
.HasMaxLength(500)
.HasColumnType("TEXT");
b.Property<int>("SkillType")
.HasColumnType("INTEGER");
b.HasKey("Name");
b.ToTable("Skill");
});
modelBuilder.Entity("EntityFrameWorkLib.SkinEntity", b =>
{
b.Property<string>("Name")
.ValueGeneratedOnAdd()
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<int?>("ChampionEntityUniqueId")
.HasColumnType("INTEGER");
b.Property<string>("Description")
.IsRequired()
.HasMaxLength(500)
.HasColumnType("TEXT");
b.Property<string>("Icon")
.IsRequired()
.HasColumnType("TEXT");
b.Property<float>("Price")
.HasColumnType("REAL");
b.HasKey("Name");
b.HasIndex("ChampionEntityUniqueId");
b.ToTable("Skins");
});
modelBuilder.Entity("EntityFrameWorkLib.ChampionEntity", b =>
{
b.HasOne("EntityFrameWorkLib.SkillEntity", null)
.WithMany("champions")
.HasForeignKey("SkillEntityName");
});
modelBuilder.Entity("EntityFrameWorkLib.LargeImageEntity", b =>
{
b.HasOne("EntityFrameWorkLib.ChampionEntity", "champion")
.WithOne("LargeImage")
.HasForeignKey("EntityFrameWorkLib.LargeImageEntity", "championId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("champion");
});
modelBuilder.Entity("EntityFrameWorkLib.RunePageEntity", b =>
{
b.HasOne("EntityFrameWorkLib.ChampionEntity", null)
.WithMany("ListRunePages")
.HasForeignKey("ChampionEntityUniqueId");
b.HasOne("EntityFrameWorkLib.RuneEntity", null)
.WithMany("ListRunePages")
.HasForeignKey("RuneEntityName");
});
modelBuilder.Entity("EntityFrameWorkLib.SkinEntity", b =>
{
b.HasOne("EntityFrameWorkLib.ChampionEntity", null)
.WithMany("Skins")
.HasForeignKey("ChampionEntityUniqueId");
});
modelBuilder.Entity("EntityFrameWorkLib.ChampionEntity", b =>
{
b.Navigation("LargeImage");
b.Navigation("ListRunePages");
b.Navigation("Skins");
});
modelBuilder.Entity("EntityFrameWorkLib.RuneEntity", b =>
{
b.Navigation("ListRunePages");
});
modelBuilder.Entity("EntityFrameWorkLib.SkillEntity", b =>
{
b.Navigation("champions");
});
#pragma warning restore 612, 618
}
}
}

@ -1,175 +0,0 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace EntityFrameWorkLib.Migrations
{
/// <inheritdoc />
public partial class MyMigration : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Runes",
columns: table => new
{
Name = table.Column<string>(type: "TEXT", nullable: false),
Description = table.Column<string>(type: "TEXT", maxLength: 500, nullable: false),
RuneFamily = table.Column<int>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Runes", x => x.Name);
});
migrationBuilder.CreateTable(
name: "Skill",
columns: table => new
{
Name = table.Column<string>(type: "TEXT", maxLength: 256, nullable: false),
Description = table.Column<string>(type: "TEXT", maxLength: 500, nullable: false),
SkillType = table.Column<int>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Skill", x => x.Name);
});
migrationBuilder.CreateTable(
name: "Champions",
columns: table => new
{
UniqueId = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Name = table.Column<string>(type: "TEXT", nullable: false),
Bio = table.Column<string>(type: "TEXT", maxLength: 256, nullable: false),
Icon = table.Column<string>(type: "TEXT", nullable: false),
Class = table.Column<int>(type: "INTEGER", nullable: false),
SkillEntityName = table.Column<string>(type: "TEXT", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Champions", x => x.UniqueId);
table.ForeignKey(
name: "FK_Champions_Skill_SkillEntityName",
column: x => x.SkillEntityName,
principalTable: "Skill",
principalColumn: "Name");
});
migrationBuilder.CreateTable(
name: "LargeImage",
columns: table => new
{
Id = table.Column<Guid>(type: "TEXT", nullable: false),
Base64 = table.Column<string>(type: "TEXT", nullable: false),
championId = table.Column<int>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_LargeImage", x => x.Id);
table.ForeignKey(
name: "FK_LargeImage_Champions_championId",
column: x => x.championId,
principalTable: "Champions",
principalColumn: "UniqueId",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "RunesPage",
columns: table => new
{
Id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Name = table.Column<string>(type: "TEXT", nullable: false),
ChampionEntityUniqueId = table.Column<int>(type: "INTEGER", nullable: true),
RuneEntityName = table.Column<string>(type: "TEXT", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_RunesPage", x => x.Id);
table.ForeignKey(
name: "FK_RunesPage_Champions_ChampionEntityUniqueId",
column: x => x.ChampionEntityUniqueId,
principalTable: "Champions",
principalColumn: "UniqueId");
table.ForeignKey(
name: "FK_RunesPage_Runes_RuneEntityName",
column: x => x.RuneEntityName,
principalTable: "Runes",
principalColumn: "Name");
});
migrationBuilder.CreateTable(
name: "Skins",
columns: table => new
{
Name = table.Column<string>(type: "TEXT", maxLength: 256, nullable: false),
Description = table.Column<string>(type: "TEXT", maxLength: 500, nullable: false),
Icon = table.Column<string>(type: "TEXT", nullable: false),
Price = table.Column<float>(type: "REAL", nullable: false),
ChampionEntityUniqueId = table.Column<int>(type: "INTEGER", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Skins", x => x.Name);
table.ForeignKey(
name: "FK_Skins_Champions_ChampionEntityUniqueId",
column: x => x.ChampionEntityUniqueId,
principalTable: "Champions",
principalColumn: "UniqueId");
});
migrationBuilder.CreateIndex(
name: "IX_Champions_SkillEntityName",
table: "Champions",
column: "SkillEntityName");
migrationBuilder.CreateIndex(
name: "IX_LargeImage_championId",
table: "LargeImage",
column: "championId",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_RunesPage_ChampionEntityUniqueId",
table: "RunesPage",
column: "ChampionEntityUniqueId");
migrationBuilder.CreateIndex(
name: "IX_RunesPage_RuneEntityName",
table: "RunesPage",
column: "RuneEntityName");
migrationBuilder.CreateIndex(
name: "IX_Skins_ChampionEntityUniqueId",
table: "Skins",
column: "ChampionEntityUniqueId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "LargeImage");
migrationBuilder.DropTable(
name: "RunesPage");
migrationBuilder.DropTable(
name: "Skins");
migrationBuilder.DropTable(
name: "Runes");
migrationBuilder.DropTable(
name: "Champions");
migrationBuilder.DropTable(
name: "Skill");
}
}
}

@ -1,5 +1,4 @@
// <auto-generated />
using System;
using EntityFrameWorkLib;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
@ -15,7 +14,7 @@ namespace EntityFrameWorkLib.Migrations
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "7.0.4");
modelBuilder.HasAnnotation("ProductVersion", "7.0.3");
modelBuilder.Entity("EntityFrameWorkLib.ChampionEntity", b =>
{
@ -25,12 +24,8 @@ namespace EntityFrameWorkLib.Migrations
b.Property<string>("Bio")
.IsRequired()
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<int>("Class")
.HasColumnType("INTEGER");
b.Property<string>("Icon")
.IsRequired()
.HasColumnType("TEXT");
@ -39,183 +34,13 @@ namespace EntityFrameWorkLib.Migrations
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("SkillEntityName")
.HasColumnType("TEXT");
b.Property<int>("championClass")
.HasColumnType("INTEGER");
b.HasKey("UniqueId");
b.HasIndex("SkillEntityName");
b.ToTable("Champions");
});
modelBuilder.Entity("EntityFrameWorkLib.LargeImageEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("Base64")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("championId")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("championId")
.IsUnique();
b.ToTable("LargeImage");
});
modelBuilder.Entity("EntityFrameWorkLib.RuneEntity", b =>
{
b.Property<string>("Name")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("Description")
.IsRequired()
.HasMaxLength(500)
.HasColumnType("TEXT");
b.Property<int>("RuneFamily")
.HasColumnType("INTEGER");
b.HasKey("Name");
b.ToTable("Runes");
});
modelBuilder.Entity("EntityFrameWorkLib.RunePageEntity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int?>("ChampionEntityUniqueId")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("RuneEntityName")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("ChampionEntityUniqueId");
b.HasIndex("RuneEntityName");
b.ToTable("RunesPage");
});
modelBuilder.Entity("EntityFrameWorkLib.SkillEntity", b =>
{
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<string>("Description")
.IsRequired()
.HasMaxLength(500)
.HasColumnType("TEXT");
b.Property<int>("SkillType")
.HasColumnType("INTEGER");
b.HasKey("Name");
b.ToTable("Skill");
});
modelBuilder.Entity("EntityFrameWorkLib.SkinEntity", b =>
{
b.Property<string>("Name")
.ValueGeneratedOnAdd()
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<int?>("ChampionEntityUniqueId")
.HasColumnType("INTEGER");
b.Property<string>("Description")
.IsRequired()
.HasMaxLength(500)
.HasColumnType("TEXT");
b.Property<string>("Icon")
.IsRequired()
.HasColumnType("TEXT");
b.Property<float>("Price")
.HasColumnType("REAL");
b.HasKey("Name");
b.HasIndex("ChampionEntityUniqueId");
b.ToTable("Skins");
});
modelBuilder.Entity("EntityFrameWorkLib.ChampionEntity", b =>
{
b.HasOne("EntityFrameWorkLib.SkillEntity", null)
.WithMany("champions")
.HasForeignKey("SkillEntityName");
});
modelBuilder.Entity("EntityFrameWorkLib.LargeImageEntity", b =>
{
b.HasOne("EntityFrameWorkLib.ChampionEntity", "champion")
.WithOne("LargeImage")
.HasForeignKey("EntityFrameWorkLib.LargeImageEntity", "championId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("champion");
});
modelBuilder.Entity("EntityFrameWorkLib.RunePageEntity", b =>
{
b.HasOne("EntityFrameWorkLib.ChampionEntity", null)
.WithMany("ListRunePages")
.HasForeignKey("ChampionEntityUniqueId");
b.HasOne("EntityFrameWorkLib.RuneEntity", null)
.WithMany("ListRunePages")
.HasForeignKey("RuneEntityName");
});
modelBuilder.Entity("EntityFrameWorkLib.SkinEntity", b =>
{
b.HasOne("EntityFrameWorkLib.ChampionEntity", null)
.WithMany("Skins")
.HasForeignKey("ChampionEntityUniqueId");
});
modelBuilder.Entity("EntityFrameWorkLib.ChampionEntity", b =>
{
b.Navigation("LargeImage");
b.Navigation("ListRunePages");
b.Navigation("Skins");
});
modelBuilder.Entity("EntityFrameWorkLib.RuneEntity", b =>
{
b.Navigation("ListRunePages");
});
modelBuilder.Entity("EntityFrameWorkLib.SkillEntity", b =>
{
b.Navigation("champions");
});
#pragma warning restore 612, 618
}
}

@ -1,5 +1,4 @@
using System;
using System.Collections.ObjectModel;
using System.ComponentModel.DataAnnotations;
using Shared;
@ -9,17 +8,15 @@ namespace EntityFrameWorkLib
public class RuneEntity
{
[Key]
//[MaxLength(256)]
public string? Name { get; set; }
[MaxLength(256)]
public string Name { get; set; }
//[Required]
[Required]
[MaxLength(500)]
public string? Description { get; set; }
public string Description { get; set; }
//[Required]
[Required]
public RuneFamily RuneFamily { get; set; }
public Collection<RunePageEntity>? ListRunePages { get; set; }
}
}

@ -1,20 +0,0 @@
using System;
namespace EntityFrameWorkLib
{
public class RunePageEntity
{
public int Id { get; set; }
public String? Name { get; set; }
}
public enum Category
{
Major,
Minor1,
Minor2,
Minor3,
OtherMinor1,
OtherMinor2
}
}

@ -1,23 +0,0 @@
using System;
using Shared;
using System.ComponentModel.DataAnnotations;
namespace EntityFrameWorkLib
{
public class SkillEntity
{
[Key]
[MaxLength(256)]
public string? Name { get; set; }
//[Required]
[MaxLength(500)]
public string? Description { get; set; }
//[Required]
public SkillType SkillType { get; set; }
public HashSet<ChampionEntity>? champions { get; set; }
}
}

@ -0,0 +1,12 @@
using System;
namespace EntityFrameWorkLib
{
public class Skin
{
public string Name { get; set; }
public string Description { get; set; }
public string Icon { get; set; }
public float Price { get; set; }
}
}

@ -1,22 +0,0 @@
using System;
using System.ComponentModel.DataAnnotations;
namespace EntityFrameWorkLib
{
public class SkinEntity
{
[Key]
[MaxLength(256)]
public string? Name { get; set; }
//[Required]
[MaxLength(500)]
public string? Description { get; set; }
public string? Icon { get; set; }
//[Required]
public float Price { get; set; }
}
}

@ -1,98 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 25.0.1704.2
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Model", "Model\Model.csproj", "{2960F9BA-49DE-494D-92E3-CE5A794BA1A9}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{C76D0C23-1FFA-4963-93CD-E12BD643F030}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleTests", "Tests\ConsoleTests\ConsoleTests.csproj", "{1889FA6E-B7C6-416E-8628-9449FB9070B9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Shared", "Shared\Shared.csproj", "{3B720C0C-53FE-4642-A2DB-87FD8634CD74}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Stub", "Stub", "{2C607793-B163-4731-A4D1-AFE8A7C4C170}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StubLib", "StubLib\StubLib.csproj", "{B01D7EF2-2D64-409A-A29A-61FB7BB7A9DB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleDB", "Tests\ConsoleDB\ConsoleDB.csproj", "{3E16421B-7372-477D-A25E-8249D5203A1E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestUnitaireLOL", "Tests\TestUnitaireLOL\TestUnitaireLOL.csproj", "{F4473EB6-6CD7-4A73-89BC-82C247A23412}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DbDatamanager", "DbDatamanager\DbDatamanager.csproj", "{B316E0A6-491B-45D6-A4E5-78AB662ABE1B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EntityFrameWorkLib", "EntityFrameWorkLib\EntityFrameWorkLib.csproj", "{C78F459C-A1CE-4978-A08D-73C6BDB4094C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApiLol", "WebApiLol\WebApiLol.csproj", "{DAE3B5A2-8904-43AE-8459-ED64C3366FDF}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{73142960-0D40-4766-973B-37094F4BD879}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleTestapi", "Tests\ConsoleTestapi\ConsoleTestapi.csproj", "{EA884D64-6425-46FB-BA25-E2EB8FE6BECE}"
EndProject
Project("{E53339B2-1760-4266-BCC7-CA923CBCF16C}") = "docker-compose", "docker-compose.dcproj", "{1B81A541-7D10-4603-B5A2-94108954D831}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2960F9BA-49DE-494D-92E3-CE5A794BA1A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2960F9BA-49DE-494D-92E3-CE5A794BA1A9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2960F9BA-49DE-494D-92E3-CE5A794BA1A9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2960F9BA-49DE-494D-92E3-CE5A794BA1A9}.Release|Any CPU.Build.0 = Release|Any CPU
{1889FA6E-B7C6-416E-8628-9449FB9070B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1889FA6E-B7C6-416E-8628-9449FB9070B9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1889FA6E-B7C6-416E-8628-9449FB9070B9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1889FA6E-B7C6-416E-8628-9449FB9070B9}.Release|Any CPU.Build.0 = Release|Any CPU
{3B720C0C-53FE-4642-A2DB-87FD8634CD74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3B720C0C-53FE-4642-A2DB-87FD8634CD74}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3B720C0C-53FE-4642-A2DB-87FD8634CD74}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3B720C0C-53FE-4642-A2DB-87FD8634CD74}.Release|Any CPU.Build.0 = Release|Any CPU
{B01D7EF2-2D64-409A-A29A-61FB7BB7A9DB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B01D7EF2-2D64-409A-A29A-61FB7BB7A9DB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B01D7EF2-2D64-409A-A29A-61FB7BB7A9DB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B01D7EF2-2D64-409A-A29A-61FB7BB7A9DB}.Release|Any CPU.Build.0 = Release|Any CPU
{3E16421B-7372-477D-A25E-8249D5203A1E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3E16421B-7372-477D-A25E-8249D5203A1E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3E16421B-7372-477D-A25E-8249D5203A1E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3E16421B-7372-477D-A25E-8249D5203A1E}.Release|Any CPU.Build.0 = Release|Any CPU
{F4473EB6-6CD7-4A73-89BC-82C247A23412}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F4473EB6-6CD7-4A73-89BC-82C247A23412}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F4473EB6-6CD7-4A73-89BC-82C247A23412}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F4473EB6-6CD7-4A73-89BC-82C247A23412}.Release|Any CPU.Build.0 = Release|Any CPU
{B316E0A6-491B-45D6-A4E5-78AB662ABE1B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B316E0A6-491B-45D6-A4E5-78AB662ABE1B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B316E0A6-491B-45D6-A4E5-78AB662ABE1B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B316E0A6-491B-45D6-A4E5-78AB662ABE1B}.Release|Any CPU.Build.0 = Release|Any CPU
{C78F459C-A1CE-4978-A08D-73C6BDB4094C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C78F459C-A1CE-4978-A08D-73C6BDB4094C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C78F459C-A1CE-4978-A08D-73C6BDB4094C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C78F459C-A1CE-4978-A08D-73C6BDB4094C}.Release|Any CPU.Build.0 = Release|Any CPU
{DAE3B5A2-8904-43AE-8459-ED64C3366FDF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DAE3B5A2-8904-43AE-8459-ED64C3366FDF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DAE3B5A2-8904-43AE-8459-ED64C3366FDF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DAE3B5A2-8904-43AE-8459-ED64C3366FDF}.Release|Any CPU.Build.0 = Release|Any CPU
{EA884D64-6425-46FB-BA25-E2EB8FE6BECE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EA884D64-6425-46FB-BA25-E2EB8FE6BECE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EA884D64-6425-46FB-BA25-E2EB8FE6BECE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EA884D64-6425-46FB-BA25-E2EB8FE6BECE}.Release|Any CPU.Build.0 = Release|Any CPU
{1B81A541-7D10-4603-B5A2-94108954D831}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1B81A541-7D10-4603-B5A2-94108954D831}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1B81A541-7D10-4603-B5A2-94108954D831}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1B81A541-7D10-4603-B5A2-94108954D831}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {92F3083D-793F-4552-8A9A-0AD6534159C9}
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{1889FA6E-B7C6-416E-8628-9449FB9070B9} = {C76D0C23-1FFA-4963-93CD-E12BD643F030}
{B01D7EF2-2D64-409A-A29A-61FB7BB7A9DB} = {2C607793-B163-4731-A4D1-AFE8A7C4C170}
{3E16421B-7372-477D-A25E-8249D5203A1E} = {C76D0C23-1FFA-4963-93CD-E12BD643F030}
{F4473EB6-6CD7-4A73-89BC-82C247A23412} = {C76D0C23-1FFA-4963-93CD-E12BD643F030}
{EA884D64-6425-46FB-BA25-E2EB8FE6BECE} = {C76D0C23-1FFA-4963-93CD-E12BD643F030}
EndGlobalSection
EndGlobal

File diff suppressed because one or more lines are too long

@ -1,40 +0,0 @@
using System;
using Microsoft.Extensions.Logging.Abstractions;
using StubLib;
using WebApiLol;
using WebApiLol.Controllers;
namespace TestUnitaireLOL
{
public class TestAPI
{
//[Theory]
//[InlineData("Beatrice", "sdfsdfd", "icon.png")]
//[InlineData("Maurice", "Ahri est un champion de League of Legends", "icon.png")]
//[InlineData("Loupiotte", "Akali est un champion de League of Legends", "icon.png")]
//public async Task TestPostChampion(string name, string bio, string icon)
//{
// // Arrange
// var data = new StubData();
// var logger = new NullLogger<ChampionController>();
// var controller = new ChampionController(data, logger);
// var champDTO = new ChampionDTO()
// {
// Name = name,
// Bio = bio,
// Icon = icon
// };
// // Act
// var nbInListBefore = data.ChampionsMgr.GetNbItems().Result;
// var result = await controller.AddChampion(champDTO);
// var nbInListAfter = data.ChampionsMgr.GetNbItems().Result;
// // Assert
// // IS the champion added to the list, number of champions in the list + 1
// Assert.Equal(nbInListBefore + 1, nbInListAfter);
// // Test le code de retour
//}
}
}

@ -1,178 +0,0 @@
using System;
using System.Collections.ObjectModel;
using EntityFrameWorkLib;
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using Model;
using Shared;
namespace TestUnitaireLOL
{
public class TestEf
{
//[Theory]
//[InlineData(0, "Zeus", "Dieu de la foudre", true)]
//[InlineData(10, "Hades", "Dieu des enfers", true)]
//[InlineData(1, "Aphrodite", "Déesse de l'amour", true)]
////[InlineData(10, "AresAresAresAresAresAresAresAresAresAres",
//// "Dieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerre" +
//// "Dieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerre" +
//// "Dieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerre", false)]
//public async Task TestAddChampionInMemory(int id, String name, String bio, bool expected)
//{
// var connection = new SqliteConnection("DataSource=:memory:");
// connection.Open();
// var options = new DbContextOptionsBuilder<LolContext>()
// .UseSqlite(connection)
// .Options;
// using (var context = new LolContext(options))
// {
// await context.Database.EnsureCreatedAsync();
// SkinEntity black = new SkinEntity { Name = "Black", Description = "Black skin", Icon = "black.png", Price = 0.99f };
// SkinEntity white = new SkinEntity { Name = "White", Description = "White skin", Icon = "white.png", Price = 150.99f };
// SkinEntity green = new SkinEntity { Name = "Green", Description = "Green skin", Icon = "green.png", Price = 4.99f };
// RunePageEntity runePage1 = new RunePageEntity { Id = 1, Name = "runepage1" };
// var Dieu = new ChampionEntity
// {
// UniqueId = id,
// Name = name,
// Bio = bio,
// Skins = new Collection<SkinEntity>(new List<SkinEntity> { black, white, green }),
// ListRunePages = new Collection<RunePageEntity>(new List<RunePageEntity> { { runePage1 } })
// };
// ChampionEntity found = await context.Champions.SingleOrDefaultAsync(c => c.Name == "Zeus");
// Assert.Null(found);
// await context.Champions.AddAsync(Dieu);
// await context.SaveChangesAsync();
// found = await context.Champions.SingleOrDefaultAsync(c => c.Name == name);
// Assert.NotNull(found);
// Assert.Equal(1, await context.Champions.CountAsync());
// Assert.Equal(name, found.Name);
// Assert.Equal(3, found.Skins.Count);
// Assert.Equal(1, found.ListRunePages.Count);
// // Test if the max length of the name is respected (30) and the max length of the bio is respected (256)
// if (expected)
// {
// Assert.True(found.Name.Length <= 30);
// Assert.True(found.Bio.Length <= 256);
// }
// else
// {
// Assert.False(found.Name.Length <= 30);
// Assert.False(found.Bio.Length <= 256);
// }
// }
//}
[Fact]
public void TestModifyChampionInMemory()
{
var connection = new SqliteConnection("DataSource=:memory:");
connection.Open();
var options = new DbContextOptionsBuilder<LolContext>()
.UseSqlite(connection)
.Options;
//prepares the database with one instance of the context
using (var context = new LolContext(options))
{
//context.Database.OpenConnection();
context.Database.EnsureCreated();
ChampionEntity chewie = new ChampionEntity { Name = "Chewbacca",Icon="Icon1", Bio = "Zeus is the king of the gods." };
ChampionEntity yoda = new ChampionEntity { Name = "Yoda",Icon="Icon2", Bio = "Zeus is the king of the gods." };
ChampionEntity ewok = new ChampionEntity { Name = "Ewok",Icon="Icon3", Bio = "Zeus is the king of the gods." };
context.Champions.Add(chewie);
context.Champions.Add(yoda);
context.Champions.Add(ewok);
context.SaveChanges();
}
//uses another instance of the context to do the tests
using (var context = new LolContext(options))
{
context.Database.EnsureCreated();
string nameToFind = "ew";
Assert.Equal(2, context.Champions.Where(n => n.Name.ToLower().Contains(nameToFind)).Count());
nameToFind = "wo";
Assert.Equal(1, context.Champions.Where(n => n.Name.ToLower().Contains(nameToFind)).Count());
var ewok = context.Champions.Where(n => n.Name.ToLower().Contains(nameToFind)).First();
ewok.Name = "Wicket";
context.SaveChanges();
}
//uses another instance of the context to do the tests
using (var context = new LolContext(options))
{
context.Database.EnsureCreated();
string nameToFind = "ew";
Assert.Equal(1, context.Champions.Where(n => n.Name.ToLower().Contains(nameToFind)).Count());
nameToFind = "wick";
Assert.Equal(1, context.Champions.Where(n => n.Name.ToLower().Contains(nameToFind)).Count());
}
}
//[Theory]
//[InlineData(0, "black", "super Skin", "icon1.png", 190000000.2f, true)]
//[InlineData(1, "White", "skin1", "icon1", 19, true)]
//[InlineData(2, "Green", "skin", "icon1.jpg", -1, false)]
//public async Task TestAddSkinToChampionInMemory(int id, String name, String description, String icon, float price, bool expected)
//{
// var connection = new SqliteConnection("DataSource=:memory:");
// connection.Open();
// var options = new DbContextOptionsBuilder<LolContext>()
// .UseSqlite(connection)
// .Options;
// using (var context = new LolContext(options))
// {
// await context.Database.EnsureCreatedAsync();
// var Dieu = new ChampionEntity
// {
// UniqueId = 0,
// Name = "Zeus",
// Bio = "Dieu de la foudre",
// Skins = new Collection<SkinEntity>()
// };
// SkinEntity item = new SkinEntity
// {
// Name = name,
// Description = description,
// Icon = icon,
// Price = price
// };
// Dieu.Skins.Add(item);
// ChampionEntity found = await context.Champions.SingleOrDefaultAsync(c => c.Name == "Zeus");
// Assert.Null(found);
// await context.Champions.AddAsync(Dieu);
// await context.SaveChangesAsync();
// found = await context.Champions.SingleOrDefaultAsync(c => c.Name == name);
// }
//}
}
}

@ -20,10 +20,6 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.4">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
@ -32,7 +28,5 @@
<ItemGroup>
<ProjectReference Include="..\..\EntityFrameWorkLib\EntityFrameWorkLib.csproj" />
<ProjectReference Include="..\..\DbDatamanager\DbDatamanager.csproj" />
<ProjectReference Include="..\..\StubLib\StubLib.csproj" />
<ProjectReference Include="..\..\WebApiLol\WebApiLol.csproj" />
</ItemGroup>
</Project>

@ -1,30 +1,11 @@
using System;
using EntityFrameWorkLib;
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
namespace TestUnitaireLOL
{
public class UnitTestDbDataManager
{
public void Test_Data_AddItem(int expectedResult,
IEnumerable<ChampionEntity> expectedChampions,
IEnumerable<ChampionEntity> expectedChampionsAdded,
params ChampionEntity[] championsToAdd)
{
var connexion = new SqliteConnection("DataSource=:memory:");
connexion.Open();
var options = new DbContextOptionsBuilder<LolContext>()
.UseSqlite(connexion)
.Options;
using (var context = new LolContext())
{
}
}
}
public UnitTestDbDataManager()
{
}
}
}

@ -4,11 +4,25 @@ namespace WebApiLol
public class ChampionDTO
{
public int UniqueId { get; set; }
public string Name { get; set; }
public string Bio { get; set; }
public string Icon { get; set; }
public string Class { get; set; }
public bool equals(ChampionDTO other)
{
return other.Name == this.Name && other.Bio == this.Bio && other.Icon == this.Icon;
}
public string toString()
{
return Name + Bio + Icon;
}
}
}

@ -1,15 +0,0 @@
using System;
namespace WebApiLol
{
public class ChampionPageDTO
{
public IEnumerable<ChampionDTO> Data { get; set; }
public int Index { get; set; }
public int Count { get; set; }
public int TotalCount { get; set; }
}
}

@ -1,9 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using System.Xml.Linq;
using Microsoft.AspNetCore.Mvc;
using Model;
using StubLib;
@ -15,43 +13,29 @@ namespace WebApiLol.Controllers;
[Route("[controller]")]
public class ChampionController : ControllerBase
{
private StubData.ChampionsManager ChampionsManager { get; set; } = new StubData.ChampionsManager(new StubData());
//private StubData.ChampionsManager ChampionManager { get; set; } = new StubData.ChampionManager(new StubData());
private IChampionsManager _dataManager;
private readonly ILogger<ChampionController> _logger;
public ChampionController(IDataManager manager,ILogger<ChampionController> logger)
private IChampionsManager _dataManager;
public ChampionController(ILogger<ChampionController> logger, IDataManager dataManager)
{
_dataManager = manager.ChampionsMgr;
_logger = logger;
_dataManager = dataManager.ChampionsMgr;
}
[HttpGet]
[ProducesResponseType(typeof(ChampionPageDTO), 200)]
public async Task<IActionResult> Get([FromQuery] int index = 0, int count = 10, string? name = "")
public async Task<IActionResult> Get()
{
_logger.LogInformation($"methode Get de ControllerChampions appelée");
int nbChampions = await _dataManager.GetNbItems();
_logger.LogInformation($"Nombre de champions : {nbChampions}");
var champs = (await _dataManager.GetItemsByName(name, index, int.MaxValue))
.Where(champ => string.IsNullOrEmpty(name) || champ.Name.Contains(name, StringComparison.InvariantCultureIgnoreCase))
.Take(count)
.Select(Model => Model.toDTO());
var page = new ChampionPageDTO
{
Data = champs,
Index = index,
Count = champs.Count(),
TotalCount = nbChampions
};
return Ok(page);
var list = await _dataManager.GetItems(0, await _dataManager.GetNbItems());
return Ok(list.Select(champion => champion?.toDTO()));
}
[HttpGet("name")]
public async Task<IActionResult> GetById(string name)
{
var championSelected = await ChampionsManager.GetItemsByName(name, 0, await ChampionsManager.GetNbItemsByName(name), null);
var championSelected = await _dataManager.GetItemsByName(name, 0, await _dataManager.GetNbItemsByName(name), null);
return Ok(championSelected.Select(c => c?.toDTO()));
}
@ -59,45 +43,45 @@ public class ChampionController : ControllerBase
public async Task<IActionResult> AddChampion([FromBody] ChampionDTO champion)
{
var newChampion = champion.toModel();
await ChampionsManager.AddItem(newChampion);
await _dataManager.AddItem(newChampion);
if (champion.Bio == "string")
{
champion.Bio = "Aucune bio";
}
Console.WriteLine("Le champion { " + champion.Name + " } avec pour bio { " + champion.Bio + " } a bien été ajouté");
Console.WriteLine("Champion { " + champion.Name + " } with bio { " + champion.Bio + " } has been succesfully added");
return Ok();
}
[HttpPut("Update")]
public async Task<IActionResult> UpdateChampion(string name, [FromBody] ChampionDTO champion)
{
var championSelected = await ChampionsManager.GetItemsByName(name, 0, await ChampionsManager.GetNbItemsByName(name), null);
var championSelected = await _dataManager.GetItemsByName(name, 0, await _dataManager.GetNbItemsByName(name), null);
var existingChampion = championSelected.FirstOrDefault();
if (existingChampion == null)
{
Console.WriteLine("Le champion { " + name + " } n'existe pas !");
Console.WriteLine("Champion { " + name + " } doesn't exist !");
return NotFound();
}
var updatedChampion = champion.toModel();
await ChampionsManager.UpdateItem(existingChampion, updatedChampion);
await _dataManager.UpdateItem(existingChampion, updatedChampion);
if (updatedChampion.Bio == "string")
{
updatedChampion.Bio = "Aucune bio";
}
Console.WriteLine("Le champion { " + name + " } a été modifié en { " + updatedChampion.Name + " } avec pour bio { " + updatedChampion.Bio + " }");
Console.WriteLine("Champion { " + name + " } has been modified in { " + updatedChampion.Name + " } with bio { " + updatedChampion.Bio + " }");
return Ok();
}
[HttpDelete("Delete")]
public async Task<IActionResult> DeleteChampion(string name)
{
var championSelected = await ChampionsManager.GetItemsByName(name, 0, await ChampionsManager.GetNbItemsByName(name), null);
if (!await ChampionsManager.DeleteItem(championSelected.FirstOrDefault()))
var championSelected = await _dataManager.GetItemsByName(name, 0, await _dataManager.GetNbItemsByName(name), null);
if (!await _dataManager.DeleteItem(championSelected.FirstOrDefault()))
{
Console.WriteLine("champion { " + name + " } non trouvé !");
Console.WriteLine("champion { " + name + " } not found !");
return NotFound();
}
Console.WriteLine("champion { " + name + " } supprimé");
Console.WriteLine("champion { " + name + " } deleted");
return Ok();
}

@ -24,27 +24,68 @@ public class RuneController : ControllerBase
_logger = logger;
}
[HttpGet(Name = "GetRune")]
public ActionResult<IEnumerable<RuneDTO>> Get()
[HttpGet]
public async Task<IActionResult> Get()
{
return Ok(Enumerable.Range(1,5).Select(index => new RuneDTO
{
Name = "La rune",
Description = "test description"
})
.ToArray());
var list = await RunesManager.GetItems(0, await RunesManager.GetNbItems());
return Ok(list.Select(rune => rune?.toDTO()));
}
[HttpGet("name")]
public async Task<IActionResult> GetById(string name)
{
var runeSelected = await RunesManager.GetItemsByName(name, 0, await RunesManager.GetNbItemsByName(name), null);
return Ok(runeSelected.Select(rune => rune?.toDTO()));
}
[HttpPost]
[HttpPost("addRune")]
public async Task<IActionResult> AddRune(RuneDTO rune)
{
var newRune = rune.toModel();
await RunesManager.AddItem(newRune);
if (rune.Description == "string")
{
rune.Description = "No bio";
}
Console.WriteLine("Rune { " + rune.Name + " } with description { " + rune.Description + " } has been succesfully modified");
return Ok(newRune);
}
[HttpPut("updateRune")]
public async Task<IActionResult> UpdateRune(string name, RuneDTO rune)
{
var runeSelected = await RunesManager.GetItemsByName(name, 0, await RunesManager.GetNbItemsByName(name), null);
var existingRune = runeSelected.FirstOrDefault();
if (existingRune == null)
{
Console.WriteLine("La rune { " + name + " } doesn't exist !");
return NotFound();
}
var updatedRune = rune.toModel();
await RunesManager.UpdateItem(existingRune, updatedRune);
if (rune.Description == "string")
{
rune.Description = "No bio";
}
Console.WriteLine("Rune { " + name + " } has been succesfully modified { " + updatedRune.Name + " } with description { " + rune.Description + " }");
return Ok();
}
[HttpDelete("deleteRune")]
public async Task<IActionResult> DeleteRune(string name)
{
var runeSelected = await RunesManager.GetItemsByName(name, 0, await RunesManager.GetNbItemsByName(name), null);
if (!await RunesManager.DeleteItem(runeSelected.FirstOrDefault()))
{
Console.WriteLine("rune { " + name + " } not found !");
return NotFound();
}
Console.WriteLine("rune { " + name + " } deleted");
return Ok();
}
}

@ -23,27 +23,67 @@ namespace WebApiLol.Controllers
_logger = logger;
}
[HttpGet(Name = "GetSkin")]
public ActionResult<IEnumerable<SkinDTO>> Get()
[HttpGet]
public async Task<IActionResult> Get()
{
return Ok(Enumerable.Range(1, 5).Select(index => new SkinDTO
{
Name = "Skin tah les fou",
Description ="Skin assez limité et sorti le 23/02/2022",
Icon = "je sais pas ce que c'est un icon",
Price = 25.0f
})
.ToArray());
var list = await SkinsManager.GetItems(0, await SkinsManager.GetNbItems());
return Ok(list.Select(skin => skin?.toDTO()));
}
[HttpGet("name")]
public async Task<IActionResult> GetById(string name)
{
var skinSelected = await SkinsManager.GetItemsByName(name, 0, await SkinsManager.GetNbItemsByName(name), null);
return Ok(skinSelected.Select(skin => skin?.toDTO()));
}
[HttpPost]
[HttpPost("addSkin")]
public async Task<IActionResult> AddSkin(SkinDTO skin)
{
var newSkin = skin.toModel();
await SkinsManager.AddItem(newSkin);
if (skin.Description == "string")
{
skin.Description = "Aucune bio";
}
Console.WriteLine("Skin { " + skin.Name + " } with description { " + skin.Description + " } has been succesfully added");
return Ok(newSkin);
}
[HttpPut("updateSkin")]
public async Task<IActionResult> UpdateChampion(string name, SkinDTO skin)
{
var skinSelected = await SkinsManager.GetItemsByName(name, 0, await SkinsManager.GetNbItemsByName(name), null);
var existingSkin = skinSelected.FirstOrDefault();
if (existingSkin == null)
{
Console.WriteLine("Le skin { " + name + " } doesn't exist !");
return NotFound();
}
var updatedSkin = skin.toModel();
await SkinsManager.UpdateItem(existingSkin, updatedSkin);
if (skin.Description == "string")
{
skin.Description = "Aucune bio";
}
Console.WriteLine("Skin { " + name + " } modified in " + " { " + updatedSkin.Name + " } with description { " + updatedSkin.Description + " }<");
return Ok();
}
[HttpDelete("deleteSkin")]
public async Task<IActionResult> DeleteChampion(string name)
{
var skinSelected = await SkinsManager.GetItemsByName(name, 0, await SkinsManager.GetNbItemsByName(name), null);
if (!await SkinsManager.DeleteItem(skinSelected.FirstOrDefault()))
{
Console.WriteLine("skin { " + name + " } not found !");
return NotFound();
}
Console.WriteLine("skin { " + name + " } deleted");
return Ok();
}
}
}

@ -8,6 +8,8 @@ namespace WebApiLol.Converter
{
Name = champion.Name,
Bio = champion.Bio,
Icon = champion.Icon,
Class = champion.Class.ToString()
};
public static Champion toModel(this ChampionDTO champion) => new Champion(champion.Name, champion.Bio);

@ -9,6 +9,8 @@ namespace WebApiLol.Converter
{
Name = skin.Name,
Description = skin.Description,
Icon = skin.Icon,
Price = skin.Price
};
public static Skin toModel(this SkinDTO skin) => new Skin(skin.Name, skin.Description);

@ -1,5 +1,8 @@
var builder = WebApplication.CreateBuilder(args);
using DbDatamanager;
using Model;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddScoped<IDataManager, DbDataManager>();
// Add services to the container.
builder.Services.AddControllers();
@ -7,6 +10,7 @@ builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
// Configure the HTTP request pipeline.

@ -7,6 +7,6 @@ namespace WebApiLol
public string Description { get; set; }
public string Icon { get; set; }
public float Price { get; set; }
}
}
}

@ -28,5 +28,11 @@
<ProjectReference Include="..\StubLib\StubLib.csproj">
<GlobalPropertiesToRemove></GlobalPropertiesToRemove>
</ProjectReference>
<ProjectReference Include="..\EntityFrameWorkLib\EntityFrameWorkLib.csproj">
<GlobalPropertiesToRemove></GlobalPropertiesToRemove>
</ProjectReference>
<ProjectReference Include="..\DbDatamanager\DbDatamanager.csproj">
<GlobalPropertiesToRemove></GlobalPropertiesToRemove>
</ProjectReference>
</ItemGroup>
</Project>

Loading…
Cancel
Save