end UT
continuous-integration/drone/push Build is passing Details

master
Maxime BATISTA 2 years ago
parent 7aa2151aa5
commit 7d1f70b092

@ -56,7 +56,7 @@ namespace LocalServices
public RecipeRate GetRate(RecipeInfo info)
{
RecipeRate rate = null;
RecipeRate? rate = null;
var ratings = db.ListRatesOf(Account.User.Id);
if (!ratings.TryGetValue(info.Id, out rate))
@ -82,7 +82,6 @@ namespace LocalServices
public void AddToFavorites(RecipeInfo info)
{
Guid userId = Account.User.Id;
var ratings = db.ListRatesOf(userId);
RecipeRate rate = GetRate(info);
db.InsertRate(userId, info.Id, new RecipeRate(true, rate.Rate));
@ -91,7 +90,6 @@ namespace LocalServices
public void RemoveFromFavorites(RecipeInfo info)
{
Guid userId = Account.User.Id;
var ratings = db.ListRatesOf(userId);
RecipeRate rate = GetRate(info);
db.InsertRate(userId, info.Id, new RecipeRate(false, rate.Rate));
@ -100,7 +98,6 @@ namespace LocalServices
public void SetReviewScore(RecipeInfo info, uint score)
{
Guid userId = Account.User.Id;
var ratings = db.ListRatesOf(userId);
RecipeRate rate = GetRate(info);
db.InsertRate(userId, info.Id, new RecipeRate(rate.IsFavorite, Math.Min(score, 5)));

@ -0,0 +1,26 @@
using LocalServices.Data;
using Models;
using Services;
using System.Collections.Immutable;
namespace Tests
{
public class AccountOwnedRecipesTest
{
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 UploadRemove()
{
var db = new Mock<IDatabase>();
db.Setup(x => x.ListAllRecipes()).Returns(() => new List<Recipe>().ToImmutableList());
var owned = new AccountOwnedRecipes(SAMPLE_ACC, db.Object);
owned.UploadRecipe(SAMPLE_RECIPE);
Assert.Contains(SAMPLE_RECIPE.Info, owned.GetAccountRecipes());
owned.RemoveRecipe(SAMPLE_RECIPE.Info);
Assert.DoesNotContain(SAMPLE_RECIPE.Info, owned.GetAccountRecipes());
}
}
}

@ -1,9 +1,46 @@
using LocalServices;
using LocalServices.Data;
using Models;
using System.Collections.Immutable;
namespace Tests
{
internal class AccountRecipesPreferencesTests
public class AccountRecipesPreferencesTests
{
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 Review()
{
var fav_inserted = false;
var rate_inserted = false;
var dict = new Dictionary<Guid, RecipeRate>();
var db = new Mock<IDatabase>();
db.Setup(x => x.ListRatesOf(SAMPLE_USER.Id)).Returns(() => dict.ToImmutableDictionary());
db.Setup(x => x.InsertRate(SAMPLE_USER.Id, SAMPLE_RECIPE.Info.Id, new RecipeRate(true, 0))).Callback(() => fav_inserted = true);
db.Setup(x => x.InsertRate(SAMPLE_USER.Id, SAMPLE_RECIPE.Info.Id, new RecipeRate(false, 3))).Callback(() => rate_inserted = true);
var pref = new AccountRecipesPreferences(SAMPLE_ACC, db.Object);
pref.AddToFavorites(SAMPLE_RECIPE.Info);
pref.SetReviewScore(SAMPLE_RECIPE.Info, 3);
Assert.True(fav_inserted);
Assert.True(rate_inserted);
}
public void AddWeeklyList()
{
var inserted = false;
var dict = new Dictionary<Guid, uint> { };
dict.Add(SAMPLE_RECIPE.Info.Id, 88);
var db = new Mock<IDatabase>();
db.Setup(x => x.GetRecipeListOf(SAMPLE_USER.Id)).Returns(() => dict);
db.Setup(x => x.InsertInUserList(SAMPLE_USER.Id, SAMPLE_RECIPE.Info.Id, 88)).Callback(() => inserted = true);
var pref = new AccountRecipesPreferences(SAMPLE_ACC, db.Object);
pref.AddToWeeklyList(SAMPLE_RECIPE.Info, 88);
Assert.True(inserted);
Assert.True(pref.GetWeeklyList().Contains((SAMPLE_RECIPE.Info, 88)));
}
}
}

@ -1,43 +0,0 @@
using LocalServices.Data;
using Models;
using static System.Runtime.InteropServices.JavaScript.JSType;
namespace Tests
{
public class CatastrophicPreformancesDatabaseTests
{
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());
/*
[Fact]
public void TestInsertRecipe()
{
var db = new CatastrophicPerformancesDatabase("/tmp");
db.InsertUser(SAMPLE_USER);
db.InsertRecipe(SAMPLE_RECIPE);
Assert.Contains(SAMPLE_RECIPE, db.ListAllRecipes());
}
[Fact]
public void TestInsertRate()
{
var db = new CatastrophicPerformancesDatabase("/tmp");
var rate = new RecipeRate(true, 4);
db.InsertUser(SAMPLE_USER);
db.InsertRate(SAMPLE_USER.Id, SAMPLE_RECIPE.Info.Id, rate);
Assert.Equal(rate, db.GetRecipeRate(SAMPLE_USER.Id, SAMPLE_RECIPE.Info.Id));
Assert.True(db.ListRatesOf(SAMPLE_USER.Id)[SAMPLE_USER.Id] == rate);
}
[Fact]
public void TestInsertWeeklyList()
{
var db = new CatastrophicPerformancesDatabase("/tmp");
db.InsertUser(SAMPLE_USER);
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);
}*/
}
}

@ -1,15 +0,0 @@
using Models;
namespace Tests
{
public class UnitTest1
{
[Fact]
public void Test1()
{
new RecipeRate(true, 4);
}
}
}
Loading…
Cancel
Save