public async Task ThrowException_WhenPassedIdIsNull() { var options = TestUtils.GetOptions(nameof(ThrowException_WhenPassedIdIsNull)); using (var assertContext = new CMContext(options)) { var sut = new NotificationServices(assertContext, _userServices.Object, _iNotificationManager.Object); var ex = await Assert.ThrowsExceptionAsync <MagicException>( async() => await sut.GetNotificationsForUserAsync(null)); } }
public async Task GetAllNotificationsForUser_WhenCalledWithCorrectId() { var options = TestUtils.GetOptions(nameof(GetAllNotificationsForUser_WhenCalledWithCorrectId)); var adminName = "pesho"; var id = "1"; var description = "new"; var userName = "******"; var notification = new Notification { Description = description, Username = userName, UserId = "1" }; 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); await arrangeContext.SaveChangesAsync(); var sut = new NotificationServices(arrangeContext, _userServices.Object, _iNotificationManager.Object); var result = await sut.GetNotificationsForUserAsync(id); Assert.AreEqual(userName, result.ToList()[0].Username); Assert.AreEqual(id, result.ToList()[0].UserId); Assert.AreEqual(description, result.ToList()[0].Description); } }