Пример #1
0
        public void Handle_WhenCalledAndUserDoesNotExist_EntityNotFoundExceptionExpected()
        {
            // ARRANGE
            var userEmail     = "*****@*****.**";
            var configuration = Substitute.For <IConfiguration>();
            var userService   = Substitute.For <IUserService>();

            userService.GetUser(default(string)).ReturnsForAnyArgs((UserForDetailedDto)null);

            var         notificationService = Substitute.For <INotificationService>();
            var         sut = new ResetPasswordRequestNotificationHandler(notificationService, userService, configuration);
            var         resetPasswordRequestNotificationEvent = new ResetPasswordRequestNotificationEvent(userEmail);
            Func <Task> action = async() => await sut.Handle(resetPasswordRequestNotificationEvent, new CancellationToken());

            // ACT & ASSERT
            action.Should().Throw <EntityNotFoundException>()
            .WithMessage($"The user with given email: {userEmail} does not exist in data store");
        }
Пример #2
0
        public async Task Handle_WhenCalled_AttemptToSendProperNotificationExpected()
        {
            // ARRANGE
            var userEmail            = "*****@*****.**";
            var configuration        = Substitute.For <IConfiguration>();
            var configurationSection = Substitute.For <IConfigurationSection>();

            configurationSection.Value = "http://server.com/ResetPassword/{token}";
            configuration.GetSection("AppSettings:ResetPasswordUriFormat").Returns(configurationSection);

            var userService = Substitute.For <IUserService>();
            var user        = new UserForDetailedDto {
                Email = userEmail, ResetPasswordToken = "reset_password_token", Username = "******"
            };

            userService.GetUser(default(string)).ReturnsForAnyArgs(user);

            var notificationService = Substitute.For <INotificationService>();
            INotificationTemplateData actualNotificationTemplateData = null;
            string actualRecipient = string.Empty;

            notificationService.When(x => x.SendAsync(Arg.Any <string>(), Arg.Any <INotificationTemplateData>())).Do(x =>
            {
                actualRecipient = x.ArgAt <string>(0);
                actualNotificationTemplateData = x.ArgAt <INotificationTemplateData>(1);
            });
            var expectedNotificationTemplateData =
                new ResetPasswordNotificationTemplateData("http://server.com/ResetPassword/reset_password_token",
                                                          user.Username);

            var sut = new ResetPasswordRequestNotificationHandler(notificationService, userService, configuration);
            var resetPasswordRequestNotificationEvent = new ResetPasswordRequestNotificationEvent(userEmail);

            // ACT
            await sut.Handle(resetPasswordRequestNotificationEvent, new CancellationToken());

            // ASSERT
            actualRecipient.Should().BeEquivalentTo(userEmail);
            actualNotificationTemplateData.Should().BeEquivalentTo(expectedNotificationTemplateData);
        }