|
|
@ -46,40 +46,50 @@ namespace TestUnitaire
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
[Fact]
|
|
|
|
public void ModifyTestInMemory()
|
|
|
|
public void ModifyTestInMemory()
|
|
|
|
{
|
|
|
|
{//connection must be opened to use In-memory database
|
|
|
|
|
|
|
|
var connection = new SqliteConnection("DataSource=:memory:");
|
|
|
|
|
|
|
|
connection.Open();
|
|
|
|
|
|
|
|
|
|
|
|
var options = new DbContextOptionsBuilder<ChampionContext>()
|
|
|
|
var options = new DbContextOptionsBuilder<ChampionContext>()
|
|
|
|
.UseInMemoryDatabase(databaseName: "Modify_Test_database")
|
|
|
|
.UseSqlite(connection)
|
|
|
|
.Options;
|
|
|
|
.Options;
|
|
|
|
|
|
|
|
|
|
|
|
//prepares the database with one instance of the context
|
|
|
|
//prepares the database with one instance of the context
|
|
|
|
|
|
|
|
|
|
|
|
using (var context = new ChampionContext(options))
|
|
|
|
using (var context = new ChampionContext(options))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
//context.Database.OpenConnection();
|
|
|
|
|
|
|
|
context.Database.EnsureCreated();
|
|
|
|
|
|
|
|
|
|
|
|
ChampionEntity chewie = new ChampionEntity { Name = "Chewbacca", Bio = "Zeus is the king of the gods." };
|
|
|
|
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 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." };
|
|
|
|
ChampionEntity ewok = new ChampionEntity { Name = "Ewok", Bio = "Zeus is the king of the gods." };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context.Champions.Add(chewie);
|
|
|
|
context.Champions.Add(chewie);
|
|
|
|
context.Champions.Add(yoda);
|
|
|
|
context.Champions.Add(yoda);
|
|
|
|
context.Champions.Add(ewok);
|
|
|
|
context.Champions.Add(ewok);
|
|
|
|
context.SaveChanges();
|
|
|
|
context.SaveChanges();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//prepares the database with one instance of the context
|
|
|
|
//uses another instance of the context to do the tests
|
|
|
|
using (var context = new ChampionContext(options))
|
|
|
|
using (var context = new ChampionContext(options))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
context.Database.EnsureCreated();
|
|
|
|
|
|
|
|
|
|
|
|
string nameToFind = "ew";
|
|
|
|
string nameToFind = "ew";
|
|
|
|
Assert.Equal(2, context.Champions.Where(n => n.Name.ToLower().Contains(nameToFind)).Count());
|
|
|
|
Assert.Equal(2, context.Champions.Where(n => n.Name.ToLower().Contains(nameToFind)).Count());
|
|
|
|
nameToFind = "ewo";
|
|
|
|
nameToFind = "wo";
|
|
|
|
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());
|
|
|
|
var ewok = context.Champions.Where(n => n.Name.ToLower().Contains(nameToFind)).First();
|
|
|
|
var ewok = context.Champions.Where(n => n.Name.ToLower().Contains(nameToFind)).First();
|
|
|
|
ewok.Name = "Wicket";
|
|
|
|
ewok.Name = "Wicket";
|
|
|
|
context.SaveChanges();
|
|
|
|
context.SaveChanges();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//prepares the database with one instance of the context
|
|
|
|
//uses another instance of the context to do the tests
|
|
|
|
using (var context = new ChampionContext(options))
|
|
|
|
using (var context = new ChampionContext(options))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
context.Database.EnsureCreated();
|
|
|
|
|
|
|
|
|
|
|
|
string nameToFind = "ew";
|
|
|
|
string nameToFind = "ew";
|
|
|
|
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());
|
|
|
|
nameToFind = "wick";
|
|
|
|
nameToFind = "wick";
|
|
|
|