Esempio n. 1
0
        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 _));
        }
Esempio n. 2
0
        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 _));
        }
Esempio n. 3
0
        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 _));
        }
Esempio n. 4
0
        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 _);
            });
        }
Esempio n. 5
0
        public void Semaphore_OpenExisting_NullName()
        {
            Assert.Throws <ArgumentNullException>(() =>
            {
                SemaphoreAcl.OpenExisting(null, SemaphoreRights.FullControl).Dispose();
            });

            Assert.Throws <ArgumentNullException>(() =>
            {
                SemaphoreAcl.TryOpenExisting(null, SemaphoreRights.FullControl, out _);
            });
        }
Esempio n. 6
0
        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 _);
            });
        }
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
        private Semaphore CreateAndVerifySemaphore(int initialCount, int maximumCount, string name, SemaphoreSecurity expectedSecurity, bool expectedCreatedNew)
        {
            Semaphore Semaphore = SemaphoreAcl.Create(initialCount, maximumCount, name, out bool createdNew, expectedSecurity);

            Assert.NotNull(Semaphore);
            Assert.Equal(createdNew, expectedCreatedNew);

            if (expectedSecurity != null)
            {
                SemaphoreSecurity actualSecurity = Semaphore.GetAccessControl();
                VerifySemaphoreSecurity(expectedSecurity, actualSecurity);
            }

            return(Semaphore);
        }