public void ConstructorTest_LogonError() { string username = "******"; string password = "******"; string domain = ""; using (var scope = new WindowsImpersonationScope(username, password, domain)) { } }
public void DisposeTest() { string username = "******"; string password = "******"; string domain = ""; using (var scope = new WindowsImpersonationScope(username, password, domain)) { // Dispose メソッドを複数回呼び出します。 scope.Dispose(); scope.Dispose(); } }
public void ConstructorTest() { string username = "******"; string password = "******"; string domain = ""; var beforeId = WindowsIdentity.GetCurrent(); Assert.AreEqual(TokenImpersonationLevel.None, beforeId.ImpersonationLevel); using (var scope = new WindowsImpersonationScope(username, password, domain)) { var id = WindowsIdentity.GetCurrent(); Assert.AreEqual(TokenImpersonationLevel.Impersonation, id.ImpersonationLevel); Assert.AreEqual(string.Format(@"{0}\{1}", string.IsNullOrEmpty(domain) ? Environment.MachineName : domain, username), id.Name, true); } var afterId = WindowsIdentity.GetCurrent(); Assert.AreEqual(TokenImpersonationLevel.None, afterId.ImpersonationLevel); Assert.AreEqual(beforeId.Name, afterId.Name); }