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.

58 lines
1.2 KiB

using EFLol;
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
namespace TestUnitaire
{
public class TestEfLol
{
[Fact]
public async Task TestAddInMemory()
{
// Arrange
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",
Bio = "Zeus is the king of the gods."
};
var Poseidon = new ChampionEntity
{
Name = "Poseidon",
Bio = "Poseidon is the king of the sea."
};
ChampionEntity found = await context.Champions.SingleOrDefaultAsync(c => c.Name == "Zeus");
Assert.Null(found);
await context.Champions.AddAsync(Zeus);
await context.Champions.AddAsync(Poseidon);
await context.SaveChangesAsync();
found = await context.Champions.SingleOrDefaultAsync(c => c.Name == "Zeus");
Assert.NotNull(found);
Assert.Equal(2, await context.Champions.CountAsync());
Assert.Equal("Zeus", found.Name);
}
}
}
}