public void WriteLockSetsServiceDatabaseLockHandle(Fake<IAdvApi32> advApi32, int serviceControlManagerHandlerValue, int serviceDatabaseLockHandleValue) { advApi32.CallsTo(_ => _.AquireServiceDatabaseLock(A<IntPtr>._)) .Returns(new IntPtr(serviceDatabaseLockHandleValue)); var sut = new ServiceDatabaseConnection(advApi32.FakedObject); var connectionHandle = new ConnectionHandle {ServiceManagerHandle = new IntPtr(serviceControlManagerHandlerValue)}; sut.WriteLock(connectionHandle); var actual = connectionHandle.ServiceDatabaseLockHandle; var expected = new IntPtr(serviceDatabaseLockHandleValue); Assert.Equal(expected, actual); }
public void AquireWriteLockRequiresConnectionHandle(Fake<IAdvApi32> advApi32) { var sut = new ServiceDatabaseConnection(advApi32.FakedObject); Assert.Throws<ArgumentNullException>(() => sut.WriteLock(null)); }
public void WriteLockCallsUnderlyingAPI(Fake<IAdvApi32> advApi32, int serviceControlManagerHandlerValue, int serviceDatabaseLockHandleValue) { advApi32.CallsTo(_ => _.AquireServiceDatabaseLock(A<IntPtr>._)) .Returns(new IntPtr(serviceDatabaseLockHandleValue)); var sut = new ServiceDatabaseConnection(advApi32.FakedObject); var connectionHandle = new ConnectionHandle {ServiceManagerHandle = new IntPtr(serviceControlManagerHandlerValue)}; sut.WriteLock(connectionHandle); advApi32.CallsTo(_ => _.AquireServiceDatabaseLock(A<IntPtr>._)).MustHaveHappened(); }