public async Task <IActionResult> SendChangeEmailEmailByAdmin(SendChangeEmailEmailByAdminRequest request) { var response = await mediator.Send(request); Log.Information( $"User #{HttpContext.GetCurrentUserId()} sent change email link to user's email address: {request.NewEmail}"); return(this.CreateResponse(response)); }
public void SetUp() { var generateChangeEmailTokenResult = new GenerateChangeEmailTokenResult { Email = Test, Token = Test, Username = Test }; var emailTemplate = new EmailTemplate { TemplateName = Test, Subject = Test, Content = Test, AllowedParameters = new[] { "{{username}}", "{{callbackUrl}}" } }; request = new SendChangeEmailEmailByAdminRequest { UserId = 1, NewEmail = Test }; userTokenGenerator = new Mock <IUserTokenGenerator>(); authValidationService = new Mock <IAuthValidationService>(); emailSender = new Mock <IEmailSender>(); emailTemplateGenerator = new Mock <IEmailTemplateGenerator>(); cryptoService = new Mock <ICryptoService>(); var configuration = new Mock <IConfiguration>(); authValidationService.Setup(avs => avs.EmailExists(It.IsAny <string>())).ReturnsAsync(false); userTokenGenerator.Setup(c => c.GenerateChangeEmailTokenByAdmin(It.IsAny <int>(), It.IsAny <string>())) .ReturnsAsync(generateChangeEmailTokenResult); cryptoService.Setup(c => c.Encrypt(It.IsAny <string>())) .Returns(Test); configuration.Setup(c => c.GetSection(It.IsAny <string>())) .Returns(new Mock <IConfigurationSection>().Object); emailTemplateGenerator.Setup(etg => etg.FindEmailTemplate(It.IsAny <string>())) .ReturnsAsync(emailTemplate); emailSender.Setup(es => es.Send(It.IsAny <EmailMessage>())) .ReturnsAsync(true); sendChangeEmailEmailByAdminCommand = new SendChangeEmailEmailByAdminCommand(userTokenGenerator.Object, authValidationService.Object, emailSender.Object, emailTemplateGenerator.Object, cryptoService.Object, configuration.Object); }