public void CheckValidator_ShouldFailIfEndDateTimeIsGreaterThenStartDateTime() { var checkBooking = new CheckValidator(); var bookingDetails = new CheckBookingDto { StartDateTime = new DateTime(2018, 08, 22, 12, 00, 00), EndDateTime = new DateTime(2018, 08, 22, 11, 00, 00) }; checkBooking.ShouldHaveValidationErrorFor(e => e.EndDateTime, bookingDetails); }
/// <summary> /// Execute before method and validate parameters of method /// </summary> /// <param name="invocation"></param> protected override void OnBefore(IInvocation invocation) { var validator = (IValidator)Activator.CreateInstance(_validatorType); var entityType = _validatorType.BaseType.GetGenericArguments()[0]; var entities = invocation.Arguments.Where(t => t.GetType() == entityType); foreach (var entity in entities) { CheckValidator.Validate(validator, entity); } }
public IResult Add(Car car) { CheckValidator.Validate(new CarValidator(), car); cardal.Add(car); if (!CheckCarImageExist(car.Id)) { carImagesDal.Add(new CarImage { CarId = car.Id, CreatedDate = DateTime.UtcNow, ImagePath = "thumbnail.png" }); } return(new SuccessResult(Messages.Add_Message(Messages.GetNameDict[typeof(Car)]))); }
public void BookingValidator_ShouldFailIfEndDateTimeIsEmpty() { var checkBooking = new CheckValidator(); checkBooking.ShouldHaveValidationErrorFor(e => e.EndDateTime, default(DateTime)); }