Implement add

pull/27/head
Corentin R 2 years ago
parent 1a753c2926
commit 6f6fc4c5e0

@ -0,0 +1,26 @@
using EntityFramework;
using EntityFramework.Manager;
using FluentAssertions;
using Microsoft.EntityFrameworkCore;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EF_UT
{
[TestClass]
public class EFDataManagerChampionTest
{
[TestMethod]
public void Add_ValidChampion_Added()
{
IDataManager dataManager = new EFDataManager();
IChampionsManager championsManager = dataManager.ChampionsMgr;
var champ = championsManager.AddItem(new Champion("test"));
}
}
}

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
@ -8,6 +8,14 @@
<StartWorkingDirectory>$(MSBuildProjectDirectory)</StartWorkingDirectory>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Manager\EFDataManager.Champion.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Manager\EFDataManager.Champion.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.2" />
@ -18,6 +26,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Model\Model.csproj" />
<ProjectReference Include="..\StubLib\StubLib.csproj" />
</ItemGroup>

@ -0,0 +1,124 @@
using EntityFramework.Mapper;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EntityFramework.Manager
{
public partial class EFDataManager
{
public class ChampionsManager : IChampionsManager
{
private readonly EFDataManager parent;
public ChampionsManager(EFDataManager parent)
{
this.parent = parent;
}
public async Task<Champion?> AddItem(Champion? item)
{
using(var context = new LoLDBContextWithStub())
{
if (item != null)
{
context.Add(item.ToEntity());
return item;
}
else
{
throw new Exception();
}
}
}
public Task<bool> DeleteItem(Champion? item)
{
throw new NotImplementedException();
}
public Task<IEnumerable<Champion?>> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false)
{
throw new NotImplementedException();
}
public Task<IEnumerable<Champion?>> GetItemsByCharacteristic(string charName, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
throw new NotImplementedException();
}
public Task<IEnumerable<Champion?>> GetItemsByClass(Model.ChampionClass championClass, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
throw new NotImplementedException();
}
public Task<IEnumerable<Champion?>> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
using (var context = new LoLDBContextWithStub())
{
IEnumerable<ChampionEntity> champ = context.Champions.Where(c => c.Name.Contains(substring));
return champ.
}
}
public Task<IEnumerable<Champion?>> GetItemsByRunePage(RunePage? runePage, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
throw new NotImplementedException();
}
public Task<IEnumerable<Champion?>> GetItemsBySkill(Skill? skill, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
throw new NotImplementedException();
}
public Task<IEnumerable<Champion?>> GetItemsBySkill(string skill, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
throw new NotImplementedException();
}
public Task<int> GetNbItems()
{
throw new NotImplementedException();
}
public Task<int> GetNbItemsByCharacteristic(string charName)
{
throw new NotImplementedException();
}
public Task<int> GetNbItemsByClass(Model.ChampionClass championClass)
{
throw new NotImplementedException();
}
public Task<int> GetNbItemsByName(string substring)
{
throw new NotImplementedException();
}
public Task<int> GetNbItemsByRunePage(RunePage? runePage)
{
throw new NotImplementedException();
}
public Task<int> GetNbItemsBySkill(Skill? skill)
{
throw new NotImplementedException();
}
public Task<int> GetNbItemsBySkill(string skill)
{
throw new NotImplementedException();
}
public Task<Champion?> UpdateItem(Champion? oldItem, Champion? newItem)
{
throw new NotImplementedException();
}
}
}
}

@ -0,0 +1,24 @@
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EntityFramework.Manager
{
public partial class EFDataManager : IDataManager
{
public EFDataManager() {
ChampionsMgr = new ChampionsManager(this);
}
public IChampionsManager ChampionsMgr { get; }
public ISkinsManager SkinsMgr { get; }
public IRunesManager RunesMgr { get; }
public IRunePagesManager RunePagesMgr { get; }
}
}

@ -12,5 +12,6 @@ namespace EntityFramework.Mapper
public static ChampionEntity ToEntity(this Champion champion) {
return new ChampionEntity(champion.Name, champion.Bio, champion.Icon);
}
}
}

Loading…
Cancel
Save