Exemplo n.º 1
0
        public void TestPerformValidation_Length()
        {
            var customer = new Customer
            {
                Name = "Maryika",
                IsFinraMember = true
            };
            var validationController = new ValidationController();

            validationController.PerformValidation(customer);
            Assert.IsFalse(customer.Errors.All.Any());
            CollectionAssert.IsEmpty(customer.Errors.All);

            customer.Name = "";
            validationController.PerformValidation(customer);
            Assert.IsTrue(customer.Errors.All.Any());
            Assert.AreEqual(2, customer.Errors.Count);
            CollectionAssert.AreEquivalent(Customer.NameErrors, customer.Errors[() => customer.Name]);

            customer.Name = "Some long name exceeds max";
            validationController.PerformValidation(customer);
            Assert.IsTrue(customer.Errors.All.Any());
            Assert.AreEqual(1, customer.Errors.Count);
            Assert.AreEqual("Name is too long (maximum is 12).", customer.Errors[() => customer.Name].First());

            var account = new Account { Number = "A0000000001" };
            validationController.PerformValidation(account);
            Assert.IsTrue(account.Errors.All.Any());
            Assert.AreEqual(1, account.Errors.Count);
            Assert.AreEqual("Number is too long (maximum is 10).", account.Errors[() => account.Number].First());

            account.Number = null;
            validationController.PerformValidation(account);
            Assert.IsFalse(account.Errors.All.Any());
            CollectionAssert.IsEmpty(account.Errors.All);

            var address = new Address();
            validationController.PerformValidation(address);
            Assert.IsTrue(address.Errors.All.Any());
            Assert.AreEqual(1, address.Errors.Count);
            Assert.AreEqual("StateCode should be 2 characters.", address.Errors[() => address.StateCode].First());

            address.StateCode = "NY";
            validationController.PerformValidation(address);
            Assert.IsFalse(address.Errors.All.Any());
            CollectionAssert.IsEmpty(address.Errors.All);
        }
Exemplo n.º 2
0
 public void TestPerformValidation_NullArg()
 {
     var validationController = new ValidationController();
     Assert.Throws<ArgumentNullException>(() => validationController.PerformValidation(null));
 }
Exemplo n.º 3
0
        public void TestPerformValidation_Presence()
        {
            var customer = new Customer();
            var validationController = new ValidationController();

            Assert.IsFalse(customer.Errors.All.Any());
            CollectionAssert.IsEmpty(customer.Errors.All);

            validationController.PerformValidation(customer);

            Assert.IsTrue(customer.Errors.All.Any());
            CollectionAssert.IsNotEmpty(customer.Errors.All);
            Assert.AreEqual(3, customer.Errors.Count);

            CollectionAssert.AreEquivalent(Customer.NameErrors, customer.Errors[() => customer.Name]);
            var finraError = customer.Errors.ForProperty(() => customer.IsFinraMember).First();
            Assert.AreEqual("IsFinraMember can't be empty.", finraError);

            customer.IsFinraMember = false;
            validationController.PerformValidation(customer);

            Assert.IsTrue(customer.Errors.All.Any());
            CollectionAssert.IsNotEmpty(customer.Errors.All);
            Assert.AreEqual(2, customer.Errors.Count);
            CollectionAssert.IsEmpty(customer.Errors.ForProperty(() => customer.IsFinraMember));
            CollectionAssert.IsNotEmpty(customer.Errors[() => customer.Name]);
            CollectionAssert.AreEquivalent(Customer.NameErrors, customer.Errors[() => customer.Name]);

            customer.Name = UnitTestHelper.CUSTOMER_NAME;
            validationController.PerformValidation(customer);

            Assert.IsFalse(customer.Errors.All.Any());
            CollectionAssert.IsEmpty(customer.Errors.All);
            CollectionAssert.IsEmpty(customer.Errors[() => customer.Name]);
        }