コード例 #1
0
ファイル: TestHelper.cs プロジェクト: rodrigosoreis/Scribe
        public static Helpers.SmtpServer StartSmtpServer()
        {
            var server = new Helpers.SmtpServer();

            server.Start();
            return(server);
        }
コード例 #2
0
        private void WaitAndValidate(Browser x, Helpers.SmtpServer server, User user)
        {
            var actual = Utility.Wait(() => !x.Elements.Divisions["confirmation"]
                                      .GetAttributeValue("class", true)
                                      .Contains("ng-hide"), 2000, 100);

            Assert.AreEqual(true, actual);

            var message = server.Messages.First();
            var to      = message.To.First();

            Assert.AreEqual(user.EmailAddress, to.User + "@" + to.Host);

            using (var database = TestHelper.GetDatabase(false))
            {
                var siteSettings = SiteSettings.Load(database, true);
                var userSettings = UserSettings.Load(database.Settings, database.Users.First(y => y.Id == user.Id));

                var expectedStart = $"MIME-Version: 1.0\r\nFrom: \"{siteSettings.ContactEmail}\" <{siteSettings.ContactEmail}>\r\nTo: \"[UserName]\" <[EmailAddress]>\r\n".Replace("[UserName]", user.UserName).Replace("[EmailAddress]", user.EmailAddress);
                var expectedEnd   = $"Subject: Scribe: Reset Password\r\nContent-Type: text/html; charset=us-ascii\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\n<p>You are receiving this email because a request has been made to reset the password associated with the email address of [EmailAddress]. If you would like to reset the password for this account simply click on the link below or paste it into the url field on your favorite browser: </p><p><a href=3D\"{TestSite}/Account/ResetPassword/[PasswordToken]\">{TestSite}/Account/ResetPassword/[PasswordToken]</a></p><p>If you didn't request this email then you can just ignore it. The forgot password link will expire in 24 hours after it was issued. Also your personal information has not been disclosed to anyone. If you have any questions, feel free to <a href=3D\"mailto:{siteSettings.ContactEmail}\">contact us</a>.</p>\r\n\r\n".Replace("[EmailAddress]", user.EmailAddress).Replace("[PasswordToken]", userSettings.ResetPasswordId.ToString());
                var actualMessage = message.Mime.Replace("=\r\n", string.Empty).ToString();

                //Console.WriteLine(expectedStart.ToJson());
                //Console.WriteLine(actualMessage.ToJson());
                //Console.WriteLine(expectedEnd.ToJson());

                Assert.IsTrue(actualMessage.StartsWith(expectedStart));
                Assert.IsTrue(actualMessage.EndsWith(expectedEnd));
            }
        }