save
continuous-integration/drone/push Build is failing Details

pull/2/head
Bastien OLLIER 2 years ago
parent efd8563e08
commit f249d70e64

@ -1,12 +1,14 @@
using EFLol; using EFLol;
using Microsoft.Data.Sqlite; using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace TestUnitaire namespace TestUnitaire
{ {
public class TestEfLol public class TestEfLol
{ {
[Theory] [Theory]
[InlineData("Zeus", "Dieu de la foudre", true)] [InlineData("Zeus", "Dieu de la foudre", true)]
[InlineData("Hades", "Dieu des enfers", true)] [InlineData("Hades", "Dieu des enfers", true)]
[InlineData("Aphrodite", "Déesse de l'amour", true)] [InlineData("Aphrodite", "Déesse de l'amour", true)]
@ -15,35 +17,34 @@ namespace TestUnitaire
"Dieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerre" + "Dieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerre" +
"Dieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerre", false)] "Dieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerre", false)]
public async Task TestAddInMemory(String name, String bio, bool expected) public async Task TestAddInMemory(String name, String bio, bool expected)
{ {
var connection = new SqliteConnection("DataSource=:memory:"); var connection = new SqliteConnection("DataSource=:memory:");
connection.Open(); connection.Open();
var options = new DbContextOptionsBuilder<MyDbContext>() var options = new DbContextOptionsBuilder<MyDbContext>()
.UseSqlite(connection) .UseSqlite(connection)
.Options; .Options;
// Act using (var context = new MyDbContext(options))
using (var context = new MyDbContext(options)) {
{ await context.Database.EnsureCreatedAsync();
await context.Database.EnsureCreatedAsync(); var Dieu = new ChampionEntity
var Dieu = new ChampionEntity {
{ Name = name,
Name = name, Bio = bio
Bio = bio };
};
ChampionEntity found = await context.Champions.SingleOrDefaultAsync(c => c.Name == "Zeus");
ChampionEntity found = await context.Champions.SingleOrDefaultAsync(c => c.Name == "Zeus"); Assert.Null(found);
Assert.Null(found);
await context.Champions.AddAsync(Dieu);
await context.Champions.AddAsync(Dieu); await context.SaveChangesAsync();
await context.SaveChangesAsync();
found = await context.Champions.SingleOrDefaultAsync(c => c.Name == name);
found = await context.Champions.SingleOrDefaultAsync(c => c.Name == name); Assert.NotNull(found);
Assert.NotNull(found);
Assert.Equal(1, await context.Champions.CountAsync());
Assert.Equal(1, await context.Champions.CountAsync()); Assert.Equal(name, found.Name);
Assert.Equal(name, found.Name);
// Test if the max length of the name is respected (30) and the max length of the bio is respected (256) // Test if the max length of the name is respected (30) and the max length of the bio is respected (256)
if (expected) if (expected)
@ -56,11 +57,11 @@ namespace TestUnitaire
Assert.False(found.Bio.Length <= 256); Assert.False(found.Bio.Length <= 256);
Assert.False(found.Name.Length <= 30); Assert.False(found.Name.Length <= 30);
} }
} }
}
} [Fact]
[Fact]
public void ModifyTestInMemory() public void ModifyTestInMemory()
{ {
var connection = new SqliteConnection("DataSource=:memory:"); var connection = new SqliteConnection("DataSource=:memory:");
@ -112,5 +113,5 @@ namespace TestUnitaire
Assert.Equal(1, context.Champions.Where(n => n.Name.ToLower().Contains(nameToFind)).Count()); Assert.Equal(1, context.Champions.Where(n => n.Name.ToLower().Contains(nameToFind)).Count());
} }
} }
} }
} }
Loading…
Cancel
Save