代码之家  ›  专栏  ›  技术社区  ›  Punter Vicky

作为单元测试一部分的Graph API调用中的Mock ServiceException

  •  0
  • Punter Vicky  · 技术社区  · 1 年前

    我目前正在单元测试中嘲笑下面的Graph API调用。如何模拟ServiceException( Microsoft.Graph.ServiceException )?

            public static void SetupMockValues(Mock<IRequestAdapter> mockRequestAdapter, HostReputation host, string value)
            {
                    mockRequestAdapter.Setup(
                    adapter => adapter.SendAsync(It.Is<RequestInformation>(
                        ri => (string) ri.PathParameters["host%2Did"] == value
                    ), Microsoft.Graph.Models.Security.HostReputation.CreateFromDiscriminatorValue, It.IsAny<Dictionary<string, ParsableFactory<IParsable>>>(), It.IsAny<CancellationToken>())
                    ).ReturnsAsync(host);
                
            }
    
    0 回复  |  直到 1 年前