示例#1
0
            /// <summary>This method is heavily inspired by NSubstitute.Core.SequenceChecking.SequenceInOrderAssertion.GetExceptionMessage</summary>
            /// <see cref="https://github.com/nsubstitute/NSubstitute/blob/master/Source/NSubstitute/Core/SequenceChecking/SequenceInOrderAssertion.cs#L62"/>
            private string GetCallOrderExceptionMessage(IEnumerable <CallSpecAndTarget> querySpec, IEnumerable <ICall> callsInOrder, string fluentError)
            {
                const string callDelimiter = "\n    ";
                var          formatter     = new SequenceFormatter(callDelimiter, querySpec.ToArray(), callsInOrder.ToArray());

                return(String.Format("\nExpected to receive these calls in order:\n{0}{1}\n" +
                                     "\nActually received calls to target instances in this order:\n{0}{2}\n\n{3}{4}",
                                     callDelimiter, formatter.FormatQuery(), formatter.FormatActualCalls(),
                                     "*** Note: calls to property getters are not considered part of the query. ***",
                                     fluentError));
            }
    public static string For(CallSpecAndTarget[] querySpec, ICall[] receivedCalls,
                             CallSpecAndTarget[] callsSpecifiedButNotReceived, ICall[] callsReceivedButNotSpecified, IQueryFilter queryFilter)
    {
        var sequenceFormatter = new SequenceFormatter("\n    ", querySpec, receivedCalls);

        var sequenceFormatterForUnexpectedAndExcessiveCalls = new SequenceFormatter("\n    ", callsSpecifiedButNotReceived,
                                                                                    callsReceivedButNotSpecified);

        return(String.Format("\nExpected to receive only these calls:\n{0}{1}\n\n"
                             + "Actually received the following calls:\n{0}{2}\n\n"
                             + "Calls expected but not received:\n{0}{3}\n\n"
                             + "Calls received but not expected:\n{0}{4}\n\n"
                             + "{5}\n\n"

                             , "\n    "
                             , sequenceFormatter.FormatQuery()
                             , sequenceFormatter.FormatActualCalls()
                             , sequenceFormatterForUnexpectedAndExcessiveCalls.FormatQuery()
                             , sequenceFormatterForUnexpectedAndExcessiveCalls.FormatActualCalls()
                             , $"*** Note: calls to {queryFilter.WhatIsFiltered} are not considered part of the query. ***")); //bug!
    }
        private static string GetExceptionMessage(
            CallSpecAndTarget[] querySpec, ICall[] receivedCalls,
            CallSpecAndTarget[] callsSpecifiedButNotReceived, ICall[] callsReceivedButNotSpecified)
        {
            var sequenceFormatter = new SequenceFormatter("\n    ", querySpec, receivedCalls);

            var sequenceFormatterForUnexpectedAndExcessiveCalls = new SequenceFormatter("\n    ", callsSpecifiedButNotReceived,
                                                                                        callsReceivedButNotSpecified);

            return(string.Format("\nExpected to receive only these calls:\n{0}{1}\n\n"
                                 + "Actually received the following calls:\n{0}{2}\n\n"
                                 + "Calls expected but not received:\n{0}{3}\n\n"
                                 + "Calls received but not expected:\n{0}{4}\n\n"
                                 + "{5}\n\n"

                                 , "\n    "
                                 , sequenceFormatter.FormatQuery()
                                 , sequenceFormatter.FormatActualCalls()
                                 , sequenceFormatterForUnexpectedAndExcessiveCalls.FormatQuery()
                                 , sequenceFormatterForUnexpectedAndExcessiveCalls.FormatActualCalls()
                                 , "*** Note: calls to property getters are not considered part of the query. ***"));
        }