public void Store_WithEmptySocialSecurityNumber_ThrowsException()
        {
            //ARRANGE
            var customer = new Customer
            {
                Accounts = new List<Customer.Account>(),
                BirthDate = DateTime.Now,
                CompanyTitle = "Baltic Amadeus",
                Name = "Vardenis",
                LastName = "Pavardenis",
                SocialSecurityNumber = ""
            };

            //ACT
            //ASSERT

            Assert.That(() => _customerRepository.Store(customer),
                Throws.Exception.InstanceOf<Exception>()
                .And.Message.Contains("Social security number is required to perform action!")
                .And.InnerException.Null);

            var exception = Assert.Throws<Exception>(() => _customerRepository.Store(customer));
            Assert.IsTrue(exception.Message.Contains("Social security number is required to perform action!"));
            Assert.IsNull(exception.InnerException);

            Assert.That(customer.SocialSecurityNumber, Is.EqualTo(""));
        }
Ejemplo n.º 2
0
        public void Store(Customer customer)
        {
            var customerValidator = new CustomerValidator();
            var validationResult = customerValidator.Validate(customer);

            if (!validationResult.IsValid)
                throw new Exception(string.Join(" ",validationResult.Errors.Select(p => p.ErrorMessage)));

            //Store into database
        }
        public void Store_WithInvalidSocialSecurityNumberFormat_ThrowsException()
        {
            //ARRANGE
            var customer = new Customer
            {
                Accounts = new List<Customer.Account>(),
                BirthDate = DateTime.Now,
                CompanyTitle = "Baltic Amadeus",
                Name = "Vardenis",
                LastName = "Pavardenis",
                SocialSecurityNumber = "20000000000"
            };

            //ACT
            //ASSERT
            Assert.That(() => _customerRepository.Store(customer), Throws.Exception.Message.Contains("Social security number is in bad format!"));
            Assert.That(customer.SocialSecurityNumber, Is.EqualTo("20000000000"));
        }