Test code in Elevated privileges
[TestInitialize]
public void TestSetUpSettings()
{
target = new CustomAscxUserControlHelper();
//Enable RunWithElevated privileges
var spSecMock = MockManager.Mock(typeof(SPSecurity));
spSecMock.MockMethodCalled += SpSecMockMockMethodCalled;
spSecMock.ExpectAlways("RunWithElevatedPrivileges");
}
static void SpSecMockMockMethodCalled(object sender, MockMethodCallEventArgs e)
{
if (e.CalledMethodName.Equals("RunWithElevatedPrivileges"))
{
var del = (SPSecurity.CodeToRunElevated)e.SentArguments[0];
var res = del.BeginInvoke(null, null);
res.AsyncWaitHandle.WaitOne();
del.EndInvoke(res);
}
}