public async Task Should_ReturnCocktailCorrectlyFromGivenName() { //arrange string cocktailName = "testName"; int cocktailId = 14; byte[] coverPhoto = new byte[0]; string[] primaryIngredients = new string[1] { "test1" }; var mockIngredientService = new Mock <IIngredientService>().Object; var options = TestUtilities.GetOptions(nameof(Should_ReturnCocktailCorrectlyFromGivenName)); using (var arrangeContext = new CocktailDatabaseContext(options)) { arrangeContext.Cocktails.Add(new Cocktail() { Name = cocktailName });; arrangeContext.SaveChanges(); } using (var assertContext = new CocktailDatabaseContext(options)) { var sut = new CocktailService(assertContext, mockIngredientService); var cocktail = await sut.FindCocktailByNameAsync(cocktailName); Assert.IsNotNull(cocktail); Assert.AreEqual(cocktailName, cocktail.Name); } }
public async Task ThrowArgumentNullException_IncorrectId() { //arrange int testId1 = 1; int testId2 = 2; var mockHasher = new Mock <IHashing>().Object; var mockBarService = new Mock <IBarService>().Object; var mockCocktailService = new Mock <ICocktailService>().Object; var options = TestUtilities.GetOptions(nameof(ThrowArgumentNullException_IncorrectId)); using (var arrangeContext = new CocktailDatabaseContext(options)) { arrangeContext.Users.Add(new User() { Id = testId1 }); arrangeContext.SaveChanges(); } using (var assertContext = new CocktailDatabaseContext(options)) { var sut = new AccountService(assertContext, mockHasher, mockBarService, mockCocktailService); var user = await sut.FindUserByIdAsync(testId2); } }
public async Task ReturnsPhoto() { int testId1 = 1; var coverPhoto = new byte[] { 1, 4, 5, 6 }; var mockHasher = new Mock <IHashing>().Object; var mockBarService = new Mock <IBarService>().Object; var mockCocktailService = new Mock <ICocktailService>().Object; var options = TestUtilities.GetOptions(nameof(ReturnsPhoto)); using (var arrangeContext = new CocktailDatabaseContext(options)) { arrangeContext.UserPhotos.Add(new UserPhoto() { UserId = testId1, UserCover = coverPhoto }); arrangeContext.SaveChanges(); } using (var assertContext = new CocktailDatabaseContext(options)) { var sut = new AccountService(assertContext, mockHasher, mockBarService, mockCocktailService); var picture = await sut.FindUserAvatarAsync(testId1); Assert.IsInstanceOfType(picture.UserCover, typeof(byte[])); } }
public async Task ReturnsIngredientI() { int ingId = 1; string ingredientName = "Ingredient"; byte type = 0; var options = TestUtilities.GetOptions(nameof(ReturnsIngredientI)); using (var arrangeContext = new CocktailDatabaseContext(options)) { arrangeContext.Ingredients.Add(new Ingredient() { Id = ingId, Name = ingredientName, Primary = type }); arrangeContext.SaveChanges(); } using (var assertContext = new CocktailDatabaseContext(options)) { var sut = new IngredientService(assertContext); var ing = await sut.FindIngredientByIdAsync(ingId); Assert.IsNotNull(ing); Assert.AreEqual(type, ing.Primary); Assert.AreEqual(ingredientName.ToLower(), ing.Name.ToLower()); } }
public async Task ReturnsNoIngredientsC() { int cocktailId = 1; byte secondary = 0; var options = TestUtilities.GetOptions(nameof(ReturnsNoIngredientsC)); using (var arrangeContext = new CocktailDatabaseContext(options)) { arrangeContext.Ingredients.Add(new Ingredient() { Name = "Se Taq", Primary = secondary }); arrangeContext.Ingredients.Add(new Ingredient() { Name = "Se Taq", Primary = secondary }); arrangeContext.SaveChanges(); } using (var assertContext = new CocktailDatabaseContext(options)) { var sut = new IngredientService(assertContext); var ingredients = await sut.GetIngredientsByCocktailAsync(cocktailId); Assert.AreEqual(0, ingredients.Count); } }
public async Task PromotesUser() { var userId = 1; var type = "Bar Crawler"; var expected = "Cocktail Magician"; var mockHasher = new Mock <IHashing>().Object; var mockBarService = new Mock <IBarService>().Object; var mockCocktailService = new Mock <ICocktailService>().Object; var options = TestUtilities.GetOptions(nameof(PromotesUser)); using (var arrangeContext = new CocktailDatabaseContext(options)) { arrangeContext.Users.Add(new User() { Id = userId, AccountType = type }); arrangeContext.SaveChanges(); } using (var actContext = new CocktailDatabaseContext(options)) { var sut = new AccountService(actContext, mockHasher, mockBarService, mockCocktailService); await sut.PromoteUserAsync(userId); } using (var assertContext = new CocktailDatabaseContext(options)) { var user = assertContext.Users.First(); Assert.AreEqual(expected, user.AccountType); } }
public async Task ReturnsTrue_CorrectData() { var testId = 1; var testUsername = "******"; var testPassword = "******"; var hashedPassword = "******"; var mockHasher = new Mock <IHashing>(); var mockBarService = new Mock <IBarService>().Object; var mockCocktailService = new Mock <ICocktailService>().Object; var options = TestUtilities.GetOptions(nameof(ReturnsTrue_CorrectData)); mockHasher.Setup(m => m.Verify(testPassword, hashedPassword)) .Returns(true); using (var arrangeContext = new CocktailDatabaseContext(options)) { arrangeContext.Users.Add(new User() { Id = testId, UserName = testUsername, Password = hashedPassword }); arrangeContext.SaveChanges(); } using (var assertContext = new CocktailDatabaseContext(options)) { var sut = new AccountService(assertContext, mockHasher.Object, mockBarService, mockCocktailService); var response = await sut.ValidateUserPasswordAsync(testId, testPassword); Assert.IsTrue(response); } }
public async Task ThrowsArgumentException_PasswordIncorrect() { var testUsername = "******"; var testPassword = "******"; var incorrectPassword = "******"; var hashedPassword = "******"; var mockHasher = new Mock <IHashing>(); var mockBarService = new Mock <IBarService>().Object; var mockCocktailService = new Mock <ICocktailService>().Object; var options = TestUtilities.GetOptions(nameof(ThrowsArgumentException_PasswordIncorrect)); mockHasher.Setup(m => m.Verify(testPassword, hashedPassword)) .Returns(true); using (var actContext = new CocktailDatabaseContext(options)) { actContext.Users.Add(new User { UserName = testUsername, Password = hashedPassword }); actContext.SaveChanges(); } using (var assertContext = new CocktailDatabaseContext(options)) { var sut = new AccountService(assertContext, mockHasher.Object, mockBarService, mockCocktailService); await sut.FindUserWebAsync(testUsername, incorrectPassword); } }
public async Task ReturnsUser() { var testUsername = "******"; var testPassword = "******"; var hashedPassword = "******"; var mockHasher = new Mock <IHashing>(); var mockBarService = new Mock <IBarService>().Object; var mockCocktailService = new Mock <ICocktailService>().Object; var options = TestUtilities.GetOptions(nameof(ReturnsUser)); mockHasher.Setup(m => m.Verify(testPassword, hashedPassword)) .Returns(true); using (var actContext = new CocktailDatabaseContext(options)) { actContext.Users.Add(new User { UserName = testUsername, Password = hashedPassword }); actContext.SaveChanges(); } using (var assertContext = new CocktailDatabaseContext(options)) { var sut = new AccountService(assertContext, mockHasher.Object, mockBarService, mockCocktailService); var user = await sut.FindUserWebAsync(testUsername, testPassword); Assert.AreEqual(testUsername, user.UserName); } }
public async Task UpdatesExistingBR() { var testUserId = 1; var testBarId = 1; var testRating = 3; var testRatingNew = 5; var mockHasher = new Mock <IHashing>().Object; var mockBarService = new Mock <IBarService>().Object; var mockCocktailService = new Mock <ICocktailService>().Object; var options = TestUtilities.GetOptions(nameof(UpdatesExistingBR)); using (var arrangeContext = new CocktailDatabaseContext(options)) { arrangeContext.BarRating.Add(new BarRating() { BarId = testBarId, UserId = testUserId, Rating = testRating }); arrangeContext.SaveChanges(); } using (var actContext = new CocktailDatabaseContext(options)) { var sut = new AccountService(actContext, mockHasher, mockBarService, mockCocktailService); await sut.RateBarAsync(testUserId, testRatingNew, testBarId); } using (var assertContext = new CocktailDatabaseContext(options)) { var rating = assertContext.BarRating.First(); Assert.AreEqual(testRatingNew, rating.Rating); } }
public async Task ReturnsNoIngredientsN() { string ingredientName = "Ingredient"; string wrongName = "se taq"; byte type = 1; var options = TestUtilities.GetOptions(nameof(ReturnsNoIngredientsN)); using (var arrangeContext = new CocktailDatabaseContext(options)) { arrangeContext.Ingredients.Add(new Ingredient() { Name = ingredientName, Primary = type }); arrangeContext.Ingredients.Add(new Ingredient() { Name = ingredientName, Primary = type }); arrangeContext.SaveChanges(); } using (var assertContext = new CocktailDatabaseContext(options)) { var sut = new IngredientService(assertContext); var ing = await sut.FindIngredientsByNameAsync(wrongName); Assert.AreEqual(0, ing.Count); } }
public async Task RemoveIngredient() { int ingId = 1; int ingId2 = 2; string ingredientName = "Ingredient"; byte type = 0; var options = TestUtilities.GetOptions(nameof(RemoveIngredient)); using (var arrangeContext = new CocktailDatabaseContext(options)) { arrangeContext.Ingredients.Add(new Ingredient() { Id = ingId, Name = ingredientName, Primary = type }); arrangeContext.Ingredients.Add(new Ingredient() { Id = ingId2, Name = ingredientName, Primary = type }); arrangeContext.SaveChanges(); } using (var actContext = new CocktailDatabaseContext(options)) { var sut = new IngredientService(actContext); await sut.RemoveIngredientAsync(ingId2); } using (var assertContext = new CocktailDatabaseContext(options)) { var ingredient = assertContext.Ingredients.FirstOrDefault(p => p.Id == ingId2); Assert.IsNull(ingredient); } }
public async Task Should_CorrectlyReturn_CityNames() { //arrange string cityName1 = "testName1"; string cityName2 = "testName2"; var mockCountryService = new Mock <ICountryService>().Object; var options = TestUtilities.GetOptions(nameof(Should_CorrectlyReturn_CityNames)); using (var arrangeContext = new CocktailDatabaseContext(options)) { var sut = new CityService(arrangeContext, mockCountryService); arrangeContext.Cities.Add(new City() { Name = cityName1 }); arrangeContext.Cities.Add(new City() { Name = cityName2 }); arrangeContext.SaveChanges(); } using (var actContext = new CocktailDatabaseContext(options)) { var sut = new CityService(actContext, mockCountryService); var cities = await sut.GetAllCityNamesAsync(); Assert.AreEqual(cities.Count(), actContext.Cities.Count()); Assert.AreEqual(cities[0], cityName1); Assert.AreEqual(cities[1], cityName2); } }
public async Task ReturnsEmptyList() { var keyword = "testName"; var pageSize = 5; var options = TestUtilities.GetOptions(nameof(ReturnsEmptyList)); using (var arrangeContext = new CocktailDatabaseContext(options)) { arrangeContext.Ingredients.Add(new Ingredient() { Id = 1, Name = "se taq" }); arrangeContext.Ingredients.Add(new Ingredient() { Id = 2, Name = "se taq" }); arrangeContext.SaveChanges(); } using (var assertContext = new CocktailDatabaseContext(options)) { var sut = new IngredientService(assertContext); var result = await sut.FindIngredientsForCatalogAsync(keyword, 1, pageSize); Assert.IsTrue(!result.Item1.Any()); } }
public async Task RemovesFavorite() { var userId = 1; var barId = 2; var mockHasher = new Mock <IHashing>().Object; var mockBarService = new Mock <IBarService>().Object; var mockCocktailService = new Mock <ICocktailService>().Object; var options = TestUtilities.GetOptions(nameof(RemovesFavorite)); using (var arrangeContext = new CocktailDatabaseContext(options)) { arrangeContext.UserBar.Add(new UserBar() { BarId = barId, UserId = userId }); arrangeContext.SaveChanges(); } using (var actContext = new CocktailDatabaseContext(options)) { var sut = new AccountService(actContext, mockHasher, mockBarService, mockCocktailService); await sut.RemoveBarFromFavoritesAsync(barId, userId); } using (var assertContext = new CocktailDatabaseContext(options)) { var fav = assertContext.UserBar.FirstOrDefault(p => p.BarId == barId && p.UserId == userId); Assert.IsNull(fav); } }
public async Task ReturnNotExist() { var userId = 1; var barId = 1; var fakeId = 2; var expected = "not exist"; var mockHasher = new Mock <IHashing>().Object; var mockBarService = new Mock <IBarService>().Object; var mockCocktailService = new Mock <ICocktailService>().Object; var options = TestUtilities.GetOptions(nameof(ReturnNotExist)); using (var arrangeContext = new CocktailDatabaseContext(options)) { arrangeContext.UserBar.Add(new UserBar() { UserId = userId, BarId = barId }); arrangeContext.SaveChanges(); } using (var assertContext = new CocktailDatabaseContext(options)) { var sut = new AccountService(assertContext, mockHasher, mockBarService, mockCocktailService); var result = await sut.CheckForFavoriteBarAsync(fakeId, fakeId); Assert.AreEqual(expected, result); } }
public async Task UpdatesExistingBC() { var testUserId = 1; var testBarId = 1; var testComment = "Initial and plain comment."; var testCommentNew = "New and improved comment."; var mockHasher = new Mock <IHashing>().Object; var mockBarService = new Mock <IBarService>().Object; var mockCocktailService = new Mock <ICocktailService>().Object; var options = TestUtilities.GetOptions(nameof(UpdatesExistingBC)); using (var arrangeContext = new CocktailDatabaseContext(options)) { arrangeContext.BarComment.Add(new BarComment() { BarId = testBarId, UserId = testUserId, Comment = testComment }); arrangeContext.SaveChanges(); } using (var actContext = new CocktailDatabaseContext(options)) { var sut = new AccountService(actContext, mockHasher, mockBarService, mockCocktailService); await sut.AddBarCommentAsync(testUserId, testCommentNew, testBarId); } using (var assertContext = new CocktailDatabaseContext(options)) { var comment = assertContext.BarComment.First(); Assert.AreEqual(testCommentNew, comment.Comment); } }
public async Task ThrowArgumentNullException_IncorrectUsername() { //arrange string testUsername1 = "TestName1"; string testUsername2 = "TestName2"; var mockHasher = new Mock <IHashing>().Object; var mockBarService = new Mock <IBarService>().Object; var mockCocktailService = new Mock <ICocktailService>().Object; var options = TestUtilities.GetOptions(nameof(ThrowArgumentNullException_IncorrectUsername)); using (var arrangeContext = new CocktailDatabaseContext(options)) { arrangeContext.Users.Add(new User() { UserName = testUsername1 }); arrangeContext.SaveChanges(); } using (var assertContext = new CocktailDatabaseContext(options)) { var sut = new AccountService(assertContext, mockHasher, mockBarService, mockCocktailService); var user = await sut.FindUserByUserNameAsync(testUsername2); } }
public async Task FreezesUser() { var userId = 1; var status = "Active"; var expected = "Frozen"; var mockHasher = new Mock <IHashing>().Object; var mockBarService = new Mock <IBarService>().Object; var mockCocktailService = new Mock <ICocktailService>().Object; var options = TestUtilities.GetOptions(nameof(FreezesUser)); using (var arrangeContext = new CocktailDatabaseContext(options)) { arrangeContext.Users.Add(new User() { Id = userId, AccountStatus = status }); arrangeContext.SaveChanges(); } using (var actContext = new CocktailDatabaseContext(options)) { var sut = new AccountService(actContext, mockHasher, mockBarService, mockCocktailService); await sut.FreezeUserAsync(userId); } using (var assertContext = new CocktailDatabaseContext(options)) { var user = assertContext.Users.First(); Assert.AreEqual(expected, user.AccountStatus); } }
public async Task Correctly_ReturnAllCountryNames() { string countryName = "countryTest"; string countryName2 = "countryNameTest2"; var options = TestUtilities.GetOptions(nameof(Correctly_ReturnAllCountryNames)); using (var arrangeContext = new CocktailDatabaseContext(options)) { arrangeContext.Countries.Add(new Country() { Name = countryName }); arrangeContext.Countries.Add(new Country() { Name = countryName2 }); arrangeContext.SaveChanges(); } using (var assertContext = new CocktailDatabaseContext(options)) { var sut = new CountryService(assertContext); var countries = await sut.GetAllCountryNamesAsync(); Assert.AreEqual(2, countries.Count()); } }
public async Task CorrectlyHideCocktail() { string cocktailName = "testName"; int cocktailId = 14; double oldRating = 2.5; byte[] coverPhoto = new byte[0]; int cocktailCommentsCount = 2; string[] primaryIngredients = new string[1] { "test1" }; var mockIngredientService = new Mock <IIngredientService>().Object; var options = TestUtilities.GetOptions(nameof(CorrectlyHideCocktail)); using (var arrangeContext = new CocktailDatabaseContext(options)) { arrangeContext.Cocktails.Add(new Cocktail() { Name = cocktailName, Id = cocktailId, Hidden = 0 }); arrangeContext.SaveChanges(); } using (var assertContext = new CocktailDatabaseContext(options)) { var sut = new CocktailService(assertContext, mockIngredientService); await sut.HideCocktailAsync(cocktailId); Assert.AreEqual(1, assertContext.Cocktails.First().Hidden); } }
public async Task Should_ReturnCity_FromGivenName() { //arrange string cityName1 = "testName1"; var mockCountryService = new Mock <ICountryService>().Object; var options = TestUtilities.GetOptions(nameof(Should_ReturnCity_FromGivenName)); using (var arrangeContext = new CocktailDatabaseContext(options)) { var sut = new CityService(arrangeContext, mockCountryService); arrangeContext.Cities.Add(new City() { Name = cityName1 }); arrangeContext.SaveChanges(); } using (var actContext = new CocktailDatabaseContext(options)) { var sut = new CityService(actContext, mockCountryService); var city = await sut.GetCityByNameAsync(cityName1); Assert.IsNotNull(city); Assert.AreEqual(cityName1, city.Name); } }
public async Task ReturnsNullI() { int ingId = 1; int wrongId = 2; string ingredientName = "Ingredient"; byte type = 1; var options = TestUtilities.GetOptions(nameof(ReturnsNullI)); using (var arrangeContext = new CocktailDatabaseContext(options)) { arrangeContext.Ingredients.Add(new Ingredient() { Id = ingId, Name = ingredientName, Primary = type }); arrangeContext.SaveChanges(); } using (var assertContext = new CocktailDatabaseContext(options)) { var sut = new IngredientService(assertContext); var ingredient = await sut.FindIngredientByIdAsync(wrongId); Assert.IsNull(ingredient); } }
public async Task ReturnCorrectBarCount() { //arrange int count = 2; string testBarName1 = "TestName1"; string testBarName2 = "TestName2"; var mockCountryService = new Mock <ICountryService>().Object; var mockCityService = new Mock <ICityService>().Object; var mockCocktailService = new Mock <ICocktailService>().Object; var mockNotificationService = new Mock <INotificationService>().Object; var options = TestUtilities.GetOptions(nameof(ReturnCorrectBarCount)); using (var arrangeContext = new CocktailDatabaseContext(options)) { arrangeContext.Bars.Add(new Bar() { Name = testBarName1 }); arrangeContext.Bars.Add(new Bar() { Name = testBarName2 }); arrangeContext.SaveChanges(); } using (var assertContext = new CocktailDatabaseContext(options)) { var sut = new BarService(assertContext, mockCountryService, mockCityService, mockCocktailService, mockNotificationService); var barsCount = await sut.BarsCountAsync(); Assert.AreEqual(count, barsCount); } }
public async Task CreatesAndSendsCNotification() { string barName = "Bar"; string cityName = "City"; int userId = 1; var options = TestUtilities.GetOptions(nameof(CreatesAndSendsCNotification)); using (var arrangeContext = new CocktailDatabaseContext(options)) { arrangeContext.Users.Add(new User() { City = cityName, Id = userId }); arrangeContext.SaveChanges(); } using (var actContext = new CocktailDatabaseContext(options)) { var sut = new NotificationService(actContext); await sut.CityNotificationAsync(barName, cityName); } using (var assertContext = new CocktailDatabaseContext(options)) { var user = assertContext.Users.Include(p => p.Notifications).First(); Assert.IsNotNull(user.Notifications.FirstOrDefault()); } }
public async Task ReturnsFalse() { string ingredientName = "Ingredient"; string wrongName = "se taq"; byte type = 1; var options = TestUtilities.GetOptions(nameof(ReturnsFalse)); using (var arrangeContext = new CocktailDatabaseContext(options)) { arrangeContext.Ingredients.Add(new Ingredient() { Name = ingredientName, Primary = type }); arrangeContext.SaveChanges(); } using (var assertContext = new CocktailDatabaseContext(options)) { var sut = new IngredientService(assertContext); var resu = await sut.CheckIfIngredientExistsAsync(wrongName, type); Assert.IsFalse(resu); } }
public async Task ReturnsUser() { //arrange int testId1 = 1; string testName = "TestName1"; var mockHasher = new Mock <IHashing>().Object; var mockBarService = new Mock <IBarService>().Object; var mockCocktailService = new Mock <ICocktailService>().Object; var options = TestUtilities.GetOptions(nameof(ReturnsUser)); using (var arrangeContext = new CocktailDatabaseContext(options)) { arrangeContext.Users.Add(new User() { Id = testId1, UserName = testName }); arrangeContext.SaveChanges(); } using (var assertContext = new CocktailDatabaseContext(options)) { var sut = new AccountService(assertContext, mockHasher, mockBarService, mockCocktailService); var user = await sut.FindUserByIdAsync(testId1); Assert.AreEqual(testName, user.UserName); } }
public async Task ThrowArgumentException_WhenNotFound() { var userId = 1; var barId = 2; var incorrectId = 3; var mockHasher = new Mock <IHashing>().Object; var mockBarService = new Mock <IBarService>().Object; var mockCocktailService = new Mock <ICocktailService>().Object; var options = TestUtilities.GetOptions(nameof(ThrowArgumentException_WhenNotFound)); using (var arrangeContext = new CocktailDatabaseContext(options)) { arrangeContext.UserBar.Add(new UserBar() { BarId = barId, UserId = userId }); arrangeContext.SaveChanges(); } using (var assertContext = new CocktailDatabaseContext(options)) { var sut = new AccountService(assertContext, mockHasher, mockBarService, mockCocktailService); await sut.RemoveBarFromFavoritesAsync(incorrectId, incorrectId); } }
public async Task CorrectlyHideBar() { //arrange int testId = 12; string testBarName1 = "TestName1"; string testBarName2 = "TestName2"; var mockCountryService = new Mock <ICountryService>().Object; var mockCityService = new Mock <ICityService>().Object; var mockCocktailService = new Mock <ICocktailService>().Object; var mockNotificationService = new Mock <INotificationService>().Object; var options = TestUtilities.GetOptions(nameof(CorrectlyHideBar)); using (var arrangeContext = new CocktailDatabaseContext(options)) { arrangeContext.Bars.Add(new Bar() { Name = testBarName1, Id = testId, Hidden = 0 }); arrangeContext.SaveChanges(); } using (var assertContext = new CocktailDatabaseContext(options)) { var sut = new BarService(assertContext, mockCountryService, mockCityService, mockCocktailService, mockNotificationService); await sut.HideBarAsync(testId); Assert.AreEqual(1, assertContext.Bars.First().Hidden); } }
public async Task ThrowArgumentNullException_InvalidId() { //arrange int testId = 9; int testIdFail = 8; string testBarName1 = "TestName1"; string testBarName2 = "TestName2"; var mockCountryService = new Mock <ICountryService>().Object; var mockCityService = new Mock <ICityService>().Object; var mockCocktailService = new Mock <ICocktailService>().Object; var mockNotificationService = new Mock <INotificationService>().Object; var options = TestUtilities.GetOptions(nameof(ThrowArgumentNullException_InvalidId)); using (var arrangeContext = new CocktailDatabaseContext(options)) { arrangeContext.Bars.Add(new Bar() { Name = testBarName1, Id = testId }); arrangeContext.Bars.Add(new Bar() { Name = testBarName2 }); arrangeContext.SaveChanges(); } using (var assertContext = new CocktailDatabaseContext(options)) { var sut = new BarService(assertContext, mockCountryService, mockCityService, mockCocktailService, mockNotificationService); var bar = await sut.FindBarByIdAsync(testIdFail); } }