private bool CheckData() { //Личный телефон if (string.IsNullOrWhiteSpace(textBoxPhone1.Text) && string.IsNullOrWhiteSpace(textBoxPhone2.Text)) { validate = ContactValidation.PhoneEmpty; return(false); } //Домашний телефон if (string.IsNullOrWhiteSpace(textBoxPhone2.Text) && string.IsNullOrWhiteSpace(textBoxPhone2.Text)) { validate = ContactValidation.Phone2Empty; return(false); } //Почтовый адресс if (string.IsNullOrWhiteSpace(textBoxEmail.Text)) { validate = ContactValidation.EmailEmpty; return(false); } //Адресс if (string.IsNullOrWhiteSpace(textBoxAdress.Text)) { validate = ContactValidation.AddressEmpty; return(false); } //Страна if (string.IsNullOrWhiteSpace(textBoxCountry.Text)) { validate = ContactValidation.CountryEmpty; return(false); } return(true); }
public async Task MustCheckEmailValid(string email, bool result) { var model = new ContactValidation(); var contact = new MF.Domain.Entities.Contact("48999995555", email); var contactValidate = model.Validate(contact).IsValid; contactValidate.Should().Be(result); }
public async Task MustCheckPhoneNumberValid(string phoneNumber, bool result) { var model = new ContactValidation(); var contact = new MF.Domain.Entities.Contact(phoneNumber, "*****@*****.**"); var contactValidate = model.Validate(contact).IsValid; contactValidate.Should().Be(result); }
public void Initialize() { contactService = new Mock <IContactService>(); userService = new Mock <IUserService>(); contactValidation = new ContactValidation(userService.Object); logger = new Mock <ILogger <Contact> >(); httpContextAccessor = new Mock <IHttpContextAccessor>(); userService.Setup(entity => entity.GetContactId(Convert.ToInt32(UserIdStr))).Returns(Task.FromResult((int?)ContactIdTest)); }
public ActionResult UpdateContact(ContactModel contact) { ModelState.AppendStatefulValidation(ContactValidation.ValidateContactModel(contact)); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } return(Ok(_contactService.UpdateContact(contact))); }
public void ValidateContactModel_GivenAFreelanceContactModelWithoutTvaNumber_ShouldReturnAFailedValidationResult() { //Arrange var contact = new ContactModel { IsFreelance = true }; //Act var result = ContactValidation.ValidateContactModel(contact); //Assert Assert.IsFalse(result[FREELANCE_TVA_VALIDATION_INDEX] == ValidationResult.Success); }
public ActionResult Index(FormCollection collection) { Contact contact = new Contact(); TryUpdateModel(contact); contact.BestTimeToCall = ConvertTimeInput(collection["Hour"], collection["Minute"], collection["Meridiem"]); bool success = false; Dictionary <String, String> disclaimers = new Dictionary <string, string>(); string EncodedResponse = Request.Form["g-Recaptcha-Response"]; bool IsCaptchaValid = EncodedResponse != null ? (Recaptcha.Validate(EncodedResponse)) : false; Dictionary <String, List <String> > validationErrors = ContactValidation.Validate(contact); ViewData["ValidationErrors"] = validationErrors; if (validationErrors.Count == 0) { if (IsCaptchaValid) { using (var db = new ContactUsEntities()) { db.Contacts.Add(contact); db.SaveChanges(); success = true; disclaimers.Add("success", "Your form has been successfully submitted!"); } } else { disclaimers.Add("warning", "ReCAPTCHA is invalid. Please try reCAPTCHA again!"); } } ViewData["Disclaimers"] = disclaimers; return(success ? View(EmptyContact()) : View(contact)); }