From 7740ae0020768eb2d109e601218d993d8ac4cf86 Mon Sep 17 00:00:00 2001 From: baollier1 Date: Sat, 4 Feb 2023 11:11:12 +0100 Subject: [PATCH] mise en place des tests in memory --- Sources/EFLol/ChampionContext.cs | 49 ++++++---- Sources/EFLol/EFLol.csproj | 5 + ... => 20230204100025_migration1.Designer.cs} | 86 +++++++++--------- ...rstMig.cs => 20230204100025_migration1.cs} | 70 +++++++------- .../ChampionContextModelSnapshot.cs | 80 ++++++++-------- Sources/EFLol/Program.cs | 25 ++++- Sources/EFLol/loldb.db | Bin 20480 -> 20480 bytes Sources/Model/Model.csproj | 8 ++ Sources/Model/loldb.db | Bin 0 -> 20480 bytes Sources/Shared/Shared.csproj | 9 ++ Sources/StubLib/StubLib.csproj | 9 ++ .../TestUnitaireAPiLol.csproj | 6 ++ .../Tests/ConsoleTests/ConsoleTests.csproj | 6 ++ Sources/apiLOL/apiLOL.csproj | 6 ++ 14 files changed, 221 insertions(+), 138 deletions(-) rename Sources/EFLol/Migrations/{20230201162158_FirstMig.Designer.cs => 20230204100025_migration1.Designer.cs} (91%) rename Sources/EFLol/Migrations/{20230201162158_FirstMig.cs => 20230204100025_migration1.cs} (92%) create mode 100644 Sources/Model/loldb.db diff --git a/Sources/EFLol/ChampionContext.cs b/Sources/EFLol/ChampionContext.cs index d1333c0..c4eaf71 100644 --- a/Sources/EFLol/ChampionContext.cs +++ b/Sources/EFLol/ChampionContext.cs @@ -1,19 +1,30 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Microsoft.EntityFrameworkCore; - -namespace EFLol -{ - internal class ChampionContext : DbContext - { - public DbSet Champions { get; set; } - - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) - { - optionsBuilder.UseSqlite("Data Source=loldb.db"); - } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; + +namespace EFLol +{ + internal class ChampionContext : DbContext + { + public DbSet Champions { get; set; } + + public ChampionContext() + { } + + public ChampionContext(DbContextOptions options) + : base(options) + { } + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + if (!optionsBuilder.IsConfigured) + { + //optionsBuilder.UseSqlServer("Data Source=loldb.db"); + optionsBuilder.UseSqlite("Data Source=loldb.db"); + } + } + } +} diff --git a/Sources/EFLol/EFLol.csproj b/Sources/EFLol/EFLol.csproj index c55d3a4..740e3bf 100644 --- a/Sources/EFLol/EFLol.csproj +++ b/Sources/EFLol/EFLol.csproj @@ -16,6 +16,11 @@ + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/Sources/EFLol/Migrations/20230201162158_FirstMig.Designer.cs b/Sources/EFLol/Migrations/20230204100025_migration1.Designer.cs similarity index 91% rename from Sources/EFLol/Migrations/20230201162158_FirstMig.Designer.cs rename to Sources/EFLol/Migrations/20230204100025_migration1.Designer.cs index 29614aa..9f54093 100644 --- a/Sources/EFLol/Migrations/20230201162158_FirstMig.Designer.cs +++ b/Sources/EFLol/Migrations/20230204100025_migration1.Designer.cs @@ -1,43 +1,43 @@ -// -using EFLol; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace EFLol.Migrations -{ - [DbContext(typeof(ChampionContext))] - [Migration("20230201162158_FirstMig")] - partial class FirstMig - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); - - modelBuilder.Entity("EFLol.ChampionEntity", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); - - b.Property("Bio") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("Name") - .IsRequired() - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.ToTable("Champions"); - }); -#pragma warning restore 612, 618 - } - } -} +// +using EFLol; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace EFLol.Migrations +{ + [DbContext(typeof(ChampionContext))] + [Migration("20230204100025_migration1")] + partial class migration1 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); + + modelBuilder.Entity("EFLol.ChampionEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Bio") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Champions"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Sources/EFLol/Migrations/20230201162158_FirstMig.cs b/Sources/EFLol/Migrations/20230204100025_migration1.cs similarity index 92% rename from Sources/EFLol/Migrations/20230201162158_FirstMig.cs rename to Sources/EFLol/Migrations/20230204100025_migration1.cs index 59c3ac5..34b673a 100644 --- a/Sources/EFLol/Migrations/20230201162158_FirstMig.cs +++ b/Sources/EFLol/Migrations/20230204100025_migration1.cs @@ -1,35 +1,35 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace EFLol.Migrations -{ - /// - public partial class FirstMig : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Champions", - columns: table => new - { - Id = table.Column(type: "INTEGER", nullable: false) - .Annotation("Sqlite:Autoincrement", true), - Name = table.Column(type: "TEXT", nullable: false), - Bio = table.Column(type: "TEXT", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Champions", x => x.Id); - }); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Champions"); - } - } -} +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace EFLol.Migrations +{ + /// + public partial class migration1 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Champions", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Name = table.Column(type: "TEXT", nullable: false), + Bio = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Champions", x => x.Id); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Champions"); + } + } +} diff --git a/Sources/EFLol/Migrations/ChampionContextModelSnapshot.cs b/Sources/EFLol/Migrations/ChampionContextModelSnapshot.cs index cf6018a..d843a6a 100644 --- a/Sources/EFLol/Migrations/ChampionContextModelSnapshot.cs +++ b/Sources/EFLol/Migrations/ChampionContextModelSnapshot.cs @@ -1,40 +1,40 @@ -// -using EFLol; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace EFLol.Migrations -{ - [DbContext(typeof(ChampionContext))] - partial class ChampionContextModelSnapshot : ModelSnapshot - { - protected override void BuildModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); - - modelBuilder.Entity("EFLol.ChampionEntity", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); - - b.Property("Bio") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("Name") - .IsRequired() - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.ToTable("Champions"); - }); -#pragma warning restore 612, 618 - } - } -} +// +using EFLol; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace EFLol.Migrations +{ + [DbContext(typeof(ChampionContext))] + partial class ChampionContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); + + modelBuilder.Entity("EFLol.ChampionEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Bio") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Champions"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Sources/EFLol/Program.cs b/Sources/EFLol/Program.cs index 775f405..2422dc4 100644 --- a/Sources/EFLol/Program.cs +++ b/Sources/EFLol/Program.cs @@ -1,6 +1,6 @@ using EFLol; -ChampionEntity Zeus = new ChampionEntity +/*ChampionEntity Zeus = new ChampionEntity { Name = "Zeus", Bio = "Zeus is the king of the gods." @@ -11,4 +11,27 @@ using (var context = new ChampionContext()) Console.WriteLine("Adding Zeus to the database..."); context.Champions.Add(Zeus); context.SaveChanges(); +}*/ + +ChampionEntity chewie = new ChampionEntity { Name = "Chewbacca", Bio = "Zeus is the king of the gods." }; +ChampionEntity yoda = new ChampionEntity { Name = "Yoda", Bio = "Zeus is the king of the gods." }; +ChampionEntity ewok = new ChampionEntity { Name = "Ewok" , Bio = "Zeus is the king of the gods." }; + +using (var context = new ChampionContext()) +{ + // Crée des nounours et les insère dans la base + Console.WriteLine("Creates and inserts new Nounours"); + context.Add(chewie); + context.Add(yoda); + context.Add(ewok); + context.SaveChanges(); +} + +using (var context = new ChampionContext()) +{ + foreach (var n in context.Champions) + { + Console.WriteLine($"{n.Id} - {n.Name}"); + } + context.SaveChanges(); } \ No newline at end of file diff --git a/Sources/EFLol/loldb.db b/Sources/EFLol/loldb.db index ef35bd0418c784d5fbba46faa9a9afb18701dc67..528f860064fbffe742fc1197454b0b8b591fbcb9 100644 GIT binary patch delta 340 zcmZozz}T>WQ71UiC$l6~AuYcsH?c&)m_dMniHX5ML4kpRfeDCNffxpuCh8cAGBN1I zOY!pmU|`|h%fNSue=Q$B@7~RV0-n5+_wt4?GEWxbJH*I1`6}N{MyAQ@`NLW6GVtHs zEU0jqUssWl*JBmZLt{>PgI z9d7b#%P`w>;?%(lRLsoZ#=w7te=UC-&yhWQ71UiC$l6~AuYcsH?c&)m_dMnk&(ecL4kpRfgOlhffxqZCh8cAvNPz# zOY!pmU|`|h%fP#r?-Ku7KK{*u0-n5+_wt4?vQHM`JH*I3`6}N{Mz+c8`NLW6Gw|Qv zEa-5RUt6A$*;?Glz{uFZ$iUFh%*fExBHk^tsJO&8Gu>RzK+lK^XcHs#UNHcAtUb~I diff --git a/Sources/Model/Model.csproj b/Sources/Model/Model.csproj index 89f6363..63fa530 100644 --- a/Sources/Model/Model.csproj +++ b/Sources/Model/Model.csproj @@ -12,6 +12,14 @@ + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/Sources/Model/loldb.db b/Sources/Model/loldb.db new file mode 100644 index 0000000000000000000000000000000000000000..c5e7c15e464d5028832356663025ace56b1a97b5 GIT binary patch literal 20480 zcmeI)J#X4T7zgk>UQ;B;T`EgiI9ZC6C=mjpmP%PdkdvZ-p~R^|rOI-GL#zh7v5nM@ z>G$c57^AOHafKmY;| zfB*y_0D%~Rb}FOn?C@@AUEJ8g?G4?@nSp&fwB5^SH(l#!RYMa-^{}Cd$lNX08rZvZ zAYcxcy zrJov|Dvb-ZePYfX*6!4s)lOHOXkAe~Gg@_>&d}6!V|Nlyr?siV(9S8;B;0h@q2opN zNV)C1^K@3JRHiAIrgqeH`o0y8@_6M0q33^EI+$2YZRwo9Y0hGf@?BV6G})LybBRy$ zY5QJpcp1L2{eTu52}`NfGa2Pwg)_(P*&ip@&>Du`xNj~!k6BteoTN|G=>DEbRJr_v z(S`y62tWV=5P$##AOHafKmY;|fWT@B zv33YR00Izz00bZa0SG_<0uX?};}O_Qq}a3LxArg?RpA68ytc)A$L$O6YTWL7y`Zqk v|7qHv-~T@_`Qh;hArlBd00Izz00bZa0SG_<0uX?}e=i{MWS-Cdeenable + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + diff --git a/Sources/StubLib/StubLib.csproj b/Sources/StubLib/StubLib.csproj index 1b714b9..a51603e 100644 --- a/Sources/StubLib/StubLib.csproj +++ b/Sources/StubLib/StubLib.csproj @@ -6,6 +6,15 @@ enable + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + diff --git a/Sources/TestUnitaireAPiLol/TestUnitaireAPiLol.csproj b/Sources/TestUnitaireAPiLol/TestUnitaireAPiLol.csproj index ed41633..393919a 100644 --- a/Sources/TestUnitaireAPiLol/TestUnitaireAPiLol.csproj +++ b/Sources/TestUnitaireAPiLol/TestUnitaireAPiLol.csproj @@ -9,6 +9,12 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/Sources/Tests/ConsoleTests/ConsoleTests.csproj b/Sources/Tests/ConsoleTests/ConsoleTests.csproj index c52655b..69373bc 100644 --- a/Sources/Tests/ConsoleTests/ConsoleTests.csproj +++ b/Sources/Tests/ConsoleTests/ConsoleTests.csproj @@ -15,6 +15,12 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/Sources/apiLOL/apiLOL.csproj b/Sources/apiLOL/apiLOL.csproj index 33350f8..f112330 100644 --- a/Sources/apiLOL/apiLOL.csproj +++ b/Sources/apiLOL/apiLOL.csproj @@ -7,6 +7,12 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive +