private void LooselyMatchAgainst <T>(IList <object> subjects, T expectation, int expectationIndex)
        {
            var results = new AssertionResultSet();

            foreach (int index in Enumerable.Range(0, subjects.Count))
            {
                if (!matchedSubjectIndexes.Contains(index))
                {
                    object subject = subjects[index];

                    using (context.TraceBlock(path => $"Comparing subject at {path}[{index}] with the expectation at {path}[{expectationIndex}]"))
                    {
                        string[] failures = TryToMatch(subject, expectation, expectationIndex);

                        results.AddSet(index, failures);
                        if (results.ContainsSuccessfulSet())
                        {
                            context.TraceSingle(_ => $"It's a match");
                            matchedSubjectIndexes.Add(index);
                            break;
                        }
                        else
                        {
                            context.TraceSingle(_ => $"Contained {failures.Length} failures");
                        }
                    }
                }
            }

            foreach (string failure in results.SelectClosestMatchFor(expectationIndex))
            {
                AssertionScope.Current.AddPreFormattedFailure(failure);
            }
        }
Example #2
0
        private bool LooselyMatchAgainst <T>(IList <object> subjects, T expectation, int expectationIndex)
        {
            var             results          = new AssertionResultSet();
            int             index            = 0;
            GetTraceMessage getMessage       = path => $"Comparing subject at {path}[{index}] with the expectation at {path}[{expectationIndex}]";
            int             indexToBeRemoved = -1;

            for (var metaIndex = 0; metaIndex < unmatchedSubjectIndexes.Count; metaIndex++)
            {
                index = unmatchedSubjectIndexes[metaIndex];
                object subject = subjects[index];

                using (context.TraceBlock(getMessage))
                {
                    string[] failures = TryToMatch(subject, expectation, expectationIndex);

                    results.AddSet(index, failures);
                    if (results.ContainsSuccessfulSet())
                    {
                        context.TraceSingle(_ => "It's a match");
                        indexToBeRemoved = metaIndex;
                        break;
                    }
                    else
                    {
                        context.TraceSingle(_ => $"Contained {failures.Length} failures");
                    }
                }
            }

            if (indexToBeRemoved != -1)
            {
                unmatchedSubjectIndexes.RemoveAt(indexToBeRemoved);
            }

            foreach (string failure in results.SelectClosestMatchFor(expectationIndex))
            {
                AssertionScope.Current.AddPreFormattedFailure(failure);
            }

            return(indexToBeRemoved != -1);
        }
        private void LooselyMatchAgainst(object[] subjects, object expectation, int expectationIndex)
        {
            var results = new AssertionResultSet();

            for (int index = 0; index < subjects.Length; index++)
            {
                object subject = subjects[index];

                results.AddSet(index, TryToMatch(subject, expectation, expectationIndex));
                if (results.ContainsSuccessfulSet)
                {
                    break;
                }
            }

            foreach (string failure in results.SelectClosestMatchFor(expectationIndex))
            {
                AssertionScope.Current.FailWith(failure);
            }
        }
Example #4
0
        private void LooselyMatchAgainst <T>(IList <T> subjects, object expectation, int expectationIndex)
        {
            var results = new AssertionResultSet();

            foreach (int index in Enumerable.Range(0, subjects.Count))
            {
                if (!matchedSubjectIndexes.Contains(index))
                {
                    T subject = subjects[index];

                    results.AddSet(index, TryToMatch(subject, expectation, expectationIndex));
                    if (results.ContainsSuccessfulSet)
                    {
                        matchedSubjectIndexes.Add(index);
                        break;
                    }
                }
            }

            foreach (string failure in results.SelectClosestMatchFor(expectationIndex))
            {
                AssertionScope.Current.FailWith(failure);
            }
        }
        private void LooselyMatchAgainst(object[] subjects, object expectation, int expectationIndex)
        {
            var results = new AssertionResultSet();

            for (int index = 0; index < subjects.Length; index++)
            {
                if (!matchedSubjectIndexes.Contains(index))
                {
                    object subject = subjects[index];

                    results.AddSet(index, TryToMatch(subject, expectation, expectationIndex));
                    if (results.ContainsSuccessfulSet)
                    {
                        matchedSubjectIndexes.Add(index);
                        break;
                    }
                }
            }

            foreach (string failure in results.SelectClosestMatchFor(expectationIndex))
            {
                AssertionScope.Current.FailWith(failure);
            }
        }