diff --git a/.vs/ENTity/v17/.suo b/.vs/ENTity/v17/.suo new file mode 100644 index 0000000..29c54b3 Binary files /dev/null and b/.vs/ENTity/v17/.suo differ diff --git a/.vs/VSWorkspaceState.json b/.vs/VSWorkspaceState.json index 6b61141..9c530b2 100644 --- a/.vs/VSWorkspaceState.json +++ b/.vs/VSWorkspaceState.json @@ -1,6 +1,7 @@ -{ - "ExpandedNodes": [ - "" - ], - "PreviewInSolutionExplorer": false +{ + "ExpandedNodes": [ + "" + ], + "SelectedNode": "\\LeagueOfLegends.sln", + "PreviewInSolutionExplorer": false } \ No newline at end of file diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/API_LoL_Project.csproj b/EntityFramework_LoL/Sources/API_LoL_Project/API_LoL_Project.csproj index d0782fd..20a2363 100644 --- a/EntityFramework_LoL/Sources/API_LoL_Project/API_LoL_Project.csproj +++ b/EntityFramework_LoL/Sources/API_LoL_Project/API_LoL_Project.csproj @@ -16,4 +16,8 @@ + + + + diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/ChampionsController.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/ChampionsController.cs index 98c9a35..d2f06f2 100644 --- a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/ChampionsController.cs +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/ChampionsController.cs @@ -13,35 +13,49 @@ namespace API_LoL_Project.Controllers [ApiController] public class ChampionsController : ControllerBase { - IChampionsManager dataManager = new StubData().ChampionsMgr; + public IChampionsManager dataManager; + + /* public ChampionsController(IChampionsManager dataManager) + { + this.dataManager = dataManager; + }*/ + public ChampionsController(IDataManager dataManager) + { + this.dataManager = dataManager.ChampionsMgr; + } + + // GET: api/ [HttpGet] - public async Task Get() + public async Task>> Get() { var champions = await dataManager.GetItems(0, await dataManager.GetNbItems()); - - return Ok(new { result = champions.Select(c => c.toDTO())}); + IEnumerable res = champions.Select(c => c.toDTO()); + return Ok(res); } + + // GET api//5 [HttpGet("{name}")] - public async Task Get(string name) + public async Task> Get(string name) { + var champion = await dataManager .GetItemsByName(name, 0, await dataManager.GetNbItems()); return Ok(new { result = champion.First().toDTO() }); } + // POST api/ [HttpPost] public async Task Post([FromBody] ChampionDTO value) { await dataManager.AddItem(value.toModel()); return Ok(); - } // PUT api//5 @@ -60,8 +74,22 @@ namespace API_LoL_Project.Controllers { var champion = await dataManager .GetItemsByName(name, 0, await dataManager.GetNbItems()); - await dataManager.DeleteItem(champion.First()); + if (champion != null) await dataManager.DeleteItem(champion.First()); + else + { + return NotFound(); + } return Ok(); } + + /* [HttpGet] + public async Task NbChampions() + { + var champions = await dataManager.GetItems(0, await dataManager.GetNbItems()); + IEnumerable res = champions.Select(c => c.toDTO()); + return Ok(res); + + }*/ + } } diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/RuneController.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/RuneController.cs new file mode 100644 index 0000000..91ed8a8 --- /dev/null +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/RuneController.cs @@ -0,0 +1,83 @@ +using Microsoft.AspNetCore.Mvc; +using Model; + +// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 + +namespace API_LoL_Project.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class RuneController : ControllerBase + { + IRunesManager runesManager; + // you should create a custom logger to be prety + private readonly ILogger _logger; + + + public RuneController(IDataManager dataManager,ILogger _logger) + { + this.dataManager = dataManager.RunesMgr; + } + + // GET: api/ + [HttpGet] + public IEnumerable Get() + { + try{ + var runes = await dataManager.GetItems(0, await dataManager.GetNbItems()); + IEnumerable res = runes.Select(c => c.toDTO()); + return Ok(res); + } + catch(Exeption e){ + _logger.LogInformation("About page visited at {e.message}", DateTime.UtcNow.ToLongTimeString()); + new HttpException(400, 'Cannot get runes') + } + } + + // GET api//5 + [HttpGet("{id}")] + public string Get(int id) + { + try{ + var rune = await dataManager + .GetItemsByName(name, 0, await dataManager.GetNbItems()); + RuneDto result = champion.First().toDTO(); + return Ok(result); + } + catch(Exeption e){ + + new HttpException(400, 'Cannot get rune :' + e.message); + } + + + } + + // POST api/ + [HttpPost] + public void Post([FromBody] string value) + { + try{ + await dataManager.AddItem(value.toModel()); + return Ok(); + } + catch(){ + new HttpException(400, 'Cannot create rune') + } + + + } + + // PUT api//5 + [HttpPut("{id}")] + public void Put(int id, [FromBody] string value) + { + + } + + // DELETE api//5 + [HttpDelete("{id}")] + public void Delete(int id) + { + } + } +} diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/ChampionMapper.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/ChampionMapper.cs index 6d16cac..779d951 100644 --- a/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/ChampionMapper.cs +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/ChampionMapper.cs @@ -5,8 +5,11 @@ namespace API_LoL_Project.Mapper { public static class ChampionMapper { + + public static ChampionDTO toDTO(this Champion item) { + return new ChampionDTO() { Name = item.Name, Bio = item.Bio @@ -15,8 +18,15 @@ namespace API_LoL_Project.Mapper public static Champion toModel(this ChampionDTO dto) { + if (dto == null) + { + var message = string.Format("Champion with name = {} not found", dto.Name); + throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, message)); + } return new Champion(dto.Name); } + + } } diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/RunesMappeur.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/RunesMappeur.cs new file mode 100644 index 0000000..ef3ede0 --- /dev/null +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/RunesMappeur.cs @@ -0,0 +1,29 @@ +using DTO; +using Model; + +namespace API_LoL_Project.Mapper +{ + public class RunesMappeur + { + public static RuneDTO toDTO(this Rune item) + { + + return new RuneDTO() + { + Name = item.Name, + Bio = item.Bio + }; + } + + public static Rune toModel(this RuneDTO dto) + { + /*if (dto == null) + { + *//* var message = string.Format("Champion with name = {} not found", dto.Name); + throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, message));*//* + }*/ + return new Rune(dto.Name); + } + + } +} diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Middleware/HttpExeption.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Middleware/HttpExeption.cs new file mode 100644 index 0000000..8b328ee --- /dev/null +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Middleware/HttpExeption.cs @@ -0,0 +1,21 @@ +namespace API_LoL_Project.Middleware +{ + public class HttpExeption + { + public HttpExeption() + { + public void AddHeaders(this HttpRequestMessage message, RequestHeaders headers) { + var headerParameters = headers.Parameters.Where(x => !KnownHeaders.IsContentHeader(x.Name!)); + + headerParameters.ForEach(x => AddHeader(x, message.Headers)); + + void AddHeader(Parameter parameter, HttpHeaders httpHeaders) { + var parameterStringValue = parameter.Value!.ToString(); + + httpHeaders.Remove(parameter.Name!); + httpHeaders.TryAddWithoutValidation(parameter.Name!, parameterStringValue); + } + } + } + } +} diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Middleware/Validator.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Middleware/Validator.cs new file mode 100644 index 0000000..555d9bc --- /dev/null +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Middleware/Validator.cs @@ -0,0 +1,8 @@ +namespace API_LoL_Project.Middleware +{ + public class Validator + { + + + } +} diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Program.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Program.cs index 48863a6..79eb2d3 100644 --- a/EntityFramework_LoL/Sources/API_LoL_Project/Program.cs +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Program.cs @@ -1,3 +1,6 @@ +using Model; +using StubLib; + var builder = WebApplication.CreateBuilder(args); // Add services to the container. @@ -7,8 +10,10 @@ builder.Services.AddControllers(); builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); +builder.Services.AddSingleton(); var app = builder.Build(); + // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { @@ -22,4 +27,5 @@ app.UseAuthorization(); app.MapControllers(); + app.Run(); diff --git a/EntityFramework_LoL/Sources/DTO/RuneDTO.cs b/EntityFramework_LoL/Sources/DTO/RuneDTO.cs new file mode 100644 index 0000000..17b7e3e --- /dev/null +++ b/EntityFramework_LoL/Sources/DTO/RuneDTO.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DTO +{ + internal class RuneDTO + { + public string Name { get; set; } + + public string Description { get; set; } + + public RuneFamily Family { get; set; } + + public string Icon { get; set; } + + public LargeImage Image { get; set; } + } +} diff --git a/EntityFramework_LoL/Sources/LeagueOfLegends.sln b/EntityFramework_LoL/Sources/LeagueOfLegends.sln index db008a1..0b0902f 100644 --- a/EntityFramework_LoL/Sources/LeagueOfLegends.sln +++ b/EntityFramework_LoL/Sources/LeagueOfLegends.sln @@ -1,63 +1,70 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.4.33205.214 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "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("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleTests", "Tests\ConsoleTests\ConsoleTests.csproj", "{1889FA6E-B7C6-416E-8628-9449FB9070B9}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "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("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StubLib", "StubLib\StubLib.csproj", "{B01D7EF2-2D64-409A-A29A-61FB7BB7A9DB}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "API_LoL_Project", "API_LoL_Project\API_LoL_Project.csproj", "{4EDC93E0-35B8-4EF1-9318-24F7A606BA97}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DTO", "DTO\DTO.csproj", "{7F6A519E-98F8-429E-B34F-9B0D20075CFB}" -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 - {4EDC93E0-35B8-4EF1-9318-24F7A606BA97}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {4EDC93E0-35B8-4EF1-9318-24F7A606BA97}.Debug|Any CPU.Build.0 = Debug|Any CPU - {4EDC93E0-35B8-4EF1-9318-24F7A606BA97}.Release|Any CPU.ActiveCfg = Release|Any CPU - {4EDC93E0-35B8-4EF1-9318-24F7A606BA97}.Release|Any CPU.Build.0 = Release|Any CPU - {7F6A519E-98F8-429E-B34F-9B0D20075CFB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {7F6A519E-98F8-429E-B34F-9B0D20075CFB}.Debug|Any CPU.Build.0 = Debug|Any CPU - {7F6A519E-98F8-429E-B34F-9B0D20075CFB}.Release|Any CPU.ActiveCfg = Release|Any CPU - {7F6A519E-98F8-429E-B34F-9B0D20075CFB}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(NestedProjects) = preSolution - {1889FA6E-B7C6-416E-8628-9449FB9070B9} = {C76D0C23-1FFA-4963-93CD-E12BD643F030} - {B01D7EF2-2D64-409A-A29A-61FB7BB7A9DB} = {2C607793-B163-4731-A4D1-AFE8A7C4C170} - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {92F3083D-793F-4552-8A9A-0AD6534159C9} - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.4.33205.214 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "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("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleTests", "Tests\ConsoleTests\ConsoleTests.csproj", "{1889FA6E-B7C6-416E-8628-9449FB9070B9}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "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("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StubLib", "StubLib\StubLib.csproj", "{B01D7EF2-2D64-409A-A29A-61FB7BB7A9DB}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "API_LoL_Project", "API_LoL_Project\API_LoL_Project.csproj", "{4EDC93E0-35B8-4EF1-9318-24F7A606BA97}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DTO", "DTO\DTO.csproj", "{7F6A519E-98F8-429E-B34F-9B0D20075CFB}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Test_Api", "Test_Api\Test_Api.csproj", "{C35C38F6-5774-4562-BD00-C81BCE13A260}" +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 + {4EDC93E0-35B8-4EF1-9318-24F7A606BA97}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4EDC93E0-35B8-4EF1-9318-24F7A606BA97}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4EDC93E0-35B8-4EF1-9318-24F7A606BA97}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4EDC93E0-35B8-4EF1-9318-24F7A606BA97}.Release|Any CPU.Build.0 = Release|Any CPU + {7F6A519E-98F8-429E-B34F-9B0D20075CFB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7F6A519E-98F8-429E-B34F-9B0D20075CFB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7F6A519E-98F8-429E-B34F-9B0D20075CFB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7F6A519E-98F8-429E-B34F-9B0D20075CFB}.Release|Any CPU.Build.0 = Release|Any CPU + {C35C38F6-5774-4562-BD00-C81BCE13A260}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C35C38F6-5774-4562-BD00-C81BCE13A260}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C35C38F6-5774-4562-BD00-C81BCE13A260}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C35C38F6-5774-4562-BD00-C81BCE13A260}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {1889FA6E-B7C6-416E-8628-9449FB9070B9} = {C76D0C23-1FFA-4963-93CD-E12BD643F030} + {B01D7EF2-2D64-409A-A29A-61FB7BB7A9DB} = {2C607793-B163-4731-A4D1-AFE8A7C4C170} + {C35C38F6-5774-4562-BD00-C81BCE13A260} = {C76D0C23-1FFA-4963-93CD-E12BD643F030} + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {92F3083D-793F-4552-8A9A-0AD6534159C9} + EndGlobalSection +EndGlobal diff --git a/EntityFramework_LoL/Sources/TestProject1/ChampionControllerTest.cs b/EntityFramework_LoL/Sources/TestProject1/ChampionControllerTest.cs new file mode 100644 index 0000000..6130a13 --- /dev/null +++ b/EntityFramework_LoL/Sources/TestProject1/ChampionControllerTest.cs @@ -0,0 +1,62 @@ +using API_LoL_Project.Controllers; +using DTO; +using Microsoft.AspNetCore.Mvc; +using Model; +using StubLib; + +namespace TestProject1 +{ + [TestClass] + public class ChampionControllerTest + { + public readonly ChampionsController championCtrl; + + public readonly IChampionsManager stubMgr; + public ChampionControllerTest() + { + stubMgr = new StubData().ChampionsMgr; + + championCtrl = new ChampionsController(stubMgr); + } + + [TestMethod] + public async Task TestGetChampions() + { + var getResult = await championCtrl.Get(); + + var objectRes = getResult as OkObjectResult; + + Assert.IsNotNull(objectRes); + + var champions = objectRes?.Value as IEnumerable; + Assert.IsNotNull(champions); + + Assert.AreEqual(champions.Count(), await stubMgr.GetNbItems()); + + } + + + [TestMethod] + public async void TestPostChampions() + { + var chamionGetResul = championCtrl.Get(); + + } + + [TestMethod] + public async void TestUpdateChampions() + { + var chamionGetResul = championCtrl.Get(); + + } + + + [TestMethod] + public async void TestDeleteChampions() + { + var chamionGetResul = championCtrl.Get(); + + } + + } +} \ No newline at end of file diff --git a/EntityFramework_LoL/Sources/TestProject1/TestProject1.csproj b/EntityFramework_LoL/Sources/TestProject1/TestProject1.csproj new file mode 100644 index 0000000..41756cb --- /dev/null +++ b/EntityFramework_LoL/Sources/TestProject1/TestProject1.csproj @@ -0,0 +1,22 @@ + + + + net6.0 + enable + enable + + false + + + + + + + + + + + + + + diff --git a/EntityFramework_LoL/Sources/TestProject1/UnitTest1.cs b/EntityFramework_LoL/Sources/TestProject1/UnitTest1.cs new file mode 100644 index 0000000..25e04d8 --- /dev/null +++ b/EntityFramework_LoL/Sources/TestProject1/UnitTest1.cs @@ -0,0 +1,11 @@ +namespace TestProject1 +{ + [TestClass] + public class UnitTest1 + { + [TestMethod] + public void TestMethod1() + { + } + } +} \ No newline at end of file diff --git a/EntityFramework_LoL/Sources/TestProject1/Usings.cs b/EntityFramework_LoL/Sources/TestProject1/Usings.cs new file mode 100644 index 0000000..ab67c7e --- /dev/null +++ b/EntityFramework_LoL/Sources/TestProject1/Usings.cs @@ -0,0 +1 @@ +global using Microsoft.VisualStudio.TestTools.UnitTesting; \ No newline at end of file diff --git a/EntityFramework_LoL/Sources/Test_Api/ChampionControllerTest.cs b/EntityFramework_LoL/Sources/Test_Api/ChampionControllerTest.cs new file mode 100644 index 0000000..1e5be2c --- /dev/null +++ b/EntityFramework_LoL/Sources/Test_Api/ChampionControllerTest.cs @@ -0,0 +1,46 @@ +using API_LoL_Project.Controllers; +using DTO; +using Microsoft.AspNetCore.Mvc; +using Model; +using StubLib; +using System.Net; + +namespace Test_Api +{ + [TestClass] + public class ChampionControllerTest + { + public readonly ChampionsController championCtrl; + + public readonly IDataManager stubMgr; + public ChampionControllerTest() + { + var stubMgr = new StubData(); + + championCtrl = new ChampionsController(stubMgr); + } + + [TestMethod] + public async Task TestGetChampions() + { + var getResult = await championCtrl.Get(); + Console.WriteLine(getResult); + var objectRes = getResult as OkObjectResult; + + Assert.AreEqual(200, objectRes.StatusCode); + + Assert.IsNotNull(objectRes); + + var champions = objectRes?.Value as IEnumerable; + + Assert.IsNotNull(champions); + +/* + Assert.AreEqual(champions.Count(), await stubMgr.ChampionsMgr.GetNbItems());*/ + + } + + + + } +} \ No newline at end of file diff --git a/EntityFramework_LoL/Sources/Test_Api/Test_Api.csproj b/EntityFramework_LoL/Sources/Test_Api/Test_Api.csproj new file mode 100644 index 0000000..e80b67b --- /dev/null +++ b/EntityFramework_LoL/Sources/Test_Api/Test_Api.csproj @@ -0,0 +1,25 @@ + + + + net6.0 + enable + enable + + false + + + + + + + + + + + + + + + + + diff --git a/EntityFramework_LoL/Sources/Test_Api/Usings.cs b/EntityFramework_LoL/Sources/Test_Api/Usings.cs new file mode 100644 index 0000000..ab67c7e --- /dev/null +++ b/EntityFramework_LoL/Sources/Test_Api/Usings.cs @@ -0,0 +1 @@ +global using Microsoft.VisualStudio.TestTools.UnitTesting; \ No newline at end of file