diff --git a/LocalServices/Data/CatastrophicPerformancesDatabase.cs b/LocalServices/Data/CatastrophicPerformancesDatabase.cs index 462417b..70ae20b 100644 --- a/LocalServices/Data/CatastrophicPerformancesDatabase.cs +++ b/LocalServices/Data/CatastrophicPerformancesDatabase.cs @@ -9,7 +9,7 @@ namespace LocalServices.Data /// Database implementation with catastrophic performances. /// This database implementation persists data in json and will save all the data in their files for each mutable requests. /// - internal class CatastrophicPerformancesDatabase : IDatabase + public class CatastrophicPerformancesDatabase : IDatabase { private static readonly string RECIPES_FILENAME = "recipes_data.xml"; diff --git a/Tests/CatastrophicPreformancesDatabaseTests.cs b/Tests/CatastrophicPreformancesDatabaseTests.cs new file mode 100644 index 0000000..bbc55cf --- /dev/null +++ b/Tests/CatastrophicPreformancesDatabaseTests.cs @@ -0,0 +1,44 @@ +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()); + private static readonly Recipe SAMPLE_RECIPE = new RecipeBuilder("foo", SAMPLE_USER).Build(); + + [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); + } + } +}