public void Can_create_a_named_Mutex()
        {
            // Arrange
            var name = Guid.NewGuid().ToString();

            // Act
            var result = MutexManager.Acquire(name);

            // Assert
            result.ShouldNotBeNull();
            result.Name.ShouldBe(name);

            result.Dispose();
        }
        public void CanAcquire_returns_false_for_a_lock_already_acquired()
        {
            // Arrange
            var name = Guid.NewGuid().ToString();

            // Act
            using (var result = MutexManager.Acquire(name))
            {
                MutexManager.CanAcquire(name).ShouldBeFalse();
            }

            // Assert
            MutexManager.Mutexes.Count.ShouldBe(0);
        }
        public void Creating_a_mutex_via_MutexManager_acquires_lock()
        {
            // Arrange
            var mutexName = "myname";

            // Act
            using (var mutex = MutexManager.Acquire(mutexName))
            {
                // Assert
                mutex.Name.ShouldBe(mutexName);
                MutexManager.Mutexes.ContainsKey(mutexName).ShouldBeTrue();
                MutexManager.Mutexes[mutexName].State.ShouldBe(MutexState.Acquired);
                MutexManager.Mutexes[mutexName].Timestamp.ShouldBeGreaterThan(DateTime.MinValue);
                MutexManager.Mutexes[mutexName].ThreadId.ShouldBe(Thread.CurrentThread.ManagedThreadId);
            }

            // Assert
            MutexManager.Mutexes.ContainsKey(mutexName).ShouldBeFalse();
        }