private static string Name(this ComparableTest test)
 {
     return($"{test.TestCaseId} - {test.TestCaseName}");
 }
        private static Difference?CompareSingleTestRun(ComparableTest pre, ComparableTest post)
        {
            if (!pre.Passed && post.Passed)
            {
                return(new Difference
                {
                    Type = ResultType.Fixed,
                    TestCaseId = post.TestCaseId,
                    TestCaseName = post.TestCaseName
                });
            }

            if (pre.Passed && !post.Passed)
            {
                return(new Difference
                {
                    Type = ResultType.NewError,
                    TestCaseId = post.TestCaseId,
                    TestCaseName = post.TestCaseName,
                    Description = JsonConvert.SerializeObject(
                        post.IterationErrors.Value
                        .SelectMany(ie => ie.Where(e => !string.IsNullOrEmpty(e)))
                        .Select(OutputFormat))
                });
            }

            if (!pre.Passed && !post.Passed)
            {
                var stepsPre  = pre.IterationErrors.Value?[0];
                var stepsPost = post.IterationErrors.Value?[0];

                if (stepsPre == null || stepsPost == null)
                {
                    var matrixRow = new ErrorMatrixLine
                    {
                        OldError = stepsPre == null ? "[error message missing in earliest run]" : "",
                        NewError = stepsPost == null ? "[error message missing in latest run]" : ""
                    };

                    return(new Difference
                    {
                        Type = ResultType.ChangedError,
                        TestCaseId = post.TestCaseId,
                        TestCaseName = post.TestCaseName,
                        ErrorMatrixDifferences = new[] { matrixRow }.ToList()
                    });
                }

                if (stepsPre.Length < stepsPost.Length)
                {
                    return(new Difference
                    {
                        Type = ResultType.ChangedTest,
                        TestCaseId = post.TestCaseId,
                        TestCaseName = post.TestCaseName,
                        Description = $"{stepsPost.Length - stepsPre.Length} steps have been added"
                    });
                }
                if (stepsPre.Length > stepsPost.Length)
                {
                    return(new Difference
                    {
                        Type = ResultType.ChangedTest,
                        TestCaseId = post.TestCaseId,
                        TestCaseName = post.TestCaseName,
                        Description = $"{stepsPre.Length - stepsPost.Length} steps have been removed"
                    });
                }
                if (pre.IterationErrors.Value.Length < post.IterationErrors.Value.Length)
                {
                    return(new Difference
                    {
                        Type = ResultType.ChangedTest,
                        TestCaseId = post.TestCaseId,
                        TestCaseName = post.TestCaseName,
                        Description = $"{post.IterationErrors.Value.Length - pre.IterationErrors.Value.Length} iterations have been added"
                    });
                }
                if (pre.IterationErrors.Value.Length > post.IterationErrors.Value.Length)
                {
                    return(new Difference
                    {
                        Type = ResultType.ChangedTest,
                        TestCaseId = post.TestCaseId,
                        TestCaseName = post.TestCaseName,
                        Description = $"{pre.IterationErrors.Value.Length - post.IterationErrors.Value.Length} iterations have been removed"
                    });
                }

                var iterationErrorDifferences = DifferenceOfIterationErrors(pre.IterationErrors.Value, post.IterationErrors.Value);
                if (iterationErrorDifferences.Count > 0)
                {
                    return(new Difference
                    {
                        Type = ResultType.ChangedError,
                        TestCaseId = post.TestCaseId,
                        TestCaseName = post.TestCaseName,
                        Description = null,
                        ErrorMatrixDifferences = iterationErrorDifferences
                    });
                }
            }
            return(null);
        }