嗨我已經創建了一個包裝器在JavascriptSerializer能夠moq這一點。嘲笑JavascriptSerializer導致錯誤
這是我的代碼:
public class JavascriptSerializerWrapper : IJavascriptSerializerWrapper
{
public JavaScriptSerializer GetJavascriptSerializer()
{
return new JavaScriptSerializer();
}
}
現在在我的單元測試,我已經tryed嘲笑這是這樣的:
private Mock<IJavascriptSerializerWrapper> m_JavascriptSerializerWrapper;
[TestInitialize]
public void Initializer()
{
m_JavascriptSerializerWrapper = new Mock<IJavascriptSerializerWrapper>();
}
[TestMethod]
public void Login_IsValidUser_ReturnsTrue()
{
const string serializedObject = "{\"EmailAddress\":\"[email protected]\",\"StudentId\":1200528,\"TeacherId\":null,\"EmployeeId\":null,\"PersonId\":82249,\"MessageUserId\":410335}";
m_JavascriptSerializerWrapper.Setup(x => x.GetJavascriptSerializer().Serialize(userInfoDTO)).Returns(serializedObject);
}
我已經調試單元測試,我得到這個錯誤:
Invalid setup on a non-virtual (overridable in VB) member: x => x.GetJavascriptSerializer().Serialize(.userInfoDTO)
我在做什麼錯在這裏,我該如何解決這個問題?