public async Task AddNotificationToDBForDeleteCocktail_WithCorrectParameters() { var options = TestUtils.GetOptions(nameof(AddNotificationToDBForDeleteCocktail_WithCorrectParameters)); var adminName = "pesho"; var id = "1"; 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.CocktailDeletedDescription(adminName, 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.CocktailDeletedNotificationToAdminAsync(id, cocktailName); Assert.AreEqual(1, arrangeContext.Notifications.Count()); } }
public async Task ThrowCorrectMessageForDeleteCocktail_WhenPassedCocktailNameIsNull() { var options = TestUtils.GetOptions(nameof(ThrowCorrectMessageForDeleteCocktail_WhenPassedCocktailNameIsNull)); var adminName = "pesho"; var id = "1"; var cocktailName = "new"; 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.CocktailDeletedDescription(adminName, cocktailName)) .Returns($"LALALALA"); using (var assertContext = new CMContext(options)) { var sut = new NotificationServices(assertContext, _userServices.Object, _iNotificationManager.Object); var ex = await Assert.ThrowsExceptionAsync <MagicException>( async() => await sut.CocktailDeletedNotificationToAdminAsync(id, null)); Assert.AreEqual(ExceptionMessages.CocktailNameNull, ex.Message); } }