Exemple #1
0
 public bool Add(ICusnew customer)
 {
     if (_customerValidator2.Validate(customer))
     //if(customer.FirstName != null)
     {
         _allCustomers.Add(customer);
         return(true);
     }
     return(false);
 }
        public void Validate_when_age_less_then_18_Return_fail()
        {
            //arrange
            ICusnew customer = Substitute.For <ICusnew>();

            customer.GetAge().Returns(16);

            //act

            var validate = _customerVal.Validate(customer);

            validate.ShouldBeFalse();
        }
        public void Validate_When_age_grather_then_18_Return_true()
        {
            //arrange
            ICusnew customer = Substitute.For <ICusnew>();

            customer.GetAge().Returns(20);

            //act

            var validate = _customerVal.Validate(customer);

            validate.ShouldBeTrue();
        }
Exemple #4
0
        //public bool Validate (ICustomer customer)  first
        //{
        //    if (customer == null) throw new ArgumentNullException();

        //    else if (customer.GetAge() < _minimumAge) return false;

        //    return true;
        //}


        public bool Validate(ICusnew customer)
        {
            if (customer == null)
            {
                throw new ArgumentNullException();
            }

            else if (customer.GetAge() < _minimumAge)
            {
                return(false);
            }

            return(true);
        }
        public void GetAge_Test_how_many_time_invoke()
        {
            //arrange
            int times = 0;

            ICusnew customer = Substitute.For <ICusnew>();

            customer.GetAge()
            .Returns(20)
            .AndDoes(info => times++);

            //Act
            customer.GetAge();
            customer.GetAge();
            //assert

            times.ShouldBe(2);
        }
        public void Throw_Exception()
        {
            ICusnew customer = Substitute.For <ICusnew>();

            customer.GetAge().Throws <NotSupportedException>();
        }