public void Should_Access_registry() { var fixture = new SevenZipRunnerFixture { Settings = new SevenZipSettings { Command = new NoCommand() } }; fixture.GivenDefaultToolDoNotExist(); fixture.GivenProcessExitsWithCode(0); var installLocation = fixture.FileSystem.CreateDirectory("/temp7z"); var file = fixture.FileSystem.CreateFile(installLocation.Path.CombineWithFilePath("7z.exe")); var sevenZipKey = new Mock <IRegistryKey>(); sevenZipKey.Setup(k => k.GetValue("Path")).Returns(installLocation.Path.FullPath); sevenZipKey.Setup(k => k.GetValue("Path64")).Returns(null); var softwareKey = new Mock <IRegistryKey>(); softwareKey.Setup(k => k.OpenKey("7-Zip")).Returns(sevenZipKey.Object); var hklm = new Mock <IRegistryKey>(); hklm.Setup(k => k.OpenKey("Software")).Returns(softwareKey.Object); fixture.Registry.Setup(r => r.LocalMachine).Returns(hklm.Object); var result = fixture.Run(); sevenZipKey.Verify(k => k.GetValue("Path"), Times.Once); sevenZipKey.Verify(k => k.GetValue("Path64"), Times.Once); result.Path.FullPath.ShouldBe(file.Path.FullPath); }
public void Should_Throw_If_SevenZip_Executable_Was_Not_Found() { var fixture = new SevenZipRunnerFixture { Settings = new SevenZipSettings { Command = new NoCommand() } }; fixture.GivenDefaultToolDoNotExist(); const string expectedMessage = "7-Zip: Could not locate executable."; Action result = () => { fixture.Run(); }; result.ShouldThrow <CakeException>().Message.ShouldBe(expectedMessage); }
public void Should_throw_ToolNotFound_if_registry_throws() { var fixture = new SevenZipRunnerFixture { Settings = new SevenZipSettings { Command = new NoCommand() } }; fixture.GivenDefaultToolDoNotExist(); var hklm = new Mock <IRegistryKey>(); hklm.Setup(k => k.OpenKey("Software")).Throws(new AccessViolationException("No!")); fixture.Registry.Setup(r => r.LocalMachine).Returns(hklm.Object); Action action = () => { fixture.Run(); }; action.ShouldThrow <CakeException>(); }