malanone/ef_core #3

Merged
maxence.lanone merged 10 commits from malanone/ef_core into master 2 years ago

@ -12,28 +12,28 @@ steps:
image: mcr.microsoft.com/dotnet/sdk:7.0
commands:
- cd Sources/
- 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
- 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
- name: tests
image: mcr.microsoft.com/dotnet/sdk:7.0
commands:
- cd Sources/
- dotnet restore LeagueOfLegends.sln
- dotnet test LeagueOfLegends.sln --no-restore
- dotnet restore LeagueOfLegends_CI.sln
- dotnet test LeagueOfLegends_CI.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.sln
- dotnet restore LeagueOfLegends_CI.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.sln -c Release --no-restore
- dotnet test LeagueOfLegends.sln --logger trx --no-restore /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura --collect "XPlat Code Coverage"
- 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"
- reportgenerator -reports:"**/coverage.cobertura.xml" -reporttypes:SonarQube -targetdir:"coveragereport"
- dotnet publish LeagueOfLegends.sln -c Release --no-restore -o $CI_PROJECT_DIR/build/release
- dotnet publish LeagueOfLegends_CI.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:

@ -1,6 +1,7 @@
using System;
using EntityFrameWorkLib;
using Model;
using Shared;
namespace DbDatamanager
{

@ -1,6 +1,8 @@
using System;
using System.Collections.ObjectModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Shared;
namespace EntityFrameWorkLib
{
@ -10,10 +12,24 @@ namespace EntityFrameWorkLib
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int UniqueId { get; set; }
public string Name { get; set; }
public string Name { get; set; }
//[Required]
[MaxLength(256)]
public string Bio { get; set; }
public string Icon { get; set; }
public ChampionClassEntity championClass { 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; }
}
}

@ -12,21 +12,20 @@
<None Remove="Microsoft.EntityFrameworkCore.Sqlite" />
<None Remove="Microsoft.EntityFrameworkCore.Tools" />
<None Remove="Microsoft.EntityFrameworkCore.Design" />
<None Remove="enums\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.3">
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.4">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.3">
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.4">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Folder Include="enums\" />
<ProjectReference Include="..\Shared\Shared.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,21 @@
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,32 +6,52 @@ namespace EntityFrameWorkLib
{
public class LolContext : DbContext
{
public DbSet<ChampionEntity> Champions { 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 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)
{
base.OnConfiguring(options.UseSqlite($"DataSource=projet.Champions.db"));
}
}
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();
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);
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<SkinEntity>()
.Property(s => s.Name)
.ValueGeneratedOnAdd();
modelBuilder.Entity<RunePageEntity>()
.Property(s => s.Id)
.ValueGeneratedOnAdd();
modelBuilder.Entity<RuneEntity>()
.Property(s => s.Name)
.ValueGeneratedOnAdd();
}
}
}
}

@ -1,50 +0,0 @@
// <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
}
}
}

@ -1,37 +0,0 @@
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");
}
}
}

@ -0,0 +1,225 @@
// <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
}
}
}

@ -0,0 +1,175 @@
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,4 +1,5 @@
// <auto-generated />
using System;
using EntityFrameWorkLib;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
@ -14,7 +15,7 @@ namespace EntityFrameWorkLib.Migrations
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "7.0.3");
modelBuilder.HasAnnotation("ProductVersion", "7.0.4");
modelBuilder.Entity("EntityFrameWorkLib.ChampionEntity", b =>
{
@ -24,8 +25,12 @@ 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");
@ -34,13 +39,183 @@ namespace EntityFrameWorkLib.Migrations
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("championClass")
.HasColumnType("INTEGER");
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
}
}

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

@ -0,0 +1,20 @@
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
}
}

@ -0,0 +1,23 @@
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; }
}
}

@ -1,12 +0,0 @@
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; }
}
}

@ -0,0 +1,22 @@
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; }
}
}

@ -0,0 +1,98 @@

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

@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:model="clr-namespace:Model;assembly=Model"
xmlns:shared="clr-namespace:Shared;assembly=Shared"
x:Class="LolApp.ContentViews.ChampionClassSelector"
x:Name="root">
<ContentView.Resources>
<model:ChampionClass x:Key="assassin">Assassin</model:ChampionClass>
<model:ChampionClass x:Key="fighter">Fighter</model:ChampionClass>
<model:ChampionClass x:Key="mage">Mage</model:ChampionClass>
<model:ChampionClass x:Key="marksman">Marksman</model:ChampionClass>
<model:ChampionClass x:Key="support">Support</model:ChampionClass>
<model:ChampionClass x:Key="tank">Tank</model:ChampionClass>
<shared:ChampionClass x:Key="assassin">Assassin</shared:ChampionClass>
<shared:ChampionClass x:Key="fighter">Fighter</shared:ChampionClass>
<shared:ChampionClass x:Key="mage">Mage</shared:ChampionClass>
<shared:ChampionClass x:Key="marksman">Marksman</shared:ChampionClass>
<shared:ChampionClass x:Key="support">Support</shared:ChampionClass>
<shared:ChampionClass x:Key="tank">Tank</shared:ChampionClass>
<ControlTemplate x:Key="RadioButtonTemplate">
<Border Stroke="{StaticResource Transparent}"

@ -1,4 +1,5 @@
using Model;
using Shared;
namespace LolApp.ContentViews;

@ -1,6 +1,7 @@
using System;
using System.Globalization;
using Model;
using Shared;
namespace LolApp.Resources.Converters
{

@ -3,8 +3,8 @@ using System.Linq;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Model;
using Shared;
using ViewModels;
namespace LolApp.ViewModels
{
public partial class AddSkillVM : ObservableObject

@ -2,6 +2,7 @@
using System.Linq;
using CommunityToolkit.Mvvm.ComponentModel;
using Model;
using Shared;
namespace LolApp.ViewModels
{

@ -3,8 +3,10 @@ using System.Reflection;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Model;
using Shared;
using ViewModels;
namespace LolApp.ViewModels
{
[ObservableObject]

@ -2,6 +2,7 @@
using System.Collections.ObjectModel;
using System.Numerics;
using System.Text;
using Shared;
namespace Model;
public class Champion : IEquatable<Champion>

@ -6,12 +6,6 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<None Remove="enums\" />
</ItemGroup>
<ItemGroup>
<Folder Include="enums\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Shared\Shared.csproj" />
</ItemGroup>

@ -1,4 +1,5 @@
using System;
using Shared;
namespace Model
{

@ -1,5 +1,5 @@
using System;
using Shared;
namespace Model
{
public class Skill : IEquatable<Skill>

@ -6,4 +6,10 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<None Remove="enums\" />
</ItemGroup>
<ItemGroup>
<Folder Include="enums\" />
</ItemGroup>
</Project>

@ -1,5 +1,5 @@
using System;
namespace Model
namespace Shared
{
public enum ChampionClass
{

@ -1,5 +1,5 @@
using System;
namespace Model
namespace Shared
{
public enum RuneFamily
{

@ -1,5 +1,5 @@
using System;
namespace Model
namespace Shared
{
public enum SkillType
{

@ -1,5 +1,6 @@
using System;
using Model;
using Shared;
namespace StubLib
{

@ -1,5 +1,6 @@
using System;
using Model;
using Shared;
namespace StubLib
{

@ -14,9 +14,9 @@
<None Remove="Microsoft.EntityFrameworkCore.Tools" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.3">
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.4">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>

File diff suppressed because one or more lines are too long

@ -4,6 +4,7 @@ using Microsoft.Extensions.DependencyInjection;
using Model;
using StubLib;
using static System.Console;
using Shared;
namespace ConsoleTests
{

@ -0,0 +1,40 @@
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
}
}
}

@ -0,0 +1,178 @@
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);
}
}
}
}

@ -19,7 +19,11 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.3" />
<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>
@ -28,5 +32,7 @@
<ItemGroup>
<ProjectReference Include="..\..\EntityFrameWorkLib\EntityFrameWorkLib.csproj" />
<ProjectReference Include="..\..\DbDatamanager\DbDatamanager.csproj" />
<ProjectReference Include="..\..\StubLib\StubLib.csproj" />
<ProjectReference Include="..\..\WebApiLol\WebApiLol.csproj" />
</ItemGroup>
</Project>

@ -1,11 +1,30 @@
using System;
using EntityFrameWorkLib;
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
namespace TestUnitaireLOL
{
public class UnitTestDbDataManager
{
public 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())
{
}
}
}
}

@ -3,6 +3,7 @@ using CommunityToolkit.Mvvm.ComponentModel;
using Model;
using Microsoft.Maui.Controls;
using System.Collections.ObjectModel;
using Shared;
namespace ViewModels

@ -6,6 +6,7 @@ using System.Collections.ObjectModel;
using CommunityToolkit.Mvvm.Input;
using System.Data.SqlTypes;
using System.Reflection;
using Shared;
namespace ViewModels;

@ -3,6 +3,7 @@ using System.Collections.ObjectModel;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Model;
using Shared;
namespace ViewModels
{

@ -1,6 +1,7 @@
using System;
using CommunityToolkit.Mvvm.ComponentModel;
using Model;
using Shared;
namespace ViewModels
{

@ -3,7 +3,6 @@ namespace WebApiLol
{
public class ChampionDTO
{
public int UniqueId { get; set; }
public string Name { get; set; }

@ -0,0 +1,15 @@
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,8 +1,11 @@
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;
using WebApiLol.Converter;
@ -14,18 +17,35 @@ public class ChampionController : ControllerBase
{
private StubData.ChampionsManager ChampionsManager { get; set; } = new StubData.ChampionsManager(new StubData());
private IChampionsManager _dataManager;
private readonly ILogger<ChampionController> _logger;
public ChampionController(ILogger<ChampionController> logger)
public ChampionController(IDataManager manager,ILogger<ChampionController> logger)
{
_dataManager = manager.ChampionsMgr;
_logger = logger;
}
[HttpGet]
public async Task<IActionResult> Get()
[ProducesResponseType(typeof(ChampionPageDTO), 200)]
public async Task<IActionResult> Get([FromQuery] int index = 0, int count = 10, string? name = "")
{
var list = await ChampionsManager.GetItems(0, await ChampionsManager.GetNbItems());
return Ok(list.Select(champion => champion?.toDTO()));
_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);
}
[HttpGet("name")]

@ -11,7 +11,7 @@
<PropertyGroup Condition=" '$(RunConfiguration)' == 'https' " />
<PropertyGroup Condition=" '$(RunConfiguration)' == 'http' " />
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.3" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.4" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>

Loading…
Cancel
Save