title: IValidatableObject passes validation but StringLength is Invalid
body: <p>I have a test class with a couple tests that check to see if the entity <code>IsValid</code>. I moved to using <code>IValidatableObject</code> from having my own custom validation but I'm stuck with the correct validation technique.</p>
  
  <p><strong>This is my Test class:</strong></p>
  
  <pre><code>[TestFixture]
  public class StudentTests {
      private static Student GetContactWithContactInfo()
      {
          return new Student(new TestableContactRepository())
                              {
                                  Phone = "7275551111"
                              };
      }
  
      private static Student GetContactWithoutContactInfo()
      {
          return new Student(new TestableContactRepository());
      }
  
      [Test]
      public void Student_Saving_StudentHasInfo_IsValid ()
      {
          // Arrange
          Student student = GetContactWithContactInfo();
          // Act
          student.Save();
          // Assert
          Assert.IsTrue(student.IsValid);
      }
  
      [Test]
      public void Student_Saving_StudentDoesNotHaveInfo_IsNotValid ()
      {
          // Arrange
          Student student = GetContactWithoutContactInfo();
          // Act
          student.Save();
          // Assert
          Assert.IsFalse(student.IsValid);
      }
  }
  </code></pre>
  
  <p><strong>This is my entity:</strong></p>
  
  <pre><code>public class Student : IValidatableObject
  {
      private readonly IContactRepository contactRepository;
  
      public Student(IContactRepository _contactRepository)
      {
          contactRepository = _contactRepository;
          Contacts = new List&lt;Student&gt;();
      }
  
      [Required]
      public int Id { get; private set; }
  
      [StringLength(10, MinimumLength = 10)]
      public string Phone { get; set; }
  
  
      public List&lt;Student&gt; Contacts { get; private set; }
  
      public bool IsValid { get; private set; }
  
      public void Save()
      {
          if (IsValidForPersistance())
          {
              IsValid = true;
              Id = contactRepository.Save();
          }
      }
  
      private bool IsValidForPersistance()
      {
          return Validator.TryValidateObject(this, new ValidationContext(this), null, true);
      }
  
      public IEnumerable&lt;ValidationResult&gt; Validate(ValidationContext validationContext)
      {
          if (string.IsNullOrEmpty(Phone) &amp;&amp; Contacts.All(c =&gt; string.IsNullOrEmpty(c.Phone)))
              yield return new ValidationResult("The student or at least one contact must have a phone number entered", new[] { "Phone Number" });
      }
  }
  </code></pre>
  
  <p>As you can see the tests test for <code>IsValid</code> by calling the <code>IsValidForPersistance</code>. <code>Validate</code> will eventually have more validation .</p>
  
  <p>The above tests all pass using this method but this test below also passes but should not. </p>
  
  <pre><code>[Test]
  public void Student_Saving_HasContactInfoWithInvalidLength_IsNotValid()
  {
      // Arrange
      Contact student = GetContactWithoutContactInfo();
      student.Phone = "string";
  
      // Act
      student.Save();
  
      // Assert
      Assert.IsFalse(student.IsValid);
  }
  </code></pre>
  
  <p>Here I'm setting my own <code>Phone</code> value of an invalid length string. I expect validation to fail because of the <code>StringLength</code> annotation set at min and max 10 characters.</p>
  
  <p>Why is this passing?</p>
  
  <p><strong>Update</strong>
  There was a problem with the custom validation, updated the code with the change. Along with the suggestion from nemesv about not having a <code>private</code> modifier on the <code>Phone</code> property it now works. I've updated all the code to working.</p>