Ejemplo n.º 1
0
        public void ShouldSetErrorsAndIsValidAfterInitialization()
        {
            _testFriend.FirstName = "";
            var wrapper = new TestFriendWrapper(_testFriend);

            Assert.IsFalse(wrapper.IsValid);
            Assert.IsTrue(wrapper.HasErrors);

            var errors = wrapper.GetErrors(nameof(wrapper.FirstName)).Cast <string>().ToList();

            Assert.AreEqual(1, errors.Count);
            Assert.AreEqual("Firstname is required", errors.First());
        }
Ejemplo n.º 2
0
        public void ShouldBeValidAgainWhenIsDeveloperIsSetBackToFalse()
        {
            var wrapper = new TestFriendWrapper(_testFriend);

            wrapper.Emails.Clear();
            Assert.IsFalse(wrapper.IsDeveloper);
            Assert.IsTrue(wrapper.IsValid);

            wrapper.IsDeveloper = true;
            Assert.IsFalse(wrapper.IsValid);


            wrapper.IsDeveloper = false;
            Assert.IsTrue(wrapper.IsValid);

            var emailsErrors = wrapper.GetErrors(nameof(wrapper.Emails)).Cast <string>().ToList();

            Assert.AreEqual(0, emailsErrors.Count);

            var isDeveloperErrors = wrapper.GetErrors(nameof(wrapper.IsDeveloper)).Cast <string>().ToList();

            Assert.AreEqual(0, isDeveloperErrors.Count);
        }
Ejemplo n.º 3
0
        public void ShouldHaveErrorsAndNotBeValidWhenIsDeveloperIsTrueAndNoEmailExists()
        {
            var expectedError = "A developer must have an email-address";

            var wrapper = new TestFriendWrapper(_testFriend);

            wrapper.Emails.Clear();
            Assert.IsFalse(wrapper.IsDeveloper);
            Assert.IsTrue(wrapper.IsValid);

            wrapper.IsDeveloper = true;
            Assert.IsFalse(wrapper.IsValid);

            var emailsErrors = wrapper.GetErrors(nameof(wrapper.Emails)).Cast <string>().ToList();

            Assert.AreEqual(1, emailsErrors.Count);
            Assert.AreEqual(expectedError, emailsErrors.Single());

            var isDeveloperErrors = wrapper.GetErrors(nameof(wrapper.IsDeveloper)).Cast <string>().ToList();

            Assert.AreEqual(1, isDeveloperErrors.Count);
            Assert.AreEqual(expectedError, isDeveloperErrors.Single());
        }
Ejemplo n.º 4
0
        public void ShouldBeValidAgainWhenEmailIsAdded()
        {
            var wrapper = new TestFriendWrapper(_testFriend);

            wrapper.Emails.Clear();
            Assert.IsFalse(wrapper.IsDeveloper);
            Assert.IsTrue(wrapper.IsValid);

            wrapper.IsDeveloper = true;
            Assert.IsFalse(wrapper.IsValid);

            wrapper.Emails.Add(new TestFriendEmailWrapper(new TestFriendEmail {
                Email = "*****@*****.**"
            }));
            Assert.IsTrue(wrapper.IsValid);

            var emailsErrors = wrapper.GetErrors(nameof(wrapper.Emails)).Cast <string>().ToList();

            Assert.AreEqual(0, emailsErrors.Count);

            var isDeveloperErrors = wrapper.GetErrors(nameof(wrapper.IsDeveloper)).Cast <string>().ToList();

            Assert.AreEqual(0, isDeveloperErrors.Count);
        }
Ejemplo n.º 5
0
        public void ShouldReturnValidationErrorIfFirstNameIsEmpty()
        {
            var wrapper = new TestFriendWrapper(_testFriend);

            Assert.IsFalse(wrapper.HasErrors);

            wrapper.FirstName = "";
            Assert.IsTrue(wrapper.HasErrors);

            var errors = wrapper.GetErrors(nameof(wrapper.FirstName)).Cast <string>().ToList();

            Assert.AreEqual(1, errors.Count);
            Assert.AreEqual("Firstname is required", errors.First());

            wrapper.FirstName = "Julia";
            Assert.IsFalse(wrapper.HasErrors);
        }