Пример #1
0
        private ServiceHandle GivenServiceCreationIsPossible(ServiceStartType serviceStartType)
        {
            GivenTheServiceControlManagerCanBeOpened();

            var serviceHandle = A.Fake <ServiceHandle>(o => o.Wrapping(new ServiceHandle {
                NativeInterop = nativeInterop
            }));

            A.CallTo(() => serviceHandle.IsInvalid).Returns(value: false);

            A.CallTo(
                () =>
                nativeInterop.CreateServiceW(serviceControlManager, TestServiceName, TestServiceDisplayName, A <ServiceControlAccessRights> ._,
                                             ServiceType.Win32OwnProcess, serviceStartType, TestServiceErrorSeverity, TestServiceBinaryPath, null, IntPtr.Zero, null,
                                             TestCredentials.UserName, TestCredentials.Password))
            .ReturnsLazily(call =>
            {
                var serviceName = (string)call.Arguments[argumentIndex: 1];
                createdServices.Add(serviceName);
                A.CallTo(() => nativeInterop.ChangeServiceConfig2W(serviceHandle, A <ServiceConfigInfoTypeLevel> ._, A <IntPtr> ._))
                .ReturnsLazily(CreateChangeService2WHandler(serviceName));
                return(serviceHandle);
            });
            return(serviceHandle);
        }