public async Task SetsNewRating_WhenValidModelIsPassed()
        {
            var options = TestUtils.GetOptions(nameof(SetsNewRating_WhenValidModelIsPassed));
            var user    = new AppUser {
                Id = "1"
            };
            var bar = new Bar {
                Id = "2"
            };
            var barReviewDTO = new BarReviewDTO
            {
                Rating      = 8,
                Description = "10",
                UserID      = "1",
                BarId       = "2"
            };
            var review = new BarReview {
                Rating = 10, Description = "0100101", BarId = "2"
            };

            using (var arrangeContext = new CMContext(options))
            {
                var sut = new ReviewServices(arrangeContext);
                arrangeContext.Add(user);
                arrangeContext.Add(bar);
                arrangeContext.Add(review);
                await arrangeContext.SaveChangesAsync();

                await sut.CreateBarReview(barReviewDTO);

                Assert.AreEqual(9, arrangeContext.Bars.First().BarRating);
            }
        }
        public async Task ThrowExceptionMessage_WhenCocktailLikeDoesntExist()
        {
            var options = TestUtils.GetOptions(nameof(ThrowExceptionMessage_WhenCocktailLikeDoesntExist));

            var cocktail = new Cocktail {
                Id = "2"
            };
            var user = new AppUser {
                Id = "1"
            };
            var review1 = new CocktailReview {
                Id = "1", Rating = 6, Description = "0100101", CocktailId = "2"
            };
            var review2 = new CocktailReview {
                Id = "2", Rating = 10, Description = "0100101", CocktailId = "2"
            };

            //var like1 = new CocktaiilReviewLike { Id = "1", BarReviewID = "1", AppUserID = "1" };
            //var like2 = new BarReviewLike { Id = "2", BarReviewID = "2", AppUserID="1" };
            using (var arrangeContext = new CMContext(options))
            {
                var sut = new ReviewServices(arrangeContext);
                arrangeContext.Add(cocktail);
                arrangeContext.Add(user);
                arrangeContext.Add(review1);
                await arrangeContext.SaveChangesAsync();

                var ex = await Assert.ThrowsExceptionAsync <MagicException>(
                    async() => await sut.RemoveBarReviewLike(review1.Id, user.Id)
                    );

                Assert.AreEqual(ExceptionMessages.LikeNull, ex.Message);
            }
        }
Example #3
0
        public async Task ExcludeDeletedCocktails_WhenCalled()
        {
            var options = TestUtils.GetOptions(nameof(ExcludeDeletedCocktails_WhenCalled));

            using (var arrangeContext = new CMContext(options))
            {
                for (int i = 0; i < 4; i++)
                {
                    arrangeContext.Add(new Cocktail());
                }
                ;
                arrangeContext.Add(new Cocktail()
                {
                    DateDeleted = DateTime.Now
                });
                arrangeContext.Add(new Cocktail()
                {
                    DateDeleted = DateTime.Now
                });
                await arrangeContext.SaveChangesAsync();
            }
            using (var assertContext = new CMContext(options))
            {
                var sut = new CocktailServices(assertContext, _fileUploadService.Object,
                                               _ingredientServices.Object, _recipeServices.Object);
                var result = await sut.GetPageCountForCocktials(2);

                Assert.AreEqual(2, result);
            }
        }
Example #4
0
        public async Task SetsNewRating_WhenValidBarIdIsPassed()
        {
            var options = TestUtils.GetOptions(nameof(SetsNewRating_WhenValidBarIdIsPassed));

            var bar = new Bar {
                Id = "2"
            };
            var Bar = new Bar
            {
                Id = "1"
            };
            var review1 = new BarReview {
                Rating = 6, Description = "0100101", BarId = "2"
            };
            var review2 = new BarReview {
                Rating = 10, Description = "0100101", BarId = "2"
            };


            using (var arrangeContext = new CMContext(options))
            {
                var sut = new ReviewServices(arrangeContext);
                arrangeContext.Add(bar);
                arrangeContext.Add(review1);
                arrangeContext.Add(review2);
                await arrangeContext.SaveChangesAsync();

                await sut.SetAverrageRatingForBar("2");

                Assert.AreEqual(8, arrangeContext.Bars.First().BarRating);
            }
        }
        public async Task ThrowException_WhenLikeDoesntExist()
        {
            var options = TestUtils.GetOptions(nameof(ThrowException_WhenLikeDoesntExist));

            var bar = new Bar {
                Id = "2"
            };
            var user = new AppUser {
                Id = "1"
            };
            var review1 = new BarReview {
                Id = "1", Rating = 6, Description = "0100101", BarId = "2"
            };
            //var review2 = new BarReview { Id = "2", Rating = 10, Description = "0100101", BarId = "2" };
            var like1 = new BarReviewLike {
                Id = "1", BarReviewID = "1", AppUserID = "1"
            };

            //var like2 = new BarReviewLike { Id = "2", BarReviewID = "2", AppUserID="1" };
            using (var arrangeContext = new CMContext(options))
            {
                var sut = new ReviewServices(arrangeContext);
                arrangeContext.Add(bar);
                arrangeContext.Add(user);
                arrangeContext.Add(review1);
                //arrangeContext.Add(review2);
                //arrangeContext.Add(like1);
                await arrangeContext.SaveChangesAsync();

                var ex = await Assert.ThrowsExceptionAsync <MagicException>(
                    async() => await sut.RemoveBarReviewLike(review1.Id, user.Id)
                    );
            }
        }
        public async Task ExcludeAllDeletedCocktailsFromResults_WhenCalled()
        {
            var options   = TestUtils.GetOptions(nameof(ExcludeAllDeletedCocktailsFromResults_WhenCalled));
            var sortOrder = "name_desc";

            using (var arrangeContext = new CMContext(options))
            {
                for (int i = 0; i < 2; i++)
                {
                    arrangeContext.Add(new Cocktail());
                }
                ;
                arrangeContext.Add(new Cocktail()
                {
                    DateDeleted = DateTime.Now
                });
                await arrangeContext.SaveChangesAsync();
            }
            using (var assertContext = new CMContext(options))
            {
                var sut = new CocktailServices(assertContext, _fileUploadService.Object,
                                               _ingredientServices.Object, _recipeServices.Object);
                var result = await sut.GetFiveSortedCocktailsAsync(sortOrder);

                Assert.AreEqual(2, result.Count);
            }
        }
        public async Task RemoveLikeBarReview_WhenValidBarIdIsPassed()
        {
            var options = TestUtils.GetOptions(nameof(RemoveLikeBarReview_WhenValidBarIdIsPassed));
            var bar     = new Bar {
                Id = "2"
            };
            var user = new AppUser {
                Id = "1"
            };
            var review1 = new BarReview {
                Id = "1", Rating = 6, Description = "0100101", BarId = "2"
            };
            var review2 = new BarReview {
                Id = "2", Rating = 10, Description = "0100101", BarId = "2"
            };
            var like1 = new BarReviewLike {
                Id = "1", BarReviewID = "1", AppUserID = "1"
            };

            //var like2 = new BarReviewLike { Id = "2", BarReviewID = "2", AppUserID="1" };
            using (var arrangeContext = new CMContext(options))
            {
                var sut = new ReviewServices(arrangeContext);
                arrangeContext.Add(bar);
                arrangeContext.Add(user);
                arrangeContext.Add(review1);
                arrangeContext.Add(like1);
                await arrangeContext.SaveChangesAsync();

                Assert.AreEqual(1, arrangeContext.BarReviewLikes.Count());
                await sut.RemoveBarReviewLike(review1.Id, user.Id);

                Assert.AreEqual(0, arrangeContext.BarReviewLikes.Count());
            }
        }
        public async Task ThrowExceptionWithCorrectMessage_WhenUserAlreadyReviewedBar()
        {
            var options = TestUtils.GetOptions(nameof(ThrowExceptionWithCorrectMessage_WhenUserAlreadyReviewedBar));
            var user    = new AppUser {
                Id = "1"
            };
            var bar = new Bar {
                Id = "2"
            };
            var barReviewDTO = new BarReviewDTO
            {
                Rating      = 10,
                Description = "10",
                UserID      = "1",
                BarId       = "2"
            };
            var review = new BarReview {
                Rating = 5, Description = "0100101", UserId = "1", BarId = "2"
            };

            using (var arrangeContext = new CMContext(options))
            {
                var sut = new ReviewServices(arrangeContext);
                arrangeContext.Add(user);
                arrangeContext.Add(bar);
                arrangeContext.Add(review);
                await arrangeContext.SaveChangesAsync();

                var ex = await Assert.ThrowsExceptionAsync <MagicException>(
                    async() => await sut.CreateBarReview(barReviewDTO)
                    );

                Assert.AreEqual("You have already reviewed this bar!", ex.Message);
            }
        }
        public async Task LikeCocktailReview_WhenValidBarIdIsPassed()
        {
            var options = TestUtils.GetOptions(nameof(LikeCocktailReview_WhenValidBarIdIsPassed));

            var cocktail = new Cocktail {
                Id = "2"
            };
            var user = new AppUser {
                Id = "1"
            };
            var review1 = new CocktailReview {
                Id = "1", Rating = 6, Description = "0100101", UserId = user.Id, CocktailId = "2"
            };
            var review2 = new CocktailReview {
                Id = "2", Rating = 10, Description = "0100101", UserId = user.Id, CocktailId = "2"
            };

            //var like1 = new BarReviewLike { Id = "1", BarReviewID = "1" , AppUserID = "1"};
            //var like2 = new BarReviewLike { Id = "2", BarReviewID = "2", AppUserID="1" };
            using (var arrangeContext = new CMContext(options))
            {
                var sut = new ReviewServices(arrangeContext);
                arrangeContext.Add(cocktail);
                arrangeContext.Add(user);
                arrangeContext.Add(review1);
                arrangeContext.Add(review2);
                await arrangeContext.SaveChangesAsync();

                await sut.LikeCocktailReview(cocktail.Id, user.Id);

                Assert.AreEqual("1", arrangeContext.CocktailReviews.First().UserId);
                Assert.AreEqual("2", arrangeContext.CocktailReviews.First().CocktailId);
            }
        }
        public async Task AddCorrectReviewToDB_WhenValidModelIsPassed()
        {
            var options = TestUtils.GetOptions(nameof(AddCorrectReviewToDB_WhenValidModelIsPassed));
            var user    = new AppUser {
                Id = "1"
            };
            var bar = new Bar {
                Id = "2"
            };
            var barReviewDTO = new BarReviewDTO
            {
                Rating      = 10,
                Description = "10",
                UserID      = "1",
                BarId       = "2"
            };

            using (var arrangeContext = new CMContext(options))
            {
                var sut = new ReviewServices(arrangeContext);
                arrangeContext.Add(user);
                arrangeContext.Add(bar);
                await arrangeContext.SaveChangesAsync();

                await sut.CreateBarReview(barReviewDTO);

                Assert.AreEqual(10, arrangeContext.BarReviews.First().Rating);
                Assert.AreEqual("10", arrangeContext.BarReviews.First().Description);
                Assert.AreEqual("1", arrangeContext.BarReviews.First().UserId);
                Assert.AreEqual("2", arrangeContext.BarReviews.First().BarId);
            }
        }
        public async Task CorrectlyLoadAllDependenciesForLoadedCocktails_WhenCalledForHomePage()
        {
            var options             = TestUtils.GetOptions(nameof(CorrectlyLoadAllDependenciesForLoadedCocktails_WhenCalledForHomePage));
            var cocktailId          = "15";
            var barId               = "51";
            var barName             = "Fofo";
            var cocktailComponentId = "15";
            var ingredientId        = "15";
            var ingredientName      = "Bira";
            var newIngredient       = new Ingredient()
            {
                Id = ingredientId, Name = ingredientName
            };
            var newCocktailComponent = new CocktailComponent()
            {
                Id = cocktailComponentId, IngredientId = ingredientId, Ingredient = newIngredient
            };
            var listComponents = new List <CocktailComponent>();

            listComponents.Add(newCocktailComponent);
            var newBar = new Bar()
            {
                Id = barId, Name = barName
            };
            var newBarCocktail = new BarCocktail()
            {
                BarId = barId, Bar = newBar, CocktailId = cocktailId
            };
            var barCocktails = new List <BarCocktail>();

            barCocktails.Add(newBarCocktail);
            var newCocktail = new Cocktail()
            {
                Id           = cocktailId, CocktailComponents = listComponents,
                BarCocktails = barCocktails
            };

            using (var arrangeContext = new CMContext(options))
            {
                arrangeContext.Add(newIngredient);
                arrangeContext.Add(newBar);
                arrangeContext.Add(newBarCocktail);
                arrangeContext.Add(newCocktailComponent);
                arrangeContext.Add(newCocktail);
                await arrangeContext.SaveChangesAsync();
            }
            using (var assertContext = new CMContext(options))
            {
                var sut = new CocktailServices(assertContext, _fileUploadService.Object,
                                               _ingredientServices.Object, _recipeServices.Object);
                var result = await sut.GetCocktailsForHomePage();

                Assert.AreEqual(cocktailId, result.ToList()[0].Id);
                Assert.AreEqual(barId, result.ToList()[0].BarCocktails[0].BarId);
                Assert.AreEqual(barName, result.ToList()[0].BarCocktails[0].Bar.Name);
                Assert.AreEqual(ingredientName, result.ToList()[0].Ingredients[0].Ingredient);
            }
        }
Example #12
0
        public async Task GetNumberOfUnseenNotificationsForUser_WhenCalledWithCorrectId()
        {
            var options = TestUtils.GetOptions(nameof(GetNumberOfUnseenNotificationsForUser_WhenCalledWithCorrectId));

            var adminName    = "pesho";
            var id           = "1";
            var description  = "new";
            var userName     = "******";
            var notification = new Notification
            {
                Description = description,
                Username    = userName,
                UserId      = "1",
                IsSeen      = false
            };
            var notification2 = new Notification
            {
                Description = "new",
                Username    = userName,
                UserId      = "1",
                IsSeen      = false
            };
            var notification3 = new Notification
            {
                Description = "new",
                Username    = userName,
                UserId      = "1",
                IsSeen      = true
            };

            var admin = new AppUser
            {
                Id       = id,
                UserName = adminName
            };

            _userServices.Setup(x => x.GetAdmin())
            .ReturnsAsync(admin);

            using (var arrangeContext = new CMContext(options))
            {
                arrangeContext.Add(admin);
                arrangeContext.Add(notification);
                arrangeContext.Add(notification2);
                arrangeContext.Add(notification3);
                await arrangeContext.SaveChangesAsync();

                var sut = new NotificationServices(arrangeContext, _userServices.Object,
                                                   _iNotificationManager.Object);
                var result = await sut.GetUnseenNotificationsCountForUserAsync(id);

                Assert.AreEqual(2, result);
            }
        }
Example #13
0
        public async Task CallNotificationManagerForMsg_WithCorrectParameters()
        {
            var options = TestUtils.GetOptions(nameof(CallNotificationManagerForMsg_WithCorrectParameters));

            var adminName = "pesho";
            var id        = "1";
            var barName   = "newBar";

            var admin = new AppUser
            {
                Id       = id,
                UserName = adminName
            };

            _userServices.Setup(x => x.GetAdmin())
            .ReturnsAsync(admin);
            _iNotificationManager.Setup(x => x.QuickMessageDescription("name", "email", "msg"))
            .Returns("msg");

            using (var arrangeContext = new CMContext(options))
            {
                arrangeContext.Add(admin);
                await arrangeContext.SaveChangesAsync();

                var sut = new NotificationServices(arrangeContext, _userServices.Object,
                                                   _iNotificationManager.Object);
                await sut.CreateNewMessageAsync("name", "email", "msg");

                _iNotificationManager.Verify(x => x.QuickMessageDescription("name", "email", "msg"), Times.Once());
            }
        }
        public async Task GetCorrectlySortedCocktails_WhenCalledWitRatingDesc()
        {
            var options   = TestUtils.GetOptions(nameof(GetCorrectlySortedCocktails_WhenCalledWitRatingDesc));
            var sortOrder = "rating_desc";

            using (var arrangeContext = new CMContext(options))
            {
                double rating = 1;
                for (int i = 0; i < 5; i++)
                {
                    arrangeContext.Add(new Cocktail {
                        Rating = rating
                    });
                    rating++;
                }
                ;
                await arrangeContext.SaveChangesAsync();
            }
            using (var assertContext = new CMContext(options))
            {
                var sut = new CocktailServices(assertContext, _fileUploadService.Object,
                                               _ingredientServices.Object, _recipeServices.Object);
                var result = await sut.GetFiveSortedCocktailsAsync(sortOrder);

                Assert.AreEqual(5, result.ToList()[0].Rating);
                Assert.AreEqual(1, result.ToList()[4].Rating);
            }
        }
Example #15
0
        public async Task EditImagePath_WhenNewImageIsPassed()
        {
            var cocktailName   = "Mojito";
            var image          = new Mock <IFormFile>().Object;
            var cocktailDtoId  = "15";
            var options        = TestUtils.GetOptions(nameof(EditImagePath_WhenNewImageIsPassed));
            var newCocktailDto = new CocktailDto
            {
                Id            = cocktailDtoId,
                Name          = cocktailName,
                CocktailImage = image
            };

            using (var arrangeContext = new CMContext(options))
            {
                var sut = new CocktailServices(arrangeContext, _fileUploadService.Object,
                                               _ingredientServices.Object, _recipeServices.Object);

                arrangeContext.Add(new Cocktail {
                    Id = cocktailDtoId, Name = "NotMojito", Image = null
                });
                await arrangeContext.SaveChangesAsync();

                await sut.Update(newCocktailDto);

                Assert.AreNotEqual(cocktailDtoId, arrangeContext.Cocktails.First().Image);
            }
        }
Example #16
0
        public async Task AddNotificationMessageToDB_WithCorrectParameters()
        {
            var options = TestUtils.GetOptions(nameof(AddNotificationMessageToDB_WithCorrectParameters));

            var adminName = "pesho";
            var id        = "1";
            var barName   = "newBar";

            var admin = new AppUser
            {
                Id       = id,
                UserName = adminName
            };

            _userServices.Setup(x => x.GetAdmin())
            .ReturnsAsync(admin);
            _iNotificationManager.Setup(x => x.QuickMessageDescription(adminName, "email", "msg"))
            .Returns("msg");

            using (var arrangeContext = new CMContext(options))
            {
                arrangeContext.Add(admin);
                await arrangeContext.SaveChangesAsync();

                var sut = new NotificationServices(arrangeContext, _userServices.Object,
                                                   _iNotificationManager.Object);
                Assert.AreEqual(0, arrangeContext.Notifications.Count());
                await sut.CreateNewMessageAsync(adminName, "email", "msg");

                Assert.AreEqual(1, arrangeContext.Notifications.Count());
                Assert.AreEqual("msg", arrangeContext.Notifications.First().Description);
                Assert.AreEqual(adminName, arrangeContext.Notifications.First().Username);
            }
        }
Example #17
0
        public async Task PreservRating_WhenCalled()
        {
            var cocktailName   = "Mojito";
            var cocktailDtoId  = "15";
            var options        = TestUtils.GetOptions(nameof(PreservRating_WhenCalled));
            var newCocktailDto = new CocktailDto
            {
                Id            = cocktailDtoId,
                Name          = cocktailName,
                CocktailImage = null,
                Image         = "555",
                Rating        = 7.00
            };

            using (var arrangeContext = new CMContext(options))
            {
                var sut = new CocktailServices(arrangeContext, _fileUploadService.Object,
                                               _ingredientServices.Object, _recipeServices.Object);

                arrangeContext.Add(new Cocktail
                {
                    Id   = cocktailDtoId,
                    Name = "NotMojito"
                    ,
                    Image  = "111",
                    Rating = 10.00
                });
                await arrangeContext.SaveChangesAsync();

                await sut.Update(newCocktailDto);

                Assert.AreEqual(10, arrangeContext.Cocktails.First().Rating);
            }
        }
Example #18
0
        public async Task CallExtractRecipeMethod_WithCorrectParametersInEdit()
        {
            var options       = TestUtils.GetOptions(nameof(CallExtractRecipeMethod_WithCorrectParametersInEdit));
            var cocktailDtoId = "15";
            var cocktailName  = "Mojito";
            var recipe        = "111";
            var image         = new Mock <IFormFile>().Object;
            var cocktailDTO   = new CocktailDto()
            {
                Id = cocktailDtoId, Name = cocktailName, Recipe = recipe, CocktailImage = image
            };

            using (var assertContext = new CMContext(options))
            {
                assertContext.Add(new Cocktail
                {
                    Id     = cocktailDtoId,
                    Name   = "NotMojito",
                    Image  = "111",
                    Rating = 10.00
                });
                await assertContext.SaveChangesAsync();

                var sut = new CocktailServices(assertContext, _fileUploadService.Object,
                                               _ingredientServices.Object, _recipeServices.Object);
                await sut.Update(cocktailDTO);

                _recipeServices.Verify(n => n.ExtractRecipe(assertContext.Cocktails.First()), Times.Once());
            }
        }
Example #19
0
        public async Task PreserveImagePath_WhenNewImageIsNullInEdit()
        {
            var cocktailName   = "Mojito";
            var cocktailDtoId  = "15";
            var options        = TestUtils.GetOptions(nameof(PreserveImagePath_WhenNewImageIsNullInEdit));
            var newCocktailDto = new CocktailDto
            {
                Id            = cocktailDtoId,
                Name          = cocktailName,
                CocktailImage = null,
                Image         = "555"
            };

            using (var arrangeContext = new CMContext(options))
            {
                var sut = new CocktailServices(arrangeContext, _fileUploadService.Object,
                                               _ingredientServices.Object, _recipeServices.Object);

                arrangeContext.Add(new Cocktail {
                    Id = cocktailDtoId, Name = "NotMojito", Image = "111"
                });
                await arrangeContext.SaveChangesAsync();

                await sut.Update(newCocktailDto);

                Assert.AreNotEqual("555", arrangeContext.Cocktails.First().Image);
            }
        }
        public async Task ThrowCorrectMessage_WhenTheCocktailIsDeleted()
        {
            var options      = TestUtils.GetOptions(nameof(ThrowCorrectMessage_WhenTheCocktailIsDeleted));
            var cocktailId   = "15";
            var cocktailName = "Mohito";
            var newCocktail  = new Cocktail()
            {
                Id = cocktailId, Name = cocktailName, DateDeleted = DateTime.Now
            };

            using (var arrangeContext = new CMContext(options))
            {
                arrangeContext.Add(newCocktail);
                await arrangeContext.SaveChangesAsync();
            }
            using (var assertContext = new CMContext(options))
            {
                var sut = new CocktailServices(assertContext, _fileUploadService.Object,
                                               _ingredientServices.Object, _recipeServices.Object);
                var ex = await Assert.ThrowsExceptionAsync <MagicException>(
                    async() => await sut.GetCocktailIdByName(cocktailName));

                Assert.AreEqual("Cocktail doesn't exist in DB!", ex.Message);
            }
        }
        public async Task CallUserManagerForDeleteBar_WithCorrectParameters()
        {
            var options = TestUtils.GetOptions(nameof(CallUserManagerForDeleteBar_WithCorrectParameters));

            var adminName = "pesho";
            var id        = "1";
            var barName   = "newBar";

            var admin = new AppUser
            {
                Id       = id,
                UserName = adminName
            };

            _userServices.Setup(x => x.GetUsernameById(id))
            .ReturnsAsync(admin.UserName);
            _userServices.Setup(x => x.GetAdmin())
            .ReturnsAsync(admin);
            _iNotificationManager.Setup(x => x.BarDeletedDescription(adminName, barName))
            .Returns($"New Bar notification: User: {adminName}, just added new Bar with name: {barName}");

            using (var arrangeContext = new CMContext(options))
            {
                arrangeContext.Add(admin);
                await arrangeContext.SaveChangesAsync();

                var sut = new NotificationServices(arrangeContext, _userServices.Object,
                                                   _iNotificationManager.Object);
                await sut.BarDeletedNotificationToAdminAsync(id, barName);

                _userServices.Verify(u => u.GetUsernameById(id), Times.Once());
            }
        }
        public async Task Get5CocktailsWithHighesRate_WhenCalled()
        {
            var options = TestUtils.GetOptions(nameof(Get5CocktailsWithHighesRate_WhenCalled));

            using (var arrangeContext = new CMContext(options))
            {
                for (int i = 0; i < 10; i++)
                {
                    arrangeContext.Add(new Cocktail()
                    {
                        Rating = i + 1
                    });
                }
                ;
                await arrangeContext.SaveChangesAsync();
            }
            using (var assertContext = new CMContext(options))
            {
                var sut = new CocktailServices(assertContext, _fileUploadService.Object,
                                               _ingredientServices.Object, _recipeServices.Object);
                var result = await sut.GetCocktailsForHomePage();

                double rating = 10f;
                foreach (var item in result)
                {
                    Assert.AreEqual(rating, item.Rating);
                    rating--;
                }
            }
        }
Example #23
0
        public async Task AddNotificationToDB_WithCorrectParameters()
        {
            var options = TestUtils.GetOptions(nameof(AddNotificationToDB_WithCorrectParameters));

            var adminName = "pesho";
            var id        = "1";
            var barName   = "newBar";

            var admin = new AppUser
            {
                Id       = id,
                UserName = adminName
            };

            _userServices.Setup(x => x.GetUsernameById(id))
            .ReturnsAsync(admin.UserName);
            _userServices.Setup(x => x.GetAdmin())
            .ReturnsAsync(admin);
            _iNotificationManager.Setup(x => x.BarAddedDescription(adminName, barName))
            .Returns($"New Bar notification: User: {adminName}, just added new Bar with name: {barName}");

            using (var arrangeContext = new CMContext(options))
            {
                arrangeContext.Add(admin);
                await arrangeContext.SaveChangesAsync();

                Assert.AreEqual(0, arrangeContext.Notifications.Count());
                var sut = new NotificationServices(arrangeContext, _userServices.Object,
                                                   _iNotificationManager.Object);
                await sut.BarCreateNotificationToAdminAsync(id, barName);

                Assert.AreEqual(1, arrangeContext.Notifications.Count());
            }
        }
        public async Task GetCorrectlySortedCocktails_WhenCalledWithoutSortOrder()
        {
            var options = TestUtils.GetOptions(nameof(GetCorrectlySortedCocktails_WhenCalledWithoutSortOrder));

            using (var arrangeContext = new CMContext(options))
            {
                string name = "A";
                for (int i = 0; i < 5; i++)
                {
                    arrangeContext.Add(new Cocktail {
                        Name = name
                    });
                    name += i;
                }
                ;
                await arrangeContext.SaveChangesAsync();
            }
            using (var assertContext = new CMContext(options))
            {
                var sut = new CocktailServices(assertContext, _fileUploadService.Object,
                                               _ingredientServices.Object, _recipeServices.Object);
                var result = await sut.GetFiveSortedCocktailsAsync(null);

                Assert.AreEqual("A", result.ToList()[0].Name);
                Assert.AreEqual("A0123", result.ToList()[4].Name);
            }
        }
Example #25
0
        public async Task CallNotificationManagerForEditNewCocktail_WithCorrectParameters()
        {
            var options = TestUtils.GetOptions(nameof(CallNotificationManagerForEditNewCocktail_WithCorrectParameters));

            var adminName    = "pesho";
            var id           = "1";
            var oldName      = "oldCocktail";
            var cocktailName = "newCocktail";

            var admin = new AppUser
            {
                Id       = id,
                UserName = adminName
            };

            _userServices.Setup(x => x.GetUsernameById(id))
            .ReturnsAsync(admin.UserName);
            _userServices.Setup(x => x.GetAdmin())
            .ReturnsAsync(admin);
            _iNotificationManager.Setup(x => x.CocktailEditedDescription(adminName, oldName, cocktailName))
            .Returns($"LALALALA");

            using (var arrangeContext = new CMContext(options))
            {
                arrangeContext.Add(admin);
                await arrangeContext.SaveChangesAsync();

                var sut = new NotificationServices(arrangeContext, _userServices.Object,
                                                   _iNotificationManager.Object);
                await sut.CocktailEditNotificationToAdminAsync(id, oldName, cocktailName);

                _iNotificationManager.Verify(x => x.CocktailEditedDescription(adminName, oldName, cocktailName), Times.Once());
            }
        }
Example #26
0
        public async Task AddNotificationToDBForEditCocktailWithCorrectDecription_WithCorrectParameters()
        {
            var options = TestUtils.GetOptions(nameof(AddNotificationToDBForEditCocktailWithCorrectDecription_WithCorrectParameters));

            var adminName    = "pesho";
            var id           = "1";
            var oldName      = "oldCocktail";
            var cocktailName = "newCocktail";
            var admin        = new AppUser
            {
                Id       = id,
                UserName = adminName
            };

            _userServices.Setup(x => x.GetUsernameById(id))
            .ReturnsAsync(admin.UserName);
            _userServices.Setup(x => x.GetAdmin())
            .ReturnsAsync(admin);
            _iNotificationManager.Setup(x => x.CocktailEditedDescription(adminName, oldName, cocktailName))
            .Returns("LALALALALA");

            using (var arrangeContext = new CMContext(options))
            {
                arrangeContext.Add(admin);
                await arrangeContext.SaveChangesAsync();

                Assert.AreEqual(0, arrangeContext.Notifications.Count());
                var sut = new NotificationServices(arrangeContext, _userServices.Object,
                                                   _iNotificationManager.Object);
                await sut.CocktailEditNotificationToAdminAsync(id, oldName, cocktailName);

                Assert.AreEqual("LALALALALA", arrangeContext.Notifications.First().Description);
                Assert.AreEqual(adminName, arrangeContext.Notifications.First().Username);
            }
        }
        public async Task ThrowCorrectMessage_WhenPassedBarIsNull()
        {
            var options = TestUtils.GetOptions(nameof(ThrowCorrectMessage_WhenPassedBarIsNull));
            var user    = new AppUser {
                Id = "1"
            };
            var barReviewDTO = new BarReviewDTO
            {
                Rating      = 10,
                Description = "10",
                UserID      = "1",
                BarId       = "2"
            };

            using (var arrangeContext = new CMContext(options))
            {
                var sut = new ReviewServices(arrangeContext);
                arrangeContext.Add(user);
                await arrangeContext.SaveChangesAsync();

                var ex = await Assert.ThrowsExceptionAsync <MagicException>(
                    async() => await sut.CreateBarReview(barReviewDTO)
                    );

                Assert.AreEqual(ExceptionMessages.BarNull, ex.Message);
            }
        }
        public async Task AddIngredient(IngredientDTO ingredientDto) //tested
        {
            ingredientDto.ValidateIfNull(ExceptionMessages.IngredientDtoNull);
            var ingredientCtx = ingredientDto.MapToCtxModel();

            ingredientCtx.ValidateIfNull(ExceptionMessages.IngredientNull);
            _context.Add(ingredientCtx);
            await _context.SaveChangesAsync();
        }
        public async Task GetCorrectCountOfLikes_WhenValidParamethersArePassed()
        {
            var options = TestUtils.GetOptions(nameof(GetCorrectCountOfLikes_WhenValidParamethersArePassed));

            var bar = new Bar {
                Id = "2"
            };
            var user = new AppUser {
                Id = "1"
            };
            var user2 = new AppUser {
                Id = "2"
            };
            var review1 = new BarReview {
                Id = "1", Rating = 6, Description = "0100101", BarId = "2"
            };
            //var review2 = new BarReview { Id = "2", Rating = 10, Description = "0100101", BarId = "2" };
            var like1 = new BarReviewLike {
                Id = "1", BarReviewID = "1", AppUserID = "1"
            };
            var like2 = new BarReviewLike {
                Id = "2", BarReviewID = "1", AppUserID = "2"
            };

            using (var arrangeContext = new CMContext(options))
            {
                var sut = new ReviewServices(arrangeContext);
                arrangeContext.Add(bar);
                arrangeContext.Add(user);
                arrangeContext.Add(user2);
                arrangeContext.Add(review1);
                //arrangeContext.Add(review2);
                arrangeContext.Add(like1);
                await arrangeContext.SaveChangesAsync();

                await sut.LikeBarReview(bar.Id, user.Id);

                var result = await sut.LikeBarReview(bar.Id, user2.Id);

                Assert.AreEqual(2, result);
            }
        }
Example #30
0
        public async Task <IActionResult> Create([Bind("ID,Name,DateOfBirth,Notes")] Professor professor)
        {
            if (ModelState.IsValid)
            {
                _context.Add(professor);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(professor));
        }