private void ValidateLayout(VideoInformationLayoutElement layout, FluentValidation.Validators.CustomContext context) { var preRoll = layout.PreRoll; var postRoll = layout.PostRoll; var totalDuration = int.Parse(context.ParentContext.RootContextData[durationLabel].ToString()); if (preRoll < 0) { context.AddFailure("preRoll value must be equal or greater than zero."); } if (postRoll < 0) { context.AddFailure("postRoll value must be equal or greater than zero."); } var tvcContent = totalDuration - (preRoll + postRoll); if (tvcContent < 1) { context.AddFailure("The sum of the layout is greater than total duration."); } }
public void when_duration_is_greater_than_one_and_layout_is_invalid_then_fail(VideoInformationLayoutElement layout, int duration) { var videoInformation = new VideoInformationElement { Duration = duration, Layout = layout }; var result = validator.TestValidate(videoInformation); result.ShouldHaveValidationErrorFor(m => m.Layout); }