You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
WF-PmAPI/WF_EF_Api/ConsoleTest/Program.cs

135 lines
5.9 KiB

using Contextlib;
using Entity;
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
using StubbedContextLib;
using static System.Net.Mime.MediaTypeNames;
using static System.Net.WebRequestMethods;
var connection = new SqliteConnection("DataSource=:memory:");
connection.Open();
var options = new DbContextOptionsBuilder<WTFContext>()
.UseSqlite(connection)
.Options;
using (var _context = new StubWTFContext(options))
{
_context.Database.EnsureCreated();
// ---- Test Image ---- //
var imageManager = new DbImagesManager(_context);
await imageManager.AddImage(new Images() { Id = 0, ImgPath = "https://www.bing.com/ck/a?!&&p=390428c2820add92760900204667aa721b17d4eb9e8537c91544d76283d06b14JmltdHM9MTc0MjQyODgwMA&ptn=3&ver=2&hsh=4&fclid=297ef5ed-ac44-66f2-2498-e058adb06776&u=a1aHR0cHM6Ly93d3cucG9rZXBlZGlhLmZyL01hamFzcGlj&ntb=1" });
await imageManager.AddImage(new Images() { Id = 0, ImgPath = "https://www.bing.com/images/search?view=detailV2&ccid=t57OzeAT&id=1CCCBB65825E5FB93F10CA6D29EFDBBFEB5CDF27&thid=OIP.t57OzeATZKjBDDrzXqbc5gHaE7&mediaurl=https%3a%2f%2fimg-19.commentcamarche.net%2fP51ArxVXHJKsgdTzGDaqajlWJ3s%3d%2f1500x%2fsmart%2f7b5dd43e607643fea1a61960e3f66fc4%2fccmcms-commentcamarche%2f39481621.jpg&cdnurl=https%3a%2f%2fth.bing.com%2fth%2fid%2fR.b79ececde01364a8c10c3af35ea6dce6%3frik%3dJ99c67%252fb7yltyg%26pid%3dImgRaw%26r%3d0&exph=999&expw=1500&q=image&simid=608026907577902968&ck=0D54F216D075AD6E0ABC46B3AAB7E80A&selectedIndex=19&itb=0" });
Console.WriteLine("---- Test ajout image (id : 11, 12)");
var images = await imageManager.GetAllImage();
foreach (var image in images.items)
{
Console.WriteLine($"- ({image.Id}) : {(image.ImgPath.Length <= 40 ? image.ImgPath : image.ImgPath.Substring(0, 40)+"...")}");
}
Console.WriteLine("");
await imageManager.UpdateImage(12, new Images() { ImgPath = "https://testUpdate/stub"});
Console.WriteLine("---- Test mise a jour image (id : 12)");
images = await imageManager.GetAllImage();
foreach (var image in images.items)
{
Console.WriteLine($"- ({image.Id}) : {(image.ImgPath.Length <= 40 ? image.ImgPath : image.ImgPath.Substring(0, 40) + "...")}");
}
Console.WriteLine("");
await imageManager.RemoveImage(12);
Console.WriteLine("---- Test suppression image (id : 12)");
images = await imageManager.GetAllImage();
foreach (var image in images.items)
{
Console.WriteLine($"- ({image.Id}) : {(image.ImgPath.Length <= 40 ? image.ImgPath : image.ImgPath.Substring(0, 40) + "...")}");
}
Console.WriteLine("");
Console.WriteLine("---- Test getById image (id : 11)");
var img = await imageManager.GetImageById(11);
Console.WriteLine($"- ({img.Id}) : {(img.ImgPath.Length <= 40 ? img.ImgPath : img.ImgPath.Substring(0, 40) + "...")}");
Console.WriteLine("");
Console.WriteLine("---- Test getSomme image (nb : 5, page : 1)");
images = await imageManager.GetSomeImage(1,5);
foreach (var image in images.items)
{
Console.WriteLine($"- ({image.Id}) : {(image.ImgPath.Length <= 40 ? image.ImgPath : image.ImgPath.Substring(0, 40) + "...")}");
}
Console.WriteLine("");
Console.WriteLine("---- Test LastId image");
var id = await imageManager.GetLastImageId();
Console.WriteLine($"- Last image id : {id}");
Console.WriteLine("");
Console.WriteLine("-------------------------------------------------------------------------------");
// ---- Test Character ---- //
var characterManager = new DbCharacterManager(_context);
await characterManager.AddCharacter(new Character() { Id = 0, Name = "Vipélière", IdImage = 11 });
Console.WriteLine("---- Test ajout charcter (id : 11)");
var characters = await characterManager.GetAll();
foreach (var charac in characters.items)
{
Console.WriteLine($"- ({charac.Id}) : {charac.Name} -> {charac.IdImage} : {(charac.Images.ImgPath.Length <= 40 ? charac.Images.ImgPath : charac.Images.ImgPath.Substring(0, 40) + "...")}");
}
Console.WriteLine("");
await characterManager.UpdateCharacter(11,new Character() {Name = "Majespic"});
Console.WriteLine("---- Test mise a jour charcter (id : 11)");
characters = await characterManager.GetAll();
foreach (var charac in characters.items)
{
Console.WriteLine($"- ({charac.Id}) : {charac.Name} -> {charac.IdImage} : {(charac.Images.ImgPath.Length <= 40 ? charac.Images.ImgPath : charac.Images.ImgPath.Substring(0, 40) + "...")}");
}
Console.WriteLine("");
await characterManager.RemoveCharacter(11);
Console.WriteLine("---- Test sup (id : 5)");
characters = await characterManager.GetAll();
foreach (var charac in characters.items)
{
Console.WriteLine($"- ({charac.Id}) : {charac.Name} -> {charac.IdImage} : {(charac.Images.ImgPath.Length <= 40 ? charac.Images.ImgPath : charac.Images.ImgPath.Substring(0, 40) + "...")}");
}
Console.WriteLine("");
Console.WriteLine("---- Test GetById (id : 5)");
var chara = await characterManager.GetCharById(5);
Console.WriteLine($"- ({chara.Id}) : {chara.Name} -> {chara.IdImage} : {(chara.Images.ImgPath.Length <= 40 ? chara.Images.ImgPath : chara.Images.ImgPath.Substring(0, 40) + "...")}");
Console.WriteLine("");
Console.WriteLine("---- Test GetByName (name : Jon Snow)");
chara = await characterManager.GetCharByName("Jon Snow");
Console.WriteLine($"- ({chara.Id}) : {chara.Name} -> {chara.IdImage} : {(chara.Images.ImgPath.Length <= 40 ? chara.Images.ImgPath : chara.Images.ImgPath.Substring(0, 40) + "...")}");
Console.WriteLine("");
Console.WriteLine("---- Test LastId Character");
id = await characterManager.GetLastCharId();
Console.WriteLine($"- Last character id : {id}");
Console.WriteLine("");
}