微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何创建 ZIO 虚拟期望?

如何解决如何创建 ZIO 虚拟期望?

我想使用 ZIO 测试如下示例。

   def subscribe(subscriptions:List[Subscription]):RIO[Repository,List[Unit]]

Subscription 是一个 case 类,根据它的子类型,我期待不同的存储库调用。所以我在我的测试类中创建了一个辅助案例类,如下所示:

case class TestExample(subscription:Subscription,repositoryFindExpectation:Option[Expectation[Repository]],repositorySaveExpectation:Expectation[Repository])

然后我创建一个示例列表:

   val repositorySaveExpectation:Expectation[Repository] = examples.map(_.repositorySaveExpectation).reduce(_ and _)
   val repositoryFindExpectation:Expectation[Repository] = ??? how to reduce here given that it might be an empty list?
   val env = (repositoryFindExpectation ++ otherMock ++ repositorySaveExpectation) >>> service
   subscribe(example.map(_.subscription)).provideLayer(env)

但是,鉴于列表可以为空,我正在努力寻找如何将 repositoryFindExpectation 折叠为单个 Expectation[Repository]。我期待在伴随对象上找到一些有用的方法,Zio 测试库中的虚拟期望在哪里找到?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。