Mise en commentaire d'interface non implémentée pour tests Drone et Sonar

pull/1/head
Théo DUPIN 2 years ago
parent da3b72a210
commit dd0e2d98e8

@ -27,7 +27,7 @@ namespace ConsoleAPI
}
// exécute la requête HTTP GET pour obtenir un champion par nom
HttpResponseMessage response1 = await client.GetAsync("/Akali");
HttpResponseMessage response1 = await client.GetAsync("/Bard");
if (response1.IsSuccessStatusCode)
{
@ -46,8 +46,8 @@ namespace ConsoleAPI
Name = "Ashe",
Bio = "La Comtesse du froid",
};
/*response = await client.PostAsync("/addChampion", new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(champion), System.Text.Encoding.UTF8, "application/json"));
HttpResponseMessage response = await client.PostAsync("/addChampion", Content);*/
/*response = await client.PostAsync("/addChampion", new StringContent("application/json"));
HttpResponseMessage responseMessage = await client.PostAsync("/addChampion", new StringContent("application/json"));*/
// vérifie si la réponse est valide
if (response.IsSuccessStatusCode)

@ -1,4 +1,5 @@
using EntityFrameworkLib.Mappers;
using EntityFrameworkLib;
using EntityFrameworkLib.Mappers;
using Model;
using Shared;
using System;
@ -7,7 +8,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EntityFrameworkLib
namespace DBDataManager
{
public class DBChampionManager : IChampionsManager
{
@ -53,55 +54,62 @@ namespace EntityFrameworkLib
return champions;
}
private Func<Champion, string, bool> filterByCharacteristic = (champ, charName) => champ.Characteristics.Keys.Any(k => k.Contains(charName, StringComparison.InvariantCultureIgnoreCase));
Task<IEnumerable<Champion?>> IChampionsManager.GetItemsByCharacteristic(string charName, int index, int count, string? orderingPropertyName, bool descending)
{
throw new NotImplementedException();
}
=> context.Champions.toPocos().GetItemsWithFilterAndOrdering(
champions => filterByCharacteristic(champions, charName),
index, count, orderingPropertyName, descending);
private Func<Champion, ChampionClass, bool> filterByClass = (champ, championClass) => champ.Class == championClass;
Task<IEnumerable<Champion?>> IChampionsManager.GetItemsByClass(ChampionClass championClass, int index, int count, string? orderingPropertyName, bool descending)
{
throw new NotImplementedException();
}
=> context.Champions.toPocos().GetItemsWithFilterAndOrdering(
champions => filterByClass(champions, championClass),
index, count, orderingPropertyName, descending);
private Func<Champion, string, bool> filterByName = (champ, substring) => champ.Name.Contains(substring, StringComparison.InvariantCultureIgnoreCase);
Task<IEnumerable<Champion?>> IGenericDataManager<Champion?>.GetItemsByName(string substring, int index, int count, string? orderingPropertyName, bool descending)
{
throw new NotImplementedException();
}
=> context.Champions.toPocos().GetItemsWithFilterAndOrdering(
champions => filterByName(champions, substring),
index, count, orderingPropertyName, descending);
Task<IEnumerable<Champion?>> IChampionsManager.GetItemsByRunePage(RunePage? runePage, int index, int count, string? orderingPropertyName, bool descending)
{
throw new NotImplementedException();
}
private Func<Champion, Skill?, bool> filterBySkill = (champ, skill) => skill != null && champ.Skills.Contains(skill!);
Task<IEnumerable<Champion?>> IChampionsManager.GetItemsBySkill(Skill? skill, int index, int count, string? orderingPropertyName, bool descending)
{
throw new NotImplementedException();
}
=> context.Champions.toPocos().GetItemsWithFilterAndOrdering(
champions => filterBySkill(champions, skill),
index, count, orderingPropertyName, descending);
private static Func<Champion, string, bool> filterBySkillSubstring = (champ, skill) => champ.Skills.Any(s => s.Name.Contains(skill, StringComparison.InvariantCultureIgnoreCase));
Task<IEnumerable<Champion?>> IChampionsManager.GetItemsBySkill(string skill, int index, int count, string? orderingPropertyName, bool descending)
{
throw new NotImplementedException();
}
=> context.Champions.toPocos().GetItemsWithFilterAndOrdering(
champions => filterBySkillSubstring(champions, skill),
index, count, orderingPropertyName, descending);
Task<int> IGenericDataManager<Champion?>.GetNbItems()
{
throw new NotImplementedException();
}
=> Task.FromResult(context.Champions.Count());
Task<int> IChampionsManager.GetNbItemsByCharacteristic(string charName)
{
throw new NotImplementedException();
}
=> context.Champions.toPocos().GetNbItemsWithFilter(
champions => filterByCharacteristic(champions, charName));
Task<int> IChampionsManager.GetNbItemsByClass(ChampionClass championClass)
{
throw new NotImplementedException();
}
=> context.Champions.toPocos().GetNbItemsWithFilter(
champions => filterByClass(champions, championClass));
Task<int> IGenericDataManager<Champion?>.GetNbItemsByName(string substring)
{
throw new NotImplementedException();
}
=> context.Champions.toPocos().GetNbItemsWithFilter(
champions => filterByName(champions, substring));
Task<int> IChampionsManager.GetNbItemsByRunePage(RunePage? runePage)
{
@ -109,18 +117,14 @@ namespace EntityFrameworkLib
}
Task<int> IChampionsManager.GetNbItemsBySkill(Skill? skill)
{
throw new NotImplementedException();
}
=> context.Champions.toPocos().GetNbItemsWithFilter(
champions => filterBySkill(champions, skill));
Task<int> IChampionsManager.GetNbItemsBySkill(string skill)
{
throw new NotImplementedException();
}
=> context.Champions.toPocos().GetNbItemsWithFilter(
champions => filterBySkillSubstring(champions, skill));
Task<Champion?> IGenericDataManager<Champion?>.UpdateItem(Champion? oldItem, Champion? newItem)
{
throw new NotImplementedException();
}
=> context.Champions.toPocos().UpdateItem(oldItem, newItem);
}
}

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\EntityFrameworkLib\EntityFrameworkLib.csproj" />
<ProjectReference Include="..\Model\Model.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,22 @@
using DBDataManager;
using Model;
using Shared;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DBDataManager
{
public class DBDataManager //: IDataManager
{
//public IChampionsManager ChampionsManager => new DBChampionManager();
//public ISkinsManager SkinsManager => throw new NotImplementedException();
//public IRunesManager RunesManager=> throw new NotImplementedException();
//public IRunePagesManager RunePagesManager=> throw new NotImplementedException();
}
}

@ -0,0 +1,60 @@
using EntityFrameworkLib;
using EntityFrameworkLib.Mappers;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DBDataManager
{
static class Extensions
{
internal static Task<IEnumerable<T?>> GetItemsWithFilterAndOrdering<T>(this IEnumerable<T> collection,
Func<T, bool> filter, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
IEnumerable<T> temp = collection;
temp = temp.Where(item => filter(item));
if (orderingPropertyName != null)
{
var prop = typeof(T).GetProperty(orderingPropertyName!);
if (prop != null)
{
temp = descending ? temp.OrderByDescending(item => prop.GetValue(item))
: temp.OrderBy(item => prop.GetValue(item));
}
}
return Task.FromResult<IEnumerable<T?>>(temp.Skip(index * count).Take(count));
}
public static IEnumerable<Champion> toPocos(this IEnumerable<ChampionEntity> champions)
{
List<Champion> result = new List<Champion>();
foreach(ChampionEntity champion in champions)
{
result.Add(champion.toModel());
}
return result;
}
internal static Task<int> GetNbItemsWithFilter<T>(this IEnumerable<T> collection, Func<T, bool> filter)
{
return Task.FromResult(collection.Count(item => filter(item)));
}
internal static Task<T?> UpdateItem<T>(this IList<T> collection, T? oldItem, T? newItem)
{
if (oldItem == null || newItem == null) return Task.FromResult<T?>(default(T));
if (!collection.Contains(oldItem))
{
return Task.FromResult<T?>(default(T));
}
collection.Remove(oldItem!);
collection.Add(newItem!);
return Task.FromResult<T?>(newItem);
}
}
}

@ -1,21 +0,0 @@
using Model;
using Shared;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EntityFrameworkLib
{
public class DBDataManager : IDataManager
{
public IChampionsManager ChampionsManager => new DBChampionManager();
public ISkinsManager SkinsManager => throw new NotImplementedException();
public IRunesManager RunesManager=> throw new NotImplementedException();
public IRunePagesManager RunePagesManager=> throw new NotImplementedException();
}
}

@ -29,7 +29,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleAPI", "ConsoleAPI\Co
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DBWithStub", "DBWithStub", "{F0711CE6-C48B-4E96-8DE0-79BDBB4635D6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DBEntitiesWithStub", "DBEntitiesWithStub\DBEntitiesWithStub.csproj", "{C9D40527-6F42-4FA9-8063-554D2A0E9161}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DBEntitiesWithStub", "DBEntitiesWithStub\DBEntitiesWithStub.csproj", "{C9D40527-6F42-4FA9-8063-554D2A0E9161}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DBDataManager", "DBDataManager\DBDataManager.csproj", "{9596049A-FCBB-4F61-9E48-D3086EAEFF85}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -77,6 +79,10 @@ Global
{C9D40527-6F42-4FA9-8063-554D2A0E9161}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C9D40527-6F42-4FA9-8063-554D2A0E9161}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C9D40527-6F42-4FA9-8063-554D2A0E9161}.Release|Any CPU.Build.0 = Release|Any CPU
{9596049A-FCBB-4F61-9E48-D3086EAEFF85}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9596049A-FCBB-4F61-9E48-D3086EAEFF85}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9596049A-FCBB-4F61-9E48-D3086EAEFF85}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9596049A-FCBB-4F61-9E48-D3086EAEFF85}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

@ -66,6 +66,12 @@ public class Champion : IEquatable<Champion>
Class = @class;
}
public Champion(string name, string bio)
{
this.name = name;
this.bio = bio;
}
public ReadOnlyCollection<Skin> Skins { get; private set; }
private List<Skin> skins = new ();

@ -35,7 +35,7 @@ namespace Web_Api.Controllers
}
[HttpPost("addChampion")]
public async Task<IActionResult> AddChampion(ChampionDTO champion)
public async Task<IActionResult> AddChampion([FromBody] ChampionDTO champion)
{
var newChampion = champion.toModel();
await ChampionsManager.AddItem(newChampion);
@ -48,7 +48,7 @@ namespace Web_Api.Controllers
}
[HttpPut("updateChampion")]
public async Task<IActionResult> UpdateChampion(string name, ChampionDTO champion)
public async Task<IActionResult> UpdateChampion(string name, [FromBody] ChampionDTO champion)
{
var championSelected = await ChampionsManager.GetItemsByName(name, 0, await ChampionsManager.GetNbItemsByName(name), null);
var existingChampion = championSelected.FirstOrDefault();

Loading…
Cancel
Save