public void Semaphore_OpenExisting_PathNotFound() { string name = @"global\foo"; Assert.Throws <IOException>(() => { SemaphoreAcl.OpenExisting(name, SemaphoreRights.FullControl).Dispose(); }); Assert.False(SemaphoreAcl.TryOpenExisting(name, SemaphoreRights.FullControl, out _)); }
public void Semaphore_OpenExisting_NameInvalid() { string name = '\0'.ToString(); Assert.Throws <WaitHandleCannotBeOpenedException>(() => { SemaphoreAcl.OpenExisting(name, SemaphoreRights.FullControl).Dispose(); }); Assert.False(SemaphoreAcl.TryOpenExisting(name, SemaphoreRights.FullControl, out _)); }
public void Semaphore_OpenExisting_NameNotFound() { string name = "ThisShouldNotExist"; Assert.Throws <WaitHandleCannotBeOpenedException>(() => { SemaphoreAcl.OpenExisting(name, SemaphoreRights.FullControl).Dispose(); }); Assert.False(SemaphoreAcl.TryOpenExisting(name, SemaphoreRights.FullControl, out _)); }
public void Semaphore_OpenExisting_EmptyName() { Assert.Throws <ArgumentException>(() => { SemaphoreAcl.OpenExisting(string.Empty, SemaphoreRights.FullControl).Dispose(); }); Assert.Throws <ArgumentException>(() => { SemaphoreAcl.TryOpenExisting(string.Empty, SemaphoreRights.FullControl, out _); }); }
public void Semaphore_OpenExisting_NullName() { Assert.Throws <ArgumentNullException>(() => { SemaphoreAcl.OpenExisting(null, SemaphoreRights.FullControl).Dispose(); }); Assert.Throws <ArgumentNullException>(() => { SemaphoreAcl.TryOpenExisting(null, SemaphoreRights.FullControl, out _); }); }
public void Semaphore_OpenExisting_BadPathName() { string name = @"\\?\Path"; Assert.Throws <IOException>(() => { SemaphoreAcl.OpenExisting(name, SemaphoreRights.FullControl).Dispose(); }); Assert.Throws <IOException>(() => { SemaphoreAcl.TryOpenExisting(name, SemaphoreRights.FullControl, out _); }); }
public void Semaphore_OpenExisting() { string name = GetRandomName(); SemaphoreSecurity expectedSecurity = GetSemaphoreSecurity(WellKnownSidType.BuiltinUsersSid, SemaphoreRights.FullControl, AccessControlType.Allow); using Semaphore semaphoreNew = CreateAndVerifySemaphore(initialCount: 1, maximumCount: 2, name, expectedSecurity, expectedCreatedNew: true); using Semaphore semaphoreExisting = SemaphoreAcl.OpenExisting(name, SemaphoreRights.FullControl); VerifyHandles(semaphoreNew, semaphoreExisting); SemaphoreSecurity actualSecurity = semaphoreExisting.GetAccessControl(); VerifySemaphoreSecurity(expectedSecurity, actualSecurity); }