You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

133 lines
4.3 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using EFlib;
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using StubEF;
using Xunit;
namespace TestEF
{
public class UniTestChampion
{
[Fact]
public async Task GetChampion_Test()
{
//connection must be opened to use In-memory database
var connection = new SqliteConnection("DataSource =:memory:");
connection.Open();
var options = new DbContextOptionsBuilder<SQLiteContext>().UseSqlite(connection).Options;
using (var context = new StubEFChampions(options))
{
//context.Database.OpenConnection();
await context.Database.EnsureCreatedAsync(); //pour créer la base si elle n'existe pas déjà
var champs = context.Champions.SingleOrDefault(c=> c.Name == "Akali");
Assert.NotNull(champs);
Assert.Equal("Akali", champs.Name);
}
}
/*
[Fact]
public void Modify_Test()
{
//connection must be opened to use In-memory database
var connection = new SqliteConnection("DataSource=:memory:");
connection.Open();
var options = new DbContextOptionsBuilder<NounoursContext>()
.UseSqlite(connection)
.Options;
//prepares the database with one instance of the context
using (var context = new NounoursContext(options))
{
//context.Database.OpenConnection();
context.Database.EnsureCreated();
Nounours chewie = new Nounours { Nom = "Chewbacca" };
Nounours yoda = new Nounours { Nom = "Yoda" };
Nounours ewok = new Nounours { Nom = "Ewok" };
context.Nounours.Add(chewie);
context.Nounours.Add(yoda);
context.Nounours.Add(ewok);
context.SaveChanges();
}
//uses another instance of the context to do the tests
using (var context = new NounoursContext(options))
{
context.Database.EnsureCreated();
string nameToFind = "ew";
Assert.Equal(2, context.Nounours.Where(n => n.Nom.ToLower().Contains(nameToFind)).Count());
nameToFind = "wo";
Assert.Equal(1, context.Nounours.Where(n => n.Nom.ToLower().Contains(nameToFind)).Count());
var ewok = context.Nounours.Where(n => n.Nom.ToLower().Contains(nameToFind)).First();
ewok.Nom = "Wicket";
context.SaveChanges();
}
//uses another instance of the context to do the tests
using (var context = new NounoursContext(options))
{
context.Database.EnsureCreated();
string nameToFind = "ew";
Assert.Equal(1, context.Nounours.Where(n => n.Nom.ToLower().Contains(nameToFind)).Count());
nameToFind = "wick";
Assert.Equal(1, context.Nounours.Where(n => n.Nom.ToLower().Contains(nameToFind)).Count());
}
}*/
/*
[SetUp]
public void Setup()
{
}
[Test]
public void TestGET()
{
//Arrange
//Act
var championResult = ChampionController.get();
//Assert
var objectResult = championResult as OkObjectResult;
//vérifie que cest un ok 200 et un objet
Assert.IsNotNull(objectResult);
var champions = objectResult?.Value as IEnumerable<ChampionDto>;
Assert.IsNotNull(champions);
Assert.AreEqual(champions.Count(), (await StubData.championsMgr.getItems(0, 5)).Count());
}
[Test]
public void TestPOST()
{
//Arrange
var championDto = new ChampionDto()
{
Name = "Darius"
};
//Act
var championResult = await ChampionController.post(championDto);
//Assert
var objectResult = championResult as CreatedAtActionResult;
Assert.IsNotNull(objectResult);
var champions = objectResult?.Value as ChampionDto;
Assert.IsNotNull(champions);
}*/
}
}