private int Expect()

in src/TestFramework/Core/ProtocolTestsManager.cs [507:586]


        private int Expect<T, V>(TimeSpan timeout, bool failIfNone, Action<TimeSpan, V[]> FailAction, Func<T, V, bool> CompareAction, Action<V, T> ExpectCheckerAction, params V[] expected) where T : class
        {
            T availableObject = TryGetNext<T>(timeout, false);
            if (availableObject == null)
            {
                if (failIfNone)
                {
                    FailAction(timeout, expected);
                }
                return -1;
            }

            List<List<TransactionEvent>> failedTransactions;
            if (failIfNone)
                failedTransactions = new List<List<TransactionEvent>>();
            else
                failedTransactions = null;
            int index = 0;
            foreach (V expectedObject in expected)
            {
                if (CompareAction(availableObject, expectedObject))
                {
                    BeginTransaction();
                    try
                    {
                        ExpectCheckerAction(expectedObject, availableObject);

                        EndTransaction(true);

                        Type serviceInterface = typeof(T);
                        if (serviceInterface.Equals(typeof(AvailableEvent)))
                        {
                            AvailableEvent dummy;
                            eventQueue.TryGet(TimeSpan.FromSeconds(0), true, out dummy);
                        }

                        if (serviceInterface.Equals(typeof(AvailableReturn)))
                        {
                            AvailableReturn dummy;
                            returnQueue.TryGet(TimeSpan.FromSeconds(0), true, out dummy);
                        }

                        return index;
                    }
                    catch (TransactionFailedException)
                    {
                        if (failIfNone)
                        {
                            failedTransactions.Add(transactionEvents);
                        }
                        EndTransaction(false);
                    }
                }

                index++;
            }

            if (!failIfNone)
                return -1;

            // build diagnosis
            StringBuilder diagnosis = new StringBuilder();
            index = 0;
            foreach (V expectedObject in expected)
            {
                if (!CompareAction(availableObject, expectedObject))
                {
                    diagnosis.AppendLine(String.Format("{0} is not matching", expectedObject.ToString()));
                }
                else
                {
                    List<TransactionEvent> t = failedTransactions[index];
                    diagnosis.AppendLine(String.Format("  {0}. outputs do not match", index + 1));
                    Describe(diagnosis, "    ", t);
                    index++;
                }
            }
            InternalAssert(false, String.Format("expected matching event, found '{0}'. Diagnosis:\r\n{1}", availableObject.ToString(), diagnosis.ToString()));
            return -1;
        }