You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为Graph Mail API的EML流下载调用设置正确Mock鉴别器值?

解决方案

针对你的Mock需求,需要根据使用的Microsoft Graph .NET SDK版本选择正确的解析器:

适用于SDK v5+(最新版)

在新版SDK中,邮件内容的下载会通过BinaryData处理二进制流,因此你需要将{???}替换为BinaryData,同时将测试流转换为BinaryData实例返回:

var mockRequestAdapter = RequestAdapterMockFactory.Create();
mockRequestAdapter.Setup(adapter => adapter.SendAsync( // Download eml stream
    It.Is<RequestInformation>(info => info.HttpMethod == Method.GET),
    BinaryData.CreateFromDiscriminatorValue,
    It.IsAny<Dictionary<string, ParsableFactory<IParsable>>>(),
    It.IsAny<CancellationToken>()))
    .ReturnsAsync(BinaryData.FromStream(EmlTestMailStream()));

说明:Content.GetAsync()内部会自动将BinaryData转换为Stream返回,因此Mock时返回BinaryData即可满足业务代码的需求。

适用于SDK v4及以下(旧版本)

如果使用的是旧版SDK,对应的二进制流封装类型是StreamResponse,此时需要替换为StreamResponse:

var mockRequestAdapter = RequestAdapterMockFactory.Create();
mockRequestAdapter.Setup(adapter => adapter.SendAsync(
    It.Is<RequestInformation>(info => info.HttpMethod == Method.GET),
    StreamResponse.CreateFromDiscriminatorValue,
    It.IsAny<Dictionary<string, ParsableFactory<IParsable>>>(),
    It.IsAny<CancellationToken>()))
    .ReturnsAsync(new StreamResponse { Content = EmlTestMailStream() });

内容的提问来源于stack exchange,提问作者user3079834

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 11:22:48