public void CloseServiceRequiresOpenServiceControlManager(Fake<IAdvApi32> advApi32)
        {
            var sut = new ServiceConnection(advApi32.FakedObject);

            var connectionHandle = new ConnectionHandle();

            Assert.Throws<MissingServiceManagerConnectionException>(() => sut.Close(connectionHandle));
        }
        public void CloseServiceCallsUnderlyingApi(Fake<IAdvApi32> advApi32, int serviceControlManagerHandleValue, int serviceHandleValue)
        {
            advApi32.CallsTo(_ => _.CloseService(A<IntPtr>._))
                    .Returns(true);

            var connectionHandle = new ConnectionHandle
                {
                    ServiceManagerHandle = new IntPtr(serviceControlManagerHandleValue),
                    ServiceHandle = new IntPtr(serviceHandleValue)
                };

            var sut = new ServiceConnection(advApi32.FakedObject);

            sut.Close(connectionHandle);

            advApi32.CallsTo(_ => _.CloseService(A<IntPtr>._)).MustHaveHappened();
        }
        public void CloseServiceSetsConnectionHandleToIntPtr(Fake<IAdvApi32> advApi32, int serviceControlManagerHandleValue,
            int serviceHandleValue)
        {
            advApi32.CallsTo(_ => _.CloseService(A<IntPtr>._))
                    .Returns(true);

            var connectionHandle = new ConnectionHandle
                {
                    ServiceManagerHandle = new IntPtr(serviceControlManagerHandleValue),
                    ServiceHandle = new IntPtr(serviceHandleValue)
                };

            var sut = new ServiceConnection(advApi32.FakedObject);

            sut.Close(connectionHandle);

            var actual = connectionHandle.ServiceHandle;

            var expected = IntPtr.Zero;

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

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