I want to test some code:
public ViewModel FillClientCreateViewModel(ViewModel model){
model.Phone = new Phone { Name = "Test"};
model.Phone = _entityInitializer.FillViewModel(model.Phone);
}
I also want to setup FillViewModel to return the same object as I give to it.
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 cleaned by my mock.
How can I setup mock to just give me the same object which i give to it.
entityInitMock.Setup(x => x.FillViewModel(It.IsAny<PhoneViewModel>()))
.Returns((PhoneViewModel m) => m);
The Moq QuickStart is a great reference for similar questions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With