add TestAddSkinToChampionInMemory
continuous-integration/drone/push Build is passing Details

EF2
bastien.ollier@gmail.com 2 years ago
parent e2a3c3e463
commit 636ae58e55

@ -18,6 +18,6 @@ namespace EFLol
//public LargeImage Image { get; set; } //public LargeImage Image { get; set; }
//public ReadOnlyDictionary<string, int> Characteristics { get; private set; } //public ReadOnlyDictionary<string, int> Characteristics { get; private set; }
//private HashSet<Skill> skills = new HashSet<Skill>(); //private HashSet<Skill> skills = new HashSet<Skill>();
public ReadOnlyCollection<SkinEntity> Skins { get; set; } public Collection<SkinEntity> Skins { get; set; }
} }
} }

@ -18,14 +18,14 @@ ChampionEntity Zeus = new ChampionEntity
{ {
Name = "Zeus", Name = "Zeus",
Bio = "Zeus is the god of the sky", Bio = "Zeus is the god of the sky",
Skins = new ReadOnlyCollection<SkinEntity>(new List<SkinEntity> { black, white }) Skins = new Collection<SkinEntity>(new List<SkinEntity> { black, white })
}; };
ChampionEntity Hera = new ChampionEntity ChampionEntity Hera = new ChampionEntity
{ {
Name = "Hera", Name = "Hera",
Bio = "Hera is the goddess of marriage", Bio = "Hera is the goddess of marriage",
Skins = new ReadOnlyCollection<SkinEntity>(new List<SkinEntity> { green }) Skins = new Collection<SkinEntity>(new List<SkinEntity> { green })
}; };
ChampionEntity Poseidon = new ChampionEntity { Name = "Poseidon", Bio = "Poseidon is the god of the sea" }; ChampionEntity Poseidon = new ChampionEntity { Name = "Poseidon", Bio = "Poseidon is the god of the sea" };

@ -1,6 +1,7 @@
using EFLol; using EFLol;
using Microsoft.Data.Sqlite; using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System.Collections.ObjectModel;
namespace TestUnitaire namespace TestUnitaire
{ {
@ -28,10 +29,16 @@ namespace TestUnitaire
using (var context = new MyDbContext(options)) using (var context = new MyDbContext(options))
{ {
await context.Database.EnsureCreatedAsync(); await context.Database.EnsureCreatedAsync();
SkinEntity black = new SkinEntity { Name = "Black", Description = "Black skin", Icon = "black.png", Price = 0.99f };
SkinEntity white = new SkinEntity { Name = "White", Description = "White skin", Icon = "white.png", Price = 150.99f };
SkinEntity green = new SkinEntity { Name = "Green", Description = "Green skin", Icon = "green.png", Price = 4.99f };
var Dieu = new ChampionEntity var Dieu = new ChampionEntity
{ {
Name = name, Name = name,
Bio = bio Bio = bio,
Skins = new Collection<SkinEntity>(new List<SkinEntity> { black, white, green })
}; };
ChampionEntity found = await context.Champions.SingleOrDefaultAsync(c => c.Name == "Zeus"); ChampionEntity found = await context.Champions.SingleOrDefaultAsync(c => c.Name == "Zeus");
@ -45,6 +52,7 @@ namespace TestUnitaire
Assert.Equal(1, await context.Champions.CountAsync()); Assert.Equal(1, await context.Champions.CountAsync());
Assert.Equal(name, found.Name); Assert.Equal(name, found.Name);
Assert.Equal(3,found.Skins.Count);
// 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)
@ -54,8 +62,8 @@ namespace TestUnitaire
} }
else else
{ {
Assert.False(found.Bio.Length <= 256);
Assert.False(found.Name.Length <= 30); Assert.False(found.Name.Length <= 30);
Assert.False(found.Bio.Length <= 256);
} }
} }
@ -113,5 +121,52 @@ 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());
} }
} }
[Theory]
[InlineData("black", "super Skin", "icon1.png",190000000.2f,true)]
[InlineData("White", "skin1", "icon1", 19, true)]
[InlineData("Green", "skin", "icon1.jpg", -1, false)]
public async Task TestAddSkinToChampionInMemory(String name, String description, String icon,float price,bool expected)
{
var connection = new SqliteConnection("DataSource=:memory:");
connection.Open();
var options = new DbContextOptionsBuilder<MyDbContext>()
.UseSqlite(connection)
.Options;
using (var context = new MyDbContext(options))
{
await context.Database.EnsureCreatedAsync();
var Dieu = new ChampionEntity
{
Name = "Zeus",
Bio = "Dieu de la foudre",
Skins = new Collection<SkinEntity>()
};
SkinEntity item = new SkinEntity
{
Name = name,
Description = description,
Icon = icon,
Price = price
};
Dieu.Skins.Add(item);
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);
}
}
} }
} }
Loading…
Cancel
Save