0
我想刪除SharePoint依賴關係並將其模擬出來。默認的索引操作洛斯喜歡在新的SharePoint以下插件模板:如何單元測試SharePoint加載項?
public ActionResult Index()
{
User spUser = null;
var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext);
using (var clientContext = spContext.CreateUserClientContextForSPHost())
{
if (clientContext != null)
{
spUser = clientContext.Web.CurrentUser;
clientContext.Load(spUser, user => user.Title);
clientContext.ExecuteQuery();
ViewBag.UserName = spUser.Title;
}
}
return View();
}
我試圖打包ClientContext插入適配器,但不能模擬出的網絡媒體:
public interface IClientContext
{
Web Web { get; }
void Load<T>(T clientObject, params Expression<Func<T, object>>[] retrievals) where T : ClientObject;
void ExecuteQuery();
}
public class ClientContextAdapter : IClientContext
{
private readonly ClientContext _wrappedClient;
public ClientContextAdapter(ClientContext client)
{
_wrappedClient = client;
}
public Web Web => _wrappedClient.Web;
public void Load<T>(T clientObject, params Expression<Func<T, object>>[] retrievals) where T : ClientObject
{
_wrappedClient.Load(clientObject, retrievals);
}
public void ExecuteQuery()
{
_wrappedClient.ExecuteQuery();
}
}
如何你是否測試你的SharePoint加載項?