pull/2/head
nathan boileau 2 years ago
parent 7ec8f5408f
commit 523d3b2774

@ -2,35 +2,52 @@
using EFLol; using EFLol;
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
namespace TestUnitaire namespace TestUnitaire
{ {
public class TestEfLol public class TestEfLol
{ {
[Fact] [Fact]
public void TestAddIntoDB() public async Task TestAddInMemory()
{ {
// Arrange // Arrange
ChampionEntity Zeus = new ChampionEntity var connection = new SqliteConnection("DataSource=:memory:");
connection.Open();
var options = new DbContextOptionsBuilder<ChampionContext>()
.UseSqlite(connection)
.Options;
// Act
using (var context = new ChampionContext(options))
{
await context.Database.EnsureCreatedAsync();
var Zeus = new ChampionEntity
{ {
Name = "Zeus", Name = "Zeus",
Bio = "Zeus is the king of the gods." Bio = "Zeus is the king of the gods."
}; };
var Poseidon = new ChampionEntity
{
Name = "Poseidon",
Bio = "Poseidon is the king of the sea."
};
// Act ChampionEntity found = await context.Champions.SingleOrDefaultAsync(c => c.Name == "Zeus");
var context = new ChampionContext(); Assert.Null(found);
context.Champions.Add(Zeus);
context.SaveChanges();
// Assert await context.Champions.AddAsync(Zeus);
var champion = context.Champions.FirstOrDefault(c => c.Name == "Zeus"); await context.Champions.AddAsync(Poseidon);
if (champion == null) await context.SaveChangesAsync();
{
Assert.True(false, "Champion not found in database."); found = await context.Champions.SingleOrDefaultAsync(c => c.Name == "Zeus");
Assert.NotNull(found);
Assert.Equal(2, await context.Champions.CountAsync());
Assert.Equal("Zeus", found.Name);
} }
Assert.NotNull(champion);
Assert.Equal("Zeus", champion.Name);
Assert.Equal("Zeus is the king of the gods.", champion.Bio);
} }
} }
} }

Loading…
Cancel
Save