1

我正在使用起订量。这个例子很简单。设置后我无法读取属性。

var mock = new Mock<HttpResponseBase>();
mock.Setup(x => x.Cookies).Returns(new HttpCookieCollection());
mock.Setup(x => x.Headers).Returns(new NameValueCollection());
var response = mock.Object;

// now I set StatusCode
response.StatusCode = 404;

// now I try to read, but StatusCode is 0 here, not 404
var statusCode = response.StatusCode

如您所见,我没有为StatusCode. 我该怎么做才能让我写和读它?

4

1 回答 1

1

这是因为,为了使属性表现得像普通属性,你应该调用SetupProperty它的方法。

mock.SetupProperty(x => x.StatusCode);
于 2012-12-08T13:15:07.303 回答