🧪 ajout des tests d'ajout et de modification pour l'EF et ajout de l'enum de Classes de champion. 🍱

pull/10/head
Pierre Ferreira 2 years ago
parent 8c351406f5
commit 792f3140a6

@ -1,46 +0,0 @@
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EntityFramework;
using System.Threading.Tasks;
namespace Api_UT
{
[TestClass]
public class EntityTest
{
[TestMethod]
public void TestAdd()
{
var options = new DbContextOptionsBuilder<LoLDbContext>()
.UseInMemoryDatabase(databaseName: "Add_Test_database").Options;
//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 ewok = new ChampionEntity("Ewok");
Console.WriteLine("Creates and inserts new Champion for tests");
context.Add(chewie);
context.Add(yoda);
context.Add(ewok);
context.SaveChanges();
}
//prepares the database with one instance of the context
using (var context = new LoLDbContext(options))
{
Assert.AreEqual(3, context.Champions.Count());
Assert.AreEqual("Chewbacca", context.Champions.First().name);
}
}
}
}

@ -6,4 +6,9 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Model\Model.csproj" />
<ProjectReference Include="..\StubLib\StubLib.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,30 @@
//using Model;
//using StubLib;
//var builder = WebApplication.CreateBuilder(args);
//// Add services to the container.
//builder.Services.AddControllers();
//// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
//builder.Services.AddEndpointsApiExplorer();
//builder.Services.AddSwaggerGen();
//builder.Services.AddScoped<IDataManager,StubData>();
//var app = builder.Build();
//// Configure the HTTP request pipeline.
//if (app.Environment.IsDevelopment())
//{
// app.UseSwagger();
// app.UseSwaggerUI();
//}
//app.UseHttpsRedirection();
//app.UseAuthorization();
//app.MapControllers();
//app.Run();

@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
<PackageReference Include="coverlet.collector" Version="3.1.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\API_LoL\API_LoL.csproj" />
<ProjectReference Include="..\Api_UT\Api_UT.csproj" />
<ProjectReference Include="..\DTO\DTO.csproj" />
<ProjectReference Include="..\EntityFramework\EntityFramework.csproj" />
<ProjectReference Include="..\Model\Model.csproj" />
<ProjectReference Include="..\StubLib\StubLib.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,87 @@
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EntityFramework;
using System.Threading.Tasks;
namespace EF_UT
{
[TestClass]
public class EntityTest
{
[TestMethod]
public void TestAdd()
{
var options = new DbContextOptionsBuilder<LoLDbContext>()
.UseInMemoryDatabase(databaseName: "Add_Test_database").Options;
//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 ewok = new ChampionEntity("Ewok");
Console.WriteLine("Creates and inserts new Champion for tests");
context.Add(chewie);
context.Add(yoda);
context.Add(ewok);
context.SaveChanges();
}
//prepares the database with one instance of the context
using (var context = new LoLDbContext(options))
{
Assert.AreEqual(3, context.Champions.Count());
Assert.AreEqual("Chewbacca", context.Champions.First().name);
}
}
[TestMethod]
public void TestUpdate()
{
var options = new DbContextOptionsBuilder<LoLDbContext>()
.UseInMemoryDatabase(databaseName: "Modify_Test_database")
.Options;
//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 ewok = new ChampionEntity("Ewok");
context.Add(chewie);
context.Add(yoda);
context.Add(ewok);
context.SaveChanges();
}
//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";
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());
}
}
}
}

@ -0,0 +1 @@
global using Microsoft.VisualStudio.TestTools.UnitTesting;

@ -15,6 +15,7 @@ namespace EntityFramework
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
public string name { get; set; }
public ChampionClass Class { get; set; }
public ChampionEntity(string name) {

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EntityFramework
{
public enum ChampionClass
{
Unknown,
Assassin,
Fighter,
Mage,
Marksman,
Support,
Tank
}
}

@ -23,6 +23,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EntityFramework", "EntityFr
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}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -61,6 +63,10 @@ Global
{20A1A7DC-1E93-4506-BD32-8597A5DADD7B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{20A1A7DC-1E93-4506-BD32-8597A5DADD7B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{20A1A7DC-1E93-4506-BD32-8597A5DADD7B}.Release|Any CPU.Build.0 = Release|Any CPU
{74F469C3-A94A-4507-9DC7-7DBADCD18173}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{74F469C3-A94A-4507-9DC7-7DBADCD18173}.Debug|Any CPU.Build.0 = Debug|Any CPU
{74F469C3-A94A-4507-9DC7-7DBADCD18173}.Release|Any CPU.ActiveCfg = Release|Any CPU
{74F469C3-A94A-4507-9DC7-7DBADCD18173}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -69,6 +75,7 @@ Global
{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}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {92F3083D-793F-4552-8A9A-0AD6534159C9}

Loading…
Cancel
Save