Moq - How to verify that a property value is set via the setter

前端 未结 5 1877
梦如初夏
梦如初夏 2020-12-16 09:22

Consider this class:

public class Content
{      
   public virtual bool IsCheckedOut {get; private set;}
   public virtual void CheckOut()
   {
      IsChec         


        
5条回答
  •  北海茫月
    2020-12-16 09:34

    why don't you simply set up the content to be checked out to start with? Remember, you are only testing the behaviour of the CheckIn function.

    [TestMethod]
    public void CheckInSetsCheckedOutStatusToFalse()
    {
        // arrange - create a checked out item
        Content c = new Content();
        c.CheckOut();
    
        // act - check it in
        c.CheckIn();
    
        // assert - IsCheckedOut should be set back to false
        Assert.AreEqual(false, c.IsCheckedOut);
    }
    

提交回复
热议问题