Quantcast
Channel: Fluent Validation for .NET
Viewing all articles
Browse latest Browse all 1917

New Post: Unit Testing on Rule for a List

$
0
0
Hi!,

I'm having an issue with writing a Unit Test for a Rule that's setted for checking the Length of a List of custom objects. The Rule is a follows:
    public class OrderValidator : AbstractValidator<Order>
    {
        public OrderValidator()
        {
            RuleFor(order => order.OrderItems.Count).LessThanOrEqualTo(10);
        }
     }
And the Unit Test on the Rule is:
        [TestMethod]
        public void Should_have_error_when_OrderItems_count_greater_than_10()
        {
            var order = A.Fake<Order>();
            order.OrderItems = new List<OrderItem>(new OrderItem[12]);

            orderValidator.ShouldHaveValidationErrorFor(o => o.OrderItems.Count, order);
        }
It throws an exception that the lambda expression must be writeable. Is there a workaround for this or I'm doing something wrong?.

Thanks!

Viewing all articles
Browse latest Browse all 1917

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>