diff --git a/Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db b/Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db index 05efb11..c187473 100644 Binary files a/Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db and b/Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db differ diff --git a/Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db-shm b/Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db-shm index fe9ac28..70a3e06 100644 Binary files a/Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db-shm and b/Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db-shm differ diff --git a/Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db-wal b/Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db-wal index e69de29..87148cb 100644 Binary files a/Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db-wal and b/Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db-wal differ diff --git a/Verax_API_EF/Verax_API_EF/API_Tests_Console/API_Tests_Console.csproj b/Verax_API_EF/Verax_API_EF/API_Tests_Console/API_Tests_Console.csproj new file mode 100644 index 0000000..1faee3d --- /dev/null +++ b/Verax_API_EF/Verax_API_EF/API_Tests_Console/API_Tests_Console.csproj @@ -0,0 +1,15 @@ + + + + Exe + net8.0 + enable + enable + + + + + + + + diff --git a/Verax_API_EF/Verax_API_EF/API_Tests_Console/Tests_Console.cs b/Verax_API_EF/Verax_API_EF/API_Tests_Console/Tests_Console.cs new file mode 100644 index 0000000..8431299 --- /dev/null +++ b/Verax_API_EF/Verax_API_EF/API_Tests_Console/Tests_Console.cs @@ -0,0 +1,427 @@ +// See https://aka.ms/new-console-template for more information + +using System.Text; +using System.Text.Json; +using Entities; +using Model; + +class Tests_Console +{ + static readonly HttpClient client = new HttpClient(); + + + static async Task Main(string[] args) + { + await TestUser(); + //await TestFormulaire(); + //await TestArticle(); + } + + private static async Task TestFormulaire() + { + await TestFormulaireGetAll(); + await TestFormulaireGetId(); + await TestFormulaireCreate(); + await TestFormulaireDelete(); + await TestFormulaireUpdate(); + } + + private static async Task TestUser() + { + //await TestUserGetAll(); + //await TestUserGetId(); + //await TestUserCreate(); + //await TestUserDelete(); + //await TestUserUpdate(); + //await TestGetAllArticleUser(); + //await TestGetArticleByUser(); + //await TestCreateArticleUser(); + //await TestDeleteArticleUser(); + await TestUpdateArticleUser(); + } + + + static async Task TestArticle() + { + await TestArticleGetId(); + await TestArticleCreate(); + await TestArticleGetAll(); + await TestArticleDelete(); + await TestArticleUpdate(); + } + + static async Task TestArticleGetAll() + { + try + { + var response = await client.GetAsync("http://localhost:5052/api/Article"); + response.EnsureSuccessStatusCode(); + var responseBody = await response.Content.ReadAsStringAsync(); + Console.WriteLine(responseBody); + } + catch (Exception e) + { + Console.WriteLine(e.Message); + } + } + + static async Task TestArticleGetId() + { + try + { + var response = await client.GetAsync("http://localhost:5052/article/1"); + response.EnsureSuccessStatusCode(); + var responseBody = await response.Content.ReadAsStringAsync(); + Console.WriteLine(responseBody); + } + catch (Exception e) + { + Console.WriteLine(e.Message); + } + } + + static async Task TestArticleCreate() + { + try + { + var article = new Article() + { + Title = "Test", + Description = "Test", + Author = "Test", + DatePublished = "Test", + LectureTime = 0 + }; + var json = JsonSerializer.Serialize(article); + var data = new StringContent(json, Encoding.UTF8, "application/json"); + var response = await client.PostAsync("http://localhost:5052/article", data); + response.EnsureSuccessStatusCode(); + var responseBody = await response.Content.ReadAsStringAsync(); + Console.WriteLine(responseBody); + } + catch (Exception e) + { + Console.WriteLine(e.Message); + } + } + + static async Task TestArticleDelete() + { + try + { + var response = await client.DeleteAsync("http://localhost:5052/article/4"); + response.EnsureSuccessStatusCode(); + var responseBody = await response.Content.ReadAsStringAsync(); + Console.WriteLine(responseBody); + } + catch (Exception e) + { + Console.WriteLine(e.Message); + } + } + + static async Task TestArticleUpdate() + { + try + { + var article = new Article() + { + Title = "Louis", + Description = "Je", + Author = "T'", + DatePublished = "aime", + LectureTime = 0 + }; + var json = JsonSerializer.Serialize(article); + var data = new StringContent(json, Encoding.UTF8, "application/json"); + var response = await client.PutAsync("http://localhost:5052/article/1", data); + response.EnsureSuccessStatusCode(); + var responseBody = await response.Content.ReadAsStringAsync(); + Console.WriteLine(responseBody); + } + catch (Exception e) + { + Console.WriteLine(e.Message); + } + } + + static async Task TestFormulaireGetAll() + { + try + { + var response = await client.GetAsync("http://localhost:5052/formulaires"); + response.EnsureSuccessStatusCode(); + var responseBody = await response.Content.ReadAsStringAsync(); + Console.WriteLine(responseBody); + } + catch (Exception e) + { + Console.WriteLine(e.Message); + } + } + + static async Task TestFormulaireGetId() + { + try + { + var response = await client.GetAsync("http://localhost:5052/formulaire/2"); + response.EnsureSuccessStatusCode(); + var responseBody = await response.Content.ReadAsStringAsync(); + Console.WriteLine(responseBody); + } + catch (Exception e) + { + Console.WriteLine(e.Message); + } + } + + static async Task TestFormulaireCreate() + { + try + { + var formulaire = new Formulaire() + { + Theme = "Test", + Date = "Test", + Lien = "Test", + UserPseudo = "Sha" + }; + var json = JsonSerializer.Serialize(formulaire); + var data = new StringContent(json, Encoding.UTF8, "application/json"); + var response = await client.PostAsync("http://localhost:5052/formulaire", data); + response.EnsureSuccessStatusCode(); + var responseBody = await response.Content.ReadAsStringAsync(); + Console.WriteLine(responseBody); + } + catch (Exception e) + { + Console.WriteLine(e.Message); + } + } + + static async Task TestFormulaireDelete() + { + try + { + var response = await client.DeleteAsync("http://localhost:5052/formulaire/5"); + response.EnsureSuccessStatusCode(); + var responseBody = await response.Content.ReadAsStringAsync(); + Console.WriteLine(responseBody); + } + catch (Exception e) + { + Console.WriteLine(e.Message); + } + } + + static async Task TestFormulaireUpdate() + { + try + { + var formulaire = new Formulaire() + { + Theme = "J'", + Date = "aime", + Lien = "Les", + UserPseudo = "Sha" + }; + var json = JsonSerializer.Serialize(formulaire); + var data = new StringContent(json, Encoding.UTF8, "application/json"); + var response = await client.PutAsync("http://localhost:5052/formulaire/4", data); + response.EnsureSuccessStatusCode(); + var responseBody = await response.Content.ReadAsStringAsync(); + Console.WriteLine(responseBody); + } + catch (Exception e) + { + Console.WriteLine(e.Message); + } + } + + static async Task TestUserGetAll() + { + try + { + var response = await client.GetAsync("http://localhost:5052/users"); + response.EnsureSuccessStatusCode(); + var responseBody = await response.Content.ReadAsStringAsync(); + Console.WriteLine(responseBody); + } + catch (Exception e) + { + Console.WriteLine(e.Message); + } + } + + static async Task TestUserGetId() + { + try + { + var response = await client.GetAsync("http://localhost:5052/user/Sha"); + response.EnsureSuccessStatusCode(); + var responseBody = await response.Content.ReadAsStringAsync(); + Console.WriteLine(responseBody); + } + catch (Exception e) + { + Console.WriteLine(e.Message); + } + } + + static async Task TestUserCreate() + { + try + { + var user = new User() + { + Pseudo = "J", + Nom = "'", + Prenom = "aime", + Mail = "les", + Mdp = "pieds", + Role = "Admin" + }; + var json = JsonSerializer.Serialize(user); + var data = new StringContent(json, Encoding.UTF8, "application/json"); + var response = await client.PostAsync("http://localhost:5052/user", data); + response.EnsureSuccessStatusCode(); + var responseBody = await response.Content.ReadAsStringAsync(); + Console.WriteLine(responseBody); + } + catch (Exception e) + { + Console.WriteLine(e.Message); + } + } + + static async Task TestUserDelete() + { + try + { + var response = await client.DeleteAsync("http://localhost:5052/user/J"); + response.EnsureSuccessStatusCode(); + var responseBody = await response.Content.ReadAsStringAsync(); + Console.WriteLine(responseBody); + } + catch (Exception e) + { + Console.WriteLine(e.Message); + } + } + + static async Task TestUserUpdate() + { + try + { + var user = new User() + { + Pseudo = "Sha", + Nom = "J'", + Prenom = "aime", + Mail = "les", + Mdp = "pieds", + Role = "Admin" + }; + var json = JsonSerializer.Serialize(user); + var data = new StringContent(json, Encoding.UTF8, "application/json"); + var response = await client.PutAsync("http://localhost:5052/user/Sha", data); + response.EnsureSuccessStatusCode(); + var responseBody = await response.Content.ReadAsStringAsync(); + Console.WriteLine(responseBody); + } + catch (Exception e) + { + Console.WriteLine(e.Message); + } + } + + static async Task TestGetAllArticleUser() + { + try + { + var response = await client.GetAsync("http://localhost:5052/ArticleUsers"); + response.EnsureSuccessStatusCode(); + var responseBody = await response.Content.ReadAsStringAsync(); + Console.WriteLine(responseBody); + } + catch (Exception e) + { + Console.WriteLine(e.Message); + } + } + + static async Task TestGetArticleByUser() + { + try + { + var response = await client.GetAsync("http://localhost:5052/user/Sha/article"); + response.EnsureSuccessStatusCode(); + var responseBody = await response.Content.ReadAsStringAsync(); + Console.WriteLine(responseBody); + } + catch (Exception e) + { + Console.WriteLine(e.Message); + } + } + + static async Task TestCreateArticleUser() + { + try + { + var articleUser = new ArticleUserEntity() + { + ArticleEntityId = 1, + UserEntityPseudo = "Sha" + }; + var json = JsonSerializer.Serialize(articleUser); + var data = new StringContent(json, Encoding.UTF8, "application/json"); + var response = await client.PostAsync("http://localhost:5052/user/article", data); + response.EnsureSuccessStatusCode(); + var responseBody = await response.Content.ReadAsStringAsync(); + Console.WriteLine(responseBody); + } + catch (Exception e) + { + Console.WriteLine(e.Message); + } + } + + static async Task TestDeleteArticleUser() + { + try + { + var response = await client.DeleteAsync("http://localhost:5052/user/Sha/article"); + response.EnsureSuccessStatusCode(); + var responseBody = await response.Content.ReadAsStringAsync(); + Console.WriteLine(responseBody); + } + catch (Exception e) + { + Console.WriteLine(e.Message); + } + } + + static async Task TestUpdateArticleUser() + { + try + { + var articleUser = new ArticleUserEntity() + { + ArticleEntityId = 1, + UserEntityPseudo = "Sha" + }; + var json = JsonSerializer.Serialize(articleUser); + var data = new StringContent(json, Encoding.UTF8, "application/json"); + var response = await client.PutAsync("http://localhost:5052/user/Sha/article", data); + response.EnsureSuccessStatusCode(); + var responseBody = await response.Content.ReadAsStringAsync(); + Console.WriteLine(responseBody); + } + catch (Exception e) + { + Console.WriteLine(e.Message); + } + } + +} \ No newline at end of file diff --git a/Verax_API_EF/Verax_API_EF/Verax_API_EF.sln b/Verax_API_EF/Verax_API_EF/Verax_API_EF.sln index ce77cf8..473c412 100644 --- a/Verax_API_EF/Verax_API_EF/Verax_API_EF.sln +++ b/Verax_API_EF/Verax_API_EF/Verax_API_EF.sln @@ -27,6 +27,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Unit_Test_EF", "Unit_Test_E EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "API_Unit_Test", "API_Unit_Test\API_Unit_Test.csproj", "{B3B9C0F5-98A3-438B-A22A-ECFF33DA8F23}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "API_Tests_Console", "API_Tests_Console\API_Tests_Console.csproj", "{EEB45245-5B65-4C99-A2B4-942991AE5F1A}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -81,6 +83,10 @@ Global {B3B9C0F5-98A3-438B-A22A-ECFF33DA8F23}.Debug|Any CPU.Build.0 = Debug|Any CPU {B3B9C0F5-98A3-438B-A22A-ECFF33DA8F23}.Release|Any CPU.ActiveCfg = Release|Any CPU {B3B9C0F5-98A3-438B-A22A-ECFF33DA8F23}.Release|Any CPU.Build.0 = Release|Any CPU + {EEB45245-5B65-4C99-A2B4-942991AE5F1A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EEB45245-5B65-4C99-A2B4-942991AE5F1A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EEB45245-5B65-4C99-A2B4-942991AE5F1A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EEB45245-5B65-4C99-A2B4-942991AE5F1A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE