fluentvalidation

Fluent Validations. Error: Validation type names in unobtrusive client validation rules must be unique

坚强是说给别人听的谎言 提交于 2019-12-17 18:33:22
问题 I got the erorr: Validation type names in unobtrusive client validation rules must be unique. The following validation type was seen more than once: required. The following validation type was seen more than once: required I used server validation. And all worked fine. But now I`m stating to use client-side validation and I got this problem. This is my validation class code: public class TestViewDataValidation : BaseTestCreateViewDataValidation<BaseTestCreateViewData> { public

ViewModel validation for a List

非 Y 不嫁゛ 提交于 2019-12-17 05:38:39
问题 I have the following viewmodel definition public class AccessRequestViewModel { public Request Request { get; private set; } public SelectList Buildings { get; private set; } public List<Person> Persons { get; private set; } } So in my application there must be at least 1 person for an access request. What approach might you use to validate? I don't want this validation to happen in my controller which would be simple to do. Is the only choice a custom validation attribute? Edit: Currently

Fluent validation with dynamic message

风格不统一 提交于 2019-12-13 13:07:45
问题 I am trying to building custom validation with dynamic message in fluent validation library. For example : public class CreateProcessValidator : AbstractValidator<CreateProcessVM> { public CreateProcessValidator() { RuleFor(x => x.ProcessFile).Must((x,e) => IsProcessFileValid(x.ProcessFile))).WithMessage("Parse failed with error : {0}"); } public bool IsProcessFileValid(HttpPostedFileBase file) { var errorMessage = "..." // pass result to validaton message ? // logic return false; } } Is here

Automate the validation process on properties using FluentValidation Library

 ̄綄美尐妖づ 提交于 2019-12-13 07:37:10
问题 Wondering is there a possibility to avoid writing rules for every fields that needs to get validated, for an example all the properties must be validated except Remarks . And I was thinking to avoid writing RuleFor for every property. public class CustomerDto { public int CustomerId { get; set; } //mandatory public string CustomerName { get; set; } //mandatory public DateTime DateOfBirth { get; set; } //mandatory public decimal Salary { get; set; } //mandatory public string Remarks { get; set

Assembly 'System.Web.Http.Cors, 5.2.3.0 uses 'System.Web.Http, 5.2.3.0' which has higher version than referenced assembly 'System.Web.Http, 5.1.0.0

风格不统一 提交于 2019-12-13 06:55:48
问题 When i am installing FluentValidation.WebApi (through package manager console command "Install-Package FluentValidation.WebAPI") to my c# project, i get following error: Assembly 'System.Web.Http.Cors, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' uses 'System.Web.Http, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' which has a higher version than referenced assembly 'System.Web.Http, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' d

Validate inherited classes using FluentValidation | C# Web API

杀马特。学长 韩版系。学妹 提交于 2019-12-13 03:40:53
问题 I want to create a validation for my c# web api. In my first question you can see my models: Click here Now I created the following validators: public class AnimalValidator<T> : AbstractValidator<T> where T : Animal { private ISessionService sessionService; public AnimalValidator(ISessionService sessionService) { this.sessionService = sessionService; RuleSet("Create", () => { // some validation }); RuleSet("Edit", () => { // some validation }); } } and... public class DogValidator :

Using FluentValidation to validate on a collection of Fields (rather than on a validator model)

流过昼夜 提交于 2019-12-13 02:53:55
问题 Im trying to see if there is a way to using FluentValidation without explicitly creating a validation model for every object type in my application. Is this technically and currently possible? Updated To rephrase this, is it possible for FluentValidation to validate Rules WITHOUT a IValidator context? Instead, i would like to pass in the item instance to be validated and use validation Rules which are constructed on-the-fly. Resolved I was able to resolve by doing a kind of a hack solution.

Access route data in FluentValidation for WebApi 2

Deadly 提交于 2019-12-12 19:36:10
问题 I have a basic C# Web Api 2 controller that has a POST method to create an entity public HttpResponseMessage Post(UserModel userModel){ ... } And also a PUT method to update said model public HttpResponseMessage Put(int id, UserModel userModel) { ... } And here is the UserModel public class UserModel { public virtual Name { get; set; } public virtual Username { get; set; } } For my validator, I want to validate that the name is not taken on Post - easy enough. For PUT, I need to validate that

How to pass RuleSet to FluentValidation constructor?

雨燕双飞 提交于 2019-12-12 18:36:57
问题 How can I pass name of specific RuleSet to inner validator (for Orders)? I would like it to be applied conditionally, based on property available in outer validator (for Clients). validator.Validate(client, ruleSet: "Production"); public class ClientValidator : AbstractValidator<Client> { public ClientValidator() { RuleSet("Production", () => { RuleFor(client => client.Orders) .SetCollectionValidator(new OrderValidator()); When(client => client.IsVIP, () => { RuleFor(client => client.Orders)

Fake Captcha from commonlibnet with FakeItEasy and FluentValidation

拟墨画扇 提交于 2019-12-12 17:14:31
问题 I am using the Captcha class from commonlibrary (http://commonlibrarynet.codeplex.com/). My code works and everything but now I'm trying to write the unit test. My validation rule is: RuleFor(x => x.CaptchaUserInput) .NotEmpty() .Must((x, captchaUserInput) => Captcha.IsCorrect(captchaUserInput, x.CaptchaGeneratedText)) .WithMessage("Invalid captcha code"); In my set up code I tried to do the following: A.CallTo(() => Captcha.IsCorrect()).Returns(true); but I get the following error message: