public void Validation_Cities_Set_Invalid_Value_During_Deserialization() { State state = new State(); state.OnDeserializing(new System.Runtime.Serialization.StreamingContext()); state.Name = "bogus"; // would fail RegExp, StrLen, etc Assert.AreEqual("bogus", state.Name); // setter should have worked state.OnDeserialized(new System.Runtime.Serialization.StreamingContext()); }
public void Validation_Cities_Fail_Invalid_Value_After_Deserialization() { State state = new State(); state.OnDeserializing(new System.Runtime.Serialization.StreamingContext()); state.Name = "bogus"; // would fail RegExp, StrLen, etc Assert.AreEqual("bogus", state.Name); // setter should still have worked state.OnDeserialized(new System.Runtime.Serialization.StreamingContext()); // Now, outside of serialization, the same property should throw ExceptionHelper.ExpectValidationException(delegate() { state.Name = "WASH"; // must be 2 letters -- [StringLength] validates that }, "The field Name must be a string with a maximum length of 2.", typeof(StringLengthAttribute), "WASH"); }