예제 #1
0
        async Task <DirectMethodReportGeneratorMetadata> ProcessSenderAndReceiverResults(
            DirectMethodTestResult dmSenderTestResult,
            bool hasSenderResult,
            bool hasReceiverResult,
            NetworkControllerStatus networkControllerStatus,
            bool isWithinTolerancePeriod)
        {
            ulong  mismatchSuccess = 0;
            string receiverSource  = this.ReceiverSource.OrDefault();
            ITestResultCollection <TestOperationResult> receiverTestResults = this.ReceiverTestResults.OrDefault();

            this.ValidateDataSource(receiverTestResults.Current, receiverSource);
            DirectMethodTestResult dmReceiverTestResult = JsonConvert.DeserializeObject <DirectMethodTestResult>(receiverTestResults.Current.Result);

            if (!string.Equals(dmSenderTestResult.TrackingId, dmReceiverTestResult.TrackingId, StringComparison.OrdinalIgnoreCase))
            {
                throw new InvalidDataException($"Sequence numbers should not match if the testResults didn't match. SenderTestResult: " +
                                               $"{dmSenderTestResult.GetFormattedResult()}. ReceiverTestResult: {dmReceiverTestResult.GetFormattedResult()}");
            }

            if (string.Equals(dmSenderTestResult.SequenceNumber, dmReceiverTestResult.SequenceNumber, StringComparison.OrdinalIgnoreCase))
            {
                hasReceiverResult = await receiverTestResults.MoveNextAsync();
            }
            else
            {
                if (int.Parse(dmSenderTestResult.SequenceNumber) > int.Parse(dmReceiverTestResult.SequenceNumber))
                {
                    return(await this.ProcessMismatchFailureCase());
                }
                else if (int.Parse(dmSenderTestResult.SequenceNumber) < int.Parse(dmReceiverTestResult.SequenceNumber))
                {
                    if (HttpStatusCode.OK.Equals(dmSenderTestResult.HttpStatusCode) &&
                        (NetworkControllerStatus.Disabled.Equals(networkControllerStatus) ||
                         (NetworkControllerStatus.Enabled.Equals(networkControllerStatus) && isWithinTolerancePeriod)))
                    {
                        mismatchSuccess++;
                        hasSenderResult = await this.SenderTestResults.MoveNextAsync();

                        return(new DirectMethodReportGeneratorMetadata {
                            MismatchSuccess = mismatchSuccess, HasReceiverResult = hasReceiverResult, HasSenderResult = hasSenderResult
                        });
                    }
                }
            }

            return(new DirectMethodReportGeneratorMetadata {
                HasSenderResult = hasSenderResult, HasReceiverResult = hasReceiverResult
            });
        }
        async Task <DirectMethodReportGeneratorMetadata> ProcessSenderAndReceiverResults(
            DirectMethodTestResult dmSenderTestResult,
            bool hasSenderResult,
            bool hasReceiverResult,
            NetworkControllerStatus networkControllerStatus,
            bool isWithinTolerancePeriod)
        {
            ulong  mismatchSuccess = 0;
            string receiverSource  = this.ReceiverSource.OrDefault();
            IAsyncEnumerator <TestOperationResult> receiverTestResults = this.ReceiverTestResults.OrDefault();

            this.ValidateDataSource(receiverTestResults.Current, receiverSource);
            DirectMethodTestResult dmReceiverTestResult = JsonConvert.DeserializeObject <DirectMethodTestResult>(receiverTestResults.Current.Result);

            if (!string.Equals(dmSenderTestResult.TrackingId, dmReceiverTestResult.TrackingId, StringComparison.OrdinalIgnoreCase))
            {
                throw new InvalidDataException($"Sequence numbers should not match if the testResults didn't match. SenderTestResult: " +
                                               $"{dmSenderTestResult.GetFormattedResult()}. ReceiverTestResult: {dmReceiverTestResult.GetFormattedResult()}");
            }

            bool didFindMatch = false;

            if (dmSenderTestResult.SequenceNumber == dmReceiverTestResult.SequenceNumber)
            {
                dmReceiverTestResult = JsonConvert.DeserializeObject <DirectMethodTestResult>(receiverTestResults.Current.Result);
                didFindMatch         = true;

                ulong receiverSequenceNumber = dmReceiverTestResult.SequenceNumber;
                while (hasReceiverResult && dmSenderTestResult.SequenceNumber == receiverSequenceNumber)
                {
                    hasReceiverResult = await receiverTestResults.MoveNextAsync();

                    if (hasReceiverResult)
                    {
                        receiverSequenceNumber = JsonConvert.DeserializeObject <DirectMethodTestResult>(receiverTestResults.Current.Result).SequenceNumber;
                    }
                }
            }

            if (!didFindMatch)
            {
                if (dmSenderTestResult.SequenceNumber > dmReceiverTestResult.SequenceNumber)
                {
                    return(await this.ProcessMismatchFailureCase());
                }
                else if (dmSenderTestResult.SequenceNumber < dmReceiverTestResult.SequenceNumber)
                {
                    if (this.IsMismatchSuccess(dmSenderTestResult, networkControllerStatus, isWithinTolerancePeriod))
                    {
                        mismatchSuccess++;
                        hasSenderResult = await this.SenderTestResults.MoveNextAsync();

                        return(new DirectMethodReportGeneratorMetadata {
                            MismatchSuccess = mismatchSuccess, HasReceiverResult = hasReceiverResult, HasSenderResult = hasSenderResult
                        });
                    }
                }
            }

            return(new DirectMethodReportGeneratorMetadata {
                HasSenderResult = hasSenderResult, HasReceiverResult = hasReceiverResult
            });
        }