Пример #1
0
        public void powercfgのファイルパスが取得できること()
        {
            var actual = new PowerConfigurationProcess().ApplicationPath;

            var expected = @"C:\windows\system32\powercfg.exe";
            StringAssert.AreEqualIgnoringCase(expected, actual);
        }
Пример #2
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();
        }
Пример #3
0
        public void 実行したプロセスの標準出力から電源プランの一覧を取得できること()
        {
            var mock = new Mock<ApplicationProcessInvoker.Interface>();
            mock.Setup(x => x.Invoke(It.IsAny<ProcessStartInfo>()))
                .Returns(File.ReadAllText(@"PowerConfigurationProcess-Class\GetPowerPlans-Method\TestData\標準出力.txt"));

            var target = new PowerConfigurationProcess();
            target.ApplicationProcessInvoker = mock.Object;
            var actuals = target.GetPowerPlans();

            Assert.AreEqual(3, actuals.Length);

            Assert.AreEqual("381b4222-f694-41f0-9685-ff5bb260df2e", actuals.ElementAt(0).Guid.ToString());
            Assert.AreEqual("バランス", actuals.ElementAt(0).Name);
            Assert.IsFalse(actuals.ElementAt(0).IsActive);

            Assert.AreEqual("8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c", actuals.ElementAt(1).Guid.ToString());
            Assert.AreEqual("高パフォーマンス", actuals.ElementAt(1).Name);
            Assert.IsTrue(actuals.ElementAt(1).IsActive);

            Assert.AreEqual("a1841308-3541-4fab-bc81-f71556f20b4a", actuals.ElementAt(2).Guid.ToString());
            Assert.AreEqual("省電力", actuals.ElementAt(2).Name);
            Assert.IsFalse(actuals.ElementAt(2).IsActive);

            mock.Verify(x => x.Invoke(It.IsAny<ProcessStartInfo>()), Times.Once);
            mock.VerifyAll();
        }
Пример #4
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();
        }