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(); }
public void PowerConfigurationProcessクラスのSetActiveメソッドが実行されること() { var mock = new Mock<PowerConfigurationProcess.Interface>(); var input = new PowerPlan(); var target = new PowerConfiguration(); target.PowerConfigurationProcess = mock.Object; target.SetActive(input); mock.Verify(x => x.SetActive(input), Times.Once); mock.VerifyAll(); }
public void PowerConfigurationProcessクラスのGetPowerPlansメソッドが実行されること() { var expected = new PowerPlan[] { new PowerPlan(), new PowerPlan(), }; var mock = new Mock<PowerConfigurationProcess.Interface>(); mock.Setup(x => x.GetPowerPlans()).Returns(expected); var target = new PowerConfiguration(); target.PowerConfigurationProcess = mock.Object; var actuals = target.GetPowerPlans(); CollectionAssert.AreEqual(expected, actuals); mock.Verify(x => x.GetPowerPlans(), Times.Once); mock.VerifyAll(); }
/// <summary> /// 指定した文字列を PowerPlan クラスのインスタンスに変換します。 /// </summary> /// <param name="itemSource">PowerPlan クラスのインスタンスに変換したい元の文字列。</param> /// <returns>変換した PowerPlan クラスのインスタンス。</returns> public static PowerPlan As(string itemSource) { PowerPlan ret = null; if (itemSource == null) { return ret; } var match = PowerPlan.PatternRegex.Match(itemSource); if (match.Success) { ret = new PowerPlan(); ret.Guid = new Guid(match.Groups["Guid"].Value); ret.Name = match.Groups["Name"].Value; ret.IsActive = match.Groups["Active"].Value.Any(); } return ret; }
/// <summary> /// 指定した電源プランをアクティブ状態にします。 /// </summary> /// <param name="powerPlan">アクティブ状態にしたい電源プラン。</param> /// <exception cref="System.ArgumentNullException">電源プランに null を指定することはできません。</exception> /// <exception cref="System.InvalidOperationException">アプリケーション実行時にエラーが発生しました。</exception> public void SetActive(PowerPlan powerPlan) { this.PowerConfigurationProcess.SetActive(powerPlan); }