fluentvalidation

Dependency-Injected Validation in Web API

偶尔善良 提交于 2019-12-09 04:21:55
问题 In MVC, I can create a Model Validator which can take Dependencies. I normally use FluentValidation for this. This allows me to, for example, check on account registration that an e-mail address hasn't been used (NB: This is a simplified example!): public class RegisterModelValidator : AbstractValidator<RegisterModel> { private readonly MyContext _context; public RegisterModelValidator(MyContext context) { _context = context; } public override ValidationResult Validate(ValidationContext

FluentValidation and ActionFilterAttribute - update model before it is validated

末鹿安然 提交于 2019-12-08 03:15:14
问题 Inside my WebAPI project I'm using FluentValidation. I'm enabling it globally by adding FluentValidationModelValidatorProvider.Configure(config); inside Startup.cs I've added custom ActionFolterAttribute that is changing model before it is used inside my method, but after testing I can see that I have bad order of execution. I want my model to be changed before it is validated by FluentVatiodation, but right now it is updated after FluentVatiodation validates my model. I need this to be able

Using FluentValidation with Castle Windsor and Entity Framework 4.0 (POCO) in MVC2

 ̄綄美尐妖づ 提交于 2019-12-08 00:31:27
问题 This isn't a very simple question, but hopefully someone has run across it. I am trying to get the following things working together: MVC2 FluentValidation Entity Framework 4.0 (POCO) Castle Windsor I've pretty much gotten everything working. I have Castle Windsor implemented and working with the Controllers being served up by the WindsorControllerFactory that is part of MVCContrib. I also have Castle serving up the FluentValidation validators as is described by this article: http://www

FluentValidation: validation type names must be unique

倖福魔咒の 提交于 2019-12-07 14:35:52
问题 I have the following rules specified in my code RuleFor(x => x.Auction_Round1Ring1Start).GreaterThan(DateTime.Now); RuleFor(x => x.Auction_Round1Ring1End).GreaterThan(x => x.Auction_Round1Ring1Start); RuleFor(x => x.Auction_Round1Ring2Start).GreaterThan(x => x.Auction_Round1Ring1End); RuleFor(x => x.Auction_Round1Ring2End).GreaterThan(x => x.Auction_Round1Ring2Start); RuleFor(x => x.Auction_Round1Ring3Start).GreaterThan(x => x.Auction_Round1Ring2End); RuleFor(x => x.Auction_Round1Ring3End)

Should i create a new Type for Collection in FluentValidation?

大城市里の小女人 提交于 2019-12-07 07:13:05
问题 I am trying to find if there is way available in FluentValidation which allows a collection to be validated for a Validator at Root Level. For e.g. As shown below, a validator is available for CustomerValidator for a class Customer . using FluentValidation; public class CustomerValidator: AbstractValidator<Customer> { public CustomerValidator() { RuleFor(customer => customer.Surname).NotEmpty(); RuleFor(customer => customer.Forename).NotEmpty().WithMessage("Please specify a first name");

How to unit test simple property has validator set?

烂漫一生 提交于 2019-12-07 02:32:34
问题 I have similar rules for some properties in multiple model objects and I want to replace them with custom property validators to avoid code duplication in unit tests. I have my property validator: public class IntIdPropertyValidator: PropertyValidator { public IntIdPropertyValidator() : base("Property {PropertyName} should be greater than 0") { } protected override bool IsValid(PropertyValidatorContext context) { var value = (int)context.PropertyValue; return value > 0; } } And wiring it up

Fluent Validation doesn't validate the entire form the first time

百般思念 提交于 2019-12-07 01:50:36
问题 So I'm using Fluent Validation on a form. When I click submit and have nothing entered, I get a validation error for Date of Birth. If I enter a DoB, then I get the validation for First Name. Why is this happening? I can't figure out what I wired up wrong. My form: @using (Html.BeginForm()) { @Html.AntiForgeryToken() @Html.HiddenFor(customer => customer.CustomerIncomeInfo.CustomerEmploymentInfoModel.EmployerModel.Id) <!-- basic customer info --> <fieldset> <legend>Customer Info</legend> @Html

FluentValidation for When & must?

≡放荡痞女 提交于 2019-12-06 19:25:29
问题 I am trying use FluentValidation validaton when dropdownlist value is yes and the field must be date. it is working when dropdownlist is yes checking for date . But also showing validation when I select No still it says Must be date . It should not validate anymore if dropdownlist value otherthan the yes . How can we do that? RuleFor(x => x.DtPublishedTimeText) .NotEmpty() .When(HasMaterialPublishedElseWhereText) .WithMessage("Required Field") .Must(BeAValidDate) .WithMessage("Must be date");

Nested Razor layouts causing client validation to fail

百般思念 提交于 2019-12-06 13:55:27
问题 Here's my original create page (no nesting) - Client validation works @model TennisClub.ViewModels.ClubMember.EditorModel @{ ViewBag.Title = "New Club Member"; ViewBag.LegendTitle = "Club Member"; } <h2>@ViewBag.Title</h2> <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script> <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script> @using (Html.BeginForm()) { @Html.ValidationSummary(true, "Errors were

Using FluentValidation with Castle Windsor and Entity Framework 4.0 (POCO) in MVC2

喜夏-厌秋 提交于 2019-12-06 05:13:20
This isn't a very simple question, but hopefully someone has run across it. I am trying to get the following things working together: MVC2 FluentValidation Entity Framework 4.0 (POCO) Castle Windsor I've pretty much gotten everything working. I have Castle Windsor implemented and working with the Controllers being served up by the WindsorControllerFactory that is part of MVCContrib. I also have Castle serving up the FluentValidation validators as is described by this article: http://www.jeremyskinner.co.uk/2010/02/22/using-fluentvalidation-with-an-ioc-container/ My problem comes in when I try