Configure Mock to return the same object that I am sending to it?

I want to check the code:

public ViewModel FillClientCreateViewModel(ViewModel model){ model.Phone = new Phone { Name = "Test"}; model.Phone = _entityInitializer.FillViewModel(model.Phone); } 

I also want to configure the FillViewModel to return the same object as me.

My test:

  entityInitMock.Setup(x => x.FillViewModel(It.IsAny<PhoneViewModel>())).Returns(It.IsAny<PhoneViewModel>()); var result = TestedInstance.FillClientCreateViewModel(CreateViewModel); result.Phone.Name.ShouldBe("Test"); 

But in this case, my test fell - because result.Phone.Name was cleared by my layout.

How to customize the layout to just give me the same object that I give it.

+4
source share
1 answer
 entityInitMock.Setup(x => x.FillViewModel(It.IsAny<PhoneViewModel>())) .Returns((PhoneViewModel m) => m); 

Moq QuickStart is a great link to related questions.

+9
source

Source: https://habr.com/ru/post/1390935/


All Articles