public void OpenServiceManagerGetsCorrectConnectionHandle(Fake<IAdvApi32> advApi32, long pointerValue)
        {
            advApi32.CallsTo(_ => _.OpenServiceControlManager(A<string>._, A<string>._, A<ScmAccess>._))
                    .Returns(new IntPtr(pointerValue));

            var sut = new ServiceDatabaseConnection(advApi32.FakedObject);

            var connectionHandle = sut.Open();

            var actual = connectionHandle.ServiceManagerHandle;
            var expected = new IntPtr(pointerValue);

            Assert.Equal(expected, actual);
        }
        public void ReleaseWriteLockCallsUnderlyingAPI(Fake<IAdvApi32> advApi32, int serviceControlManagerHandlerValue,
            int serviceDatabaseLockHandleValue)
        {
            var sut = new ServiceDatabaseConnection(advApi32.FakedObject);

            var connectionHandle = new ConnectionHandle
                {
                    ServiceManagerHandle = new IntPtr(serviceControlManagerHandlerValue),
                    ServiceDatabaseLockHandle = new IntPtr(serviceDatabaseLockHandleValue)
                };

            sut.ReleaseLock(connectionHandle);

            advApi32.CallsTo(_ => _.ReleaseServiceDatabaseLock(A<IntPtr>._)).MustHaveHappened();
        }
        public void CloseServiceManagerResetsConnectionHandleToIntPtrZero(Fake<IAdvApi32> advApi32, int serviceManagerHandleValue)
        {
            advApi32.CallsTo(_ => _.CloseServiceControlManager(A<IntPtr>._))
                    .Returns(true);

            var sut = new ServiceDatabaseConnection(advApi32.FakedObject);

            var connectionHandle = new ConnectionHandle {ServiceManagerHandle = new IntPtr(serviceManagerHandleValue)};

            sut.Close(connectionHandle);

            var actual = connectionHandle.ServiceManagerHandle;
            var expected = IntPtr.Zero;

            Assert.Equal(expected, actual);
        }
        public void ReleaseWriteLockResetsDatabaseLockHandle(Fake<IAdvApi32> advApi32, int serviceControlManagerHandlerValue,
            int serviceDatabaseLockHandleValue)
        {
            advApi32.CallsTo(_ => _.ReleaseServiceDatabaseLock(A<IntPtr>._))
                    .Returns(true);

            var sut = new ServiceDatabaseConnection(advApi32.FakedObject);

            var connectionHandle = new ConnectionHandle
                {
                    ServiceManagerHandle = new IntPtr(serviceControlManagerHandlerValue),
                    ServiceDatabaseLockHandle = new IntPtr(serviceDatabaseLockHandleValue)
                };

            sut.ReleaseLock(connectionHandle);

            var actual = connectionHandle.ServiceDatabaseLockHandle;
            var expected = IntPtr.Zero;

            Assert.Equal(expected, actual);
        }
        public void AquireWriteLockRequiresConnectionHandle(Fake<IAdvApi32> advApi32)
        {
            var sut = new ServiceDatabaseConnection(advApi32.FakedObject);

            Assert.Throws<ArgumentNullException>(() => sut.WriteLock(null));
        }