public async Task <ITestResultReportGenerator> CreateAsync( string trackingId, ITestReportMetadata testReportMetadata) { Preconditions.CheckNonWhiteSpace(trackingId, nameof(trackingId)); Preconditions.CheckNotNull(testReportMetadata, nameof(testReportMetadata)); switch (testReportMetadata.TestReportType) { case TestReportType.CountingReport: { var metadata = (CountingReportMetadata)testReportMetadata; var expectedTestResults = this.GetResults(metadata.ExpectedSource); var actualTestResults = this.GetResults(metadata.ActualSource); await this.LonghaulSettings.ForEachAsync(async (longhaulSettings) => { TestResultFilter filter = new TestResultFilter(new SimpleTestOperationResultComparer()); TimeSpan unmatchedResultTolerance = longhaulSettings.UnmatchedResultTolerance; (expectedTestResults, actualTestResults) = await filter.FilterResults(unmatchedResultTolerance, expectedTestResults, actualTestResults); }); return(new CountingReportGenerator( metadata.TestDescription, trackingId, metadata.ExpectedSource, expectedTestResults.GetAsyncEnumerator(), metadata.ActualSource, actualTestResults.GetAsyncEnumerator(), testReportMetadata.TestOperationResultType.ToString(), new SimpleTestOperationResultComparer(), Settings.Current.UnmatchedResultsMaxSize)); } case TestReportType.TwinCountingReport: { var metadata = (TwinCountingReportMetadata)testReportMetadata; var expectedTestResults = this.GetTwinExpectedResults(metadata); var actualTestResults = this.GetResults(metadata.ActualSource); return(new TwinCountingReportGenerator( metadata.TestDescription, trackingId, metadata.ExpectedSource, expectedTestResults.GetAsyncEnumerator(), metadata.ActualSource, actualTestResults.GetAsyncEnumerator(), testReportMetadata.TestOperationResultType.ToString(), new SimpleTestOperationResultComparer(), Settings.Current.UnmatchedResultsMaxSize)); } case TestReportType.LegacyTwinReport: { var metadata = (LegacyTwinReportMetadata)testReportMetadata; var testResults = this.GetResults(metadata.SenderSource); return(new LegacyTwinReportGenerator( metadata.TestDescription, trackingId, testReportMetadata.TestOperationResultType.ToString(), metadata.SenderSource, testResults.GetAsyncEnumerator())); } case TestReportType.DeploymentTestReport: { var metadata = (DeploymentTestReportMetadata)testReportMetadata; var expectedTestResults = this.GetResults(metadata.ExpectedSource); var actualTestResults = this.GetResults(metadata.ActualSource); return(new DeploymentTestReportGenerator( metadata.TestDescription, trackingId, metadata.ExpectedSource, expectedTestResults.GetAsyncEnumerator(), metadata.ActualSource, actualTestResults.GetAsyncEnumerator(), Settings.Current.UnmatchedResultsMaxSize)); } case TestReportType.DirectMethodConnectivityReport: { var metadata = (DirectMethodConnectivityReportMetadata)testReportMetadata; var senderTestResults = this.GetResults(metadata.SenderSource); var receiverTestResultsEnumerator = metadata.ReceiverSource.Map(x => this.GetResults(x).GetAsyncEnumerator()); var tolerancePeriod = metadata.TolerancePeriod; var networkStatusTimeline = await this.GetNetworkStatusTimelineAsync(tolerancePeriod); return(new DirectMethodConnectivityReportGenerator( metadata.TestDescription, trackingId, metadata.SenderSource, senderTestResults.GetAsyncEnumerator(), metadata.ReceiverSource, receiverTestResultsEnumerator, metadata.TestOperationResultType.ToString(), networkStatusTimeline, this.NetworkControllerType)); } case TestReportType.DirectMethodLongHaulReport: { var metadata = (DirectMethodLongHaulReportMetadata)testReportMetadata; var senderTestResults = this.GetResults(metadata.SenderSource); var receiverTestResults = this.GetResults(metadata.ReceiverSource); await this.LonghaulSettings.ForEachAsync(async (longhaulSettings) => { TestResultFilter filter = new TestResultFilter(new DirectMethodTestOperationResultComparer()); TimeSpan unmatchedResultTolerance = longhaulSettings.UnmatchedResultTolerance; (senderTestResults, receiverTestResults) = await filter.FilterResults(unmatchedResultTolerance, senderTestResults, receiverTestResults); }); return(new DirectMethodLongHaulReportGenerator( metadata.TestDescription, trackingId, metadata.SenderSource, senderTestResults.GetAsyncEnumerator(), metadata.ReceiverSource, receiverTestResults.GetAsyncEnumerator(), metadata.TestOperationResultType.ToString())); } case TestReportType.EdgeHubRestartDirectMethodReport: { var metadata = (EdgeHubRestartDirectMethodReportMetadata)testReportMetadata; var senderTestResults = this.GetResults(metadata.SenderSource); var receiverTestResults = this.GetResults(metadata.ReceiverSource); return(new EdgeHubRestartDirectMethodReportGenerator( metadata.TestDescription, trackingId, metadata.SenderSource, metadata.ReceiverSource, metadata.TestReportType, senderTestResults.GetAsyncEnumerator(), receiverTestResults.GetAsyncEnumerator())); } case TestReportType.EdgeHubRestartMessageReport: { var metadata = (EdgeHubRestartMessageReportMetadata)testReportMetadata; var senderTestResults = this.GetResults(metadata.SenderSource); var receiverTestResults = this.GetResults(metadata.ReceiverSource); return(new EdgeHubRestartMessageReportGenerator( metadata.TestDescription, trackingId, metadata.SenderSource, metadata.ReceiverSource, metadata.TestReportType, senderTestResults.GetAsyncEnumerator(), receiverTestResults.GetAsyncEnumerator())); } case TestReportType.NetworkControllerReport: { var metadata = (NetworkControllerReportMetadata)testReportMetadata; var testResults = this.GetResults(metadata.Source); return(new SimpleReportGenerator( metadata.TestDescription, trackingId, metadata.Source, testResults.GetAsyncEnumerator(), TestOperationResultType.Network)); } case TestReportType.ErrorReport: { var metadata = (ErrorReportMetadata)testReportMetadata; var testResults = this.GetResults(metadata.Source); return(new SimpleReportGenerator( metadata.TestDescription, trackingId, metadata.Source, testResults.GetAsyncEnumerator(), TestOperationResultType.Error)); } case TestReportType.TestInfoReport: { var metadata = (TestInfoReportMetadata)testReportMetadata; var testResults = this.GetResults(metadata.Source); return(new SimpleReportGenerator( metadata.TestDescription, trackingId, metadata.Source, testResults.GetAsyncEnumerator(), TestOperationResultType.TestInfo)); } default: { throw new NotSupportedException($"Report type {testReportMetadata.TestReportType} is not supported."); } } }
public async Task <ITestResultReportGenerator> CreateAsync( string trackingId, ITestReportMetadata testReportMetadata) { Preconditions.CheckNonWhiteSpace(trackingId, nameof(trackingId)); Preconditions.CheckNotNull(testReportMetadata, nameof(testReportMetadata)); switch (testReportMetadata.TestReportType) { case TestReportType.CountingReport: { var metadata = (CountingReportMetadata)testReportMetadata; var expectedTestResults = this.GetResults(metadata.ExpectedSource); var actualTestResults = this.GetResults(metadata.ActualSource); return(new CountingReportGenerator( trackingId, metadata.ExpectedSource, expectedTestResults, metadata.ActualSource, actualTestResults, testReportMetadata.TestOperationResultType.ToString(), new SimpleTestOperationResultComparer())); } case TestReportType.TwinCountingReport: { var metadata = (TwinCountingReportMetadata)testReportMetadata; var expectedTestResults = this.GetTwinExpectedResults(metadata); var actualTestResults = this.GetResults(metadata.ActualSource); return(new TwinCountingReportGenerator( trackingId, metadata.ExpectedSource, expectedTestResults, metadata.ActualSource, actualTestResults, testReportMetadata.TestOperationResultType.ToString(), new SimpleTestOperationResultComparer())); } case TestReportType.DeploymentTestReport: { var metadata = (DeploymentTestReportMetadata)testReportMetadata; var expectedTestResults = this.GetResults(metadata.ExpectedSource); var actualTestResults = this.GetResults(metadata.ActualSource); return(new DeploymentTestReportGenerator( trackingId, metadata.ExpectedSource, expectedTestResults, metadata.ActualSource, actualTestResults)); } case TestReportType.DirectMethodReport: { var metadata = (DirectMethodReportMetadata)testReportMetadata; var senderTestResults = this.GetResults(metadata.SenderSource); var receiverTestResults = metadata.ReceiverSource.Map(x => this.GetResults(x)); var tolerancePeriod = metadata.TolerancePeriod; var networkStatusTimeline = await this.GetNetworkStatusTimelineAsync(tolerancePeriod); return(new DirectMethodReportGenerator( trackingId, metadata.SenderSource, senderTestResults, metadata.ReceiverSource, receiverTestResults, metadata.TestOperationResultType.ToString(), networkStatusTimeline)); } case TestReportType.NetworkControllerReport: { var metadata = (NetworkControllerReportMetadata)testReportMetadata; var testResults = this.GetResults(metadata.Source); return(new NetworkControllerReportGenerator( trackingId, metadata.Source, testResults)); } default: { throw new NotSupportedException($"Report type {testReportMetadata.TestReportType} is not supported."); } } }