ef : premier test unitaire créé 🆒

là je finis le CRUD, et après faudra essayer de déployer
master
pasquizzat 2 years ago
parent ab1e33a816
commit 459400406c

@ -14,8 +14,8 @@ var dataMgr = new DataBdd();
List<Champion> list = dataMgr.ChampionsMgr.GetItems(0, dataMgr.ChampionsMgr.GetNbItems().Result).Result.ToList();
/*
ChampionContext data = new ChampionContext();
/*ChampionContext data = new ChampionContext();
data.Champs.ToList();
List<ChampionEntity> l = data.listChampions();*/

@ -35,6 +35,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApiDePaul", "ApiDePaul\ApiD
{B01D7EF2-2D64-409A-A29A-61FB7BB7A9DB} = {B01D7EF2-2D64-409A-A29A-61FB7BB7A9DB}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestsTresImportants", "TestsTresImportants\TestsTresImportants.csproj", "{4982C56F-3FB0-4BD0-AE03-CB157F9CAEF8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -73,6 +75,10 @@ Global
{245F7BAC-8487-4510-8066-D12B5B2B816B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{245F7BAC-8487-4510-8066-D12B5B2B816B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{245F7BAC-8487-4510-8066-D12B5B2B816B}.Release|Any CPU.Build.0 = Release|Any CPU
{4982C56F-3FB0-4BD0-AE03-CB157F9CAEF8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4982C56F-3FB0-4BD0-AE03-CB157F9CAEF8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4982C56F-3FB0-4BD0-AE03-CB157F9CAEF8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4982C56F-3FB0-4BD0-AE03-CB157F9CAEF8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

@ -8,15 +8,16 @@ namespace LibEntityFramework
{
public class ChampionContext : DbContext
{
public ChampionContext() { }
public ChampionContext(DbContextOptions<ChampionContext> options) : base(options) { }
public DbSet<ChampionEntity> Champs { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder options)
{
/*if (!options.IsConfigured)
if (!options.IsConfigured)
{
options.UseSqlite("DataSource=laBdd.db");
} */
options.UseSqlite("DataSource=laBdd.db");
}
}
}
}

@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Model2\LibEntityFramework.csproj" />
<ProjectReference Include="..\TrucAuMilieu\TrucAuMilieu.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,43 @@
using LibEntityFramework;
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using Model;
using TrucAuMilieu;
namespace TestsTresImportants
{
public class UTestsChampion
{
[Fact]
public void Test()
{
var connection = new SqliteConnection("DataSource=:memory:");
connection.Open();
var options = new DbContextOptionsBuilder<ChampionContext>()
.UseSqlite(connection)
.Options;
using (var context = new ChampionContext(options))
{
context.Database.EnsureCreated();
Champion c1 = new Champion("Joe");
Champion c2 = new Champion("Billy");
Champion c3 = new Champion("Robert");
context.Champs.Add(c1.ChampToEf());
context.Champs.Add(c2.ChampToEf());
context.Champs.Add(c3.ChampToEf());
context.SaveChanges();
}
using(var context= new ChampionContext(options))
{
context.Database.EnsureCreated();
Assert.Equal(3, context.Champs.Count());
Assert.Equal("Joe", context.Champs.First().Name);
}
}
}
}

@ -33,29 +33,25 @@ namespace TrucAuMilieu
public async Task<IEnumerable<Champion?>> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false)
{
if (descending)
if (orderingPropertyName != null)
{
return await Task.FromResult(parent.contextCh.Champs.OrderByDescending(c => typeof(ChampionEntity).GetProperty(orderingPropertyName)).Skip(index * count).Take(count).Select(ce => ce.EfToChamp()));
if (descending)
{
return await Task.FromResult(parent.contextCh.Champs.OrderByDescending(c => typeof(ChampionEntity).GetProperty(orderingPropertyName)).Skip(index * count).Take(count).Select(ce => ce.EfToChamp()));
}
else
{
var pap = await Task.FromResult(parent.contextCh.Champs.OrderBy(c => typeof(ChampionEntity).GetProperty(orderingPropertyName)).Skip(index * count).Take(count).Select(ce => ce.EfToChamp()));
return pap;
//ya une petite betise ça marche pas trop menfin bref c'est a corriger
}
}
else
{
var hi = parent.contextCh.Champs.OrderBy(c => typeof(ChampionEntity).GetProperty(orderingPropertyName)).Skip(index * count).Take(count).Select(ce => ce.EfToChamp());
return Task.FromResult(hi); //ya une petite betise ça marche pas trop menfin bref c'est a corriger
{
var pap2= await Task.FromResult(parent.contextCh.Champs.Skip(index*count).Take(count).Select(ce => ce.EfToChamp()));
return pap2;
}
}
/*
=> parent.contextCh.Champs.Take(count).Skip(index). /*
=> parent.contextCh..GetItemsWithFilterAndOrdering(
c => true,
index, count,
orderingPropertyName, descending);
{// hihihi les arguments servent à rien pour l'instant y'a zero arguments utilises oupsi
List<ChampionEntity> lch = parent.contextCh.Champs.Take(count).Skip(index).ToList();
List<Champion> items = new List<Champion>();
foreach (var c in lch) { items.Add(c.EfToChamp()); }
return items;
}*/
public Task<IEnumerable<Champion?>> GetItemsByCharacteristic(string charName, int index, int count, string? orderingPropertyName = null, bool descending = false)
{

Loading…
Cancel
Save