public void Validation_Cities_Fail_Set_Long_StringLength() {
            // Must first set non-null since setter is NOP if incoming value == existing value
            State state = new State() { Name = "WA", FullName = "Washington" };

            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");
        }
        public void Validation_Cities_Fail_Set_Bad_RegExp() {
            // Must first set non-null since setter is NOP if incoming value == existing value
            State state = new State() { Name = "WA", FullName = "Washington" };

            ExceptionHelper.ExpectValidationException(delegate() {
                state.Name = "wa";
            }, "The field Name must match the regular expression '^[A-Z]*'.", typeof(RegularExpressionAttribute), "wa");
        }
        public void Validation_Cities_Fail_Set_Short_StringLength() {
            // Must first set non-null since setter is NOP if incoming value == existing value
            State state = new State() { Name = "WA", FullName = "Washington" };

            ExceptionHelper.ExpectValidationException(delegate() {
                state.Name = "W";   // must be 2 letters -- custom validation exception checks that
            }, "The value for Name must have exactly 2 letters", typeof(CustomValidationAttribute), "W");
        }
        public void Validation_Cities_Fail_Set_Null_Required() {
            // Must first set non-null since setter is NOP if incoming value == existing value
            State state = new State() { Name = "WA", FullName = "Washington" };

            ExceptionHelper.ExpectValidationException(delegate() {
                state.Name = null;
            }, "The Name field is required.", typeof(RequiredAttribute), null);
        }
 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_Set_Null_Required_Passes_If_Already_Null() {
     State state = new State() { Name = null };
 }
 public void Validation_Cities_Ctor_State() {
     State state = new State() { Name = "WA", FullName = "Washington" };
     Assert.AreEqual("WA", state.Name);
     Assert.AreEqual("Washington", state.FullName);
 }
        public void Validation_Cities_Fail_Object_Null_Required() {
            // construct object with null Name -- this is invalid
            State state = new State() { FullName = "Washington" };

            ExceptionHelper.ExpectValidationException(delegate() {
                ValidationContext context = new ValidationContext(state, null, null);
                Validator.ValidateObject(state, context);
                state.Name = null;
            }, "The Name field is required.", typeof(RequiredAttribute), null);
        }
        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");

        }
 public void UpdateState(State current)
 {
     State original = this.ChangeSet.GetOriginal(current);
     State state = _cityData.States.SingleOrDefault(p => p.Name == original.Name && p.FullName == original.FullName);
     state.FullName = current.FullName;
     state.Name = current.Name;
     state.TimeZone = current.TimeZone;
 }
Esempio n. 11
0
 private bool FilterState(State entity)
 {
     return (entity.Name == this.StateName);
 }