Exemplo n.º 1
0
 public List<string> validateCompany(ICompany company)
 {
     if (string.IsNullOrEmpty(company.Name))
     {
         validationErrors.Add("Company Name is required.");
     }
     if (string.IsNullOrEmpty(company.PhoneNumber))
     {
         validationErrors.Add("Company Phone Number is required.");
     }
     else
     {
         long n;
         if (!long.TryParse(company.PhoneNumber, out n))
         {
             validationErrors.Add("Company Phone Number is not properly formatted.");
         }
         if (company.PhoneNumber.Length != 10)
         {
             validationErrors.Add("Company Phone Number must have 10 digits.");
         }
     }
     if (company.Address == null)
     {
         validationErrors.Add("Company Address is required.");
     }
     else
     {
         AddressValidator v = new AddressValidator();
         validationErrors.AddRange(v.validateAddress(company.Address));
     }
     return validationErrors;
 }
        public void TestAddressDoesntHaveValidPostalCode()
        {
            var address = new Address { Street1 = "123 Main St.", City = "St. Paul", PostalCode = "fivefivefivefive", StateCode = "MN" };
            AddressValidator validator = new AddressValidator();

            List<string> errors = new List<string>();

            errors = validator.validateAddress(address);

            Assert.AreNotEqual(0, errors.Count);
        }
        public void TestAddressDoesntHaveStreet()
        {
            var address = new Address {City = "St. Paul", PostalCode = "55117", StateCode = "MN" };
            AddressValidator validator = new AddressValidator();

            List<string> errors = new List<string>();

            errors = validator.validateAddress(address);

            Assert.AreNotEqual(0, errors.Count);
        }
        public void TestAddressIsEmpty()
        {
            var address = new Address();
            AddressValidator validator = new AddressValidator();

            List<string> errors = new List<string>();

            errors = validator.validateAddress(address);

            Assert.AreNotEqual(0, errors.Count);
        }
        public void TestValidAddressPasses()
        {
            var address = new Address { Street1 = "123 Main St.", City = "St. Paul", PostalCode = "55117", StateCode = "MN" };
               AddressValidator validator = new AddressValidator();

               List<string> errors = new List<string>();

               errors = validator.validateAddress(address);

               Assert.AreEqual(0, errors.Count);
        }