private void SendWelcomeEmail(User user) { if (user.WelcomeEmailDateUtc == null) { var welcomedata = new WelcomeEmailModel(user); _welcomeEmailService.Send(welcomedata); user.WelcomeEmailDateUtc = _clock.UtcNow; } _context.Save(); }
public WelcomeEmailDefinition Get(WelcomeEmailModel model, string toEmail) { var page = GetWelcomeEmailPage(); if (page == null) { _logger.LogError("Cannot find the welcome email page at channel({SystemId}) and website({WebsiteSystemId}). Cannot send email to {ToEmail}.", ChannelModel.SystemId, ChannelModel.Channel.WebsiteSystemId, toEmail); } return(new WelcomeEmailDefinition(page, ChannelModel.SystemId, model, toEmail)); }
public void Constructor_Test() { var user = new User() { Email = "actual email address", FirstName = "FirstName there are spaces at the end " }; var personalisation = new Dictionary <string, dynamic>() { { "first_name", user.FirstName.Trim() } }; var model = new WelcomeEmailModel(user); Assert.AreEqual(user.Email, model.EmailAddress); CollectionAssert.AreEqual(personalisation, model.Personalisation); }
public void Send() { var user = new User() { Email = "actual email address", FirstName = "FirstName there are spaces at the end " }; var personalisation = new Dictionary <string, dynamic>() { { "first_name", user.FirstName.Trim() } }; var model = new WelcomeEmailModel(user); _service.Send(model); _mockNotificationClientWrapper.Verify(x => x.SendEmail(user.Email, _templateId, personalisation, null, null), Times.Once); }
public async Task SignInTest() { var firstSignInTime = new DateTime(2017, 12, 31, 23, 59, 59); _mockTime = firstSignInTime; const string bobSubject = "2C4B4170-8979-444F-8D44-DC6DE22BEABF"; var userDetails1 = new JsonUserDetails { Email = _testUserBob.Email, GivenName = "2.Bobby", FamilyName = "Charlton", // different to contents of McUsers to check it gets updated Subject = bobSubject, }; // bob signs in for the first time var bob = await _userService.GetAndUpdateUserAsync(userDetails1); await _userService.LoggedInAsync(bob); // check user data updated from claims and timestamps have been set CheckUserDataUpdated(_testUserBob, userDetails1); _testUserBob.FirstLoginDateUtc.Should().Be(firstSignInTime); _testUserBob.LastLoginDateUtc.Should().Be(firstSignInTime); // check welcome email sent & logged _testUserBob.WelcomeEmailDateUtc.Should().Be(firstSignInTime); var welcomeModelBob = new WelcomeEmailModel(_testUserBob); _mockWelcomeEmailService.Verify( x => x.Send(It.Is <WelcomeEmailModel>(model => (model.EmailAddress == welcomeModelBob.EmailAddress))), Times.Once); var secondSignInTime = _mockTime.AddHours(8); _mockTime = secondSignInTime; // bob signs in again, with a new name & email // this checks that we are now relying on the sign-in guid and not the email address, // and also that the email address gets updated var userDetails2 = new JsonUserDetails { Email = _testUserBob.Email, //Email = "*****@*****.**"; // todo: check for email address changes, blocked by use of email as an FK GivenName = "3.Sir Bob", FamilyName = "Charlton the legend", Subject = bobSubject, }; var bob2 = await _userService.GetAndUpdateUserAsync(userDetails2); // would throw if it couldn't find the McUser entry await _userService.LoggedInAsync(bob2); // check user data updated from claims and timestamps have been set CheckUserDataUpdated(_testUserBob, userDetails2); _testUserBob.LastLoginDateUtc.Should().Be(secondSignInTime); // check original timestamps have not been altered _testUserBob.FirstLoginDateUtc.Should().Be(firstSignInTime); _testUserBob.WelcomeEmailDateUtc.Should().Be(firstSignInTime); // check only one email was sent _mockWelcomeEmailService.Verify(x => x.Send(It.IsAny <WelcomeEmailModel>()), Times.Once); }