Moq how to correctly mock set only properties
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: What is the correct way for dealing with interfaces the expose set-only properties with Moq? Previously I've added the other accessor but this has bled into my domain too far with random throw new NotImplementedException() statements throughout. I just want to do something simple like: mock.VerifySet(view => view.SetOnlyValue, Times.Never()); But this yields a compile error of The property 'SetOnlyValue' has no getter 回答1: public class Xyz { public virtual string AA { set {} } } public class VerifySyntax { [ Fact ] public void