【发布时间】:2020-03-20 14:59:32
【问题描述】:
我有 http Azure 函数,我正在编写该函数的单元测试。我遇到了错误
消息:测试方法 Functions.Tests.CacheFunctionTests.CacheRefreshFunction 抛出异常: System.InvalidOperationException:请求没有关联的配置对象或提供的配置为空。
单元测试
[TestMethod]
public async Task CacheRefreshFunction()
{
// Arrange
mockLog.Setup(x => x.Info(It.IsAny<string>()));
mockService.Setup(x => x.RefreshCache()).Returns(Task.FromResult(0));
HttpRequestMessage httpRequestMessage = new HttpRequestMessage() {
RequestUri = new System.Uri("http://localhost:0895/CacheRefreshFunction"),
Method = HttpMethod.Get
};
// Act
await Functions.CacheRefreshFunction.Run(httpRequestMessage, mockRuleService.Object, mockLog.Object);
// Assert
Assert.IsTrue(true);
}
我想,我没有在“HttpRequestMessage”属性中传递一些基本值。有什么想法吗?
【问题讨论】:
-
猜你缺少配置,就像错误告诉你的那样...stackoverflow.com/questions/44447232/…
标签: c# unit-testing azure-functions