public ClassRegistration Get(long id) { MySqlCommand cmd = _unitOfWork.CreateCommand(@"select RegistrationId, RegistrationData, Created, Completed From Registrations Where RegistrationId = @RegistrationId", System.Data.CommandType.Text); cmd.Parameters.AddWithValue("@RegistrationId", id); ClassRegistration registration = null; var contractResolver = new PrivateMemberContractResolver(); var deserializeSettings = new JsonSerializerSettings() { ContractResolver = contractResolver }; using (MySqlDataReader r = cmd.ExecuteReader()) { if (r.Read()) { registration = JsonConvert.DeserializeObject <ClassRegistration>(r.GetString(1), deserializeSettings); } } return(registration); }
public void RegisterWithInvalidPhoneNumber() { RegistrationRequest request = new RegistrationRequest() { Phone = "123" }; ClassRegistration result = ClassRegistration.Process(request, new[] { new PhoneValidator() }); Assert.AreEqual("A phone number is required", result.GetError("Phone")); }
public void RegisterWithPaymentAmountOutsideAllowableRange() { RegistrationRequest request = new RegistrationRequest() { PaymentAmount = "600" }; ClassRegistration result = ClassRegistration.Process(request, new[] { new PaymentAmountValidator(5, 500) }); Assert.AreEqual("Payment amount must be between $5 and $500", result.GetError("PaymentAmount")); }
public void RegisterWithOnlyFirstNameFilled() { RegistrationRequest request = new RegistrationRequest() { Name = "Shelly" }; ClassRegistration result = ClassRegistration.Process(request, null); Assert.AreEqual("Shelly", result.FirstName); }
public void RegisterWithValidPaymentAmount() { RegistrationRequest request = new RegistrationRequest() { Name = "Sweet Ride", PaymentAmount = "300" }; ClassRegistration result = ClassRegistration.Process(request, new[] { new PaymentAmountValidator(5, 500) }); Assert.AreEqual(300, result.PaymentAmount); }
public void RegisterWithFullName() { RegistrationRequest request = new RegistrationRequest() { Name = "Shelly Von Trapp" }; ClassRegistration result = ClassRegistration.Process(request, null); Assert.AreEqual("Shelly", result.FirstName); Assert.AreEqual("Von Trapp", result.LastName); }
public void RegisterWithValidEmailAddress() { RegistrationRequest request = new RegistrationRequest() { Name = "Joe", Email = "*****@*****.**" }; ClassRegistration result = ClassRegistration.Process(request, new[] { new EmailValidator() }); Assert.AreEqual("*****@*****.**", result.Email); }
public void RegisterWithInvalidEmailAddress() { RegistrationRequest request = new RegistrationRequest() { Name = "Joe", Email = "Smith@ish" }; ClassRegistration result = ClassRegistration.Process(request, new[] { new EmailValidator() }); Assert.AreEqual("A valid email address is required", result.GetError("Email")); }
public void RegisterWithNameMissing() { RegistrationRequest request = new RegistrationRequest() { Name = null, }; ClassRegistration result = ClassRegistration.Process(request, null); Assert.IsFalse(result.IsValid); Assert.AreEqual("Name is required", result.GetError("Name")); }
public void Save(ClassRegistration registration) { MySqlCommand cmd = _unitOfWork.CreateCommand(@"insert into Registrations(RegistrationId, RegistrationData, Created, Completed) Values(@RegistrationId, @RegistrationData, @Created, @Completed)", System.Data.CommandType.Text); cmd.Parameters.AddWithValue("@RegistrationId", registration.RegistrationId); cmd.Parameters.AddWithValue("@RegistrationData", Newtonsoft.Json.JsonConvert.SerializeObject(registration)); cmd.Parameters.AddWithValue("@Created", registration.Created); cmd.Parameters.AddWithValue("@Completed", registration.Completed); cmd.ExecuteNonQuery(); }
public void RegisterWithValidShortPhoneNumber() { RegistrationRequest request = new RegistrationRequest() { Name = "Joe", Phone = "283-5266" }; ClassRegistration result = ClassRegistration.Process(request, new[] { new PhoneValidator() }); Assert.AreEqual("413", result.PhoneAreaCode); Assert.AreEqual("283", result.PhonePrefix); Assert.AreEqual("5266", result.PhoneSuffix); }
public void RegisterWithOptionalFieldsFilled() { RegistrationRequest request = new RegistrationRequest() { Name = "Joe", Address = "Address 1", Town = "Townie", SpecialInstructions = "Environment needs to be quiet.", EventName = "Event name", EventDescription = "Event description" }; ClassRegistration result = ClassRegistration.Process(request, new Validator <RegistrationRequest>[] { }); Assert.AreEqual("Address 1", result.Address1); Assert.AreEqual("Townie", result.City); Assert.AreEqual("Environment needs to be quiet.", result.SpecialInstructions); Assert.AreEqual("Event name", result.EventName); Assert.AreEqual("Event description", result.EventDescription); }
public void SaveCustomerRegistration() { ClassRegistrationRepository repo = new ClassRegistrationRepository(_unitOfWork); RegistrationRequest request = new RegistrationRequest() { Name = "Joe Smith", SpecialInstructions = "Really needy", EventDescription = "Event Description" }; var classRegistration = ClassRegistration.Process(request, new Validator <RegistrationRequest>[] { }); repo.Save(classRegistration); ClassRegistration savedRegistration = repo.Get(classRegistration.RegistrationId); Assert.IsNotNull(savedRegistration.RegistrationId); Assert.AreEqual("Really needy", savedRegistration.SpecialInstructions); Assert.AreEqual("Event Description", savedRegistration.EventDescription); }
// POST api/<controller> public IHttpActionResult Post([FromBody] RegistrationRequest request) { var validators = new Validator <RegistrationRequest>[] { new PaymentAmountValidator(decimal.Parse(ConfigurationManager.AppSettings["MinPaymentAmount"]), decimal.Parse(ConfigurationManager.AppSettings["MaxPaymentAmount"])), new PhoneValidator(), new EmailValidator() }; ClassRegistration registration = ClassRegistration.Process(request, validators); if (registration.IsValid) { StringBuilder body = new StringBuilder(); body.AppendFormat("<p>This e-mail is a notification that the class registration process has started. This notification <strong>does not indicate</strong> that the customer has successfully completed payment process through PayPal. The Registration ID and other contact information can be used to track payment status in PayPal.</p>"); body.AppendFormat("<div>Registration ID: {0}</div>", registration.RegistrationId); body.AppendFormat("<div>Event: {0}</div>", registration.EventName); body.AppendFormat("<div>Name: {0}</div>", registration.FullName); body.AppendFormat("<div>Payment Amount: {0}</div>", registration.PaymentAmount); body.AppendFormat("<div>Address: {0}</div>", registration.Address1); body.AppendFormat("<div>Town: {0}</div>", registration.City); body.AppendFormat("<div>Phone: {0}</div>", registration.FormattedPhone); body.AppendFormat("<div>Email: {0}</div>", registration.Email); body.AppendFormat("<div>Special Instructions:</div><p>{0}</p>", registration.SpecialInstructions); SiteMessage siteMessage = new SiteMessage() { From = registration.Email, To = ConfigurationManager.AppSettings["ContactUsEmailAddress"], Subject = "Class Registration: Interactive School House", Body = body.ToString() }; SendGridMailAdapter sendGridMailAdapter = new SendGridMailAdapter(); sendGridMailAdapter.Send(siteMessage); } return(Ok(registration)); }
public decimal ProcessRegistration(ClassRegistration classRegistration) { classRegistration.Create(); return(classRegistration.Total); }
public decimal ProcessRegistration(ClassRegistration registration) { registration.Create(); return registration.Total; }