title: FluentValidation - Value must be assignable; Parameter name: left
body: <p>I am trying to mock my fluentValidation validators in unit tests.  For some reason i have a couple that throw this error?</p>
  
  <p>Here is my entity (EF6)</p>
  
  <pre><code>public class Content : AuditableEntity
  {
      public long PageId { get; set; }
  
      public virtual Page Page { get; set; }
  
      public short Position { get; set; }
  
      public short Width { get; set; }
  
      public Content() 
      {
          Position = 1;
      }
  
  }
  </code></pre>
  
  <p>Here is my validator</p>
  
  <pre><code>public class ContentValidator : AbstractValidator&lt;Content&gt;
  {
      public ContentValidator()
      {
          RuleFor(e =&gt; e.Page).NotNull().WithMessage("You must select a page for this content").When(e =&gt; e.PageId == 0);
  
          RuleFor(e =&gt; e.Position).GreaterThan((short)0).LessThan((short)256).WithMessage("Position must be between 1 and 255");
  
          RuleFor(e =&gt; e.Width).GreaterThan((short)0).LessThan((short)13).WithMessage("Width must be between 1 and 12");
      }
  }
  </code></pre>
  
  <p>Here are my mock tests (that fail)</p>
  
  <pre><code>private ContentValidator _validator;
  
  [TestInitialize]
  public void TestInit()
  {
      _validator = new ContentValidator();
  }
  [TestMethod]
  public void ContentValidator_ShouldHaveErrorWhenPositionLessThanOne()
  {
      _validator.ShouldHaveValidationErrorFor(e =&gt; e.Position, 0);
  }
  
  [TestMethod]
  public void ContentValidator_ShouldHaveErrorWhenPositionGreaterThanTwoHundredAndFiftyFive()
  {
      _validator.ShouldHaveValidationErrorFor(e =&gt; e.Position, 256);
  }
  
  [TestMethod]
  public void ContentValidator_ShouldHaveErrorWhenWidthLessThanOne()
  {
      _validator.ShouldHaveValidationErrorFor(e =&gt; e.Width, 0);
  }
  
  [TestMethod]
  public void ContentValidator_ShouldHaveErrorWhenWidthGreaterThanTwelve()
  {
      _validator.ShouldHaveValidationErrorFor(e =&gt; e.Width, 13);
  }
  </code></pre>
  
  <p>For some reason these tests throw an error.  Here is the error from one of the tests, the rest are all the same, just different method</p>
  
  <pre><code>Test Name:  ContentValidator_ShouldHaveErrorWhenPositionGreaterThanTwoHundredAndFiftyFive
  Test FullName:  Tests.TestContentValidator.ContentValidator_ShouldHaveErrorWhenPositionGreaterThanTwoHundredAndFiftyFive
  Test Source:    e:\Sample Projects\Tests\TestContentValidator.cs : line 75
  Test Outcome:   Failed
  Test Duration:  0:00:00.001921
  
  Result Message: 
  Test method TestContentValidator.ContentValidator_ShouldHaveErrorWhenPositionGreaterThanTwoHundredAndFiftyFive threw exception: 
  System.ArgumentException: Expression must be writeable
  Parameter name: left
  Result StackTrace:  
  at System.Linq.Expressions.Expression.RequiresCanWrite(Expression expression, String paramName)
     at System.Linq.Expressions.Expression.Assign(Expression left, Expression right)
     at FluentValidation.MemberAccessor`2.CreateSetExpression(Expression`1 getExpression) in c:\Projects\FluentValidation\src\FluentValidation\MemberAccessor.cs:line 29
     at FluentValidation.MemberAccessor`2..ctor(Expression`1 getExpression) in c:\Projects\FluentValidation\src\FluentValidation\MemberAccessor.cs:line 23
     at FluentValidation.MemberAccessor`2.op_Implicit(Expression`1 this) in c:\Projects\FluentValidation\src\FluentValidation\MemberAccessor.cs:line 66
     at FluentValidation.TestHelper.ValidatorTester`2..ctor(Expression`1 expression, IValidator`1 validator, TValue value, String ruleSet) in c:\Projects\FluentValidation\src\FluentValidation\TestHelper\ValidatorTester.cs:line 33
     at FluentValidation.TestHelper.ValidationTestExtension.ShouldHaveValidationErrorFor[T,TValue](IValidator`1 validator, Expression`1 expression, TValue value, String ruleSet) in c:\Projects\FluentValidation\src\FluentValidation\TestHelper\ValidatorTestExtensions.cs:line 29
     at Tests.TestContentValidator.ContentValidator_ShouldHaveErrorWhenPositionGreaterThanTwoHundredAndFiftyFive() in e:\Sample Projects\Tests\TestContentValidator.cs:line 76
  </code></pre>