public void prepend_property() { var message = new NotificationMessage(ValidationKeys.Required); message.AddAccessor(ReflectionHelper.GetAccessor<ContactModel>(x => x.FirstName)); message.AddAccessor(ReflectionHelper.GetAccessor<ContactModel>(x => x.LastName)); var property = ReflectionHelper.GetAccessor<CompositeModel>(x => x.Contact); var prepended = message.Prepend(property); prepended.ShouldNotBeTheSameAs(message); prepended.Accessors.Select(x => x.Name).ShouldHaveTheSameElementsAs("ContactFirstName", "ContactLastName"); prepended.StringToken.ShouldEqual(ValidationKeys.Required); }
public void prepend_property() { var message = new NotificationMessage(ValidationKeys.REQUIRED); message.AddAccessor(ReflectionHelper.GetAccessor <ContactModel>(x => x.FirstName)); message.AddAccessor(ReflectionHelper.GetAccessor <ContactModel>(x => x.LastName)); var property = ReflectionHelper.GetAccessor <CompositeModel>(x => x.Contact); var prepended = message.Prepend(property); prepended.ShouldNotBeTheSameAs(message); prepended.Accessors.Select(x => x.Name).ShouldHaveTheSameElementsAs("ContactFirstName", "ContactLastName"); prepended.StringToken.ShouldEqual(ValidationKeys.REQUIRED); }
public void to_validation_error_if_multiple_accessors_match_a_message() { var notification = new Notification(); var token = StringToken.FromKeyString("test1", "test1"); var message = new NotificationMessage(token); message.AddAccessor(ReflectionHelper.GetAccessor<EntityToValidate>(x => x.Something)); message.AddAccessor(ReflectionHelper.GetAccessor<EntityToValidate>(x => x.Else)); notification.RegisterMessage(message); var errors = notification.ToValidationErrors(); errors.Length.ShouldEqual(2); errors.Each(x => x.message.ShouldEqual("test1")); errors.First().field.ShouldEqual("Something"); errors.Last().field.ShouldEqual("Else"); }
public void to_validation_error_if_multiple_accessors_match_a_message() { var notification = new Notification(); var token = StringToken.FromKeyString("test1", "test1"); var message = new NotificationMessage(token); message.AddAccessor(ReflectionHelper.GetAccessor <EntityToValidate>(x => x.Something)); message.AddAccessor(ReflectionHelper.GetAccessor <EntityToValidate>(x => x.Else)); notification.RegisterMessage(message); var errors = notification.ToValidationErrors(); errors.Length.ShouldEqual(2); errors.Each(x => x.message.ShouldEqual("test1")); errors.First().field.ShouldEqual("Something"); errors.Last().field.ShouldEqual("Else"); }
public void Validate(long count, ValidationContext context) { if (count <= 0) { return; } var message = new NotificationMessage(FastPackKeys.FIELD_MUST_BE_UNIQUE); _properties.Each(p => message.AddAccessor(new SingleProperty(p))); context.Notification.RegisterMessage(message); }