diff --git a/Sources/TestUnitaire/TestEfLol.cs b/Sources/TestUnitaire/TestEfLol.cs index b8c0440..d9bae90 100644 --- a/Sources/TestUnitaire/TestEfLol.cs +++ b/Sources/TestUnitaire/TestEfLol.cs @@ -1,12 +1,14 @@ -using EFLol; -using Microsoft.Data.Sqlite; -using Microsoft.EntityFrameworkCore; - -namespace TestUnitaire -{ - public class TestEfLol - { +using EFLol; +using Microsoft.Data.Sqlite; +using Microsoft.EntityFrameworkCore; + +namespace TestUnitaire +{ + public class TestEfLol + { + [Theory] + [InlineData("Zeus", "Dieu de la foudre", true)] [InlineData("Hades", "Dieu des enfers", 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", false)] public async Task TestAddInMemory(String name, String bio, bool expected) - { - var connection = new SqliteConnection("DataSource=:memory:"); - connection.Open(); - - var options = new DbContextOptionsBuilder() - .UseSqlite(connection) - .Options; - - // Act - using (var context = new MyDbContext(options)) - { - await context.Database.EnsureCreatedAsync(); - var Dieu = new ChampionEntity - { - Name = name, - Bio = bio - }; - - ChampionEntity found = await context.Champions.SingleOrDefaultAsync(c => c.Name == "Zeus"); - Assert.Null(found); - - await context.Champions.AddAsync(Dieu); - await context.SaveChangesAsync(); - - found = await context.Champions.SingleOrDefaultAsync(c => c.Name == name); - Assert.NotNull(found); - - Assert.Equal(1, await context.Champions.CountAsync()); - Assert.Equal(name, found.Name); + { + var connection = new SqliteConnection("DataSource=:memory:"); + connection.Open(); + + var options = new DbContextOptionsBuilder() + .UseSqlite(connection) + .Options; + + using (var context = new MyDbContext(options)) + { + await context.Database.EnsureCreatedAsync(); + var Dieu = new ChampionEntity + { + Name = name, + Bio = bio + }; + + ChampionEntity found = await context.Champions.SingleOrDefaultAsync(c => c.Name == "Zeus"); + Assert.Null(found); + + await context.Champions.AddAsync(Dieu); + await context.SaveChangesAsync(); + + found = await context.Champions.SingleOrDefaultAsync(c => c.Name == name); + Assert.NotNull(found); + + Assert.Equal(1, await context.Champions.CountAsync()); + 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) if (expected) @@ -56,11 +57,11 @@ namespace TestUnitaire Assert.False(found.Bio.Length <= 256); Assert.False(found.Name.Length <= 30); } - } + } + + } - } - - [Fact] + [Fact] public void ModifyTestInMemory() { 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()); } } - } + } } \ No newline at end of file