예제 #1
0
    public static string ReceivedDifferentCountThanExpectedCallsMessageFor <T>(T substitute, string descriptionOfConstraint) where T : class
    {
        var formatter = new SequenceFormatter("\n    ", new CallSpecAndTarget[] {}, substitute.ReceivedCalls().ToArray());
        var message   = $"\nExpected to receive *{descriptionOfConstraint}*.\n"
                        + $"Actually received the following calls:\n\n    {formatter.FormatActualCalls()}\n\n";

        return(message);
    }
예제 #2
0
    public static string ReceivedNoCallsMatchingPredicateMessageFor <T>(T substitute, Func <ICall, bool> predicate, string descriptionOfConstraint) where T : class
    {
        var formatter = new SequenceFormatter("\n    ", new CallSpecAndTarget[] {}, substitute.ReceivedCalls().Where(predicate).ToArray());
        var message   = $"\nExpected to receive *{descriptionOfConstraint}*.\n"
                        + $"Actually received the following calls:\n\n    {formatter.FormatActualCalls()}\n\n";

        return(message);
    }
예제 #3
0
    public static string ReceivedNothingMessageFor <T>(T substitute) where T : class
    {
        var formatter = new SequenceFormatter("\n    ", new CallSpecAndTarget[] {}, substitute.ReceivedCalls().ToArray());
        var message   = "\nExpected to receive *no calls*.\n"
                        + $"Actually received the following calls:\n\n    {formatter.FormatActualCalls()}\n\n";

        return(message);
    }
예제 #4
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));
            }
예제 #5
0
        private static string GetMessage <T>(T substitute) where T : class
        {
            var formatter = new SequenceFormatter("\n    ", new CallSpecAndTarget[] {}, substitute.ReceivedCalls().ToArray());
            var message   = string.Format(
                "\nExpected to receive *no calls*.\n"
                + "Actually received the following calls:\n{0}{1}\n\n"
                , "\n    "
                , formatter.FormatActualCalls());

            return(message);
        }
    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. ***"));
        }