Пример #1
0
 public void AppService_ConfirmEmailBadCodeValidation()
 {
     try
     {
         var service = new AppService(DocumentStore, _MockEmailService.Object);
         service.ConfirmEmail("invalid_confirmation_code");
     }
     catch (ServiceValidationException serviceEx)
     {
         Assert.IsTrue(serviceEx.ErrorCodes.Contains(ErrorCode.ConfirmEmail_EmailDoesNotExist));
         throw;
     }
 }
Пример #2
0
        public void AppService_ZZCompleteRoundTripWithConfirmation()
        {
            var appService = new AppService(DocumentStore, _MockEmailService.Object);

            // Save via service
            var validApp = new AppModel { Name = "MyApp", ContactEmails = {"*****@*****.**", "*****@*****.**"} };
            var savedApp = appService.CreateApp(validApp);
            string savedAppId = savedApp.Id;

            // Verify app and contact emails are saved
            List<string> emailConfirmCodes;

            using (var session = DocumentStore.OpenSession())
            {
                App loadedApp = session
                    .Include<App>(a => a.ContactEmailIds)
                    .Load<App>(savedAppId);

                Assert.IsNotNull(loadedApp);
                Assert.AreEqual("MyApp", loadedApp.Name);
                Assert.IsNotNull(loadedApp.ApiKey);
                Assert.AreNotEqual(default(DateTime), loadedApp.CreatedTimestampUtc);

                var loadedEmails = session.Load<ContactEmail>(loadedApp.ContactEmailIds);
                foreach (var email in loadedEmails)
                {
                    TestContext.WriteLine("Loaded email with confirm code " + email.ConfirmationCode);
                }

                Assert.AreEqual(2, loadedEmails.Length);
                Assert.IsTrue(loadedEmails.Any(ce => ce.EmailAddress == "*****@*****.**"));
                Assert.IsTrue(loadedEmails.Any(ce => ce.EmailAddress == "*****@*****.**"));
                Assert.IsFalse(loadedEmails.Any(ce => ce.Confirmed));
                Assert.IsFalse(loadedEmails.Any(ce => String.IsNullOrEmpty(ce.ConfirmationCode)));

                // Verify confirmation emails were sent
                _MockEmailService.Verify(s => s.SendConfirmationEmails(It.IsAny<IEnumerable<ContactEmail>>()));

                emailConfirmCodes = loadedEmails.Select(e => e.ConfirmationCode).ToList();
            }

            // Confirm the contact emails: should not be already confirmed
            foreach (var confirmCode in emailConfirmCodes)
            {
                TestContext.WriteLine("Confirming email with code " + confirmCode);

                var confirmModel = appService.ConfirmEmail(confirmCode);
                Assert.IsTrue(confirmModel.Confirmed);
                Assert.IsFalse(confirmModel.AlreadyConfirmed);
            }

            // Re-confirm the contact emails: should be already confirmed
            foreach (var confirmCode in emailConfirmCodes)
            {
                var confirmModel = appService.ConfirmEmail(confirmCode);
                Assert.IsTrue(confirmModel.Confirmed);
                Assert.IsTrue(confirmModel.AlreadyConfirmed);
            }
        }