Пример #1
0
        public void 想定したProcessStartInfoクラスのインスタンスが引数でプロセスが実行されていること()
        {
            var input = new PowerPlan();

            var expectedArgument = new ProcessStartInfo(
                new PowerConfigurationProcess().ApplicationPath, $"/setactive {input.Guid}");
            expectedArgument.UseShellExecute = false;
            expectedArgument.CreateNoWindow = true;
            expectedArgument.RedirectStandardError = true;

            ProcessStartInfo actualArgument = null;

            var mock = new Mock<ApplicationProcessInvoker.Interface>();
            mock
                .Setup(x => x.Invoke(It.IsAny<ProcessStartInfo>()))
                .Callback<ProcessStartInfo>(x => actualArgument = x);

            var target = new PowerConfigurationProcess();
            target.ApplicationProcessInvoker = mock.Object;
            target.SetActive(input);

            Assert.AreEqual(expectedArgument.FileName, new PowerConfigurationProcess().ApplicationPath);
            Assert.AreEqual(expectedArgument.Arguments, actualArgument.Arguments);
            Assert.AreEqual(expectedArgument.UseShellExecute, actualArgument.UseShellExecute);
            Assert.AreEqual(expectedArgument.CreateNoWindow, actualArgument.CreateNoWindow);
            Assert.AreEqual(expectedArgument.RedirectStandardError, actualArgument.RedirectStandardError);

            mock.Verify(x => x.Invoke(It.IsAny<ProcessStartInfo>()), Times.Once);
            mock.VerifyAll();
        }
Пример #2
0
        public void 引数にnullを指定した場合ArgumentNullExceptionをスローすること()
        {
            var mock = new Mock<ApplicationProcessInvoker.Interface>();

            var target = new PowerConfigurationProcess();
            target.ApplicationProcessInvoker = mock.Object;
            var actualException = Assert.Throws<ArgumentNullException>(
                () => target.SetActive(null));

            Assert.AreEqual("powerPlan", actualException.ParamName);

            mock.Verify(x => x.Invoke(It.IsAny<ProcessStartInfo>()), Times.Never);
            mock.VerifyAll();
        }