add other test
continuous-integration/drone/push Build is passing Details

master
maxime.BATISTA@etu.uca.fr 2 years ago
parent c4fe9350d4
commit 7aa2151aa5

@ -5,7 +5,7 @@ using System.Collections.Immutable;
namespace Services
{
internal class AccountOwnedRecipes : IAccountOwnedRecipesService
public class AccountOwnedRecipes : IAccountOwnedRecipesService
{
public Account Account { get; init; }

@ -5,7 +5,7 @@ using System.Collections.Immutable;
namespace LocalServices
{
internal class AccountRecipesPreferences : IAccountRecipesPreferencesService
public class AccountRecipesPreferences : IAccountRecipesPreferencesService
{
private readonly IDatabase db;

@ -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;

@ -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");
}

@ -5,7 +5,7 @@ using System.Collections.Immutable;
namespace LocalServices
{
internal class RecipesService : IRecipesService
public class RecipesService : IRecipesService
{
private readonly IDatabase db;

@ -0,0 +1,9 @@
using LocalServices;
using LocalServices.Data;
namespace Tests
{
internal class AccountRecipesPreferencesTests
{
}
}

@ -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<IDatabase>();
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<IDatabase>();
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"));
}
}
}

@ -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);
}
}*/
}
}

@ -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<IDatabase>();
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);
}
}
}

@ -11,6 +11,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="Moq" Version="4.18.4" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

@ -1 +1,2 @@
global using Xunit;
global using Moq;
Loading…
Cancel
Save