Ejemplo n.º 1
0
    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);
    }
Ejemplo n.º 2
0
    public void Should_not_access_registry_if_Default_exists()
    {
        var fixture = new SevenZipRunnerFixture
        {
            Settings = new SevenZipSettings
            {
                Command = new NoCommand()
            }
        };

        fixture.GivenProcessExitsWithCode(0);

        var sevenZipKey = new Mock <IRegistryKey>();

        sevenZipKey.Setup(k => k.GetValue("Path")).Returns(string.Empty);
        sevenZipKey.Setup(k => k.GetValue("Path64")).Returns(string.Empty);
        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.Never);
        result.Path.FullPath.ShouldBe(fixture.DefaultToolPath.FullPath);
    }