Posts

Showing posts with the label Moq

Check If A Property Was Set - Using Moq

Answer : I think VerifySet is the right approach. It would look something like this: //Arrange var mock = new Mock<IDRepository>(); var mockRequest = new Mock<Request>(); // TODO: set some expectations here var dManager = new DManager(mock.Object); //Act dManager.Create(mockRequest.Object); //Assert mockRequest.VerifySet(x => x.Status = Status.Submitted); I believe in your case, it blows up because you haven't set up your Request mock to handle the set operation on Status. One easy way to do that is using SetupAllProperties , like so: //Arrange var mock = new Mock<IDRepository>(); var mockRequest = new Mock<Request>(); mockRequest.SetupAllProperties(); I think you should use strict behavior by default, then you can make the verification with a single call. It also makes you write your test more explicitly. [TestMethod] public void AddingNewRequestSetsStatusToSubmitted() { //Arrange var mock = new Mock<IDRepository>(MockBehav...