diff --git a/Sources/API_LoL/Controllers/ChampionsController.cs b/Sources/API_LoL/Controllers/ChampionsController.cs index 9461ad4..1d4efad 100644 --- a/Sources/API_LoL/Controllers/ChampionsController.cs +++ b/Sources/API_LoL/Controllers/ChampionsController.cs @@ -12,14 +12,19 @@ namespace API_LoL.Controllers [ApiController] public class ChampionsController : ControllerBase { - private StubData.ChampionsManager ChampionsManager { get; set; } = new StubData.ChampionsManager(new StubData()); + + public ChampionsController(IDataManager Manager) { + this.ChampionsManager= Manager.ChampionsMgr; + } + + private IChampionsManager ChampionsManager; // GET: api/ [HttpGet] public async Task Get() { var list = await ChampionsManager.GetItems(0,await ChampionsManager.GetNbItems()); - if (list.Count() == 0) { + if (list.Count() != 0) { return Ok(list.Select(champion => champion?.toDTO())); }else { return NoContent(); @@ -27,11 +32,12 @@ namespace API_LoL.Controllers } // GET api//5 + /* [HttpGet("{id}")] public string Get(String name) { return "value"; - } + }*/ // POST api/ [HttpPost] @@ -43,8 +49,8 @@ namespace API_LoL.Controllers } else { - //ChampionsManager.AddItem(champion) - return CreatedAtAction("Post",champion.Name); + await ChampionsManager.AddItem(champion.toChampion()); + return CreatedAtAction("Post",champion); } } diff --git a/Sources/API_LoL/Mapper/ChampionMapper.cs b/Sources/API_LoL/Mapper/ChampionMapper.cs index f091999..b380b7e 100644 --- a/Sources/API_LoL/Mapper/ChampionMapper.cs +++ b/Sources/API_LoL/Mapper/ChampionMapper.cs @@ -11,11 +11,13 @@ namespace DTO.Mapper { public static ChampionDTO toDTO(this Champion champion) { - return new ChampionDTO() - { - Name = champion.Name, - Bio = champion.Bio, - }; + return new ChampionDTO(champion.Name, champion.Bio, champion.Icon); + } + + public static Champion toChampion(this ChampionDTO champion) + { + return new Champion(champion.Name, ChampionClass.Unknown, champion.Icon, "", champion.Bio); + } } } diff --git a/Sources/API_LoL/Program.cs b/Sources/API_LoL/Program.cs index 48863a6..d4fb3b8 100644 --- a/Sources/API_LoL/Program.cs +++ b/Sources/API_LoL/Program.cs @@ -1,3 +1,6 @@ +using Model; +using StubLib; + var builder = WebApplication.CreateBuilder(args); // Add services to the container. @@ -7,6 +10,8 @@ builder.Services.AddControllers(); builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); +builder.Services.AddScoped(); + var app = builder.Build(); // Configure the HTTP request pipeline. diff --git a/Sources/ApiTests/ApiTests.csproj b/Sources/ApiTests/ApiTests.csproj deleted file mode 100644 index 74abf5c..0000000 --- a/Sources/ApiTests/ApiTests.csproj +++ /dev/null @@ -1,10 +0,0 @@ - - - - Exe - net6.0 - enable - enable - - - diff --git a/Sources/ApiTests/Program.cs b/Sources/ApiTests/Program.cs deleted file mode 100644 index a5af879..0000000 --- a/Sources/ApiTests/Program.cs +++ /dev/null @@ -1 +0,0 @@ -// See https://aka.ms/new-console-template for more information diff --git a/Sources/Api_UT/Api_UT.csproj b/Sources/Api_UT/Api_UT.csproj new file mode 100644 index 0000000..089bff3 --- /dev/null +++ b/Sources/Api_UT/Api_UT.csproj @@ -0,0 +1,25 @@ + + + + net6.0 + enable + enable + + false + + + + + + + + + + + + + + + + + diff --git a/Sources/Api_UT/UnitTest1.cs b/Sources/Api_UT/UnitTest1.cs new file mode 100644 index 0000000..13a5577 --- /dev/null +++ b/Sources/Api_UT/UnitTest1.cs @@ -0,0 +1,33 @@ +using API_LoL.Controllers; +using DTO; +using Microsoft.AspNetCore.Mvc; +using Model; +using StubLib; + +namespace Api_UT +{ + [TestClass] + public class UnitTest1 + { + [TestMethod] + public async Task TestGet() + { + List list = new List {new ChampionDTO("Akali","",""), new ChampionDTO("Aatrox", "", ""), new ChampionDTO("Ahri", "", ""), new ChampionDTO("Akshan", "", ""), new ChampionDTO("Bard", "", ""), new ChampionDTO("Alistar", "", "") }; + ChampionsController api = new ChampionsController(new StubData()); + IActionResult a = await api.Get(); + Assert.IsNotNull(a); + Assert.AreEqual(list,((OkObjectResult)a).Value); + } + + [TestMethod] + public async Task TestPostValid() + { + ChampionsController api = new ChampionsController(new StubData()); + IActionResult a = await api.Post(new ChampionDTO("nom","bio","icon")); + Assert.IsNotNull(a); + ChampionDTO champ = new ChampionDTO("nom", "bio", "icon"); + Assert.AreEqual(champ,((CreatedAtActionResult)a).Value); + } + + } +} \ No newline at end of file diff --git a/Sources/Api_UT/Usings.cs b/Sources/Api_UT/Usings.cs new file mode 100644 index 0000000..ab67c7e --- /dev/null +++ b/Sources/Api_UT/Usings.cs @@ -0,0 +1 @@ +global using Microsoft.VisualStudio.TestTools.UnitTesting; \ No newline at end of file diff --git a/Sources/DTO/ChampionDTO.cs b/Sources/DTO/ChampionDTO.cs index 35c9515..c6bb27c 100644 --- a/Sources/DTO/ChampionDTO.cs +++ b/Sources/DTO/ChampionDTO.cs @@ -2,10 +2,19 @@ { public class ChampionDTO { + public ChampionDTO(string name, string bio, string icon) + { + Name = name; + Bio = bio; + Icon = icon; + } + public string Name { get; set; } public string Bio { get; set; } - + public string Icon { get; set; } + + } } \ No newline at end of file diff --git a/Sources/EntityFramework/ChampionEntity.cs b/Sources/EntityFramework/ChampionEntity.cs new file mode 100644 index 0000000..0520665 --- /dev/null +++ b/Sources/EntityFramework/ChampionEntity.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EntityFramework +{ + [Table("Champion")] + class ChampionEntity + { + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public int Id { get; set; } + public string name { get; set; } + + + public ChampionEntity(string name) { + this.name = name; + } + } +} diff --git a/Sources/EntityFramework/EntityFramework.csproj b/Sources/EntityFramework/EntityFramework.csproj new file mode 100644 index 0000000..66899d0 --- /dev/null +++ b/Sources/EntityFramework/EntityFramework.csproj @@ -0,0 +1,20 @@ + + + + Exe + net6.0 + enable + enable + $(MSBuildProjectDirectory) + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + diff --git a/Sources/EntityFramework/LoLDbContext.cs b/Sources/EntityFramework/LoLDbContext.cs new file mode 100644 index 0000000..bc537f9 --- /dev/null +++ b/Sources/EntityFramework/LoLDbContext.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; + +namespace EntityFramework +{ + class LoLDbContext : DbContext + { + public DbSet Champions { get; set; } + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + base.OnConfiguring(optionsBuilder); + optionsBuilder.UseSqlite("Data Source=champion.db"); + } + } +} diff --git a/Sources/EntityFramework/Program.cs b/Sources/EntityFramework/Program.cs new file mode 100644 index 0000000..29ee9d8 --- /dev/null +++ b/Sources/EntityFramework/Program.cs @@ -0,0 +1,10 @@ +// See https://aka.ms/new-console-template for more information +using EntityFramework; + +Console.WriteLine("Hello, World!"); + +using( var context = new LoLDbContext()) +{ + context.Add(new ChampionEntity("test") ); + context.SaveChanges(); +} \ No newline at end of file diff --git a/Sources/EntityFramework/champion.db b/Sources/EntityFramework/champion.db new file mode 100644 index 0000000..df42e8e Binary files /dev/null and b/Sources/EntityFramework/champion.db differ diff --git a/Sources/LeagueOfLegends.sln b/Sources/LeagueOfLegends.sln index 5339e1f..07ae039 100644 --- a/Sources/LeagueOfLegends.sln +++ b/Sources/LeagueOfLegends.sln @@ -17,9 +17,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StubLib", "StubLib\StubLib. EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "API_LoL", "API_LoL\API_LoL.csproj", "{BE86E19B-3461-4EF6-8871-94E6CCB75928}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ApiTests", "ApiTests\ApiTests.csproj", "{AE65F7E0-FA95-4D64-938D-78DB6C905F7B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DTO", "DTO\DTO.csproj", "{E39C3FBC-DE5E-4DAF-945A-98CE4ADE54D9}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DTO", "DTO\DTO.csproj", "{E39C3FBC-DE5E-4DAF-945A-98CE4ADE54D9}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EntityFramework", "EntityFramework\EntityFramework.csproj", "{23483395-5091-4956-822F-17234E8C9E5C}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Api_UT", "Api_UT\Api_UT.csproj", "{20A1A7DC-1E93-4506-BD32-8597A5DADD7B}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -47,14 +49,18 @@ Global {BE86E19B-3461-4EF6-8871-94E6CCB75928}.Debug|Any CPU.Build.0 = Debug|Any CPU {BE86E19B-3461-4EF6-8871-94E6CCB75928}.Release|Any CPU.ActiveCfg = Release|Any CPU {BE86E19B-3461-4EF6-8871-94E6CCB75928}.Release|Any CPU.Build.0 = Release|Any CPU - {AE65F7E0-FA95-4D64-938D-78DB6C905F7B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {AE65F7E0-FA95-4D64-938D-78DB6C905F7B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {AE65F7E0-FA95-4D64-938D-78DB6C905F7B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {AE65F7E0-FA95-4D64-938D-78DB6C905F7B}.Release|Any CPU.Build.0 = Release|Any CPU {E39C3FBC-DE5E-4DAF-945A-98CE4ADE54D9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {E39C3FBC-DE5E-4DAF-945A-98CE4ADE54D9}.Debug|Any CPU.Build.0 = Debug|Any CPU {E39C3FBC-DE5E-4DAF-945A-98CE4ADE54D9}.Release|Any CPU.ActiveCfg = Release|Any CPU {E39C3FBC-DE5E-4DAF-945A-98CE4ADE54D9}.Release|Any CPU.Build.0 = Release|Any CPU + {23483395-5091-4956-822F-17234E8C9E5C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {23483395-5091-4956-822F-17234E8C9E5C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {23483395-5091-4956-822F-17234E8C9E5C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {23483395-5091-4956-822F-17234E8C9E5C}.Release|Any CPU.Build.0 = Release|Any CPU + {20A1A7DC-1E93-4506-BD32-8597A5DADD7B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {20A1A7DC-1E93-4506-BD32-8597A5DADD7B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {20A1A7DC-1E93-4506-BD32-8597A5DADD7B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {20A1A7DC-1E93-4506-BD32-8597A5DADD7B}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -62,7 +68,7 @@ Global GlobalSection(NestedProjects) = preSolution {1889FA6E-B7C6-416E-8628-9449FB9070B9} = {C76D0C23-1FFA-4963-93CD-E12BD643F030} {B01D7EF2-2D64-409A-A29A-61FB7BB7A9DB} = {2C607793-B163-4731-A4D1-AFE8A7C4C170} - {AE65F7E0-FA95-4D64-938D-78DB6C905F7B} = {C76D0C23-1FFA-4963-93CD-E12BD643F030} + {20A1A7DC-1E93-4506-BD32-8597A5DADD7B} = {C76D0C23-1FFA-4963-93CD-E12BD643F030} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {92F3083D-793F-4552-8A9A-0AD6534159C9} diff --git a/Sources/Model/Properties/launchSettings.json b/Sources/Model/Properties/launchSettings.json new file mode 100644 index 0000000..ed8cba2 --- /dev/null +++ b/Sources/Model/Properties/launchSettings.json @@ -0,0 +1,12 @@ +{ + "profiles": { + "Model": { + "commandName": "Project", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "https://localhost:49972;http://localhost:49973" + } + } +} \ No newline at end of file diff --git a/Sources/Tests/ConsoleTests/ConsoleTests.csproj b/Sources/Tests/ConsoleTests/ConsoleTests.csproj index 1602b94..d401cce 100644 --- a/Sources/Tests/ConsoleTests/ConsoleTests.csproj +++ b/Sources/Tests/ConsoleTests/ConsoleTests.csproj @@ -1,4 +1,4 @@ - + Exe @@ -8,6 +8,7 @@ + diff --git a/Sources/Tests/ConsoleTests/Properties/launchSettings.json b/Sources/Tests/ConsoleTests/Properties/launchSettings.json new file mode 100644 index 0000000..c8ab57c --- /dev/null +++ b/Sources/Tests/ConsoleTests/Properties/launchSettings.json @@ -0,0 +1,12 @@ +{ + "profiles": { + "ConsoleTests": { + "commandName": "Project", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "https://localhost:49970;http://localhost:49971" + } + } +} \ No newline at end of file diff --git a/Sources/Tests/Tests.csproj b/Sources/Tests/Tests.csproj new file mode 100644 index 0000000..01bb70b --- /dev/null +++ b/Sources/Tests/Tests.csproj @@ -0,0 +1,18 @@ + + + + net7.0 + enable + enable + + false + + + + + + + + + + diff --git a/Sources/Tests/UnitTest1.cs b/Sources/Tests/UnitTest1.cs new file mode 100644 index 0000000..872f935 --- /dev/null +++ b/Sources/Tests/UnitTest1.cs @@ -0,0 +1,10 @@ +namespace Tests; + +[TestClass] +public class UnitTest1 +{ + [TestMethod] + public void TestMethod1() + { + } +} \ No newline at end of file diff --git a/Sources/Tests/Usings.cs b/Sources/Tests/Usings.cs new file mode 100644 index 0000000..ab67c7e --- /dev/null +++ b/Sources/Tests/Usings.cs @@ -0,0 +1 @@ +global using Microsoft.VisualStudio.TestTools.UnitTesting; \ No newline at end of file