Esempio n. 1
0
        public async Task Handle_WhenAlertJobNotExists_ThenItDoesNotCallSendNotificationAsync()
        {
            //arrange
            int id = 5;

            var mockAlertJobService = new Mock <IAlertJobService>();
            var mockNotifierService = new Mock <IAlertNotifierService>();
            var mockUserManager     = MockUserManager <IdentityUser>();

            mockAlertJobService.Setup(x => x.GetAlertJobDetailsAsync(id))
            .Returns(Task.FromResult <AlertJob>(null))
            .Verifiable();

            var eventHandler = new AlerterEmailSendStatusCheckedEventHandler(
                mockAlertJobService.Object, mockNotifierService.Object, mockUserManager.Object);

            //act
            await eventHandler.Handle(new Data.Events.StatusCheckedEvent(id, true),
                                      It.IsAny <CancellationToken>());

            //assert
            mockUserManager.Verify(x => x.FindByIdAsync(It.IsAny <string>()), Times.Never);
            mockNotifierService.Verify(x => x.SendNotificationAsync(It.IsAny <Dictionary <string, string> >()),
                                       Times.Never);
        }
Esempio n. 2
0
        public async Task Handle_WhenAlertJobExists_ThenItCallsSendNotificationAsync()
        {
            //arrange
            int  id     = fixture.Create <int>();
            Guid userId = fixture.Create <Guid>();
            var  email  = fixture.Create <string>();

            var mockAlertJobService = new Mock <IAlertJobService>();
            var mockNotifierService = new Mock <IAlertNotifierService>();
            var mockUserManager     = MockUserManager <IdentityUser>();

            mockAlertJobService.Setup(x => x.GetAlertJobDetailsAsync(id))
            .Returns(Task.FromResult(new AlertJob()
            {
                Id     = id,
                UserId = userId
            }))
            .Verifiable();

            mockUserManager.Setup(x => x.FindByIdAsync(userId.ToString()))
            .Returns(Task.FromResult(new IdentityUser {
                Email = email
            }))
            .Verifiable();

            var eventHandler = new AlerterEmailSendStatusCheckedEventHandler(
                mockAlertJobService.Object, mockNotifierService.Object, mockUserManager.Object);

            //act
            await eventHandler.Handle(new Data.Events.StatusCheckedEvent(id, true),
                                      It.IsAny <CancellationToken>());

            //assert
            mockUserManager.Verify(x => x.FindByIdAsync(userId.ToString()), Times.Once);
            mockNotifierService.Verify(x => x.SendNotificationAsync(It.Is <Dictionary <string, string> >(
                                                                        y => y["email"] == email)), Times.Once);
        }