public void linked_resources_included_in_html_body() { // Arrange var mailer = new RegistrationMailer(smtpConfiguration); var addresses = new List <MailboxAddress>(); addresses.Add(new MailboxAddress("Kinger", "*****@*****.**")); var guid = "18c1c20f-81f0-4308-8fd8-f3c65a276882"; List <LinkedResource> linkedResources = null; linkedResources = new List <LinkedResource>(); linkedResources.Add(new LinkedResource { Name = "logoCid", Cid = "techwizLogo", Path = @"C:\Users\king\source\repos\KahanuMailer\ConsoleApp1\Views\RegistrationMailer\techwiz-logo.png" }); linkedResources.Add(new LinkedResource { Name = "parakeetCid", Cid = "parakeet", Path = @"C:\Users\king\source\repos\KahanuMailer\ConsoleApp1\Views\RegistrationMailer\parakeet.png" }); var ctx = new RegistrationMailerContext { Now = "7/13/2020 4:05:49 PM", FirstName = "Mike", LastName = "Jones", CustomerMessage = "This is the customer message.", Subject = "This is the customer subject", ToAddresses = addresses, Guid = guid }; if (linkedResources != null) { ctx.LinkedResources = linkedResources; } // Act var actual = mailer.Customer(ctx); var expectedBody = @"<!DOCTYPE html>" + Environment.NewLine + "<html lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\">" + Environment.NewLine + "<head>" + Environment.NewLine + " <meta charset=\"utf-8\" />" + Environment.NewLine + " <title></title>" + Environment.NewLine + " <style>" + Environment.NewLine + " .header {" + Environment.NewLine + " padding: 10px;" + Environment.NewLine + " background-color: #f7d736;" + Environment.NewLine + " margin-bottom: 20px;" + Environment.NewLine + " width: 100%;" + Environment.NewLine + " }" + Environment.NewLine + "" + Environment.NewLine + " .footer {" + Environment.NewLine + " padding: 10px;" + Environment.NewLine + " background-color: #f7f7f7;" + Environment.NewLine + " margin-top: 20px;" + Environment.NewLine + " width: 100%;" + Environment.NewLine + " }" + Environment.NewLine + " </style>" + Environment.NewLine + "</head>" + Environment.NewLine + "<body>" + Environment.NewLine + " <div class=\"header\">" + Environment.NewLine + " <img src=\"cid:techwizLogo\" />" + Environment.NewLine + " </div>" + Environment.NewLine + "<p>7/13/2020 4:05:49 PM</p>" + Environment.NewLine + "<p>Mike Jones,</p>" + Environment.NewLine + "This is the customer message." + Environment.NewLine + "<p>My bird: <img src='cid:parakeet' /></p>" + Environment.NewLine + "<p>Link: <a href=\"somepage/18c1c20f-81f0-4308-8fd8-f3c65a276882\">Link with Guid</a></p>" + Environment.NewLine + "<p>Thanks, TechWiz Support.</p>" + Environment.NewLine + " <div class=\"footer\">" + Environment.NewLine + " ©2020 Tech - All rights reserved." + Environment.NewLine + " </div>" + Environment.NewLine + "</body>" + Environment.NewLine + "</html>"; // assert actual.HtmlBody.Should().Be(expectedBody); }
public JsonResult CreateAccount(CreateAccount account) { try { var check = (from x in db.Registrations where x.Email == account.Email select x).Count(); if (check > 0) { return(Json(new { ResponseCode = 01, Message = "Account Already Exist" }, JsonRequestBehavior.AllowGet)); } if (account.Password.Equals(account.ConfirmPassword)) { Regex r = new Regex("^[a-zA-Z0-9]*$"); if (r.IsMatch(account.Password)) { return(Json(new { ResponseCode = 02, Message = "Password Must Be Alphanumeric" }, JsonRequestBehavior.AllowGet)); } else if (account.Password.Length < 7) { return(Json(new { ResponseCode = 03, Message = "Password Lenght must be greater than 7" }, JsonRequestBehavior.AllowGet)); } else if (account.Password.Contains("PASSWORD") || account.Password.Contains("Password") || account.Password.Contains("password")) { return(Json(new { ResponseCode = 04, Message = "Your selected password must not contain password" }, JsonRequestBehavior.AllowGet)); } } else { return(Json(new { ResponseCode = 08, Message = "Password Does Not Match" }, JsonRequestBehavior.AllowGet)); } //Create directories for new merchants DirectoryInfo AccountDirectoryForUsers = Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "\\" + "AccountDirectory" + "\\" + account.Email); AccountDirectoryForUsers.CreateSubdirectory("MerchantLogo"); AccountDirectoryForUsers.CreateSubdirectory("InvoiceDocuments"); AccountDirectoryForUsers.CreateSubdirectory("GoLiveDocument"); //creating hashpassword string salt = BCryptHelper.GenerateSalt(6); var hashedPassword = BCryptHelper.HashPassword(account.Password, salt); Registration register = new Registration() { BusinessName = account.FullName, PhoneNo = account.PhoneNo, Email = account.Email, Password = hashedPassword, Date = DateTime.UtcNow.ToString("yyyy-MM-dd") }; db.Registrations.Add(register); db.SaveChanges(); string path = Server.MapPath("~/App_Data/Template/WelcomeMail.html"); dev.generateTestKeys(account.Email); RegistrationMailer.Send(account.FullName, account.Email, GetConstants.RegistrationSubject, path); return(Json(new { ResponseCode = 00, Message = "Account Created Successfully" }, JsonRequestBehavior.AllowGet)); } catch (Exception) { throw; } }