Example #1
0
        async void DoWorkAsync(object state)
        {
            var tesReportGeneratorFactory = new TestReportGeneratorFactory(this.storage);
            List <ITestReportMetadata> reportMetadataList = await Settings.Current.GetReportMetadataListAsync(this.logger);

            ITestResultReport[] testResultReports = await TestReportUtil.GenerateTestResultReportsAsync(Settings.Current.TrackingId, reportMetadataList, tesReportGeneratorFactory, this.logger);

            if (testResultReports.Length == 0)
            {
                this.logger.LogInformation("No test result report is generated.");
                return;
            }

            var    testSummary    = new TestSummary(testResultReports);
            string reportsContent = JsonConvert.SerializeObject(testSummary, Formatting.Indented);

            this.logger.LogInformation($"Test result report{Environment.NewLine}{reportsContent}");

            await AzureLogAnalytics.Instance.PostAsync(
                Settings.Current.LogAnalyticsWorkspaceId,
                Settings.Current.LogAnalyticsSharedKey,
                reportsContent,
                Settings.Current.LogAnalyticsLogType);

            this.logger.LogInformation("Successfully send reports to LogAnalytics");
        }
Example #2
0
        public async Task TestGenerateTestResultReportsAsync_ReportGeneration(
            bool throwExceptionForTestReport1,
            bool throwExceptionForTestReport2,
            bool throwExceptionForTestReport3,
            bool throwExceptionForTestReport4,
            bool throwExceptionForTestReport5,
            int expectedReportCount)
        {
            var mockLogger = new Mock <ILogger>();
            var mockTestReportGeneratorFactory = new Mock <ITestReportGeneratorFactory>();

            string trackingId                 = "fakeTrackingId";
            var    countingReportMetadata     = new CountingReportMetadata("CountingExpectedSource", "CountingAcutalSource", TestOperationResultType.Messages, TestReportType.CountingReport);
            var    twinCountingReportMetadata = new TwinCountingReportMetadata("TwinExpectedSource", "TwinActualSource", TestReportType.TwinCountingReport, TwinTestPropertyType.Desired);
            var    deploymentReportMetadata   = new DeploymentTestReportMetadata("DeploymentExpectedSource", "DeploymentActualSource");
            var    directMethodReportMetadata = new DirectMethodReportMetadata("DirectMethodSenderSource", new TimeSpan(0, 0, 0, 0, 5), "DirectMethodReceiverSource");
            var    directMethodReportMetadataWithoutReceiverSource = new DirectMethodReportMetadata("DirectMethodSenderSource", new TimeSpan(0, 0, 0, 0, 5), "DirectMethodReceiverSource");

            var mockTestReportGenerator1 = new Mock <ITestResultReportGenerator>();

            mockTestReportGenerator1.Setup(g => g.CreateReportAsync()).Returns(this.MockTestResultReport(throwExceptionForTestReport1));

            var mockTestReportGenerator2 = new Mock <ITestResultReportGenerator>();

            mockTestReportGenerator2.Setup(g => g.CreateReportAsync()).Returns(this.MockTestResultReport(throwExceptionForTestReport2));

            var mockTestReportGenerator3 = new Mock <ITestResultReportGenerator>();

            mockTestReportGenerator3.Setup(g => g.CreateReportAsync()).Returns(this.MockTestResultReport(throwExceptionForTestReport3));

            var mockTestReportGenerator4 = new Mock <ITestResultReportGenerator>();

            mockTestReportGenerator4.Setup(g => g.CreateReportAsync()).Returns(this.MockTestResultReport(throwExceptionForTestReport4));

            var mockTestReportGenerator5 = new Mock <ITestResultReportGenerator>();

            mockTestReportGenerator5.Setup(g => g.CreateReportAsync()).Returns(this.MockTestResultReport(throwExceptionForTestReport5));

            mockTestReportGeneratorFactory.Setup(f => f.CreateAsync(trackingId, countingReportMetadata)).Returns(Task.FromResult(mockTestReportGenerator1.Object));
            mockTestReportGeneratorFactory.Setup(f => f.CreateAsync(trackingId, twinCountingReportMetadata)).Returns(Task.FromResult(mockTestReportGenerator2.Object));
            mockTestReportGeneratorFactory.Setup(f => f.CreateAsync(trackingId, deploymentReportMetadata)).Returns(Task.FromResult(mockTestReportGenerator3.Object));
            mockTestReportGeneratorFactory.Setup(f => f.CreateAsync(trackingId, directMethodReportMetadata)).Returns(Task.FromResult(mockTestReportGenerator4.Object));
            mockTestReportGeneratorFactory.Setup(f => f.CreateAsync(trackingId, directMethodReportMetadataWithoutReceiverSource)).Returns(Task.FromResult(mockTestReportGenerator5.Object));

            ITestResultReport[] reports = await TestReportUtil.GenerateTestResultReportsAsync(
                trackingId,
                new List <ITestReportMetadata>
            {
                countingReportMetadata,
                twinCountingReportMetadata,
                deploymentReportMetadata,
                directMethodReportMetadata,
                directMethodReportMetadataWithoutReceiverSource
            },
                mockTestReportGeneratorFactory.Object,
                mockLogger.Object);

            Assert.Equal(expectedReportCount, reports.Length);
        }
Example #3
0
        public async Task TestGenerateTestResultReportsAsync_MissingTrackingId()
        {
            var mockLogger = new Mock <ILogger>();
            var mockTestReportGeneratorFactory = new Mock <ITestReportGeneratorFactory>();

            ArgumentException ex = await Assert.ThrowsAsync <ArgumentException>(() =>
                                                                                TestReportUtil.GenerateTestResultReportsAsync(
                                                                                    string.Empty,
                                                                                    new List <ITestReportMetadata>(),
                                                                                    mockTestReportGeneratorFactory.Object,
                                                                                    mockLogger.Object));

            Assert.StartsWith("trackingId", ex.Message, StringComparison.Ordinal);
        }
Example #4
0
        async void DoWorkAsync(object state)
        {
            var testReportGeneratorFactory = new TestReportGeneratorFactory(this.storage, Settings.Current.NetworkControllerType, Settings.Current.LongHaulSpecificSettings);
            List <ITestReportMetadata> reportMetadataList = await Settings.Current.GetReportMetadataListAsync(this.logger);

            ITestResultReport[] testResultReports = await TestReportUtil.GenerateTestResultReportsAsync(Settings.Current.TrackingId, reportMetadataList, testReportGeneratorFactory, this.logger);

            if (testResultReports.Length == 0)
            {
                this.logger.LogInformation("No test result report is generated.");
                return;
            }

            string blobContainerUri = string.Empty;

            if (this.serviceSpecificSettings.LogUploadEnabled)
            {
                try
                {
                    Uri blobContainerWriteUriForLog = await TestReportUtil.GetOrCreateBlobContainerSasUriForLogAsync(this.serviceSpecificSettings.StorageAccountConnectionString);

                    blobContainerUri = $"{blobContainerWriteUriForLog.Scheme}{Uri.SchemeDelimiter}{blobContainerWriteUriForLog.Authority}{blobContainerWriteUriForLog.AbsolutePath}";

                    await TestReportUtil.UploadLogsAsync(Settings.Current.IoTHubConnectionString, blobContainerWriteUriForLog, this.logUploadDuration, this.logger);
                }
                catch (Exception ex)
                {
                    this.logger.LogError(ex, "Exception happened when uploading logs");
                }
            }

            var    testSummary    = new TestSummary(Settings.Current.TestInfo, testResultReports, blobContainerUri);
            string reportsContent = JsonConvert.SerializeObject(testSummary, Formatting.Indented);

            this.logger.LogInformation($"Test summary{Environment.NewLine}{reportsContent}");

            await AzureLogAnalytics.Instance.PostAsync(
                this.serviceSpecificSettings.LogAnalyticsWorkspaceId,
                this.serviceSpecificSettings.LogAnalyticsSharedKey,
                reportsContent,
                this.serviceSpecificSettings.LogAnalyticsLogType);

            this.logger.LogInformation("Successfully send reports to LogAnalytics");
        }
Example #5
0
        public async Task <ContentResult> GetReportsAsync()
        {
            var testReportGeneratorFactory = new TestReportGeneratorFactory(this.storage);
            List <ITestReportMetadata> reportMetadataList = await Settings.Current.GetReportMetadataListAsync(Logger);

            ITestResultReport[] testResultReports = await TestReportUtil.GenerateTestResultReportsAsync(Settings.Current.TrackingId, reportMetadataList, testReportGeneratorFactory, Logger);

            if (testResultReports.Length == 0)
            {
                return(new ContentResult {
                    Content = "No test report generated"
                });
            }

            return(new ContentResult
            {
                Content = this.AddManualRunReportingHeading(JsonConvert.SerializeObject(testResultReports, Formatting.Indented)) // explicit serialization needed due to the wrapping list
            });
        }
Example #6
0
        public async Task TestGenerateTestResultReportsAsync_NullReportMetadata()
        {
            var mockLogger = new Mock <ILogger>();
            var mockTestReportGeneratorFactory = new Mock <ITestReportGeneratorFactory>();

            ArgumentNullException ex = await Assert.ThrowsAsync <ArgumentNullException>(() =>
                                                                                        TestReportUtil.GenerateTestResultReportsAsync(
                                                                                            "fakeTrackingId",
                                                                                            null,
                                                                                            mockTestReportGeneratorFactory.Object,
                                                                                            mockLogger.Object));

            Assert.Equal("reportMetadatalist", ex.ParamName);
        }
Example #7
0
        public async Task TestGenerateTestResultReportsAsync_ReportGeneration(
            bool throwExceptionForTestReport1,
            bool throwExceptionForTestReport2,
            bool throwExceptionForTestReport3,
            bool throwExceptionForTestReport4,
            bool throwExceptionForTestReport5,
            bool throwExceptionForTestReport6,
            bool throwExceptionForTestReport7,
            bool throwExceptionForTestReport8,
            bool throwExceptionForTestReport9,
            int expectedReportCount)
        {
            var mockLogger = new Mock <ILogger>();
            var mockTestReportGeneratorFactory = new Mock <ITestReportGeneratorFactory>();

            string trackingId                             = "fakeTrackingId";
            var    countingReportMetadata                 = new CountingReportMetadata(TestDescription, "CountingExpectedSource", "CountingAcutalSource", TestOperationResultType.Messages, TestReportType.CountingReport, false);
            var    twinCountingReportMetadata             = new TwinCountingReportMetadata(TestDescription, "TwinExpectedSource", "TwinActualSource", TestReportType.TwinCountingReport, TwinTestPropertyType.Desired);
            var    deploymentReportMetadata               = new DeploymentTestReportMetadata(TestDescription, "DeploymentExpectedSource", "DeploymentActualSource");
            var    directMethodConnectivityReportMetadata = new DirectMethodConnectivityReportMetadata(TestDescription, "DirectMethodSenderSource", new TimeSpan(0, 0, 0, 0, 5), "DirectMethodReceiverSource");
            var    directMethodConnectivityReportMetadataWithoutReceiverSource = new DirectMethodConnectivityReportMetadata(TestDescription, "DirectMethodSenderSource", new TimeSpan(0, 0, 0, 0, 5), "DirectMethodReceiverSource");
            var    directMethodLongHaulReportMetadata = new DirectMethodLongHaulReportMetadata(TestDescription, "DirectMethodSenderSource", "DirectMethodReceiverSource");
            var    directMethodLongHaulReportMetadataWithoutReceiverSource = new DirectMethodLongHaulReportMetadata(TestDescription, "DirectMethodSenderSource", "DirectMethodReceiverSource");
            var    edgeHubRestartMessageReportMetadata      = new EdgeHubRestartMessageReportMetadata(TestDescription, "edgeHubRestartTester1.EdgeHubRestartMessage", "relayer1.receive");
            var    edgeHubRestartDirectMethodReportMetadata = new EdgeHubRestartDirectMethodReportMetadata(TestDescription, "edgeHubRestartTester1.EdgeHubRestartDirectMethod", "directMethodReceiver1.receive");

            var mockTestReportGenerator1 = new Mock <ITestResultReportGenerator>();

            mockTestReportGenerator1.Setup(g => g.CreateReportAsync()).Returns(this.MockTestResultReport(throwExceptionForTestReport1));

            var mockTestReportGenerator2 = new Mock <ITestResultReportGenerator>();

            mockTestReportGenerator2.Setup(g => g.CreateReportAsync()).Returns(this.MockTestResultReport(throwExceptionForTestReport2));

            var mockTestReportGenerator3 = new Mock <ITestResultReportGenerator>();

            mockTestReportGenerator3.Setup(g => g.CreateReportAsync()).Returns(this.MockTestResultReport(throwExceptionForTestReport3));

            var mockTestReportGenerator4 = new Mock <ITestResultReportGenerator>();

            mockTestReportGenerator4.Setup(g => g.CreateReportAsync()).Returns(this.MockTestResultReport(throwExceptionForTestReport4));

            var mockTestReportGenerator5 = new Mock <ITestResultReportGenerator>();

            mockTestReportGenerator5.Setup(g => g.CreateReportAsync()).Returns(this.MockTestResultReport(throwExceptionForTestReport5));

            var mockTestReportGenerator6 = new Mock <ITestResultReportGenerator>();

            mockTestReportGenerator6.Setup(g => g.CreateReportAsync()).Returns(this.MockTestResultReport(throwExceptionForTestReport6));

            var mockTestReportGenerator7 = new Mock <ITestResultReportGenerator>();

            mockTestReportGenerator7.Setup(g => g.CreateReportAsync()).Returns(this.MockTestResultReport(throwExceptionForTestReport7));

            var mockTestReportGenerator8 = new Mock <ITestResultReportGenerator>();

            mockTestReportGenerator8.Setup(g => g.CreateReportAsync()).Returns(this.MockTestResultReport(throwExceptionForTestReport8));

            var mockTestReportGenerator9 = new Mock <ITestResultReportGenerator>();

            mockTestReportGenerator9.Setup(g => g.CreateReportAsync()).Returns(this.MockTestResultReport(throwExceptionForTestReport9));

            mockTestReportGeneratorFactory.Setup(f => f.CreateAsync(trackingId, countingReportMetadata)).Returns(Task.FromResult(mockTestReportGenerator1.Object));
            mockTestReportGeneratorFactory.Setup(f => f.CreateAsync(trackingId, twinCountingReportMetadata)).Returns(Task.FromResult(mockTestReportGenerator2.Object));
            mockTestReportGeneratorFactory.Setup(f => f.CreateAsync(trackingId, deploymentReportMetadata)).Returns(Task.FromResult(mockTestReportGenerator3.Object));
            mockTestReportGeneratorFactory.Setup(f => f.CreateAsync(trackingId, directMethodConnectivityReportMetadata)).Returns(Task.FromResult(mockTestReportGenerator4.Object));
            mockTestReportGeneratorFactory.Setup(f => f.CreateAsync(trackingId, directMethodConnectivityReportMetadataWithoutReceiverSource)).Returns(Task.FromResult(mockTestReportGenerator5.Object));
            mockTestReportGeneratorFactory.Setup(f => f.CreateAsync(trackingId, directMethodLongHaulReportMetadata)).Returns(Task.FromResult(mockTestReportGenerator6.Object));
            mockTestReportGeneratorFactory.Setup(f => f.CreateAsync(trackingId, directMethodLongHaulReportMetadataWithoutReceiverSource)).Returns(Task.FromResult(mockTestReportGenerator7.Object));
            mockTestReportGeneratorFactory.Setup(f => f.CreateAsync(trackingId, edgeHubRestartMessageReportMetadata)).Returns(Task.FromResult(mockTestReportGenerator8.Object));
            mockTestReportGeneratorFactory.Setup(f => f.CreateAsync(trackingId, edgeHubRestartDirectMethodReportMetadata)).Returns(Task.FromResult(mockTestReportGenerator9.Object));

            ITestResultReport[] reports = await TestReportUtil.GenerateTestResultReportsAsync(
                trackingId,
                new List <ITestReportMetadata>
            {
                countingReportMetadata,
                twinCountingReportMetadata,
                deploymentReportMetadata,
                directMethodConnectivityReportMetadata,
                directMethodConnectivityReportMetadataWithoutReceiverSource,
                directMethodLongHaulReportMetadata,
                directMethodLongHaulReportMetadataWithoutReceiverSource,
                edgeHubRestartMessageReportMetadata,
                edgeHubRestartDirectMethodReportMetadata
            },
                mockTestReportGeneratorFactory.Object,
                mockLogger.Object);

            Assert.Equal(expectedReportCount, reports.Length);
        }