public void GetUserBySub() { var user = new User() { UserId = 4, Username = "******", Auth0 = "Stuff" }; var result1 = new User(); var result2 = new User(); using (var context = new InTheKitchenDBContext(testOptions)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); context.Add(user); context.SaveChanges(); result2 = context.Users.FirstOrDefault(u => u.Auth0 == user.Auth0); } using (var context = new InTheKitchenDBContext(testOptions)) { context.Database.EnsureCreated(); var msr = new KitchenRepository(context); result1 = msr.GetUserDataBySub(user.Auth0); } Assert.Equal(result1.Username, result2.Username); }
public async Task TestIngredient() { var ingredient = new Ingredient() { IngredientId = 34, IngredientName = "Cheese" }; var result1 = new Ingredient(); var result2 = new Ingredient(); using (var context = new InTheKitchenDBContext(testOptions)) { context.Database.EnsureDeletedAsync(); context.Database.EnsureCreatedAsync(); context.Add(ingredient); context.SaveChanges(); result2 = await context.Ingredients.Where(i => i.IngredientName == ingredient.IngredientName).FirstOrDefaultAsync(); } using (var context = new InTheKitchenDBContext(testOptions)) { await context.Database.EnsureCreatedAsync(); var msr = new ReviewStepTagLogic(context); result1 = await msr.getOneIngredientByName(ingredient.IngredientName); } Assert.Equal(result1.IngredientName, result2.IngredientName); }
public void GetRecipeByID() { var recipe = new Recipe() { RecipeId = 4, RecipeAuthor = "Anis" }; var result1 = new Recipe(); var result2 = new Recipe(); using (var context = new InTheKitchenDBContext(testOptions)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); context.Add(recipe); context.SaveChanges(); result2 = context.Recipes.Where(r => r.RecipeId == recipe.RecipeId) .Include(r => r.RecipeIngredients) .ThenInclude(ri => ri.Ingredient) .Include(r => r.RecipeTags) .ThenInclude(rt => rt.Tag) .Include(r => r.Steps) .Include(r => r.Reviews) .FirstOrDefault(); } using (var context = new InTheKitchenDBContext(testOptions)) { context.Database.EnsureCreated(); var msr = new KitchenRepository(context); result1 = msr.GetRecipeById(recipe.RecipeId); } Assert.Equal(result1.RecipeAuthor, result2.RecipeAuthor); }
public void GetRecipes() { var reviews = new List <Recipe>(); var review1 = new Recipe() { RecipeId = 32, RecipeAuthor = "Anis", RecipeDescription = "Tacos" }; var review2 = new Recipe() { RecipeId = 320, RecipeAuthor = "Anis", RecipeDescription = "Tacos" }; reviews.Add(review1); reviews.Add(review2); var result1 = new List <Recipe>(); var result2 = new List <Recipe>(); using (var context = new InTheKitchenDBContext(testOptions)) { context.Database.EnsureDeletedAsync(); context.Database.EnsureCreatedAsync(); context.Add(review1); context.Add(review2); context.SaveChanges(); result2 = context.Recipes .Include(r => r.RecipeIngredients) .ThenInclude(ri => ri.Ingredient) .Include(r => r.RecipeTags) .ThenInclude(rt => rt.Tag) .Include(r => r.Steps) .ToList(); } using (var context = new InTheKitchenDBContext(testOptions)) { context.Database.EnsureCreatedAsync(); var msr = new KitchenRepository(context); result1 = (List <Recipe>)msr.GetAllRecipes(); } Assert.Equal(result1.Count, result2.Count); }
public void TestListUser() { List <User> users = new List <User>(); var user1 = (new User() { UserId = 23, Firstname = "Anis" }); var user2 = (new User() { UserId = 234, Firstname = "Nour" }); var user3 = (new User() { UserId = 231, Firstname = "Beau" }); users.Add(user1); users.Add(user2); users.Add(user3); List <User> result1 = new List <User>(); List <User> result2 = new List <User>(); using (var context = new InTheKitchenDBContext(testOptions)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); context.Add(user1); context.Add(user2); context.Add(user3); context.SaveChanges(); result2 = context.Users.ToList(); } using (var context = new InTheKitchenDBContext(testOptions)) { context.Database.EnsureCreated(); var msr = new UserLogic(context); result1 = msr.getAllUsers(); } Assert.Equal(result1.Count, result2.Count); }
public async Task TestListReview() { var reviews = new List <Review>(); var review1 = new Review() { ReviewId = 12, Recipe = new Recipe() { RecipeName = "Tacos" }, ReviewDescription = "Some description" }; var review2 = new Review() { ReviewId = 120, Recipe = new Recipe() { RecipeName = "Tacos" }, ReviewDescription = "Some other description" }; reviews.Add(review1); reviews.Add(review2); using (var context = new InTheKitchenDBContext(testOptions)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); context.Add(review1); context.Add(review2); context.SaveChanges(); } List <Review> result1; using (var context2 = new InTheKitchenDBContext(testOptions)) { context2.Database.EnsureCreated(); var msr = new ReviewStepTagLogic(context2); result1 = await msr.getReviewsByRecipeName("Tacos"); } Assert.Equal(reviews.Count, result1.Count); }
public async Task TestListTag() { var tags = new List <Tag>(); var tag1 = (new Tag() { TagId = 12, TagName = "Cheese", TagDescription = "Some description" }); var tag2 = (new Tag() { TagId = 120, TagName = "Beef", TagDescription = "Some other description" }); tags.Add(tag1); tags.Add(tag2); var result1 = new List <Tag>(); var result2 = new List <Tag>(); await using (var context = new InTheKitchenDBContext(testOptions)) { await context.Database.EnsureDeletedAsync(); await context.Database.EnsureCreatedAsync(); context.Add(tag1); context.Add(tag2); context.SaveChanges(); result2 = await context.Tags.ToListAsync(); } await using (var context = new InTheKitchenDBContext(testOptions)) { await context.Database.EnsureCreatedAsync(); var msr = new ReviewStepTagLogic(context); result1 = await msr.geTags(); } Assert.Equal(result1.Count, result2.Count); }
public async Task TestListIngredient() { var ingredients = new List <Ingredient>(); var ing1 = new Ingredient() { IngredientId = 12, IngredientName = "Cheese", IngredientDescription = "Some description" }; var ing2 = new Ingredient() { IngredientId = 120, IngredientName = "Beef", IngredientDescription = "Some other description" }; ingredients.Add(ing2); ingredients.Add(ing1); var result1 = new List <Ingredient>(); using (var context = new InTheKitchenDBContext(testOptions)) { context.Database.EnsureDeletedAsync(); context.Database.EnsureCreatedAsync(); context.Add(ing1); context.Add(ing2); context.SaveChanges(); } using (var context = new InTheKitchenDBContext(testOptions)) { context.Database.EnsureCreatedAsync(); var msr = new ReviewStepTagLogic(context); result1 = await msr.getIngredients(); } Assert.Equal(result1.Count, ingredients.Count); }
public bool UpdateUserAuth0Data(User user) { // todo: talk about what we want to save // * {"sub":"auth0|606e2aeaa32e9700697566ba", // * "nickname":"noureldinashraf6", // * "name":"*****@*****.**", // * "picture":"https://s.gravatar.com/avatar/162c31c37ca4c96d5bf9e43b9e2bd5a0?s=480&r=pg&d=https%3A%2F%2Fcdn.auth0.com%2Favatars%2Fno.png", // * "updated_at":"2021-04-08T13:21:23.390Z", // * "email":"*****@*****.**", // * "email_verified":false} var dbUser = _context.Users.FirstOrDefault(u => u.Auth0 == user.Auth0); dbUser.Email = user.Email; dbUser.ImageUrl = user.ImageUrl; // dbUser.DateLastAccessed = TimeManager.GetTimeNow(); dbUser.DateLastAccessed = DateTime.Now; _context.SaveChanges(); return(true); }