diff --git a/Sources/EFLol/ChampionContext.cs b/Sources/EFLol/ChampionContext.cs index d1333c0..813108d 100644 --- a/Sources/EFLol/ChampionContext.cs +++ b/Sources/EFLol/ChampionContext.cs @@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore; namespace EFLol { - internal class ChampionContext : DbContext + public class ChampionContext : DbContext { public DbSet Champions { get; set; } diff --git a/Sources/EFLol/ChampionEntity.cs b/Sources/EFLol/ChampionEntity.cs index e9fe819..8c8ac7f 100644 --- a/Sources/EFLol/ChampionEntity.cs +++ b/Sources/EFLol/ChampionEntity.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace EFLol { - internal class ChampionEntity + public class ChampionEntity { public int Id { get; set; } public string Name { get; set; } diff --git a/Sources/EFLol/Migrations/20230201162158_FirstMig.Designer.cs b/Sources/EFLol/Migrations/20230204101816_migration1.Designer.cs similarity index 94% rename from Sources/EFLol/Migrations/20230201162158_FirstMig.Designer.cs rename to Sources/EFLol/Migrations/20230204101816_migration1.Designer.cs index 29614aa..6210419 100644 --- a/Sources/EFLol/Migrations/20230201162158_FirstMig.Designer.cs +++ b/Sources/EFLol/Migrations/20230204101816_migration1.Designer.cs @@ -10,8 +10,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace EFLol.Migrations { [DbContext(typeof(ChampionContext))] - [Migration("20230201162158_FirstMig")] - partial class FirstMig + [Migration("20230204101816_migration1")] + partial class migration1 { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) diff --git a/Sources/EFLol/Migrations/20230201162158_FirstMig.cs b/Sources/EFLol/Migrations/20230204101816_migration1.cs similarity index 95% rename from Sources/EFLol/Migrations/20230201162158_FirstMig.cs rename to Sources/EFLol/Migrations/20230204101816_migration1.cs index 59c3ac5..c50961f 100644 --- a/Sources/EFLol/Migrations/20230201162158_FirstMig.cs +++ b/Sources/EFLol/Migrations/20230204101816_migration1.cs @@ -5,7 +5,7 @@ namespace EFLol.Migrations { /// - public partial class FirstMig : Migration + public partial class migration1 : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) diff --git a/Sources/EFLol/Program.cs b/Sources/EFLol/Program.cs index 775f405..38f62aa 100644 --- a/Sources/EFLol/Program.cs +++ b/Sources/EFLol/Program.cs @@ -11,4 +11,8 @@ using (var context = new ChampionContext()) Console.WriteLine("Adding Zeus to the database..."); context.Champions.Add(Zeus); context.SaveChanges(); -} \ No newline at end of file +} + + + + diff --git a/Sources/EFLol/loldb.db b/Sources/EFLol/loldb.db index ef35bd0..4764763 100644 Binary files a/Sources/EFLol/loldb.db and b/Sources/EFLol/loldb.db differ diff --git a/Sources/LeagueOfLegends.sln b/Sources/LeagueOfLegends.sln index 380b252..2d87936 100644 --- a/Sources/LeagueOfLegends.sln +++ b/Sources/LeagueOfLegends.sln @@ -28,10 +28,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "apiLOL", "apiLOL\apiLOL.csp EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFLol", "EFLol\EFLol.csproj", "{7AEE66D2-490B-4049-B9D3-C629D7F78DA7}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestUnitaireAPiLol", "TestUnitaireAPiLol\TestUnitaireAPiLol.csproj", "{AD7F3A69-AC84-42CA-BD7E-FB037DAB1581}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestUnitaire", "TestUnitaire\TestUnitaire.csproj", "{5702F240-97BD-4757-918C-6E485C57D0EC}" ProjectSection(ProjectDependencies) = postProject - {2960F9BA-49DE-494D-92E3-CE5A794BA1A9} = {2960F9BA-49DE-494D-92E3-CE5A794BA1A9} {65B824B5-FADB-4C89-8B4B-D541B62B7DCA} = {65B824B5-FADB-4C89-8B4B-D541B62B7DCA} + {7AEE66D2-490B-4049-B9D3-C629D7F78DA7} = {7AEE66D2-490B-4049-B9D3-C629D7F78DA7} {B01D7EF2-2D64-409A-A29A-61FB7BB7A9DB} = {B01D7EF2-2D64-409A-A29A-61FB7BB7A9DB} EndProjectSection EndProject @@ -65,10 +65,10 @@ Global {7AEE66D2-490B-4049-B9D3-C629D7F78DA7}.Debug|Any CPU.Build.0 = Debug|Any CPU {7AEE66D2-490B-4049-B9D3-C629D7F78DA7}.Release|Any CPU.ActiveCfg = Release|Any CPU {7AEE66D2-490B-4049-B9D3-C629D7F78DA7}.Release|Any CPU.Build.0 = Release|Any CPU - {AD7F3A69-AC84-42CA-BD7E-FB037DAB1581}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {AD7F3A69-AC84-42CA-BD7E-FB037DAB1581}.Debug|Any CPU.Build.0 = Debug|Any CPU - {AD7F3A69-AC84-42CA-BD7E-FB037DAB1581}.Release|Any CPU.ActiveCfg = Release|Any CPU - {AD7F3A69-AC84-42CA-BD7E-FB037DAB1581}.Release|Any CPU.Build.0 = Release|Any CPU + {5702F240-97BD-4757-918C-6E485C57D0EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5702F240-97BD-4757-918C-6E485C57D0EC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5702F240-97BD-4757-918C-6E485C57D0EC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5702F240-97BD-4757-918C-6E485C57D0EC}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Sources/TestUnitaire/TestAPILol.cs b/Sources/TestUnitaire/TestAPILol.cs new file mode 100644 index 0000000..43a6d08 --- /dev/null +++ b/Sources/TestUnitaire/TestAPILol.cs @@ -0,0 +1,37 @@ +using apiLOL; +using apiLOL.Controllers; +using Microsoft.AspNetCore.Mvc; +using StubLib; + +namespace TestUnitaire +{ + public class TestAPILol + { + [Fact] + public void Test1() + { + + } + + [Fact] + public void TestPostChampion() + { + // Arrange + var data = new StubData(); + var controller = new ControllerChampions(new StubData()); + var champDTO = new ChampionDTO("Charles", "Charles est un champion de League of Legends"); + + // Act + var result = controller.Post(champDTO); + data.ChampionsMgr.AddItem(champDTO.ToModel()); + var nbItem = data.ChampionsMgr.GetNbItems(); + Task nbItemTask = nbItem; + + // Assert + Assert.IsType(result); + // Verify that the champions is added to the stub + Assert.Equal(7, nbItemTask.Result); + + } + } +} \ No newline at end of file diff --git a/Sources/TestUnitaire/TestEfLol.cs b/Sources/TestUnitaire/TestEfLol.cs new file mode 100644 index 0000000..a6fec54 --- /dev/null +++ b/Sources/TestUnitaire/TestEfLol.cs @@ -0,0 +1,40 @@ + + + +using EFLol; + +namespace TestUnitaire +{ + public class TestEfLol + { + [Fact] + public void TestAddIntoDB() + { + // Arrange + ChampionEntity Zeus = new ChampionEntity + { + Name = "Zeus", + Bio = "Zeus is the king of the gods." + }; + + // Act + var context = new ChampionContext(); + context.Champions.Add(Zeus); + context.SaveChanges(); + + // Assert + var champion = context.Champions.FirstOrDefault(c => c.Name == "Zeus"); + if (champion == null) + { + Assert.True(false, "Champion not found in database."); + } + Assert.NotNull(champion); + Assert.Equal("Zeus", champion.Name); + Assert.Equal("Zeus is the king of the gods.", champion.Bio); + } + } +} + + + + diff --git a/Sources/TestUnitaire/TestUnitaire.csproj b/Sources/TestUnitaire/TestUnitaire.csproj new file mode 100644 index 0000000..e625409 --- /dev/null +++ b/Sources/TestUnitaire/TestUnitaire.csproj @@ -0,0 +1,30 @@ + + + + net6.0 + enable + enable + + false + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + + + diff --git a/Sources/TestUnitaire/Usings.cs b/Sources/TestUnitaire/Usings.cs new file mode 100644 index 0000000..8c927eb --- /dev/null +++ b/Sources/TestUnitaire/Usings.cs @@ -0,0 +1 @@ +global using Xunit; \ No newline at end of file diff --git a/Sources/TestUnitaireAPiLol/UnitTest1.cs b/Sources/TestUnitaireAPiLol/TestAPILol.cs similarity index 93% rename from Sources/TestUnitaireAPiLol/UnitTest1.cs rename to Sources/TestUnitaireAPiLol/TestAPILol.cs index ab3973d..b2a1758 100644 --- a/Sources/TestUnitaireAPiLol/UnitTest1.cs +++ b/Sources/TestUnitaireAPiLol/TestAPILol.cs @@ -3,9 +3,9 @@ using apiLOL.Controllers; using Microsoft.AspNetCore.Mvc; using StubLib; -namespace TestUnitaireAPiLol +namespace TestUnitaire { - public class UnitTest1 + public class TestAPILol { [Fact] public void Test1() diff --git a/Sources/TestUnitaireAPiLol/TestEFLol.cs b/Sources/TestUnitaireAPiLol/TestEFLol.cs new file mode 100644 index 0000000..491f46e --- /dev/null +++ b/Sources/TestUnitaireAPiLol/TestEFLol.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TestUnitaire +{ + public class TestEFLol + { + public void TestAddIntoDB() + { + // Arrange + ChampionEntity Zeus = new ChampionEntity + { + Name = "Zeus", + Bio = "Zeus is the king of the gods." + }; + + // Act + using (var context = new ChampionContext()) + { + Console.WriteLine("Adding Zeus to the database..."); + context.Champions.Add(Zeus); + context.SaveChanges(); + } + + // Assert + using (var context = new ChampionContext()) + { + var champion = context.Champions.FirstOrDefault(c => c.Name == "Zeus"); + if (champion == null) + { + Assert.True(false, "Champion not found in database."); + } + Assert.NotNull(champion); + Assert.Equal("Zeus", champion.Name); + Assert.Equal("Zeus is the king of the gods.", champion.Bio); + } + } + + public void TestDeleteFromDB() + { + // Act + + } + + } +} diff --git a/Sources/TestUnitaireAPiLol/TestUnitaireAPiLol.csproj b/Sources/TestUnitaireAPiLol/TestUnitaire.csproj similarity index 100% rename from Sources/TestUnitaireAPiLol/TestUnitaireAPiLol.csproj rename to Sources/TestUnitaireAPiLol/TestUnitaire.csproj