ADD tests for API
continuous-integration/drone/push Build is passing Details

master
Tony Fages 1 year ago
parent c9d7db1ff6
commit 50e52b317c

@ -1,4 +1,4 @@
Private property of Exodus: 51118@MacBook-Pro-de-Fages.local
Private property of Exodus: 16477@macbook-pro-de-fages.home
jetbrains.exodus.io.LockingManager.lock(LockingManager.kt:88)
jetbrains.exodus.io.LockingManager.lock(LockingManager.kt:39)

@ -6,12 +6,17 @@
<projectFile>API_Tests_Console/API_Tests_Console.csproj</projectFile>
<projectFile>Test_Console_EF/Test_Console_EF.csproj</projectFile>
</component>
<component name="AutoImportSettings">
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="454eaf08-7244-4002-811f-5409ccfe6a2a" name="Changes" comment="">
<change afterPath="$PROJECT_DIR$/API_Tests_Console/Tests_Console_Connect_API.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/.idea.Verax_API_EF/.idea/copilot/chatSessions/00000000000.xd" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.Verax_API_EF/.idea/copilot/chatSessions/00000000000.xd" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/.idea.Verax_API_EF/.idea/copilot/chatSessions/xd.lck" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.Verax_API_EF/.idea/copilot/chatSessions/xd.lck" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/.idea.Verax_API_EF/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.Verax_API_EF/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Model/ArticleOrderCriteria.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Model/ArticleOrderCriteria.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Model/FormOrderCriteria.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Model/FormOrderCriteria.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Model/UserOrderCriteria.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Model/UserOrderCriteria.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/API/log.txt" beforeDir="false" afterPath="$PROJECT_DIR$/API/log.txt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/API_Tests_Console/Tests_Console.cs" beforeDir="false" afterPath="$PROJECT_DIR$/API_Tests_Console/Tests_Console_Connect_Localhost.cs" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -22,9 +27,9 @@
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/.." />
</component>
<component name="MetaFilesCheckinStateConfiguration" checkMetaFiles="true" />
<component name="ProjectColorInfo"><![CDATA[{
"associatedIndex": 0
}]]></component>
<component name="ProjectColorInfo">{
&quot;associatedIndex&quot;: 0
}</component>
<component name="ProjectId" id="2eXuZ2IMoPdjqkvkhUH8MxoFt4X" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
@ -32,9 +37,15 @@
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
".NET Launch Settings Profile.API: http.executor": "Run",
".NET Project.API_Tests_Console.executor": "Run",
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"git-widget-placeholder": "master",
"node.js.detected.package.eslint": "true",
"node.js.detected.package.tslint": "true",
"node.js.selected.package.eslint": "(autodetect)",
"node.js.selected.package.tslint": "(autodetect)",
"nodejs_package_manager_path": "npm",
"vue.rearranger.settings.migration": "true"
},
@ -46,7 +57,7 @@
]
}
}]]></component>
<component name="RunManager" selected=".NET Project.Test_Console_EF">
<component name="RunManager" selected=".NET Project.API_Tests_Console">
<configuration name="API_Tests_Console" type="DotNetProject" factoryName=".NET Project">
<option name="EXE_PATH" value="" />
<option name="PROGRAM_PARAMETERS" value="" />
@ -122,7 +133,8 @@
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1712063297753</updated>
<workItem from="1712063301685" duration="205000" />
<workItem from="1712063301685" duration="548000" />
<workItem from="1712498505089" duration="722000" />
</task>
<servers />
</component>

@ -1778,3 +1778,36 @@ info: 04/02/2024 08:37:34.355 RelationalEventId.CommandExecuted[20101] (Microsof
Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT "a"."Id", "a"."Author", "a"."DatePublished", "a"."Description", "a"."LectureTime", "a"."Title"
FROM "ArticleSet" AS "a"
info: 04/07/2024 16:10:11.515 RelationalEventId.CommandExecuted[20101] (Microsoft.EntityFrameworkCore.Database.Command)
Executed DbCommand (6ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT COUNT(*) FROM "sqlite_master" WHERE "name" = '__EFMigrationsHistory' AND "type" = 'table';
info: 04/07/2024 16:10:11.519 RelationalEventId.CommandExecuted[20101] (Microsoft.EntityFrameworkCore.Database.Command)
Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT COUNT(*) FROM "sqlite_master" WHERE "name" = '__EFMigrationsHistory' AND "type" = 'table';
info: 04/07/2024 16:10:11.526 RelationalEventId.CommandExecuted[20101] (Microsoft.EntityFrameworkCore.Database.Command)
Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT "MigrationId", "ProductVersion"
FROM "__EFMigrationsHistory"
ORDER BY "MigrationId";
info: 04/07/2024 16:10:11.535 RelationalEventId.MigrationsNotApplied[20405] (Microsoft.EntityFrameworkCore.Migrations)
No migrations were applied. The database is already up to date.
info: 04/07/2024 16:10:55.561 RelationalEventId.CommandExecuted[20101] (Microsoft.EntityFrameworkCore.Database.Command)
Executed DbCommand (2ms) [Parameters=[@__p_0='?' (DbType = Int64)], CommandType='Text', CommandTimeout='30']
SELECT "a"."Id", "a"."Author", "a"."DatePublished", "a"."Description", "a"."LectureTime", "a"."Title"
FROM "ArticleSet" AS "a"
WHERE "a"."Id" = @__p_0
LIMIT 1
info: 04/07/2024 16:11:07.649 RelationalEventId.CommandExecuted[20101] (Microsoft.EntityFrameworkCore.Database.Command)
Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT "a"."Id", "a"."Author", "a"."DatePublished", "a"."Description", "a"."LectureTime", "a"."Title"
FROM "ArticleSet" AS "a"
info: 04/07/2024 16:11:26.504 RelationalEventId.CommandExecuted[20101] (Microsoft.EntityFrameworkCore.Database.Command)
Executed DbCommand (0ms) [Parameters=[@__p_0='?' (DbType = Int64)], CommandType='Text', CommandTimeout='30']
SELECT "a"."Id", "a"."Author", "a"."DatePublished", "a"."Description", "a"."LectureTime", "a"."Title"
FROM "ArticleSet" AS "a"
WHERE "a"."Id" = @__p_0
LIMIT 1
info: 04/07/2024 16:11:26.514 RelationalEventId.CommandExecuted[20101] (Microsoft.EntityFrameworkCore.Database.Command)
Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT "a"."Id", "a"."Author", "a"."DatePublished", "a"."Description", "a"."LectureTime", "a"."Title"
FROM "ArticleSet" AS "a"

@ -0,0 +1,430 @@
namespace API_Tests_Console;
using System.Text;
using System.Text.Json;
using Entities;
using Model;
public class Tests_Console_Connect_API
{
// See https://aka.ms/new-console-template for more information
static readonly HttpClient client = new HttpClient();
static async Task Main2(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("https://codefirst.iut.uca.fr/containers/Verax-verax-api/articles");
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("https://codefirst.iut.uca.fr/containers/Verax-verax-api/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("https://codefirst.iut.uca.fr/containers/Verax-verax-api/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("https://codefirst.iut.uca.fr/containers/Verax-verax-api/article/1");
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("https://codefirst.iut.uca.fr/containers/Verax-verax-api/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("https://codefirst.iut.uca.fr/containers/Verax-verax-api/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("https://codefirst.iut.uca.fr/containers/Verax-verax-api/formulaire/1");
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("https://codefirst.iut.uca.fr/containers/Verax-verax-api/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("https://codefirst.iut.uca.fr/containers/Verax-verax-api/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("https://codefirst.iut.uca.fr/containers/Verax-verax-api/", 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("https://codefirst.iut.uca.fr/containers/Verax-verax-api/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("https://codefirst.iut.uca.fr/containers/Verax-verax-api/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("https://codefirst.iut.uca.fr/containers/Verax-verax-api/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("https://codefirst.iut.uca.fr/containers/Verax-verax-api/user/Sha");
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("https://codefirst.iut.uca.fr/containers/Verax-verax-api/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("https://codefirst.iut.uca.fr/containers/Verax-verax-api/article/users");
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("https://codefirst.iut.uca.fr/containers/Verax-verax-api/user/Sha/articles");
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("https://codefirst.iut.uca.fr/containers/Verax-verax-api/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("https://codefirst.iut.uca.fr/containers/Verax-verax-api/user/Sha/3");
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 = 2,
UserEntityPseudo = "Sha"
};
long oldId = 3;
var json = JsonSerializer.Serialize(articleUser);
var data = new StringContent(json, Encoding.UTF8, "application/json");
var response = await client.PutAsync($"https://codefirst.iut.uca.fr/containers/Verax-verax-api/user/Sha/{oldId}", data);
response.EnsureSuccessStatusCode();
var responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseBody);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}

@ -5,16 +5,15 @@ using System.Text.Json;
using Entities;
using Model;
class Tests_Console
{
static readonly HttpClient client = new HttpClient();
class Tests_Console_Connect_Localhost
{static readonly HttpClient client = new HttpClient();
static async Task Main(string[] args)
{
await TestUser();
//await TestUser();
//await TestFormulaire();
//await TestArticle();
await TestArticle();
}
private static async Task TestFormulaire()
@ -44,17 +43,17 @@ class Tests_Console
static async Task TestArticle()
{
await TestArticleGetId();
await TestArticleCreate();
//await TestArticleCreate();
await TestArticleGetAll();
await TestArticleDelete();
await TestArticleUpdate();
// await TestArticleDelete();
// await TestArticleUpdate();
}
static async Task TestArticleGetAll()
{
try
{
var response = await client.GetAsync("http://localhost:5052/api/Article");
var response = await client.GetAsync("http://localhost:5052/articles");
response.EnsureSuccessStatusCode();
var responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseBody);
@ -425,4 +424,5 @@ class Tests_Console
}
}
}
Loading…
Cancel
Save