public void RegisterResources()
        {
            var services = new ServiceContainer();

            var rmMock = new Mock <IRestartManagerService>();

            services.AddService(rmMock.Object);

            var sessionId  = 1;
            var sessionKey = "1234abcd";

            rmMock.Setup(x => x.StartSession(out sessionId, out sessionKey)).Returns(NativeMethods.ERROR_SUCCESS);
            rmMock.Setup(x => x.RegisterResources(sessionId, It.IsAny <IEnumerable <string> >(), It.IsAny <IEnumerable <RM_UNIQUE_PROCESS> >(), It.IsAny <IEnumerable <string> >())).Returns(NativeMethods.ERROR_SUCCESS);

            var files = new HashSet <string>(StringComparer.OrdinalIgnoreCase)
            {
                @"C:\ShouldNotExist",
            };

            using (var sut = new RestartManagerSession(services))
            {
                sut.RegisterResources(files: files);
            }

            rmMock.Verify(x => x.RegisterResources(1, It.Is <IEnumerable <string> >(y => files.SetEquals(y)), null, null), Times.Once);
        }
        public void RegisterResources_Throws()
        {
            var services = new ServiceContainer();

            var rmMock = new Mock <IRestartManagerService>();

            services.AddService(rmMock.Object);

            var sessionId  = 1;
            var sessionKey = "1234abcd";

            rmMock.Setup(x => x.StartSession(out sessionId, out sessionKey)).Returns(NativeMethods.ERROR_SUCCESS);
            rmMock.Setup(x => x.RegisterResources(sessionId, It.IsAny <IEnumerable <string> >(), It.IsAny <IEnumerable <RM_UNIQUE_PROCESS> >(), It.IsAny <IEnumerable <string> >())).Returns(NativeMethods.ERROR_OUTOFMEMORY);

            using (var sut = new RestartManagerSession(services))
            {
                Assert.Throws <OutOfMemoryException>(() => sut.RegisterResources(files: new[] { @"C:\ShouldNotExist" }));
            }
        }
        public void RegisterResources_No_Resources()
        {
            var services = new ServiceContainer();

            var rmMock = new Mock <IRestartManagerService>();

            services.AddService(rmMock.Object);

            var sessionId  = 1;
            var sessionKey = "1234abcd";

            rmMock.Setup(x => x.StartSession(out sessionId, out sessionKey)).Returns(NativeMethods.ERROR_SUCCESS);

            using (var sut = new RestartManagerSession(services))
            {
                sut.RegisterResources();
            }

            rmMock.Verify(x => x.RegisterResources(It.IsAny <int>(), It.IsAny <IEnumerable <string> >(), It.IsAny <IEnumerable <RM_UNIQUE_PROCESS> >(), It.IsAny <IEnumerable <string> >()), Times.Never);
        }
        public void RegisterResources_Disposed_Throws()
        {
            var services = new ServiceContainer();

            var rmMock = new Mock <IRestartManagerService>();

            services.AddService(rmMock.Object);

            var sessionId  = 1;
            var sessionKey = "1234abcd";

            rmMock.Setup(x => x.StartSession(out sessionId, out sessionKey)).Returns(NativeMethods.ERROR_SUCCESS);

            RestartManagerSession sut;

            using (sut = new RestartManagerSession(services))
            {
            }

            Assert.Throws <ObjectDisposedException>(() => sut.RegisterResources(files: new[] { @"C:\ShouldNotExist" }));
        }