|
|
@ -2,6 +2,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using EFLol;
|
|
|
|
using EFLol;
|
|
|
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
|
|
|
|
|
|
namespace TestUnitaire
|
|
|
|
namespace TestUnitaire
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -32,6 +33,79 @@ namespace TestUnitaire
|
|
|
|
Assert.Equal("Zeus", champion.Name);
|
|
|
|
Assert.Equal("Zeus", champion.Name);
|
|
|
|
Assert.Equal("Zeus is the king of the gods.", champion.Bio);
|
|
|
|
Assert.Equal("Zeus is the king of the gods.", champion.Bio);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//InMemoryTest
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
|
|
public void AddInMemory()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var options = new DbContextOptionsBuilder<ChampionContext>()
|
|
|
|
|
|
|
|
.UseInMemoryDatabase(databaseName: "Add_Test_database").Options;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//prepares the database with one instance of the context
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using (var context = new ChampionContext(options))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
ChampionEntity chewie = new ChampionEntity { Name = "Chewbacca", Bio = "Zeus is the king of the gods." };
|
|
|
|
|
|
|
|
ChampionEntity yoda = new ChampionEntity { Name = "Yoda", Bio = "Zeus is the king of the gods." };
|
|
|
|
|
|
|
|
ChampionEntity ewok = new ChampionEntity { Name = "Ewok", Bio = "Zeus is the king of the gods." };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context.Champions.Add(chewie);
|
|
|
|
|
|
|
|
context.Champions.Add(yoda);
|
|
|
|
|
|
|
|
context.Champions.Add(ewok);
|
|
|
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//prepares the database with one instance of the context
|
|
|
|
|
|
|
|
using (var context = new ChampionContext(options))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Assert.Equal(3, context.Champions.Count());
|
|
|
|
|
|
|
|
Assert.Equal("Chewbacca", context.Champions.First().Name);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
|
|
public void ModifyTestInMemory()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var options = new DbContextOptionsBuilder<ChampionContext>()
|
|
|
|
|
|
|
|
.UseInMemoryDatabase(databaseName: "Modify_Test_database")
|
|
|
|
|
|
|
|
.Options;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//prepares the database with one instance of the context
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using (var context = new ChampionContext(options))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
ChampionEntity chewie = new ChampionEntity { Name = "Chewbacca", Bio = "Zeus is the king of the gods." };
|
|
|
|
|
|
|
|
ChampionEntity yoda = new ChampionEntity { Name = "Yoda", Bio = "Zeus is the king of the gods." };
|
|
|
|
|
|
|
|
ChampionEntity ewok = new ChampionEntity { Name = "Ewok", Bio = "Zeus is the king of the gods." };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context.Champions.Add(chewie);
|
|
|
|
|
|
|
|
context.Champions.Add(yoda);
|
|
|
|
|
|
|
|
context.Champions.Add(ewok);
|
|
|
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//prepares the database with one instance of the context
|
|
|
|
|
|
|
|
using (var context = new ChampionContext(options))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
string nameToFind = "ew";
|
|
|
|
|
|
|
|
Assert.Equal(2, context.Champions.Where(n => n.Name.ToLower().Contains(nameToFind)).Count());
|
|
|
|
|
|
|
|
nameToFind = "ewo";
|
|
|
|
|
|
|
|
Assert.Equal(1, context.Champions.Where(n => n.Name.ToLower().Contains(nameToFind)).Count());
|
|
|
|
|
|
|
|
var ewok = context.Champions.Where(n => n.Name.ToLower().Contains(nameToFind)).First();
|
|
|
|
|
|
|
|
ewok.Name = "Wicket";
|
|
|
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//prepares the database with one instance of the context
|
|
|
|
|
|
|
|
using (var context = new ChampionContext(options))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
string nameToFind = "ew";
|
|
|
|
|
|
|
|
Assert.Equal(1, context.Champions.Where(n => n.Name.ToLower().Contains(nameToFind)).Count());
|
|
|
|
|
|
|
|
nameToFind = "wick";
|
|
|
|
|
|
|
|
Assert.Equal(1, context.Champions.Where(n => n.Name.ToLower().Contains(nameToFind)).Count());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|