@ -1,4 +1,3 @@
using Microsoft.EntityFrameworkCore ;
using MyFlib ;
using Xunit ;
@ -20,9 +19,7 @@ namespace UT_EF
ChampionEntity hecarim = new ChampionEntity { Name = "Hecarim" , Class = ChampionClassEntity . Fighter , Bio = "" , Icon = "" , Image = "" } ;
ChampionEntity yuumi = new ChampionEntity { Name = "yuumi" , Class = ChampionClassEntity . Mage , Bio = "" , Icon = "" , Image = "" } ;
context . Champions . Add ( sylas ) ;
context . Champions . Add ( hecarim ) ;
context . Champions . Add ( yuumi ) ;
context . Champions . AddRange ( sylas , hecarim , yuumi ) ;
context . SaveChanges ( ) ;
}
@ -46,20 +43,22 @@ namespace UT_EF
ChampionEntity hecarim = new ChampionEntity { Name = "Hecarim" , Class = ChampionClassEntity . Fighter , Bio = "" , Icon = "" , Image = "" } ;
ChampionEntity yuumi = new ChampionEntity { Name = "yuumi" , Class = ChampionClassEntity . Mage , Bio = "" , Icon = "" , Image = "" } ;
context . Champions . Add ( sylas ) ;
context . Champions . Add ( hecarim ) ;
context . Champions . Add ( yuumi ) ;
context . Champions . AddRange ( sylas , hecarim , yuumi ) ;
context . SaveChanges ( ) ;
}
using ( var context = new LolDbContext ( options ) )
{
string nameToFind = "m" ;
ChampionClassEntity type = ChampionClassEntity . Fighter ;
Assert . Equal ( 2 , context . Champions . Where ( c = > c . Name . ToLower ( ) . Contains ( nameToFind ) ) . Count ( ) ) ;
Assert . Equal ( 1 , context . Champions . Where ( c = > c . Class = = type ) . Count ( ) ) ;
nameToFind = "yuu" ;
Assert . Equal ( 1 , context . Champions . Where ( c = > c . Name . ToLower ( ) . Contains ( nameToFind ) ) . Count ( ) ) ;
var ewok = context . Champions . Where ( c = > c . Name . ToLower ( ) . Contains ( nameToFind ) ) . First ( ) ;
ewok . Name = "Garen" ;
ewok . Bio = "Magic resist" ;
ewok . Class = type ;
context . SaveChanges ( ) ;
}
@ -68,8 +67,50 @@ namespace UT_EF
string nameToFind = "m" ;
Assert . Equal ( 1 , context . Champions . Where ( c = > c . Name . ToLower ( ) . Contains ( nameToFind ) ) . Count ( ) ) ;
nameToFind = "garen" ;
string bioToFind = "magic resist" ;
ChampionClassEntity type = ChampionClassEntity . Fighter ;
Assert . Equal ( 1 , context . Champions . Where ( c = > c . Name . ToLower ( ) . Contains ( nameToFind ) ) . Count ( ) ) ;
Assert . Equal ( 1 , context . Champions . Where ( c = > c . Bio . ToLower ( ) . Contains ( bioToFind ) ) . Count ( ) ) ;
Assert . Equal ( 2 , context . Champions . Where ( c = > c . Class = = type ) . Count ( ) ) ;
}
}
[Fact]
public void Delete_Test ( )
{
var options = new DbContextOptionsBuilder < LolDbContext > ( )
. UseInMemoryDatabase ( databaseName : "Delete_Test_database" )
. Options ;
using ( var context = new LolDbContext ( options ) )
{
ChampionEntity sylas = new ChampionEntity { Name = "Sylas" , Class = ChampionClassEntity . Assassin , Bio = "" , Icon = "" , Image = "" } ;
ChampionEntity hecarim = new ChampionEntity { Name = "Hecarim" , Class = ChampionClassEntity . Fighter , Bio = "" , Icon = "" , Image = "" } ;
ChampionEntity yuumi = new ChampionEntity { Name = "yuumi" , Class = ChampionClassEntity . Mage , Bio = "" , Icon = "" , Image = "" } ;
context . Champions . AddRange ( sylas , hecarim , yuumi ) ;
context . SaveChanges ( ) ;
}
using ( var context = new LolDbContext ( options ) )
{
var ewok = context . Champions . First ( ) ;
string nameToFind = "sylas" ;
Assert . Equal ( 1 , context . Champions . Where ( c = > c . Name . ToLower ( ) . Contains ( nameToFind ) ) . Count ( ) ) ;
Assert . Equal ( 3 , context . Champions . Count ( ) ) ;
context . Champions . Remove ( ewok ) ;
context . SaveChanges ( ) ;
}
using ( var context = new LolDbContext ( options ) )
{
string nameToFind = "sylas" ;
Assert . Equal ( 0 , context . Champions . Where ( c = > c . Name . ToLower ( ) . Contains ( nameToFind ) ) . Count ( ) ) ;
Assert . Equal ( 2 , context . Champions . Count ( ) ) ;
}
}
}
}