如何用標題模擬 IGraphService?
List<Option> requestOptions = new List<Option>();
requestOptions.Add(new QueryOption("$count", "true"));
var test = await _graphServiceClient.Me.TransitiveMemberOf
.Request(requestOptions)
.Header("ConsistencyLevel", "eventual")
.Filter("startsWith(displayName,'a')")
.GetAsync();
到目前為止我嘗試了什么..但回傳 System.NotSupportedException
System.NotSupportedException : Unsupported expression: ... => ....Header(It.IsAny(), It.IsAny()) 擴展方法(此處為:HeaderHelper.Header)不得用于設定/驗證運算式。
mockGraph.Setup(x => x.Me
.TransitiveMemberOf
.Request(It.IsAny<List<Option>>())
.Header(It.IsAny<string>(), It.IsAny<string>())
.Filter(It.IsAny<string>())
.ReturnsAsync(page);
uj5u.com熱心網友回復:
您不能模擬擴展方法,例如.Header(). Header()方法創建一個新的HeaderOption類實體并將其添加到請求標頭中。
通過添加將ConsistencyLevel標題添加到requestOptions集合中HeaderOption。
List<Option> requestOptions = new List<Option>();
requestOptions.Add(new QueryOption("$count", "true"));
// another way how to add header
requestOptions.Add(new HeaderOption("ConsistencyLevel", "eventual"));
// removed calling .Header method
var test = await _graphServiceClient.Me.TransitiveMemberOf
.Request(requestOptions)
.Filter("startsWith(displayName,'a')")
.GetAsync();
修改單元測驗
// removed calling .Header method
mockGraph.Setup(x => x.Me
.TransitiveMemberOf
.Request(It.IsAny<List<Option>>())
.Filter(It.IsAny<string>())
.ReturnsAsync(page);
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/529356.html
標籤:C#单元测试嘲弄微软图形 SDK
上一篇:如何從協程回傳值/等待協程完成
