From 7aa2151aa5e3ad1136488c8f091d0986d4d7416e Mon Sep 17 00:00:00 2001 From: "maxime.BATISTA@etu.uca.fr" Date: Thu, 1 Jun 2023 18:31:46 +0200 Subject: [PATCH] add other test --- LocalServices/AccountOwnedRecipes.cs | 2 +- LocalServices/AccountRecipesPreferences.cs | 2 +- LocalServices/AuthService.cs | 8 +---- LocalServices/Constants.cs | 2 +- LocalServices/RecipesService.cs | 2 +- Tests/AccountRecipesPreferencesTests.cs | 9 +++++ Tests/AuthServiceTests.cs | 35 +++++++++++++++++++ .../CatastrophicPreformancesDatabaseTests.cs | 5 ++- Tests/RecipeServicesTests.cs | 25 +++++++++++++ Tests/Tests.csproj | 1 + Tests/Usings.cs | 3 +- 11 files changed, 79 insertions(+), 15 deletions(-) create mode 100644 Tests/AccountRecipesPreferencesTests.cs create mode 100644 Tests/AuthServiceTests.cs create mode 100644 Tests/RecipeServicesTests.cs diff --git a/LocalServices/AccountOwnedRecipes.cs b/LocalServices/AccountOwnedRecipes.cs index 6e6ba77..590f4a9 100644 --- a/LocalServices/AccountOwnedRecipes.cs +++ b/LocalServices/AccountOwnedRecipes.cs @@ -5,7 +5,7 @@ using System.Collections.Immutable; namespace Services { - internal class AccountOwnedRecipes : IAccountOwnedRecipesService + public class AccountOwnedRecipes : IAccountOwnedRecipesService { public Account Account { get; init; } diff --git a/LocalServices/AccountRecipesPreferences.cs b/LocalServices/AccountRecipesPreferences.cs index 8697a50..0582cf2 100644 --- a/LocalServices/AccountRecipesPreferences.cs +++ b/LocalServices/AccountRecipesPreferences.cs @@ -5,7 +5,7 @@ using System.Collections.Immutable; namespace LocalServices { - internal class AccountRecipesPreferences : IAccountRecipesPreferencesService + public class AccountRecipesPreferences : IAccountRecipesPreferencesService { private readonly IDatabase db; diff --git a/LocalServices/AuthService.cs b/LocalServices/AuthService.cs index a68cf5b..a229afa 100644 --- a/LocalServices/AuthService.cs +++ b/LocalServices/AuthService.cs @@ -1,16 +1,10 @@ using Models; using Services; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using LocalServices.Data; -using System.Security.Cryptography; namespace LocalServices { - internal class AuthService : IAuthService + public class AuthService : IAuthService { private readonly IDatabase db; diff --git a/LocalServices/Constants.cs b/LocalServices/Constants.cs index 0f626ec..cfb7bf8 100644 --- a/LocalServices/Constants.cs +++ b/LocalServices/Constants.cs @@ -2,7 +2,7 @@ namespace LocalServices { - internal class Constants + public class Constants { public static readonly Uri DEFAULT_ACCOUNT_IMAGE = new Uri("https://www.pngkey.com/png/full/115-1150152_default-profile-picture-avatar-png-green.png"); } diff --git a/LocalServices/RecipesService.cs b/LocalServices/RecipesService.cs index 2237b04..fcd9de1 100644 --- a/LocalServices/RecipesService.cs +++ b/LocalServices/RecipesService.cs @@ -5,7 +5,7 @@ using System.Collections.Immutable; namespace LocalServices { - internal class RecipesService : IRecipesService + public class RecipesService : IRecipesService { private readonly IDatabase db; diff --git a/Tests/AccountRecipesPreferencesTests.cs b/Tests/AccountRecipesPreferencesTests.cs new file mode 100644 index 0000000..7d81a9a --- /dev/null +++ b/Tests/AccountRecipesPreferencesTests.cs @@ -0,0 +1,9 @@ +using LocalServices; +using LocalServices.Data; + +namespace Tests +{ + internal class AccountRecipesPreferencesTests + { + } +} diff --git a/Tests/AuthServiceTests.cs b/Tests/AuthServiceTests.cs new file mode 100644 index 0000000..0747e62 --- /dev/null +++ b/Tests/AuthServiceTests.cs @@ -0,0 +1,35 @@ + +using Models; +using LocalServices.Data; +using Moq; +using LocalServices; +using Services; + +namespace Tests +{ + public class AuthServiceTests + { + private static readonly User SAMPLE_USER = new User(new Uri("https://www.referenseo.com/wp-content/uploads/2019/03/image-attractive-960x540.jpg"), "user", Guid.NewGuid()); + private static readonly Account SAMPLE_ACC = new Account(SAMPLE_USER, "mail"); + + [Fact] + public void TestLogin() + { + var database = new Mock(); + database.Setup(x => x.GetAccount("mail", "1234")).Returns(SAMPLE_ACC); + var service = new AuthService(database.Object); + var acc = service.Login("mail", "1234"); + Assert.Equal(acc, SAMPLE_ACC); + } + + [Fact] + public void TestRegister() + { + var database = new Mock(); + database.Setup(x => x.GetAccount("mail", "1234")).Returns(SAMPLE_ACC); + var service = new AuthService(database.Object); + var acc = service.Register("mail", "foo", "1234"); + Assert.Equal(acc, new Account(new User(Constants.DEFAULT_ACCOUNT_IMAGE, "foo", acc.User.Id), "mail")); + } + } +} diff --git a/Tests/CatastrophicPreformancesDatabaseTests.cs b/Tests/CatastrophicPreformancesDatabaseTests.cs index bbc55cf..9742179 100644 --- a/Tests/CatastrophicPreformancesDatabaseTests.cs +++ b/Tests/CatastrophicPreformancesDatabaseTests.cs @@ -8,8 +8,7 @@ namespace Tests { private static readonly User SAMPLE_USER = new User(new Uri("https://www.referenseo.com/wp-content/uploads/2019/03/image-attractive-960x540.jpg"), "user", Guid.NewGuid()); - private static readonly Recipe SAMPLE_RECIPE = new RecipeBuilder("foo", SAMPLE_USER).Build(); - + /* [Fact] public void TestInsertRecipe() { @@ -39,6 +38,6 @@ namespace Tests db.InsertRecipe(SAMPLE_RECIPE); db.InsertInUserList(SAMPLE_USER.Id, SAMPLE_RECIPE.Info.Id, 99); Assert.True(db.GetRecipeListOf(SAMPLE_USER.Id)[SAMPLE_RECIPE.Info.Id] == 99); - } + }*/ } } diff --git a/Tests/RecipeServicesTests.cs b/Tests/RecipeServicesTests.cs new file mode 100644 index 0000000..b598009 --- /dev/null +++ b/Tests/RecipeServicesTests.cs @@ -0,0 +1,25 @@ +using LocalServices.Data; +using Models; +using LocalServices; +using Services; +using System.Collections.Immutable; + +namespace Tests +{ + public class RecipeServicesTests + { + private static readonly User SAMPLE_USER = new User(new Uri("https://www.referenseo.com/wp-content/uploads/2019/03/image-attractive-960x540.jpg"), "user", Guid.NewGuid()); + private static readonly Account SAMPLE_ACC = new Account(SAMPLE_USER, "mail"); + private static readonly Recipe SAMPLE_RECIPE = new RecipeBuilder("foo", SAMPLE_USER).Build(); + + [Fact] + public void GetRecipe() + { + var database = new Mock(); + database.Setup(x => x.GetRecipe(SAMPLE_RECIPE.Info.Id)).Returns(SAMPLE_RECIPE); + var service = new RecipesService(database.Object); + Assert.Equal(service.GetRecipe(SAMPLE_RECIPE.Info), SAMPLE_RECIPE); + } + + } +} diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index 1716292..a268461 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -11,6 +11,7 @@ + runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/Tests/Usings.cs b/Tests/Usings.cs index 8c927eb..7a8920d 100644 --- a/Tests/Usings.cs +++ b/Tests/Usings.cs @@ -1 +1,2 @@ -global using Xunit; \ No newline at end of file +global using Xunit; +global using Moq; \ No newline at end of file