public async Task ThrowCorrectMessage_WhenPassedNewNameIsNull() { var options = TestUtils.GetOptions(nameof(ThrowCorrectMessage_WhenPassedNewNameIsNull)); var adminName = "pesho"; var id = "1"; string cocktailName = null; string oldName = "old"; 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 assertContext = new CMContext(options)) { var sut = new NotificationServices(assertContext, _userServices.Object, _iNotificationManager.Object); var ex = await Assert.ThrowsExceptionAsync <MagicException>( async() => await sut.CocktailEditNotificationToAdminAsync(id, oldName, cocktailName)); Assert.AreEqual(ExceptionMessages.CocktailNameNull, ex.Message); } }
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()); } }
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); } }