diff --git a/.drone.yml b/.drone.yml
index 6aec404..82743c5 100644
--- a/.drone.yml
+++ b/.drone.yml
@@ -62,3 +62,14 @@ steps:
from_secret: SECRET_SONAR_LOGIN
depends_on: [tests]
+ # container deployment
+ - name: deploy-container
+ image: hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-dockerproxy-clientdrone:latest
+ environment:
+ IMAGENAME: hub.codefirst.iut.uca.fr/corentin.richard/entityframework_consodeservices_tp:latest
+ CONTAINERNAME: entityframework_consodeservices_tp
+ COMMAND: create
+ OVERWRITE: true
+ ADMIN: corentinrichard,pierreferreira
+ depends_on: [ code-analysis, docker-build-and-push ]
+
diff --git a/Sources/API_LoL/API_LoL.csproj b/Sources/API_LoL/API_LoL.csproj
index 5ada54d..a8c4de7 100644
--- a/Sources/API_LoL/API_LoL.csproj
+++ b/Sources/API_LoL/API_LoL.csproj
@@ -9,6 +9,8 @@
+
+
diff --git a/Sources/API_LoL/Controllers/ChampionsController.cs b/Sources/API_LoL/Controllers/ChampionsController.cs
index 9aefc31..1b2b021 100644
--- a/Sources/API_LoL/Controllers/ChampionsController.cs
+++ b/Sources/API_LoL/Controllers/ChampionsController.cs
@@ -4,26 +4,34 @@ using StubLib;
using DTO;
using DTO.Mapper;
using System.CodeDom.Compiler;
+using System.Drawing;
+using System;
+using API_LoL.Mapper;
+using System.Xml.Linq;
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
namespace API_LoL.Controllers
{
- [Route("api/[controller]")]
+ //[Route("api/[controller]")]
+ [ApiVersion("1.0")]
+ [Route("api/v{version:apiVersion}/[controller]")]
[ApiController]
public class ChampionsController : ControllerBase
{
public ChampionsController(IDataManager Manager) {
- this.ChampionsManager= Manager.ChampionsMgr;
+ this.ChampionsManager = Manager.ChampionsMgr;
+ this.SkinsManager = Manager.SkinsMgr;
}
private IChampionsManager ChampionsManager;
+ private ISkinsManager SkinsManager;
// GET api//5
[HttpGet]
- public async Task Get(String? name= null,String? skill = null, String? characteristic = null,int index = 0,int size =10)
+ public async Task Get(string? name = null,String? skill = null, String? characteristic = null,int index = 0,int size =10)
{
if (size - index > 10)
{
@@ -31,13 +39,14 @@ namespace API_LoL.Controllers
}
if (!string.IsNullOrEmpty(name))
{
- var list = await ChampionsManager.GetItemsByName(name, index,size);
+ var list = await ChampionsManager.GetItemsByName(name, index, size);
if (list.Count() != 0)
{
return Ok(list.Select(champion => champion?.ToDTO()));
}
else { return NoContent(); }
- }else if(!string.IsNullOrEmpty(skill)) {
+ }
+ else if(!string.IsNullOrEmpty(skill)) {
var list = await ChampionsManager.GetItemsBySkill(skill, index, size);
if (list.Count() != 0)
{
@@ -63,8 +72,38 @@ namespace API_LoL.Controllers
}
}
- // POST api/
- [HttpPost]
+ [HttpGet("name")]
+ public async Task GetByName(String name)
+ {
+ if (string.IsNullOrEmpty(name)) return BadRequest();
+ var list = await ChampionsManager.GetItemsByName(name, 0, 1);
+ if (list.Count() == 1)
+ {
+ return Ok(list.Select(champion => champion?.ToDTO()).First());
+ }
+ else { return NoContent(); }
+
+ }
+
+ [HttpGet("name/skins")]
+ public async Task GetSkinsByName(String name)
+ {
+ if (string.IsNullOrEmpty(name)) return BadRequest();
+ var list = await ChampionsManager.GetItemsByName(name, 0, 1);
+ if (list.Count() == 1)
+ {
+ var skins = await SkinsManager.GetItemsByChampion(list.First(), 0, await SkinsManager.GetNbItemsByChampion(list.First()));
+ if (skins.Count() != 0)
+ {
+ return Ok(skins.Select(skin => skin?.ToDTO()));
+ }
+ else { return NoContent(); }
+ }
+ else { return NoContent(); }
+ }
+
+ // POST api/
+ [HttpPost]
public async Task Post(ChampionDTO champion)
{
if (champion == null)
diff --git a/Sources/API_LoL/Controllers/ChampionsControllerVersioned.cs b/Sources/API_LoL/Controllers/ChampionsControllerVersioned.cs
new file mode 100644
index 0000000..87598d9
--- /dev/null
+++ b/Sources/API_LoL/Controllers/ChampionsControllerVersioned.cs
@@ -0,0 +1,108 @@
+using Microsoft.AspNetCore.Mvc;
+using Model;
+using StubLib;
+using DTO;
+using DTO.Mapper;
+using System.CodeDom.Compiler;
+
+namespace API_LoL.Controllers
+{
+ [ApiVersion("2.0")]
+ [ApiVersion("2.2")]
+ [Route("api/v{version:apiVersion}/versioned")]
+ [ApiController]
+ public class ChampionsControllerVersioned : ControllerBase
+ {
+ public ChampionsControllerVersioned(IDataManager Manager)
+ {
+ this.ChampionsManager = Manager.ChampionsMgr;
+ }
+
+ private IChampionsManager ChampionsManager;
+
+ // GET api//5
+
+ //[HttpGet]
+ //public async Task Get(String? name = null, String? skill = null, String? characteristic = null, int index = 0, int size = 10)
+ //{
+ // if (size - index > 10)
+ // {
+ // return BadRequest();
+ // }
+ // if (!string.IsNullOrEmpty(name))
+ // {
+ // var list = await ChampionsManager.GetItemsByName(name, index, size);
+ // if (list.Count() != 0)
+ // {
+ // return Ok(list.Select(champion => champion?.ToDTO()));
+ // }
+ // else { return NoContent(); }
+ // }
+ // else if (!string.IsNullOrEmpty(skill))
+ // {
+ // var list = await ChampionsManager.GetItemsBySkill(skill, index, size);
+ // if (list.Count() != 0)
+ // {
+ // return Ok(list.Select(champion => champion?.ToDTO()));
+ // }
+ // else { return NoContent(); }
+ // }
+ // else if (!string.IsNullOrEmpty(characteristic))
+ // {
+ // var list = await ChampionsManager.GetItems(index, size);
+ // if (list.Count() != 0)
+ // {
+ // return Ok(list.Select(champion => champion?.ToDTO()));
+ // }
+ // else { return NoContent(); }
+ // }
+ // else
+ // {
+ // var list = await ChampionsManager.GetItems(index, size);
+ // if (list.Count() != 0)
+ // {
+ // return Ok(list.Select(champion => champion?.ToDTO()));
+ // }
+ // else { return NoContent(); }
+ // }
+ //}
+
+
+ //// POST api/
+ //[HttpPost]
+ //public async Task Post(ChampionDTO champion)
+ //{
+ // if (champion == null)
+ // {
+ // return UnprocessableEntity();
+ // }
+ // else
+ // {
+ // await ChampionsManager.AddItem(champion.ToChampion());
+ // return CreatedAtAction("Post", champion);
+ // }
+ //}
+
+ //// PUT api//5
+ //[HttpPut("{id}")]
+ //public void Put(int id, [FromBody] string value)
+ //{
+ //}
+
+ //// DELETE api//5
+ //[HttpDelete("{id}")]
+ //public void Delete(int id)
+ //{
+ //}
+
+
+ ///---------- Versioning ----------///
+ [HttpGet, MapToApiVersion("2.0")]
+ public string GetThatOnlySayHello() => "Hello v2.0!";
+
+
+ //! FIXME : not working, mais avec la version 2.0 ca marche !
+ [HttpGet, MapToApiVersion("2.2")]
+ public string GetThatOnlySayHelloV2() => "Hello but i'm from v2.2!";
+ }
+}
diff --git a/Sources/API_LoL/Mapper/ChampionClassMapper.cs b/Sources/API_LoL/Mapper/ChampionClassMapper.cs
new file mode 100644
index 0000000..638f500
--- /dev/null
+++ b/Sources/API_LoL/Mapper/ChampionClassMapper.cs
@@ -0,0 +1,34 @@
+using DTO;
+using Model;
+
+namespace API_LoL.Mapper
+{
+ public static class ChampionClassMapper
+ {
+ public static string ToDTO(this ChampionClass championClass)
+ {
+ return championClass.ToString();
+ }
+
+ public static ChampionClass ToChampionClass(this String championClass)
+ {
+ switch (championClass)
+ {
+ case "Assassin":
+ return ChampionClass.Assassin;
+ case "Fighter":
+ return ChampionClass.Fighter;
+ case "Mage":
+ return ChampionClass.Mage;
+ case "Marksman":
+ return ChampionClass.Marksman;
+ case "Support":
+ return ChampionClass.Support;
+ case "Tank":
+ return ChampionClass.Tank;
+ default:
+ return ChampionClass.Unknown;
+ }
+ }
+ }
+}
diff --git a/Sources/API_LoL/Mapper/ChampionMapper.cs b/Sources/API_LoL/Mapper/ChampionMapper.cs
index c2e8d0b..3dd6a11 100644
--- a/Sources/API_LoL/Mapper/ChampionMapper.cs
+++ b/Sources/API_LoL/Mapper/ChampionMapper.cs
@@ -1,4 +1,5 @@
-using Model;
+using API_LoL.Mapper;
+using Model;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -11,13 +12,13 @@ namespace DTO.Mapper
{
public static ChampionDTO ToDTO(this Champion champion)
{
- return new ChampionDTO(champion.Name, champion.Bio, champion.Icon);
+ return new ChampionDTO(champion.Name, champion.Bio, champion.Icon,champion.Class.ToDTO().ToString());
//return new ChampionDTO(champion.Name, champion.Bio, champion.Icon, champion.Skills);
}
public static Champion ToChampion(this ChampionDTO champion)
{
- Champion champ = new Champion(champion.Name, ChampionClass.Unknown, champion.Icon, "", champion.Bio);
+ Champion champ = new Champion(champion.Name, champion.Class.ToChampionClass(), champion.Icon, "", champion.Bio);
//foreach (Skill skill in champion.Skills)
//{
diff --git a/Sources/API_LoL/Mapper/SkinMapper.cs b/Sources/API_LoL/Mapper/SkinMapper.cs
new file mode 100644
index 0000000..25ac8f6
--- /dev/null
+++ b/Sources/API_LoL/Mapper/SkinMapper.cs
@@ -0,0 +1,18 @@
+using DTO;
+using Model;
+
+namespace API_LoL.Mapper
+{
+ public static class SkinMapper
+ {
+ public static SkinDTO ToDTO(this Skin skin)
+ {
+ return new SkinDTO(skin.Name, skin.Description, skin.Icon);
+ }
+
+ public static Skin ToSkin(this SkinDTO skin)
+ {
+ return new Skin(skin.Name, null, icon:skin.Icon) ;
+ }
+ }
+}
diff --git a/Sources/API_LoL/Program.cs b/Sources/API_LoL/Program.cs
index d4fb3b8..c192eac 100644
--- a/Sources/API_LoL/Program.cs
+++ b/Sources/API_LoL/Program.cs
@@ -1,24 +1,65 @@
+using API_LoL;
+using Microsoft.AspNetCore.Mvc.ApiExplorer;
+using Microsoft.AspNetCore.Mvc.Versioning;
using Model;
using StubLib;
var builder = WebApplication.CreateBuilder(args);
-// Add services to the container.
-builder.Services.AddControllers();
+//Versioning
+
+///NOT WORKING WHEN CHANGING VERSIONS :
+/// voir sur https://blog.christian-schou.dk/how-to-use-api-versioning-in-net-core-web-api/ rubrique "Configure SwaggerOptions"
+/// (mais requiere l'injection de dépendance).
+/// Sinon, code plus simple disponible par le prof
+
+
+
+// Add ApiExplorer to discover versions
+builder.Services.AddVersionedApiExplorer(setup =>
+{
+ setup.GroupNameFormat = "'v'VVV";
+ setup.SubstituteApiVersionInUrl = true;
+});
+
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
+builder.Services.ConfigureOptions();
+
+
+builder.Services.AddApiVersioning(o => o.ApiVersionReader = new UrlSegmentApiVersionReader());
+
+// Add services to the container.
+builder.Services.AddControllers();
+
+
+
builder.Services.AddScoped();
+
+
+
var app = builder.Build();
+var apiVersionDescriptionProvider = app.Services.GetRequiredService();
+
+
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
- app.UseSwaggerUI();
+ app.UseSwaggerUI(options =>
+ {
+
+ foreach (var description in apiVersionDescriptionProvider.ApiVersionDescriptions)
+ {
+ options.SwaggerEndpoint($"/swagger/{description.GroupName}/swagger.json",
+ description.GroupName.ToUpperInvariant());
+ }
+ });
}
app.UseHttpsRedirection();
diff --git a/Sources/API_LoL/SwaggerOptions.cs b/Sources/API_LoL/SwaggerOptions.cs
new file mode 100644
index 0000000..46ad759
--- /dev/null
+++ b/Sources/API_LoL/SwaggerOptions.cs
@@ -0,0 +1,61 @@
+using Microsoft.AspNetCore.Mvc.ApiExplorer;
+using Microsoft.Extensions.Options;
+using Microsoft.OpenApi.Models;
+using Swashbuckle.AspNetCore.SwaggerGen;
+
+namespace API_LoL
+{
+ public class ConfigureSwaggerOptions : IConfigureNamedOptions
+ {
+ private readonly IApiVersionDescriptionProvider _provider;
+
+ public ConfigureSwaggerOptions(IApiVersionDescriptionProvider provider)
+ {
+ _provider = provider;
+ }
+
+ ///
+ /// Configure each API discovered for Swagger Documentation
+ ///
+ ///
+ public void Configure(SwaggerGenOptions options)
+ {
+ // add swagger document for every API version discovered
+ foreach (var description in _provider.ApiVersionDescriptions)
+ {
+ options.SwaggerDoc(description.GroupName, CreateVersionInfo(description));
+ }
+ }
+
+ ///
+ /// Configure Swagger Options. Inherited from the Interface
+ ///
+ ///
+ ///
+ public void Configure(string name, SwaggerGenOptions options)
+ {
+ Configure(options);
+ }
+
+ ///
+ /// Create information about the version of the API
+ ///
+ ///
+ /// Information about the API
+ private OpenApiInfo CreateVersionInfo(ApiVersionDescription desc)
+ {
+ var info = new OpenApiInfo()
+ {
+ Title = ".NET Core (.NET 6) Web API",
+ Version = desc.ApiVersion.ToString()
+ };
+
+ if (desc.IsDeprecated)
+ {
+ info.Description += " This API version has been deprecated. Please use one of the new APIs available from the explorer.";
+ }
+
+ return info;
+ }
+ }
+}
diff --git a/Sources/Api_UT/ChampionControllerTest.cs b/Sources/Api_UT/ChampionControllerTest.cs
index 16fccaa..a3ca675 100644
--- a/Sources/Api_UT/ChampionControllerTest.cs
+++ b/Sources/Api_UT/ChampionControllerTest.cs
@@ -21,7 +21,7 @@ namespace Api_UT
public async Task Get_Default_OkList()
{
- List list = new List {new ChampionDTO("Akali","",""), new ChampionDTO("Aatrox", "", ""), new ChampionDTO("Ahri", "", ""), new ChampionDTO("Akshan", "", ""), new ChampionDTO("Bard", "", ""), new ChampionDTO("Alistar", "", "") };
+ List list = new List {new ChampionDTO("Akali","","","Assassin"), new ChampionDTO("Aatrox", "", "", "Fighter"), new ChampionDTO("Ahri", "", "", "Mage"), new ChampionDTO("Akshan", "", "", "Marksman"), new ChampionDTO("Bard", "", "","Support"), new ChampionDTO("Alistar", "", "","Tank") };
IActionResult a = await api.Get();
a.Should().NotBeNull();
var aObject = a as OkObjectResult;
@@ -42,7 +42,7 @@ namespace Api_UT
[TestMethod]
public async Task Get_2First_OkListOf2()
{
- List list = new List { new ChampionDTO("Akali", "", ""), new ChampionDTO("Aatrox", "", "") };
+ List list = new List { new ChampionDTO("Akali", "", "", "Assassin"), new ChampionDTO("Aatrox", "", "", "Fighter") };
IActionResult a = await api.Get(index: 0,size: 2);
@@ -57,7 +57,7 @@ namespace Api_UT
[TestMethod]
public async Task Get_FilterAName_OkListOf5()
{
- List list = new List { new ChampionDTO("Akali", "", ""), new ChampionDTO("Akshan", "", "") };
+ List list = new List { new ChampionDTO("Akali", "", "", "Assassin"), new ChampionDTO("Akshan", "", "", "Marksman") };
IActionResult a = await api.Get(name: "Ak");
@@ -75,9 +75,9 @@ namespace Api_UT
public async Task Post_ValidChampion_Created()
{
ChampionsController api = new ChampionsController(new StubData());
- IActionResult a = await api.Post(new ChampionDTO("nom","bio","icon"));
+ IActionResult a = await api.Post(new ChampionDTO("nom","bio","icon", "Assassin"));
Assert.IsNotNull(a);
- ChampionDTO champ = new ChampionDTO("nom", "bio", "icon");
+ ChampionDTO champ = new ChampionDTO("nom", "bio", "icon","Assassin");
Assert.IsTrue(champ.equals((ChampionDTO)((CreatedAtActionResult)a).Value));
}
diff --git a/Sources/Api_UT/UnitTest1.cs b/Sources/Api_UT/UnitTest1.cs
deleted file mode 100644
index de78d2b..0000000
--- a/Sources/Api_UT/UnitTest1.cs
+++ /dev/null
@@ -1,41 +0,0 @@
-using API_LoL.Controllers;
-using DTO;
-using FluentAssertions;
-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();
-
- /// utilisation du nuggets fluentAssertion
- //Assert.IsNotNull(a);
- a.Should().NotBeNull();
- //Assert.AreEqual(list,((OkObjectResult)a).Value);
- var aObject = a as OkObjectResult;
- aObject.Should().NotBeNull();
- var championresult = aObject.Value as IEnumerable;
- list.Should().BeEquivalentTo(championresult);
- }
-
- [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/DTO/ChampionClassDTO.cs b/Sources/DTO/ChampionClassDTO.cs
new file mode 100644
index 0000000..c85525f
--- /dev/null
+++ b/Sources/DTO/ChampionClassDTO.cs
@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DTO
+{
+ public class ChampionClassDTO
+ {
+ public string Name;
+ public ChampionClassDTO(string name) {
+ this.Name = name;
+ }
+ }
+}
diff --git a/Sources/DTO/ChampionDTO.cs b/Sources/DTO/ChampionDTO.cs
index 922d56e..723d7b4 100644
--- a/Sources/DTO/ChampionDTO.cs
+++ b/Sources/DTO/ChampionDTO.cs
@@ -5,26 +5,19 @@ namespace DTO
{
public class ChampionDTO
{
- public ChampionDTO(string name, string bio, string icon)
+ public ChampionDTO(string name, string bio, string icon, string championClassDTO)
{
Name = name;
Bio = bio;
Icon = icon;
+ Class = championClassDTO;
}
-
- //public ChampionDTO(string name, string bio, string icon, ICollection skills)
- //{
- // Name = name;
- // Bio = bio;
- // Icon = icon;
- // Skills = skills;
- //}
-
public string Name { get; set; }
public string Bio { get; set; }
- //public ChampionClass Class { get; set; }
public string Icon { get; set; }
+ public string Class { get; set; }
+
public bool equals(ChampionDTO other)
{
return other.Name==this.Name && other.Bio==this.Bio && other.Icon==this.Icon;
diff --git a/Sources/DTO/SkinDTO.cs b/Sources/DTO/SkinDTO.cs
new file mode 100644
index 0000000..32696d6
--- /dev/null
+++ b/Sources/DTO/SkinDTO.cs
@@ -0,0 +1,23 @@
+using Model;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DTO
+{
+ public class SkinDTO
+ {
+ public string Name { get; set; }
+ public string Description { get; set; }
+ public string Icon { get; set; }
+
+ public SkinDTO(string name,string description,string icon) {
+ this.Name = name;
+ this.Description = description;
+ this.Icon = icon;
+
+ }
+ }
+}
diff --git a/Sources/EF_UT/EntityTest.cs b/Sources/EF_UT/EntityTest.cs
index f162b09..bd0005b 100644
--- a/Sources/EF_UT/EntityTest.cs
+++ b/Sources/EF_UT/EntityTest.cs
@@ -55,8 +55,8 @@ namespace EF_UT
//prepares the database with one instance of the context
using (var context = new LoLDbContext(options))
{
- ChampionEntity chewie = new ChampionEntity("Chewbacca", "", "");
- ChampionEntity yoda = new ChampionEntity("Yoda", "", "");
+ ChampionEntity chewie = new ChampionEntity("Chewbacca", "ewa", "");
+ ChampionEntity yoda = new ChampionEntity("Yoda", "wewo", "");
ChampionEntity ewok = new ChampionEntity("Ewok", "", "");
context.Add(chewie);
@@ -68,23 +68,23 @@ namespace EF_UT
//prepares the database with one instance of the context
using (var context = new LoLDbContext(options))
{
- string NameToFind = "ew";
- Assert.AreEqual(2, context.Champions.Where(n => n.Name.ToLower().Contains(NameToFind)).Count());
- NameToFind = "ewo";
- Assert.AreEqual(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";
+ string BioToFind = "ew";
+ Assert.AreEqual(2, context.Champions.Where(n => n.Bio.ToLower().Contains(BioToFind)).Count());
+ BioToFind = "ewo";
+ Assert.AreEqual(1, context.Champions.Where(n => n.Bio.ToLower().Contains(BioToFind)).Count());
+ var ewok = context.Champions.Where(n => n.Bio.ToLower().Contains(BioToFind)).First();
+ ewok.Bio = "Wicket";
context.SaveChanges();
}
//prepares the database with one instance of the context
- using (var context = new LoLDbContext(options))
- {
- string NameToFind = "ew";
- Assert.AreEqual(1, context.Champions.Where(n => n.Name.ToLower().Contains(NameToFind)).Count());
- NameToFind = "wick";
- Assert.AreEqual(1, context.Champions.Where(n => n.Name.ToLower().Contains(NameToFind)).Count());
- }
+ //using (var context = new LoLDbContext(options))
+ //{
+ // string NameToFind = "ew";
+ // Assert.AreEqual(1, context.Champions.Where(n => n.Bio.ToLower().Contains(NameToFind)).Count());
+ // NameToFind = "wick";
+ // Assert.AreEqual(1, context.Champions.Where(n => n.Bio.ToLower().Contains(NameToFind)).Count());
+ //}
}
}
}
diff --git a/Sources/EntityFramework/ChampionEntity.cs b/Sources/EntityFramework/ChampionEntity.cs
index 1810ae8..d4a53e4 100644
--- a/Sources/EntityFramework/ChampionEntity.cs
+++ b/Sources/EntityFramework/ChampionEntity.cs
@@ -13,11 +13,11 @@ namespace EntityFramework
[Table("Champion")]
public class ChampionEntity
{
- [Key]
- [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
- public int Id { get; set; }
+ //[Key]
+ //[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
+ //public int Id { get; set; }
- [Required]
+ [Key]
[MaxLength(50)]
public string Name { get; set; }
diff --git a/Sources/EntityFramework/EntityFramework.csproj b/Sources/EntityFramework/EntityFramework.csproj
index 6ca2f66..2d1f7fc 100644
--- a/Sources/EntityFramework/EntityFramework.csproj
+++ b/Sources/EntityFramework/EntityFramework.csproj
@@ -18,7 +18,7 @@
-
+
diff --git a/Sources/EntityFramework/LoLDBContextWithStub.cs b/Sources/EntityFramework/LoLDBContextWithStub.cs
new file mode 100644
index 0000000..7379162
--- /dev/null
+++ b/Sources/EntityFramework/LoLDBContextWithStub.cs
@@ -0,0 +1,25 @@
+using EntityFramework.Mapper;
+using Microsoft.EntityFrameworkCore;
+using StubLib;
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace EntityFramework
+{
+ public class LoLDBContextWithStub : LoLDbContext
+ {
+ protected override async void OnModelCreating(ModelBuilder modelBuilder)
+ {
+ base.OnModelCreating(modelBuilder);
+ var stub = new StubData.ChampionsManager(new StubData());
+ var list = await stub.GetItems(0, await stub.GetNbItems());
+ modelBuilder.Entity().HasData(
+ list.Select(champion => champion.ToEntity())
+ );
+ }
+ }
+}
diff --git a/Sources/EntityFramework/LoLDbContext.cs b/Sources/EntityFramework/LoLDbContext.cs
index 91b440a..9bbf417 100644
--- a/Sources/EntityFramework/LoLDbContext.cs
+++ b/Sources/EntityFramework/LoLDbContext.cs
@@ -34,11 +34,11 @@ namespace EntityFramework
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
- modelBuilder.Entity().HasKey(entity => entity.Id);
+ modelBuilder.Entity().HasKey(entity => entity.Name);
modelBuilder.Entity().ToTable("Champion");
- modelBuilder.Entity().Property(entity => entity.Id)
- .ValueGeneratedOnAdd();
+ //modelBuilder.Entity().Property(entity => entity.Id)
+ // .ValueGeneratedOnAdd();
modelBuilder.Entity().Property(entity => entity.Name)
.IsRequired()
diff --git a/Sources/EntityFramework/Mapper/ChampionMapper.cs b/Sources/EntityFramework/Mapper/ChampionMapper.cs
new file mode 100644
index 0000000..862264d
--- /dev/null
+++ b/Sources/EntityFramework/Mapper/ChampionMapper.cs
@@ -0,0 +1,16 @@
+using Model;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace EntityFramework.Mapper
+{
+ public static class ChampionMapper
+ {
+ public static ChampionEntity ToEntity(this Champion champion) {
+ return new ChampionEntity(champion.Name, champion.Bio, champion.Icon);
+ }
+ }
+}
diff --git a/Sources/EntityFramework/Migrations/20230312170120_stubMig.Designer.cs b/Sources/EntityFramework/Migrations/20230312170120_stubMig.Designer.cs
new file mode 100644
index 0000000..2b24874
--- /dev/null
+++ b/Sources/EntityFramework/Migrations/20230312170120_stubMig.Designer.cs
@@ -0,0 +1,83 @@
+//
+using EntityFramework;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+
+#nullable disable
+
+namespace EntityFramework.Migrations
+{
+ [DbContext(typeof(LoLDBContextWithStub))]
+ [Migration("20230312170120_stubMig")]
+ partial class stubMig
+ {
+ ///
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder.HasAnnotation("ProductVersion", "7.0.2");
+
+ modelBuilder.Entity("EntityFramework.ChampionEntity", b =>
+ {
+ b.Property("Name")
+ .HasMaxLength(50)
+ .HasColumnType("TEXT");
+
+ b.Property("Bio")
+ .IsRequired()
+ .HasMaxLength(500)
+ .HasColumnType("string")
+ .HasColumnName("Bio");
+
+ b.Property("Icon")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.HasKey("Name");
+
+ b.ToTable("Champion", (string)null);
+
+ b.HasData(
+ new
+ {
+ Name = "Akali",
+ Bio = "",
+ Icon = ""
+ },
+ new
+ {
+ Name = "Aatrox",
+ Bio = "",
+ Icon = ""
+ },
+ new
+ {
+ Name = "Ahri",
+ Bio = "",
+ Icon = ""
+ },
+ new
+ {
+ Name = "Akshan",
+ Bio = "",
+ Icon = ""
+ },
+ new
+ {
+ Name = "Bard",
+ Bio = "",
+ Icon = ""
+ },
+ new
+ {
+ Name = "Alistar",
+ Bio = "",
+ Icon = ""
+ });
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/Sources/EntityFramework/Migrations/20230312170120_stubMig.cs b/Sources/EntityFramework/Migrations/20230312170120_stubMig.cs
new file mode 100644
index 0000000..3323fa4
--- /dev/null
+++ b/Sources/EntityFramework/Migrations/20230312170120_stubMig.cs
@@ -0,0 +1,49 @@
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional
+
+namespace EntityFramework.Migrations
+{
+ ///
+ public partial class stubMig : Migration
+ {
+ ///
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.CreateTable(
+ name: "Champion",
+ columns: table => new
+ {
+ Name = table.Column(type: "TEXT", maxLength: 50, nullable: false),
+ Bio = table.Column(type: "string", maxLength: 500, nullable: false),
+ Icon = table.Column(type: "TEXT", nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_Champion", x => x.Name);
+ });
+
+ migrationBuilder.InsertData(
+ table: "Champion",
+ columns: new[] { "Name", "Bio", "Icon" },
+ values: new object[,]
+ {
+ { "Aatrox", "", "" },
+ { "Ahri", "", "" },
+ { "Akali", "", "" },
+ { "Akshan", "", "" },
+ { "Alistar", "", "" },
+ { "Bard", "", "" }
+ });
+ }
+
+ ///
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropTable(
+ name: "Champion");
+ }
+ }
+}
diff --git a/Sources/EntityFramework/Migrations/20230313155631_MyMigr.Designer.cs b/Sources/EntityFramework/Migrations/20230313155631_MyMigr.Designer.cs
deleted file mode 100644
index 7c3459c..0000000
--- a/Sources/EntityFramework/Migrations/20230313155631_MyMigr.Designer.cs
+++ /dev/null
@@ -1,145 +0,0 @@
-//
-using System;
-using EntityFramework;
-using Microsoft.EntityFrameworkCore;
-using Microsoft.EntityFrameworkCore.Infrastructure;
-using Microsoft.EntityFrameworkCore.Migrations;
-using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
-
-#nullable disable
-
-namespace EntityFramework.Migrations
-{
- [DbContext(typeof(LoLDbContext))]
- [Migration("20230313155631_MyMigr")]
- partial class MyMigr
- {
- ///
- protected override void BuildTargetModel(ModelBuilder modelBuilder)
- {
-#pragma warning disable 612, 618
- modelBuilder.HasAnnotation("ProductVersion", "7.0.2");
-
- modelBuilder.Entity("EntityFramework.ChampionEntity", b =>
- {
- b.Property("Id")
- .ValueGeneratedOnAdd()
- .HasColumnType("INTEGER");
-
- b.Property("Bio")
- .IsRequired()
- .HasMaxLength(500)
- .HasColumnType("string")
- .HasColumnName("Bio");
-
- b.Property("Icon")
- .IsRequired()
- .HasColumnType("TEXT");
-
- b.Property("Image")
- .HasColumnType("TEXT");
-
- b.Property("Name")
- .IsRequired()
- .HasMaxLength(50)
- .HasColumnType("TEXT");
-
- b.HasKey("Id");
-
- b.ToTable("Champion", (string)null);
- });
-
- modelBuilder.Entity("EntityFramework.LargeImageEntity", b =>
- {
- b.Property("Id")
- .ValueGeneratedOnAdd()
- .HasColumnType("INTEGER");
-
- b.Property("Base64")
- .IsRequired()
- .HasColumnType("TEXT");
-
- b.HasKey("Id");
-
- b.ToTable("Image");
- });
-
- modelBuilder.Entity("EntityFramework.SkillEntity", b =>
- {
- b.Property("Name")
- .HasColumnType("TEXT");
-
- b.Property("ChampionEntityId")
- .HasColumnType("INTEGER");
-
- b.Property("Description")
- .IsRequired()
- .HasColumnType("TEXT");
-
- b.Property("Type")
- .HasColumnType("INTEGER");
-
- b.HasKey("Name");
-
- b.HasIndex("ChampionEntityId");
-
- b.ToTable("SkillEntity");
- });
-
- modelBuilder.Entity("EntityFramework.SkinEntity", b =>
- {
- b.Property("Name")
- .ValueGeneratedOnAdd()
- .HasColumnType("TEXT");
-
- b.Property("ChampionEntityForeignKey")
- .HasColumnType("INTEGER");
-
- b.Property("Description")
- .HasColumnType("TEXT");
-
- b.Property("Icon")
- .IsRequired()
- .HasColumnType("TEXT");
-
- b.Property("Image")
- .HasColumnType("TEXT");
-
- b.Property("Price")
- .HasColumnType("REAL");
-
- b.HasKey("Name");
-
- b.HasIndex("ChampionEntityForeignKey");
-
- b.ToTable("Skins");
- });
-
- modelBuilder.Entity("EntityFramework.SkillEntity", b =>
- {
- b.HasOne("EntityFramework.ChampionEntity", null)
- .WithMany("Skills")
- .HasForeignKey("ChampionEntityId");
- });
-
- modelBuilder.Entity("EntityFramework.SkinEntity", b =>
- {
- b.HasOne("EntityFramework.ChampionEntity", "Champion")
- .WithMany("skins")
- .HasForeignKey("ChampionEntityForeignKey")
- .OnDelete(DeleteBehavior.Cascade)
- .IsRequired();
-
- b.Navigation("Champion");
- });
-
- modelBuilder.Entity("EntityFramework.ChampionEntity", b =>
- {
- b.Navigation("Skills");
-
- b.Navigation("skins");
- });
-#pragma warning restore 612, 618
- }
- }
-}
diff --git a/Sources/EntityFramework/Migrations/LoLDBContextWithStubModelSnapshot.cs b/Sources/EntityFramework/Migrations/LoLDBContextWithStubModelSnapshot.cs
new file mode 100644
index 0000000..ba61c51
--- /dev/null
+++ b/Sources/EntityFramework/Migrations/LoLDBContextWithStubModelSnapshot.cs
@@ -0,0 +1,80 @@
+//
+using EntityFramework;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+
+#nullable disable
+
+namespace EntityFramework.Migrations
+{
+ [DbContext(typeof(LoLDBContextWithStub))]
+ partial class LoLDBContextWithStubModelSnapshot : ModelSnapshot
+ {
+ protected override void BuildModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder.HasAnnotation("ProductVersion", "7.0.2");
+
+ modelBuilder.Entity("EntityFramework.ChampionEntity", b =>
+ {
+ b.Property("Name")
+ .HasMaxLength(50)
+ .HasColumnType("TEXT");
+
+ b.Property("Bio")
+ .IsRequired()
+ .HasMaxLength(500)
+ .HasColumnType("string")
+ .HasColumnName("Bio");
+
+ b.Property("Icon")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.HasKey("Name");
+
+ b.ToTable("Champion", (string)null);
+
+ b.HasData(
+ new
+ {
+ Name = "Akali",
+ Bio = "",
+ Icon = ""
+ },
+ new
+ {
+ Name = "Aatrox",
+ Bio = "",
+ Icon = ""
+ },
+ new
+ {
+ Name = "Ahri",
+ Bio = "",
+ Icon = ""
+ },
+ new
+ {
+ Name = "Akshan",
+ Bio = "",
+ Icon = ""
+ },
+ new
+ {
+ Name = "Bard",
+ Bio = "",
+ Icon = ""
+ },
+ new
+ {
+ Name = "Alistar",
+ Bio = "",
+ Icon = ""
+ });
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/Sources/EntityFramework/Migrations/LoLDbContextModelSnapshot.cs b/Sources/EntityFramework/Migrations/LoLDbContextModelSnapshot.cs
deleted file mode 100644
index 410088f..0000000
--- a/Sources/EntityFramework/Migrations/LoLDbContextModelSnapshot.cs
+++ /dev/null
@@ -1,142 +0,0 @@
-//
-using System;
-using EntityFramework;
-using Microsoft.EntityFrameworkCore;
-using Microsoft.EntityFrameworkCore.Infrastructure;
-using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
-
-#nullable disable
-
-namespace EntityFramework.Migrations
-{
- [DbContext(typeof(LoLDbContext))]
- partial class LoLDbContextModelSnapshot : ModelSnapshot
- {
- protected override void BuildModel(ModelBuilder modelBuilder)
- {
-#pragma warning disable 612, 618
- modelBuilder.HasAnnotation("ProductVersion", "7.0.2");
-
- modelBuilder.Entity("EntityFramework.ChampionEntity", b =>
- {
- b.Property("Id")
- .ValueGeneratedOnAdd()
- .HasColumnType("INTEGER");
-
- b.Property("Bio")
- .IsRequired()
- .HasMaxLength(500)
- .HasColumnType("string")
- .HasColumnName("Bio");
-
- b.Property("Icon")
- .IsRequired()
- .HasColumnType("TEXT");
-
- b.Property("Image")
- .HasColumnType("TEXT");
-
- b.Property("Name")
- .IsRequired()
- .HasMaxLength(50)
- .HasColumnType("TEXT");
-
- b.HasKey("Id");
-
- b.ToTable("Champion", (string)null);
- });
-
- modelBuilder.Entity("EntityFramework.LargeImageEntity", b =>
- {
- b.Property("Id")
- .ValueGeneratedOnAdd()
- .HasColumnType("INTEGER");
-
- b.Property("Base64")
- .IsRequired()
- .HasColumnType("TEXT");
-
- b.HasKey("Id");
-
- b.ToTable("Image");
- });
-
- modelBuilder.Entity("EntityFramework.SkillEntity", b =>
- {
- b.Property("Name")
- .HasColumnType("TEXT");
-
- b.Property("ChampionEntityId")
- .HasColumnType("INTEGER");
-
- b.Property("Description")
- .IsRequired()
- .HasColumnType("TEXT");
-
- b.Property("Type")
- .HasColumnType("INTEGER");
-
- b.HasKey("Name");
-
- b.HasIndex("ChampionEntityId");
-
- b.ToTable("SkillEntity");
- });
-
- modelBuilder.Entity("EntityFramework.SkinEntity", b =>
- {
- b.Property("Name")
- .ValueGeneratedOnAdd()
- .HasColumnType("TEXT");
-
- b.Property("ChampionEntityForeignKey")
- .HasColumnType("INTEGER");
-
- b.Property("Description")
- .HasColumnType("TEXT");
-
- b.Property("Icon")
- .IsRequired()
- .HasColumnType("TEXT");
-
- b.Property("Image")
- .HasColumnType("TEXT");
-
- b.Property("Price")
- .HasColumnType("REAL");
-
- b.HasKey("Name");
-
- b.HasIndex("ChampionEntityForeignKey");
-
- b.ToTable("Skins");
- });
-
- modelBuilder.Entity("EntityFramework.SkillEntity", b =>
- {
- b.HasOne("EntityFramework.ChampionEntity", null)
- .WithMany("Skills")
- .HasForeignKey("ChampionEntityId");
- });
-
- modelBuilder.Entity("EntityFramework.SkinEntity", b =>
- {
- b.HasOne("EntityFramework.ChampionEntity", "Champion")
- .WithMany("skins")
- .HasForeignKey("ChampionEntityForeignKey")
- .OnDelete(DeleteBehavior.Cascade)
- .IsRequired();
-
- b.Navigation("Champion");
- });
-
- modelBuilder.Entity("EntityFramework.ChampionEntity", b =>
- {
- b.Navigation("Skills");
-
- b.Navigation("skins");
- });
-#pragma warning restore 612, 618
- }
- }
-}
diff --git a/Sources/EntityFramework/champion.db b/Sources/EntityFramework/champion.db
deleted file mode 100644
index 95e56f3..0000000
Binary files a/Sources/EntityFramework/champion.db and /dev/null differ
diff --git a/Sources/LeagueOfLegends.sln b/Sources/LeagueOfLegends.sln
index 6415543..a5d27bb 100644
--- a/Sources/LeagueOfLegends.sln
+++ b/Sources/LeagueOfLegends.sln
@@ -7,8 +7,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Model", "Model\Model.csproj
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}"
@@ -20,10 +18,13 @@ EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DTO", "DTO\DTO.csproj", "{E39C3FBC-DE5E-4DAF-945A-98CE4ADE54D9}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EntityFramework", "EntityFramework\EntityFramework.csproj", "{23483395-5091-4956-822F-17234E8C9E5C}"
+ ProjectSection(ProjectDependencies) = postProject
+ {2960F9BA-49DE-494D-92E3-CE5A794BA1A9} = {2960F9BA-49DE-494D-92E3-CE5A794BA1A9}
+ EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Api_UT", "Api_UT\Api_UT.csproj", "{20A1A7DC-1E93-4506-BD32-8597A5DADD7B}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EF_UT", "EF_UT\EF_UT.csproj", "{74F469C3-A94A-4507-9DC7-7DBADCD18173}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EF_UT", "EF_UT\EF_UT.csproj", "{74F469C3-A94A-4507-9DC7-7DBADCD18173}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -35,10 +36,6 @@ Global
{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
@@ -72,7 +69,6 @@ Global
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}
{20A1A7DC-1E93-4506-BD32-8597A5DADD7B} = {C76D0C23-1FFA-4963-93CD-E12BD643F030}
{74F469C3-A94A-4507-9DC7-7DBADCD18173} = {C76D0C23-1FFA-4963-93CD-E12BD643F030}