/// <summary>
        /// Verifies that a ResultSummary at a given position as expected within the list of ResultSummary items
        /// </summary>
        /// <param name="batchIdResultSetId">The batchId and ResultSetId for this list of events</param>
        /// <param name="position">The position with resultSetEventParamsList that we are verifying in this call<</param>
        /// <param name="resultSetEventParamsList">The list of resultSetParams that we are verifying</param>
        /// <param name="completeSummary"> This should be null when we start validating the list of ResultSetEventParams</param>
        /// <param name="lastResultSetSummary"> This should be null when we start validating the list of ResultSetEventParams</param>
        private static void VerifyResultSummary(string batchIdResultSetId, int position, List <ResultSetEventParams> resultSetEventParamsList, ref ResultSetSummary completeSummary, ref ResultSetSummary lastResultSetSummary)
        {
            ResultSetEventParams resultSetEventParams = resultSetEventParamsList[position];

            switch (resultSetEventParams.GetType().Name)
            {
            case nameof(ResultSetAvailableEventParams):
                // Save the lastResultSetSummary for this event for other verifications.
                //
                lastResultSetSummary = resultSetEventParams.ResultSetSummary;
                break;

            case nameof(ResultSetUpdatedEventParams):
                // Verify that the updateEvent is not the first in the sequence. Since we set lastResultSetSummary on each available or updatedEvent, we check that there has been no lastResultSetSummary previously set yet.
                //
                Assert.True(null != lastResultSetSummary,
                            $"UpdateResultSet was found to be the first message received for {batchIdResultSetId}"
                            + $"\r\nresultSetEventParamsList is:{string.Join("\r\n\t\t", resultSetEventParamsList.ConvertAll((p) => p.GetType() + ":" + p.ResultSetSummary))}"
                            );

                // Verify that the number of rows in the current updatedSummary is >= those in the lastResultSetSummary
                //
                Assert.True(resultSetEventParams.ResultSetSummary.RowCount >= lastResultSetSummary.RowCount,
                            $"UpdatedResultSetSummary at position: {position} has less rows than LastUpdatedSummary (or AvailableSummary) received for {batchIdResultSetId}"
                            + $"\r\nresultSetEventParamsList is:{string.Join("\r\n\t\t", resultSetEventParamsList.ConvertAll((p) => p.GetType() + ":" + p.ResultSetSummary))}"
                            + $"\r\n\t\t LastUpdatedSummary (or Available):{lastResultSetSummary}"
                            + $"\r\n\t\t UpdatedResultSetSummary:{resultSetEventParams.ResultSetSummary}");

                // Save the lastResultSetSummary for this event for other verifications.
                //
                lastResultSetSummary = resultSetEventParams.ResultSetSummary;
                break;

            case nameof(ResultSetCompleteEventParams):
                // Verify that there is only one completeEvent
                //
                Assert.True(null == completeSummary,
                            $"CompleteResultSet was received multiple times for {batchIdResultSetId}"
                            + $"\r\nresultSetEventParamsList is:{string.Join("\r\n\t\t", resultSetEventParamsList.ConvertAll((p) => p.GetType() + ":" + p.ResultSetSummary))}"
                            );

                // Save the completeSummary for this event for other verifications.
                //
                completeSummary = resultSetEventParams.ResultSetSummary;

                // Verify that the complete flag is set
                //
                Assert.True(completeSummary.Complete,
                            $"completeSummary.Complete is not true"
                            + $"\r\nresultSetEventParamsList is:{string.Join("\r\n\t\t", resultSetEventParamsList.ConvertAll((p) => p.GetType() + ":" + p.ResultSetSummary))}"
                            );
                break;

            default:
                throw new AssertionException(
                          $"Unknown type of ResultSetEventParams, actual type received is: {resultSetEventParams.GetType().Name}");
            }
        }
Example #2
0
        private static void ExecuteAndCompleteQuery(string ownerUri, Query query,
                                                    IEventSender eventSender,
                                                    Query.QueryAsyncEventHandler querySuccessCallback,
                                                    Query.QueryAsyncErrorEventHandler queryFailureCallback)
        {
            // Setup the callback to send the complete event
            Query.QueryAsyncEventHandler completeCallback = async q =>
            {
                // Send back the results
                QueryCompleteParams eventParams = new QueryCompleteParams
                {
                    OwnerUri       = ownerUri,
                    BatchSummaries = q.BatchSummaries
                };

                await eventSender.SendEvent(QueryCompleteEvent.Type, eventParams);
            };

            // Setup the callback to send the complete event
            Query.QueryAsyncErrorEventHandler failureCallback = async(q, e) =>
            {
                // Send back the results
                QueryCompleteParams eventParams = new QueryCompleteParams
                {
                    OwnerUri       = ownerUri,
                    BatchSummaries = q.BatchSummaries
                };

                await eventSender.SendEvent(QueryCompleteEvent.Type, eventParams);
            };
            query.QueryCompleted += completeCallback;
            query.QueryFailed    += failureCallback;

            // Add the callbacks that were provided by the caller
            // If they're null, that's no problem
            query.QueryCompleted += querySuccessCallback;
            query.QueryFailed    += queryFailureCallback;

            // Setup the batch callbacks
            Batch.BatchAsyncEventHandler batchStartCallback = async b =>
            {
                BatchEventParams eventParams = new BatchEventParams
                {
                    BatchSummary = b.Summary,
                    OwnerUri     = ownerUri
                };

                await eventSender.SendEvent(BatchStartEvent.Type, eventParams);
            };
            query.BatchStarted += batchStartCallback;

            Batch.BatchAsyncEventHandler batchCompleteCallback = async b =>
            {
                BatchEventParams eventParams = new BatchEventParams
                {
                    BatchSummary = b.Summary,
                    OwnerUri     = ownerUri
                };

                await eventSender.SendEvent(BatchCompleteEvent.Type, eventParams);
            };
            query.BatchCompleted += batchCompleteCallback;

            Batch.BatchAsyncMessageHandler batchMessageCallback = async m =>
            {
                MessageParams eventParams = new MessageParams
                {
                    Message  = m,
                    OwnerUri = ownerUri
                };
                await eventSender.SendEvent(MessageEvent.Type, eventParams);
            };
            query.BatchMessageSent += batchMessageCallback;

            // Setup the ResultSet completion callback
            ResultSet.ResultSetAsyncEventHandler resultCallback = async r =>
            {
                ResultSetEventParams eventParams = new ResultSetEventParams
                {
                    ResultSetSummary = r.Summary,
                    OwnerUri         = ownerUri
                };
                await eventSender.SendEvent(ResultSetCompleteEvent.Type, eventParams);
            };
            query.ResultSetCompleted += resultCallback;

            // Launch this as an asynchronous task
            query.Execute();
        }
        private static void ExecuteAndCompleteQuery(string ownerUri, IEventSender eventSender, Query query)
        {
            // Skip processing if the query is null
            if (query == null)
            {
                return;
            }

            // Setup the query completion/failure callbacks
            Query.QueryAsyncEventHandler callback = async q =>
            {
                // Send back the results
                QueryCompleteParams eventParams = new QueryCompleteParams
                {
                    OwnerUri       = ownerUri,
                    BatchSummaries = q.BatchSummaries
                };

                await eventSender.SendEvent(QueryCompleteEvent.Type, eventParams);
            };

            query.QueryCompleted += callback;
            query.QueryFailed    += callback;

            // Setup the batch callbacks
            Batch.BatchAsyncEventHandler batchStartCallback = async b =>
            {
                BatchEventParams eventParams = new BatchEventParams
                {
                    BatchSummary = b.Summary,
                    OwnerUri     = ownerUri
                };

                await eventSender.SendEvent(BatchStartEvent.Type, eventParams);
            };
            query.BatchStarted += batchStartCallback;

            Batch.BatchAsyncEventHandler batchCompleteCallback = async b =>
            {
                BatchEventParams eventParams = new BatchEventParams
                {
                    BatchSummary = b.Summary,
                    OwnerUri     = ownerUri
                };

                await eventSender.SendEvent(BatchCompleteEvent.Type, eventParams);
            };
            query.BatchCompleted += batchCompleteCallback;

            Batch.BatchAsyncMessageHandler batchMessageCallback = async m =>
            {
                MessageParams eventParams = new MessageParams
                {
                    Message  = m,
                    OwnerUri = ownerUri
                };
                await eventSender.SendEvent(MessageEvent.Type, eventParams);
            };
            query.BatchMessageSent += batchMessageCallback;

            // Setup the ResultSet completion callback
            ResultSet.ResultSetAsyncEventHandler resultCallback = async r =>
            {
                ResultSetEventParams eventParams = new ResultSetEventParams
                {
                    ResultSetSummary = r.Summary,
                    OwnerUri         = ownerUri
                };
                await eventSender.SendEvent(ResultSetCompleteEvent.Type, eventParams);
            };
            query.ResultSetCompleted += resultCallback;

            // Launch this as an asynchronous task
            query.Execute();
        }