c# - Pose Shim:测试无限期运行
问题描述
我正在尝试使用 Pose (请参阅https://github.com/tonerdo/pose)来填充 XDocument 类的实例方法,如下所示:
被测代码:
/// <exception cref="ArgumentException" />
public void Persist<T>(XDocument document) where T : IEntity
{
if (!HasRegistration(typeof(T))) throw new ArgumentException("oops");
try
{
var filePath = filePaths[typeof(T)];
document.Save(filePath);
}
catch (System.IO.IOException)
{
Thread.Sleep(50);
Persist<T>(document);
throw;
}
catch (Exception)
{
throw;
}
}
单元测试:
[TestMethod()]
public void PersistenceService_Persist_T_Works()
{
var saved = false;
var mockFileSystem = new Mock<IFileSystem>();
mockFileSystem.Setup(T => T.Directory.GetCurrentDirectory()).Returns("");
mockFileSystem.Setup(T => T.Directory.GetParent(It.IsAny<string>())).CallBase();
mockFileSystem.Setup(T => T.Directory.GetParent(It.IsAny<string>()).Parent.FullName).Returns("");
var persister = new PersistenceService(mockFileSystem.Object);
var xDoc = new XDocument();
Shim xDocumentShim = Shim
.Replace(() => xDoc.Save(Is.A<string>()))
.With(delegate (XDocument @this, string s) { saved = true; });
Assert.IsFalse(saved);
persister.Persist<IEducationEntity>(xDoc);
Assert.IsTrue(saved);
}
我的意图是,当在被测代码中调用 xDoc.Save(string) 时,对单元测试进行回调以翻转保存的标志。
测试运行了几分钟,然后由于堆栈溢出而中止。
关于我做错了什么的任何指示?
解决方案
推荐阅读
- vba - VBA:从 Outlook 中与 Access 交互
- c# - Identity Server 4 - IDX10630:PII 被隐藏
- python - python 正则表达式匹配文件名但得到无
- go - 即使不再维护,我还能继续使用 mgo 吗?
- linux - 如何在不使用 ls 命令的情况下获取大目录的文件列表(90GB)
- mongodb - Mongodb:其中一个字段不区分大小写的复合索引
- angular - 如何在 Angular 材料 7 上创建大型菜单
- javascript - 视频错误 - 未捕获(承诺中)DOMException:播放()请求被暂停()调用中断
- scala - Scala 到 Java 字节码工具
- python - Python上的pyhdb编码问题