Merge pull request 'pagination' (#1) from pagination into master
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
Reviewed-on: #1testTony
commit
600b55de43
@ -0,0 +1,53 @@
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: CI
|
||||
|
||||
trigger:
|
||||
event:
|
||||
- push
|
||||
|
||||
steps:
|
||||
- name: build
|
||||
image: mcr.microsoft.com/dotnet/sdk:8.0
|
||||
commands:
|
||||
- cd Verax_API_EF
|
||||
- cd Verax_API_EF
|
||||
- dotnet restore Verax_API_EF.sln
|
||||
- dotnet build Verax_API_EF.sln -c Release --no-restore
|
||||
- dotnet publish Verax_API_EF.sln -c Release --no-restore -o $CI_PROJECT_DIR/build/release
|
||||
|
||||
- name: tests
|
||||
image: mcr.microsoft.com/dotnet/sdk:8.0
|
||||
commands:
|
||||
- cd Verax_API_EF
|
||||
- cd Verax_API_EF
|
||||
- dotnet restore Verax_API_EF.sln
|
||||
- dotnet test Verax_API_EF.sln --no-restore
|
||||
depends_on: [build]
|
||||
|
||||
- name: code-inspection
|
||||
image: hub.codefirst.iut.uca.fr/marc.chevaldonne/codefirst-dronesonarplugin-dotnet7
|
||||
secrets: [ SECRET_SONAR_LOGIN ]
|
||||
environment:
|
||||
sonar_host: https://codefirst.iut.uca.fr/sonar/
|
||||
sonar_token:
|
||||
from_secret: SECRET_SONAR_LOGIN
|
||||
project_key: Verax_API_EF
|
||||
coverage_exclusions: "TestsUnitaires/**"
|
||||
commands:
|
||||
- cd Verax_API_EF/
|
||||
- cd Verax_API_EF/
|
||||
- dotnet restore Verax_API_EF.sln
|
||||
- dotnet sonarscanner begin /k:$${project_key} /d:sonar.host.url=$${sonar_host} /d:sonar.coverageReportPaths="coveragereport/SonarQube.xml" /d:sonar.coverage.exclusions=$${coverage_exclusions} /d:sonar.login=$${sonar_token}
|
||||
- dotnet build Verax_API_EF.sln -c Release --no-restore
|
||||
- dotnet test Verax_API_EF.sln --logger trx --no-restore
|
||||
- reportgenerator -reports:"**/coverage.cobertura.xml" -reporttypes:SonarQube -targetdir:"coveragereport"
|
||||
- dotnet publish Verax_API_EF.sln -c Release --no-restore -o $CI_PROJECT_DIR/build/release
|
||||
- dotnet sonarscanner end /d:sonar.login=$${sonar_token}
|
||||
when:
|
||||
branch:
|
||||
- master
|
||||
event:
|
||||
- push
|
||||
- pull_request
|
||||
depends_on: [build,tests]
|
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$" vcs="" />
|
||||
</component>
|
||||
</project>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,34 @@
|
||||
info: 03/15/2024 16:59:22.173 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: 03/15/2024 16:59:22.176 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: 03/15/2024 16:59:22.182 RelationalEventId.CommandExecuted[20101] (Microsoft.EntityFrameworkCore.Database.Command)
|
||||
Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
|
||||
SELECT "MigrationId", "ProductVersion"
|
||||
FROM "__EFMigrationsHistory"
|
||||
ORDER BY "MigrationId";
|
||||
info: 03/15/2024 16:59:22.190 RelationalEventId.MigrationsNotApplied[20405] (Microsoft.EntityFrameworkCore.Migrations)
|
||||
No migrations were applied. The database is already up to date.
|
||||
info: 03/15/2024 16:59:30.063 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: 03/15/2024 17:08:29.557 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: 03/15/2024 17:08:29.561 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: 03/15/2024 17:08:29.567 RelationalEventId.CommandExecuted[20101] (Microsoft.EntityFrameworkCore.Database.Command)
|
||||
Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
|
||||
SELECT "MigrationId", "ProductVersion"
|
||||
FROM "__EFMigrationsHistory"
|
||||
ORDER BY "MigrationId";
|
||||
info: 03/15/2024 17:08:29.575 RelationalEventId.MigrationsNotApplied[20405] (Microsoft.EntityFrameworkCore.Migrations)
|
||||
No migrations were applied. The database is already up to date.
|
||||
info: 03/15/2024 17:08:33.305 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"
|
@ -1,12 +1,30 @@
|
||||
using API_Services;
|
||||
using DbContextLib;
|
||||
using Model;
|
||||
|
||||
namespace DbDataManager;
|
||||
|
||||
public class DbManager
|
||||
public class DbManager : IDataManager
|
||||
{
|
||||
protected LibraryContext _context;
|
||||
protected LibraryContext _context { get; set; }
|
||||
|
||||
public DbManager()
|
||||
{
|
||||
_context = new LibraryContext();
|
||||
ArticleService = new DbManagerArticle(_context);
|
||||
UserService = new DbManagerUser(_context);
|
||||
FormulaireService = new DbManagerFormulaire(_context);
|
||||
}
|
||||
|
||||
public DbManager(LibraryContext context)
|
||||
{
|
||||
_context = context;
|
||||
ArticleService = new DbManagerArticle(_context);
|
||||
UserService = new DbManagerUser(_context);
|
||||
FormulaireService = new DbManagerFormulaire(_context);
|
||||
}
|
||||
|
||||
public IArticleService ArticleService { get; set; }
|
||||
public IUserService UserService { get; set; }
|
||||
public IFormulaireService FormulaireService { get; set; }
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
namespace Model;
|
||||
using API_Services;
|
||||
|
||||
public interface IDataManager
|
||||
{
|
||||
|
||||
|
||||
IArticleService ArticleService { get; }
|
||||
IUserService UserService { get; }
|
||||
IFormulaireService FormulaireService { get; }
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,30 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0"/>
|
||||
<PackageReference Include="Moq" Version="4.20.70" />
|
||||
<PackageReference Include="xunit" Version="2.4.2"/>
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.0">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\API_Services\API_Services.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1 @@
|
||||
global using Xunit;
|
@ -0,0 +1,129 @@
|
||||
using API_Services;
|
||||
using Model;
|
||||
using Moq;
|
||||
|
||||
namespace API_Unit_Test;
|
||||
|
||||
public class UnitTest_Article
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
[Fact]
|
||||
public void TestGetArticleById()
|
||||
{
|
||||
var mockArticleService = new Mock<IArticleService>();
|
||||
var expected = new Article()
|
||||
{
|
||||
Id = 1,
|
||||
Title = "Test",
|
||||
Description = "Test",
|
||||
Author = "Test",
|
||||
DatePublished = "Test",
|
||||
LectureTime = 10
|
||||
};
|
||||
mockArticleService.Setup(x => x.GetArticleById(1)).ReturnsAsync(expected);
|
||||
var result = mockArticleService.Object.GetArticleById(1);
|
||||
Assert.Equal(expected, result.Result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestGetAllArticles()
|
||||
{
|
||||
var mockArticleService = new Mock<IArticleService>();
|
||||
var expected = new List<Article>()
|
||||
{
|
||||
new Article()
|
||||
{
|
||||
Id = 1,
|
||||
Title = "Test",
|
||||
Description = "Test",
|
||||
Author = "Test",
|
||||
DatePublished = "Test",
|
||||
LectureTime = 10
|
||||
},
|
||||
new Article()
|
||||
{
|
||||
Id = 2,
|
||||
Title = "Test",
|
||||
Description = "Test",
|
||||
Author = "Test",
|
||||
DatePublished = "Test",
|
||||
LectureTime = 10
|
||||
}
|
||||
};
|
||||
mockArticleService.Setup(x => x.GetAllArticles(0, 10, ArticleOrderCriteria.None)).ReturnsAsync(expected);
|
||||
var result = mockArticleService.Object.GetAllArticles(0, 10, ArticleOrderCriteria.None);
|
||||
Assert.Equal(expected, result.Result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestAddArticle()
|
||||
{
|
||||
var mockArticleService = new Mock<IArticleService>();
|
||||
var expected = new Article()
|
||||
{
|
||||
Id = 1,
|
||||
Title = "Test",
|
||||
Description = "Test",
|
||||
Author = "Test",
|
||||
DatePublished = "Test",
|
||||
LectureTime = 10
|
||||
};
|
||||
mockArticleService.Setup(x => x.CreateArticle(expected)).ReturnsAsync(expected);
|
||||
var result = mockArticleService.Object.CreateArticle(expected);
|
||||
Assert.Equal(expected, result.Result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UpdateArticle()
|
||||
{
|
||||
var mockArticleService = new Mock<IArticleService>();
|
||||
var expected = new Article()
|
||||
{
|
||||
Title = "Test",
|
||||
Description = "Test",
|
||||
Author = "Test",
|
||||
DatePublished = "Test",
|
||||
LectureTime = 10
|
||||
};
|
||||
mockArticleService.Setup(x => x.CreateArticle(expected));
|
||||
var result = mockArticleService.Object.CreateArticle(expected);
|
||||
Assert.Equal(1, result.Id );
|
||||
var updated = new Article()
|
||||
{
|
||||
Title = "Updated Test",
|
||||
Description = "Test",
|
||||
Author = "Test",
|
||||
DatePublished = "Test",
|
||||
LectureTime = 10
|
||||
};
|
||||
mockArticleService.Setup(x => x.UpdateArticle(1, updated)).ReturnsAsync(updated);
|
||||
var resultUpdated = mockArticleService.Object.UpdateArticle(1, updated);
|
||||
Assert.Equal(updated ,resultUpdated.Result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
static void DeletedArticle()
|
||||
{
|
||||
var mockArticleService = new Mock<IArticleService>();
|
||||
var expected = new Article()
|
||||
{
|
||||
Id = 1,
|
||||
Title = "Test",
|
||||
Description = "Test",
|
||||
Author = "Test",
|
||||
DatePublished = "Test",
|
||||
LectureTime = 10
|
||||
};
|
||||
mockArticleService.Setup(x => x.CreateArticle(expected)).ReturnsAsync(expected);
|
||||
var result = mockArticleService.Object.CreateArticle(expected);
|
||||
Assert.Equal(expected, result.Result);
|
||||
mockArticleService.Setup(x => x.DeleteArticle(1)).ReturnsAsync(expected);
|
||||
var resultDeleted = mockArticleService.Object.DeleteArticle(1);
|
||||
Assert.Equal(expected, result.Result);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,99 @@
|
||||
using API_Services;
|
||||
using Model;
|
||||
using Moq;
|
||||
|
||||
namespace API_Unit_Test;
|
||||
|
||||
public class UnitTest_Form
|
||||
{
|
||||
[Fact]
|
||||
public void TestGetAllForm()
|
||||
{
|
||||
var mockFormService = new Mock<IFormulaireService>();
|
||||
var expected = new List<Formulaire>()
|
||||
{
|
||||
new Formulaire()
|
||||
{
|
||||
Lien = "Test",
|
||||
Theme = "Test",
|
||||
Date = "Test",
|
||||
UserPseudo = "Test"
|
||||
},
|
||||
new Formulaire()
|
||||
{
|
||||
Lien = "Test",
|
||||
Theme = "Test",
|
||||
Date = "Test",
|
||||
UserPseudo = "Test"
|
||||
}
|
||||
};
|
||||
mockFormService.Setup(x => x.GetAllForm(0, 10, FormOrderCriteria.None)).ReturnsAsync(expected);
|
||||
var result = mockFormService.Object.GetAllForm(0, 10, FormOrderCriteria.None);
|
||||
Assert.Equal(expected, result.Result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestGetFormById()
|
||||
{
|
||||
var mockFormService = new Mock<IFormulaireService>();
|
||||
var expected = new Formulaire()
|
||||
{
|
||||
Lien = "Test",
|
||||
Theme = "Test",
|
||||
Date = "Test",
|
||||
UserPseudo = "Test"
|
||||
};
|
||||
mockFormService.Setup(x => x.GetById(1)).ReturnsAsync(expected);
|
||||
var result = mockFormService.Object.GetById(1);
|
||||
Assert.Equal(expected, result.Result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestCreateForm()
|
||||
{
|
||||
var mockFormService = new Mock<IFormulaireService>();
|
||||
var expected = new Formulaire()
|
||||
{
|
||||
Lien = "Test",
|
||||
Theme = "Test",
|
||||
Date = "Test",
|
||||
UserPseudo = "Test"
|
||||
};
|
||||
mockFormService.Setup(x => x.CreateForm(expected)).ReturnsAsync(expected);
|
||||
var result = mockFormService.Object.CreateForm(expected);
|
||||
Assert.Equal(expected, result.Result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestUpdateForm()
|
||||
{
|
||||
var mockFormService = new Mock<IFormulaireService>();
|
||||
var expected = new Formulaire()
|
||||
{
|
||||
Lien = "Test",
|
||||
Theme = "Test",
|
||||
Date = "Test",
|
||||
UserPseudo = "Test"
|
||||
};
|
||||
mockFormService.Setup(x => x.CreateForm(expected)).ReturnsAsync(expected);
|
||||
var result = mockFormService.Object.CreateForm(expected);
|
||||
Assert.Equal(expected, result.Result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestDeleteForm()
|
||||
{
|
||||
var mockFormService = new Mock<IFormulaireService>();
|
||||
var expected = new Formulaire()
|
||||
{
|
||||
Lien = "Test",
|
||||
Theme = "Test",
|
||||
Date = "Test",
|
||||
UserPseudo = "Test"
|
||||
};
|
||||
mockFormService.Setup(x => x.DeleteForm(1)).ReturnsAsync(expected);
|
||||
var result = mockFormService.Object.DeleteForm(1);
|
||||
Assert.Equal(expected, result.Result);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,215 @@
|
||||
using API_Services;
|
||||
using Entities;
|
||||
using Model;
|
||||
using Moq;
|
||||
|
||||
namespace API_Unit_Test;
|
||||
|
||||
public class UnitTest_User
|
||||
{
|
||||
|
||||
[Fact]
|
||||
static void TestAllUser()
|
||||
{
|
||||
var mockUserService = new Mock<IUserService>();
|
||||
var expected = new List<User>()
|
||||
{
|
||||
new User()
|
||||
{
|
||||
Pseudo = "Tofgasy",
|
||||
Prenom = "Tony",
|
||||
Nom = "Fages",
|
||||
Mail = "mail@mail.com",
|
||||
Mdp = "1234",
|
||||
Role = "Admin"
|
||||
},
|
||||
new User()
|
||||
{
|
||||
Pseudo = "Blizzard",
|
||||
Prenom = "Louis",
|
||||
Nom = "Laborie",
|
||||
Mail = "mail@mail.com",
|
||||
Mdp = "1234",
|
||||
Role = "Admin",
|
||||
},
|
||||
};
|
||||
mockUserService.Setup(x => x.GetAll(0, 10, UserOrderCriteria.None)).ReturnsAsync(expected);
|
||||
var result = mockUserService.Object.GetAll(0, 10, UserOrderCriteria.None);
|
||||
Assert.Equal(expected, result.Result);
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
static void TestGetUserByPseudo()
|
||||
{
|
||||
var mockUserService = new Mock<IUserService>();
|
||||
var expected = new User()
|
||||
{
|
||||
Pseudo = "Tofgasy",
|
||||
Prenom = "Tony",
|
||||
Nom = "Fages",
|
||||
Mail = "mail@mail.com",
|
||||
Mdp = "1234",
|
||||
Role = "Admin"
|
||||
};
|
||||
mockUserService.Setup(x => x.GetByPseudo("Tofgasy")).ReturnsAsync(expected);
|
||||
var result = mockUserService.Object.GetByPseudo("Tofgasy");
|
||||
Assert.Equal(expected, result.Result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
static void TestCreateUser()
|
||||
{
|
||||
var mockUserService = new Mock<IUserService>();
|
||||
var user = new User()
|
||||
{
|
||||
Pseudo = "Tofgasy",
|
||||
Prenom = "Tony",
|
||||
Nom = "Fages",
|
||||
Mail = "mail@mail.com",
|
||||
Mdp = "1234",
|
||||
Role = "Admin"
|
||||
};
|
||||
mockUserService.Setup(x => x.Create(user)).ReturnsAsync(user);
|
||||
var result = mockUserService.Object.Create(user);
|
||||
Assert.Equal( user,result.Result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
static void TestUpdateUser()
|
||||
{
|
||||
var mockUserService = new Mock<IUserService>();
|
||||
var user = new User()
|
||||
{
|
||||
Pseudo = "Tofgasy",
|
||||
Prenom = "Tonio",
|
||||
Nom = "Fages",
|
||||
Mail = "mail@mail.com",
|
||||
Mdp = "1234",
|
||||
Role = "Admin"
|
||||
};
|
||||
mockUserService.Setup(x => x.Update(user, "Tofgasy")).ReturnsAsync(user);
|
||||
var result = mockUserService.Object.Update(user, "Tofgasy");
|
||||
Assert.Equal( user,result.Result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
static void TestDeleteUser()
|
||||
{
|
||||
var mockUserService = new Mock<IUserService>();
|
||||
var user = new User()
|
||||
{
|
||||
Pseudo = "Tofgasy",
|
||||
Prenom = "Tonio",
|
||||
Nom = "Fages",
|
||||
Mail = "mail@mail.com",
|
||||
Mdp = "1234",
|
||||
Role = "Admin"
|
||||
};
|
||||
mockUserService.Setup(x => x.Delete("Tofgasy")).ReturnsAsync(user);
|
||||
var result = mockUserService.Object.Delete("Tofgasy");
|
||||
Assert.Equal( user,result.Result);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
static void TestGetAllArticleUsers()
|
||||
{
|
||||
var mockUserService = new Mock<IUserService>();
|
||||
var expected = new List<User>()
|
||||
{
|
||||
new User()
|
||||
{
|
||||
Pseudo = "Tofgasy",
|
||||
Prenom = "Tony",
|
||||
Nom = "Fages",
|
||||
Mail = "",
|
||||
Mdp = "",
|
||||
Role = "",
|
||||
},
|
||||
new User()
|
||||
{
|
||||
Pseudo = "Blizzard",
|
||||
Prenom = "Louis",
|
||||
Nom = "Laborie",
|
||||
Mail = "",
|
||||
Mdp = "",
|
||||
Role = "",
|
||||
},
|
||||
};
|
||||
mockUserService.Setup(x => x.GetAllArticleUsers()).ReturnsAsync(expected);
|
||||
var result = mockUserService.Object.GetAllArticleUsers();
|
||||
Assert.Equal(expected, result.Result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
static void TestGetArticleUser()
|
||||
{
|
||||
var mockUserService = new Mock<IUserService>();
|
||||
var expected = new List<Article>()
|
||||
{
|
||||
new Article()
|
||||
{
|
||||
Id = 1,
|
||||
Title = "Test",
|
||||
Description = "Test",
|
||||
Author = "Test",
|
||||
DatePublished = "Test",
|
||||
LectureTime = 10
|
||||
},
|
||||
new Article()
|
||||
{
|
||||
Id = 2,
|
||||
Title = "Test",
|
||||
Description = "Test",
|
||||
Author = "Test",
|
||||
DatePublished = "Test",
|
||||
LectureTime = 10
|
||||
}
|
||||
};
|
||||
mockUserService.Setup(x => x.GetArticleUser("Tofgasy")).ReturnsAsync(expected);
|
||||
var result = mockUserService.Object.GetArticleUser("Tofgasy");
|
||||
Assert.Equal(expected, result.Result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
static void TestCreateArticleUser()
|
||||
{
|
||||
var mockUserService = new Mock<IUserService>();
|
||||
var articleUser = new ArticleUserEntity()
|
||||
{
|
||||
ArticleEntityId = 1,
|
||||
UserEntityPseudo = "Tofgasy"
|
||||
};
|
||||
mockUserService.Setup(x => x.CreateArticleUser(articleUser)).ReturnsAsync(true);
|
||||
var result = mockUserService.Object.CreateArticleUser(articleUser);
|
||||
Assert.True(result.Result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
static void TestDeleteArticleUser()
|
||||
{
|
||||
var mockUserService = new Mock<IUserService>();
|
||||
mockUserService.Setup(x => x.DeleteArticleUser("Tofgasy", 1)).ReturnsAsync(true);
|
||||
var result = mockUserService.Object.DeleteArticleUser("Tofgasy", 1);
|
||||
Assert.True(result.Result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
static void TestUpdateArticleUser()
|
||||
{
|
||||
var mockUserService = new Mock<IUserService>();
|
||||
var articleUser = new ArticleUserEntity()
|
||||
{
|
||||
ArticleEntityId = 1,
|
||||
UserEntityPseudo = "Tofgasy"
|
||||
};
|
||||
mockUserService.Setup(x => x.UpdateArticleUser(articleUser)).ReturnsAsync(true);
|
||||
var result = mockUserService.Object.UpdateArticleUser(articleUser);
|
||||
Assert.True(result.Result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,16 +1,16 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Entities;
|
||||
|
||||
public class FormEntity
|
||||
{
|
||||
[Key]
|
||||
public long Id { get; set; }
|
||||
public string Theme { get; set; } = string.Empty;
|
||||
public string DatePublication { get; set; } = string.Empty;
|
||||
public string Link { get; set; } = string.Empty;
|
||||
public string Pseudo { get; set; } = string.Empty;
|
||||
|
||||
|
||||
public long UserEntityId { get; set; }
|
||||
public UserEntity User { get; set; } = null;
|
||||
|
||||
public string UserEntityPseudo{ get; set; }
|
||||
public UserEntity User { get; set; } = null!;
|
||||
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
namespace Model;
|
||||
|
||||
public enum ArticleOrderCriteria
|
||||
{
|
||||
None, ByTitle, ByAuthor, ByLectureTime, ByDatePublished, ByDescription
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
namespace Model;
|
||||
|
||||
public enum FormOrderCriteria
|
||||
{
|
||||
None, ByTheme, ByDate, ByPseudo, ByLien
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
namespace Model;
|
||||
|
||||
public enum UserOrderCriteria
|
||||
{
|
||||
None, ByFirstName, ByLastName
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
using Entities;
|
||||
using Model;
|
||||
|
||||
namespace StubbedContextLib;
|
||||
|
||||
public class StubTest
|
||||
{
|
||||
private List<Article> _article;
|
||||
|
||||
public List<Article> StubArticle()
|
||||
{
|
||||
_article = new List<Article>
|
||||
{
|
||||
new Article
|
||||
{
|
||||
Id = 1,
|
||||
Title = "Test",
|
||||
Description = "Test",
|
||||
Author = "Test",
|
||||
DatePublished = "Test",
|
||||
LectureTime = 1
|
||||
}
|
||||
};
|
||||
return _article;
|
||||
}
|
||||
}
|
Binary file not shown.
@ -1,9 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="xunit" version="2.1.0" targetFramework="net45" />
|
||||
<package id="xunit.abstractions" version="2.0.0" targetFramework="net45" />
|
||||
<package id="xunit.assert" version="2.1.0" targetFramework="net45" />
|
||||
<package id="xunit.core" version="2.1.0" targetFramework="net45" />
|
||||
<package id="xunit.extensibility.core" version="2.1.0" targetFramework="net45" />
|
||||
<package id="xunit.extensibility.execution" version="2.1.0" targetFramework="net45" />
|
||||
</packages>
|
@ -0,0 +1,102 @@
|
||||
using DbContextLib;
|
||||
using Entities;
|
||||
using Microsoft.Data.Sqlite;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace TestsUnitaires;
|
||||
|
||||
public class TestsArticleEntity
|
||||
{
|
||||
[Fact]
|
||||
public void Add_Test()
|
||||
{
|
||||
var connection = new SqliteConnection("DataSource=:memory:");
|
||||
connection.Open();
|
||||
|
||||
var options = new DbContextOptionsBuilder<LibraryContext>()
|
||||
.UseSqlite(connection)
|
||||
.Options;
|
||||
|
||||
using (var context = new LibraryContext(options))
|
||||
{
|
||||
context.Database.EnsureCreated();
|
||||
ArticleEntity a1 = new ArticleEntity { Title = "Breaking News Elisabeth 2 Died", Description = "The queen of England died today at the age of 95", DatePublished = "2022-02-06", LectureTime = 2, Author = "Tom Smith" };
|
||||
ArticleEntity a2 = new ArticleEntity { Title = "The new iPhone 15", Description = "The new iPhone 15 is out and it's the best phone ever", DatePublished = "2022-02-06", LectureTime = 3, Author = "Tom Smith" };
|
||||
ArticleEntity a3 = new ArticleEntity { Title = "M&M's new recipe", Description = "M&M's new recipe is out and it's the best chocolate ever", DatePublished = "2022-02-06", LectureTime = 1, Author = "M&M's Red" };
|
||||
|
||||
context.ArticleSet.Add(a1);
|
||||
context.ArticleSet.Add(a2);
|
||||
context.ArticleSet.Add(a3);
|
||||
|
||||
context.SaveChanges();
|
||||
|
||||
Assert.Equal(3, context.ArticleSet.Count());
|
||||
Assert.Equal("Tom Smith", context.ArticleSet.First().Author);
|
||||
connection.Close();
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Modify_Test()
|
||||
{
|
||||
var connection = new SqliteConnection("DataSource=:memory:");
|
||||
connection.Open();
|
||||
|
||||
var options = new DbContextOptionsBuilder<LibraryContext>()
|
||||
.UseSqlite(connection)
|
||||
.Options;
|
||||
using (var context = new LibraryContext(options))
|
||||
{
|
||||
context.Database.EnsureCreated();
|
||||
ArticleEntity a1 = new ArticleEntity { Id = 1, Title = "Breaking News Elisabeth 2 Died", Description = "The queen of England died today at the age of 95", DatePublished = "2022-02-06", LectureTime = 2, Author = "Tom Smith" };
|
||||
ArticleEntity a2 = new ArticleEntity { Id = 2, Title = "The new iPhone 15", Description = "The new iPhone 15 is out and it's the best phone ever", DatePublished = "2022-02-06", LectureTime = 3, Author = "Tom Smith" };
|
||||
ArticleEntity a3 = new ArticleEntity { Id = 3, Title = "M&M's new recipe", Description = "M&M's new recipe is out and it's the best chocolate ever", DatePublished = "2022-02-06", LectureTime = 1, Author = "M&M's Red" };
|
||||
context.ArticleSet.Add(a1);
|
||||
context.ArticleSet.Add(a2);
|
||||
context.ArticleSet.Add(a3);
|
||||
|
||||
context.SaveChanges();
|
||||
|
||||
var article = context.ArticleSet.First(a => a.Title.Equals("Breaking News Elisabeth 2 Died"));
|
||||
article.Author = "Louis Laborie";
|
||||
context.SaveChanges();
|
||||
string persRemove = "Tom Smith";
|
||||
string persNew = "Louis Laborie";
|
||||
Assert.Equal(1, context.ArticleSet.Count(a => a.Author.Equals(persRemove)));
|
||||
Assert.Equal(1, context.ArticleSet.Count(a => a.Author.Equals(persNew)));
|
||||
connection.Close();
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Remove_Test()
|
||||
{
|
||||
var connection = new SqliteConnection("DataSource=:memory:");
|
||||
connection.Open();
|
||||
|
||||
var options = new DbContextOptionsBuilder<LibraryContext>()
|
||||
.UseSqlite(connection)
|
||||
.Options;
|
||||
using (var context = new LibraryContext(options))
|
||||
{
|
||||
context.Database.EnsureCreated();
|
||||
ArticleEntity a1 = new ArticleEntity { Id = 1, Title = "Breaking News Elisabeth 2 Died", Description = "The queen of England died today at the age of 95", DatePublished = "2022-02-06", LectureTime = 2, Author = "Tom Smith" };
|
||||
ArticleEntity a2 = new ArticleEntity { Id = 2, Title = "The new iPhone 15", Description = "The new iPhone 15 is out and it's the best phone ever", DatePublished = "2022-02-06", LectureTime = 3, Author = "Tom Smith" };
|
||||
ArticleEntity a3 = new ArticleEntity { Id = 3, Title = "M&M's new recipe", Description = "M&M's new recipe is out and it's the best chocolate ever", DatePublished = "2022-02-06", LectureTime = 1, Author = "M&M's Red" };
|
||||
|
||||
context.Add(a1);
|
||||
context.Add(a2);
|
||||
context.Add(a3);
|
||||
|
||||
context.SaveChanges();
|
||||
|
||||
var article = context.ArticleSet.First(a => a.Title.Equals("Breaking News Elisabeth 2 Died"));
|
||||
context.Remove(article);
|
||||
context.SaveChanges();
|
||||
Assert.Equal(2, context.ArticleSet.Count());
|
||||
Assert.Equal(0, context.ArticleSet.Count(a => a.Title.Equals("Breaking News Elisabeth 2 Died")));
|
||||
connection.Close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,182 @@
|
||||
using DbContextLib;
|
||||
using Entities;
|
||||
using Microsoft.Data.Sqlite;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Tests;
|
||||
|
||||
public class TestsUserEntity
|
||||
{
|
||||
[Fact]
|
||||
public void Add_Test()
|
||||
{
|
||||
var connection = new SqliteConnection("DataSource=:memory:");
|
||||
connection.Open();
|
||||
|
||||
var options = new DbContextOptionsBuilder<LibraryContext>()
|
||||
.UseSqlite(connection)
|
||||
.Options;
|
||||
|
||||
using (var context = new LibraryContext(options))
|
||||
{
|
||||
context.Database.EnsureCreated();
|
||||
UserEntity u1 = new UserEntity
|
||||
{
|
||||
Pseudo = "Tofgasy", Prenom = "Tony", Nom = "Fages", Mail = "he@gmail.com", Mdp = "1234", Role = "Admin"
|
||||
};
|
||||
UserEntity u2 = new UserEntity
|
||||
{
|
||||
Pseudo = "Blizzard", Prenom = "Louis", Nom = "Laborie", Mail = "he@gmail.com", Mdp = "1234",
|
||||
Role = "Admin"
|
||||
};
|
||||
UserEntity u3 = new UserEntity
|
||||
{
|
||||
Pseudo = "TomS", Prenom = "Tom", Nom = "Smith", Mail = "TomS@gmail.com", Mdp = "1234", Role = "User"
|
||||
};
|
||||
UserEntity u4 = new UserEntity
|
||||
{
|
||||
Pseudo = "Siwa", Prenom = "Jean", Nom = "Marcillac", Mail = "occitan@gmail.com", Mdp = "1234",
|
||||
Role = "Amin"
|
||||
};
|
||||
UserEntity u5 = new UserEntity
|
||||
{
|
||||
Pseudo = "Sha", Prenom = "Shana", Nom = "Cascarra", Mail = "shacas@gmail.com", Mdp = "1234",
|
||||
Role = "Modérator"
|
||||
};
|
||||
UserEntity u6 = new UserEntity
|
||||
{
|
||||
Pseudo = "NoaSil", Prenom = "Noa", Nom = "Sillard", Mail = "noaSillar@gmail.com", Mdp = "1234",
|
||||
Role = "Admin"
|
||||
};
|
||||
context.UserSet.Add(u1);
|
||||
context.UserSet.Add(u2);
|
||||
context.UserSet.Add(u3);
|
||||
context.UserSet.Add(u4);
|
||||
context.UserSet.Add(u5);
|
||||
context.UserSet.Add(u6);
|
||||
context.SaveChanges();
|
||||
|
||||
Assert.Equal(6, context.UserSet.Count());
|
||||
Assert.Equal("Blizzard", context.UserSet.First().Pseudo);
|
||||
connection.Close();
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Modify_Test()
|
||||
{
|
||||
var connection = new SqliteConnection("DataSource=:memory:");
|
||||
connection.Open();
|
||||
|
||||
var options = new DbContextOptionsBuilder<LibraryContext>()
|
||||
.UseSqlite(connection)
|
||||
.Options;
|
||||
using (var context = new LibraryContext(options))
|
||||
{
|
||||
context.Database.EnsureCreated();
|
||||
UserEntity u1 = new UserEntity
|
||||
{
|
||||
Pseudo = "Tofgasy", Prenom = "Tony", Nom = "Fages", Mail = "he@gmail.com", Mdp = "1234", Role = "Admin"
|
||||
};
|
||||
UserEntity u2 = new UserEntity
|
||||
{
|
||||
Pseudo = "Blizzard", Prenom = "Louis", Nom = "Laborie", Mail = "he@gmail.com", Mdp = "1234",
|
||||
Role = "Admin"
|
||||
};
|
||||
UserEntity u3 = new UserEntity
|
||||
{
|
||||
Pseudo = "TomS", Prenom = "Tom", Nom = "Smith", Mail = "TomS@gmail.com", Mdp = "1234", Role = "User"
|
||||
};
|
||||
UserEntity u4 = new UserEntity
|
||||
{
|
||||
Pseudo = "Siwa", Prenom = "Jean", Nom = "Marcillac", Mail = "occitan@gmail.com", Mdp = "1234",
|
||||
Role = "Amin"
|
||||
};
|
||||
UserEntity u5 = new UserEntity
|
||||
{
|
||||
Pseudo = "Sha", Prenom = "Shana", Nom = "Cascarra", Mail = "shacas@gmail.com", Mdp = "1234",
|
||||
Role = "Modérator"
|
||||
};
|
||||
UserEntity u6 = new UserEntity
|
||||
{
|
||||
Pseudo = "NoaSil", Prenom = "Noa", Nom = "Sillard", Mail = "noaSillar@gmail.com", Mdp = "1234",
|
||||
Role = "Admin"
|
||||
};
|
||||
context.UserSet.Add(u1);
|
||||
context.UserSet.Add(u2);
|
||||
context.UserSet.Add(u3);
|
||||
context.UserSet.Add(u4);
|
||||
context.UserSet.Add(u5);
|
||||
context.UserSet.Add(u6);
|
||||
context.SaveChanges();
|
||||
|
||||
var user = context.UserSet.First(u => u.Pseudo.Equals("Tofgasy"));
|
||||
user.Prenom = "Tof";
|
||||
context.SaveChanges();
|
||||
string persRemove = "Tony";
|
||||
string persNew = "Tof";
|
||||
Assert.Equal(1, context.UserSet.Count(u => u.Prenom.Equals(persNew)));
|
||||
Assert.Equal(0, context.UserSet.Count(u => u.Prenom.Equals(persRemove)));
|
||||
connection.Close();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Remove_Test()
|
||||
{
|
||||
var connection = new SqliteConnection("DataSource=:memory:");
|
||||
connection.Open();
|
||||
|
||||
var options = new DbContextOptionsBuilder<LibraryContext>()
|
||||
.UseSqlite(connection)
|
||||
.Options;
|
||||
using (var context = new LibraryContext(options))
|
||||
{
|
||||
context.Database.EnsureCreated();
|
||||
UserEntity u1 = new UserEntity
|
||||
{
|
||||
Pseudo = "Tofgasy", Prenom = "Tony", Nom = "Fages", Mail = "he@gmail.com", Mdp = "1234", Role = "Admin"
|
||||
};
|
||||
UserEntity u2 = new UserEntity
|
||||
{
|
||||
Pseudo = "Blizzard", Prenom = "Louis", Nom = "Laborie", Mail = "he@gmail.com", Mdp = "1234",
|
||||
Role = "Admin"
|
||||
};
|
||||
UserEntity u3 = new UserEntity
|
||||
{
|
||||
Pseudo = "TomS", Prenom = "Tom", Nom = "Smith", Mail = "TomS@gmail.com", Mdp = "1234", Role = "User"
|
||||
};
|
||||
UserEntity u4 = new UserEntity
|
||||
{
|
||||
Pseudo = "Siwa", Prenom = "Jean", Nom = "Marcillac", Mail = "occitan@gmail.com", Mdp = "1234",
|
||||
Role = "Amin"
|
||||
};
|
||||
UserEntity u5 = new UserEntity
|
||||
{
|
||||
Pseudo = "Sha", Prenom = "Shana", Nom = "Cascarra", Mail = "shacas@gmail.com", Mdp = "1234",
|
||||
Role = "Modérator"
|
||||
};
|
||||
UserEntity u6 = new UserEntity
|
||||
{
|
||||
Pseudo = "NoaSil", Prenom = "Noa", Nom = "Sillard", Mail = "noaSillar@gmail.com", Mdp = "1234",
|
||||
Role = "Admin"
|
||||
};
|
||||
context.UserSet.Add(u1);
|
||||
context.UserSet.Add(u2);
|
||||
context.UserSet.Add(u3);
|
||||
context.UserSet.Add(u4);
|
||||
context.UserSet.Add(u5);
|
||||
context.UserSet.Add(u6);
|
||||
context.SaveChanges();
|
||||
|
||||
Assert.Equal(6, context.UserSet.Count());
|
||||
var user = context.UserSet.First(u => u.Pseudo.Equals("Tofgasy"));
|
||||
context.Remove(user);
|
||||
context.SaveChanges();
|
||||
Assert.Equal(5, context.UserSet.Count());
|
||||
Assert.Equal(0, context.UserSet.Count(u => u.Pseudo.Equals("Tofgasy")));
|
||||
connection.Close();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
<RootNamespace>TestsUnitaires</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.2" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.2" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.2" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
|
||||
<PackageReference Include="xunit" Version="2.7.0" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\DbContextLib\DbContextLib.csproj" />
|
||||
<ProjectReference Include="..\Entities\Entities.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="Xunit" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,15 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Rider ignored files
|
||||
/modules.xml
|
||||
/projectSettingsUpdater.xml
|
||||
/.idea.Verax_API_EF.iml
|
||||
/contentModel.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
# GitHub Copilot persisted chat sessions
|
||||
/copilot/chatSessions
|
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="UserContentModel">
|
||||
<attachedFolders />
|
||||
<explicitIncludes />
|
||||
<explicitExcludes />
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
Loading…
Reference in new issue