当我在测试中运行以下代码时,
Mock<XmlWriter> mockXmlWriter = new Mock<System.Xml.XmlWriter>();
Language language = Language.GetLangauge(langId);
language.WriteXml(mockXmlWriter.Object);
mockXmlWriter.Verify(writer => writer.WriteAttributeString("ID", language.LanguageID.ToString()));
Moq 可以理解地引发以下异常:System.NotSupportedException : Invalid verify on a non-virtual (overridable in VB) member: writer => writer.WriteAttributeString("ID", .language.LanguageID.ToString())
.
愚蠢的抽象XmlWriter
仍然有一些非抽象、非虚拟的方法,比如WriteAttributeString()
:(
我寻找 anXmlWriterBase
或 a System.Xml.Abstractions
,就像我寻找HttpContext
and Co. 一样,但什么也没找到 :(
我将如何克服这个问题,以便我可以测试我的WriteXml
方法是否正在做它应该做的事情?