问题
I understand that in Moq, you need to set up properties before you can assign values. My question is why doesn't Moq just allow you to set properties by default without having to "set" them up.
回答1:
That is a question for the developer. Till then you can take a look at the Quickstart and see if it helps answer your question.
mock.SetupAllProperties();
which stubs all properties on a mock.
My guess would be that not all mocks would possess properties so making the framework attempt to look up and setup properties would not make for an efficient API. the opt-in option of setting it up if needed seems like an optimal approach.
来源:https://stackoverflow.com/questions/42630709/why-doesnt-moq-setup-all-properties-by-default