public async Task MaxInstancesToLaunchAsync()
    {
        DiffRunner.MaxInstancesToLaunch(1);
        try
        {
            await Task.Delay(500);

            ProcessCleanup.Refresh();
            var result = await DiffRunner.LaunchAsync(file1, "fake.txt");

            await Task.Delay(300);

            Assert.Equal(LaunchResult.StartedNewInstance, result);
            ProcessCleanup.Refresh();
            result = await DiffRunner.LaunchAsync(file2, "fake.txt");

            Assert.Equal(LaunchResult.TooManyRunningDiffTools, result);
            ProcessCleanup.Refresh();
            DiffRunner.Kill(file1, "fake.txt");
            DiffRunner.Kill(file2, "fake.txt");
        }
        finally
        {
            DiffRunner.MaxInstancesToLaunch(5);
        }
    }
    public async Task LaunchAndKillDisabledAsync()
    {
        DiffRunner.Disabled = true;
        try
        {
            Assert.False(IsRunning());
            Assert.False(ProcessCleanup.IsRunning(command));
            var result = await DiffRunner.LaunchAsync(file1, file2);

            Assert.Equal(LaunchResult.Disabled, result);
            Thread.Sleep(500);
            ProcessCleanup.Refresh();
            Assert.False(IsRunning());
            Assert.False(ProcessCleanup.IsRunning(command));
            DiffRunner.Kill(file1, file2);
            Thread.Sleep(500);
            ProcessCleanup.Refresh();
            Assert.False(IsRunning());
            Assert.False(ProcessCleanup.IsRunning(command));
        }
        finally
        {
            DiffRunner.Disabled = false;
        }
    }
Exemple #3
0
 static bool IsRunning()
 {
     Thread.Sleep(500);
     return(ProcessCleanup
            .FindAll()
            .Any(x => x.Command.Contains("FakeDiffTool")));
 }
Exemple #4
0
    static async Task InitialVerifySplit(TypeToSplit target, bool hasMatchingDiffTool, VerifySettings settings, FilePair info, FilePair file1, FilePair file2)
    {
        if (settings.autoVerify)
        {
            await Verifier.Verify(target, settings);

            AssertExists(info.Verified);
            AssertExists(file1.Verified);
            AssertExists(file2.Verified);
        }
        else
        {
            await Throws(() => Verifier.Verify(target, settings));

            ProcessCleanup.Refresh();
            AssertProcess(hasMatchingDiffTool, info, file1, file2);
            if (hasMatchingDiffTool)
            {
                AssertExists(info.Verified);
                AssertExists(file1.Verified);
                AssertExists(file2.Verified);
            }

            AssertExists(info.Received);
            AssertExists(file1.Received);
            AssertExists(file2.Received);
        }
    }
    /// <summary>
    /// Find and kill a diff tool process.
    /// </summary>
    public static void Kill(string tempFile, string targetFile)
    {
        if (Disabled)
        {
            return;
        }

        var extension = Extensions.GetExtension(tempFile);

        if (!DiffTools.TryFindByExtension(extension, out var diffTool))
        {
            Logging.Write($"Extension not found. {extension}");
            return;
        }

        var command = diffTool.BuildCommand(tempFile, targetFile);

        if (diffTool.IsMdi)
        {
            Logging.Write($"DiffTool is Mdi so not killing. diffTool: {diffTool.ExePath}");
            return;
        }

        ProcessCleanup.Kill(command);
    }
Exemple #6
0
    static void AssertProcess(bool isRunning, params FilePair[] pairs)
    {
        foreach (var pair in pairs)
        {
            var command = tool.BuildCommand(pair.Received, pair.Verified);
            if (isRunning == ProcessCleanup.IsRunning(command))
            {
                continue;
            }

            var    commands = string.Join(Environment.NewLine, ProcessCleanup.Commands.Select(x => x.Command));
            string message;
            if (isRunning)
            {
                message = "Expected command running";
            }
            else
            {
                message = "Expected command not running";
            }

            throw new Exception($@"{message}
{command}
Commands:
{commands}");
        }
    }
Exemple #7
0
    public void Find()
    {
        var enumerable = ProcessCleanup.FindAll().ToList();

        foreach (var x in enumerable)
        {
            Debug.WriteLine($"{x.Process} {x.Command}");
        }
    }
Exemple #8
0
    public async Task Kill()
    {
        await DiffRunner.Launch(file1, file2);

        ProcessCleanup.Refresh();
        #region DiffRunnerKill
        DiffRunner.Kill(file1, file2);
        #endregion
    }
    public void Find()
    {
        var list = ProcessCleanup.FindAll().ToList();

        // new processes have large Ids
        Assert.True(list[0].Process > list[1].Process);
        foreach (var x in list)
        {
            Debug.WriteLine($"{x.Process} {x.Command}");
        }
    }
Exemple #10
0
    async Task ReVerify(Func <object> target, VerifySettings settings, FilePair pair)
    {
        var command = BuildCommand(pair);

        ProcessCleanup.Refresh();
        await Verify(target(), settings);

        ProcessCleanup.Refresh();
        AssertProcessNotRunning(command);

        AssertNotExists(pair.Received);
        AssertExists(pair.Verified);
    }
    public async Task LaunchAndKillAsync()
    {
        Assert.False(IsRunning());
        Assert.False(ProcessCleanup.IsRunning(command));
        var result = await DiffRunner.LaunchAsync(file1, file2);

        Assert.Equal(LaunchResult.StartedNewInstance, result);
        Thread.Sleep(500);
        ProcessCleanup.Refresh();
        Assert.True(IsRunning());
        Assert.True(ProcessCleanup.IsRunning(command));
        DiffRunner.Kill(file1, file2);
        Thread.Sleep(500);
        ProcessCleanup.Refresh();
        Assert.False(IsRunning());
        Assert.False(ProcessCleanup.IsRunning(command));
    }
    async Task ReVerifySplit(TypeToSplit target, VerifySettings settings, FilePair info, FilePair file1, FilePair file2)
    {
        var infoCommand  = tool.BuildCommand(info.Received, info.Verified);
        var file1Command = tool.BuildCommand(file1.Received, file1.Verified);
        var file2Command = tool.BuildCommand(file2.Received, file2.Verified);

        ProcessCleanup.Refresh();
        await Verify(target, settings);

        ProcessCleanup.Refresh();
        AssertProcessNotRunning(infoCommand);
        AssertProcessNotRunning(file1Command);
        AssertProcessNotRunning(file2Command);

        AssertNotExists(info.Received);
        AssertExists(info.Verified);
        AssertNotExists(file1.Received);
        AssertExists(file1.Verified);
        AssertNotExists(file2.Received);
        AssertExists(file2.Verified);
    }
Exemple #13
0
    async Task InitialVerify(Func <object> target, bool hasMatchingDiffTool, VerifySettings settings, FilePair pair)
    {
        if (settings.autoVerify)
        {
            await Verify(target(), settings);

            AssertExists(pair.Verified);
        }
        else
        {
            await Throws(() => Verify(target(), settings));

            ProcessCleanup.Refresh();
            AssertProcess(hasMatchingDiffTool, pair);
            if (hasMatchingDiffTool)
            {
                AssertExists(pair.Verified);
            }

            AssertExists(pair.Received);
        }
    }
Exemple #14
0
    public void LaunchAndKill()
    {
        if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
        {
            return;
        }
        DiffTools.AddTool(
            name: "FakeDiffTool",
            autoRefresh: true,
            isMdi: false,
            supportsText: true,
            requiresTarget: true,
            arguments: (path1, path2) => $"\"{path1}\" \"{path2}\"",
            exePath: FakeDiffTool.Exe,
            binaryExtensions: new[] { "knownBin" });
        var tempFile   = Path.Combine(SourceDirectory, "DiffRunner.file1.txt");
        var targetFile = Path.Combine(SourceDirectory, "DiffRunner.file2.txt");

        DiffRunner.Launch(tempFile, targetFile);
        Assert.True(IsRunning());
        ProcessCleanup.Refresh();
        DiffRunner.Kill(tempFile, targetFile);
        Assert.False(IsRunning());
    }
Exemple #15
0
 static bool IsRunning() =>
 ProcessCleanup
 .FindAll()
 .Any(x => x.Command.Contains("FakeDiffTool"));
Exemple #16
0
 static void AssertProcessNotRunning(string command)
 {
     Assert.False(ProcessCleanup.IsRunning(command));
 }