Esempio n. 1
0
        GivenQueuingReportAndPolling_WhenTargetHandlerArgsDataIsNotNull_TargetHandlerArgsIsSerializedAndDeserializedSuccessfully_EventReportDownloadedEventIsPublished()
        {
            // arrange
            var validReportType                = $"{_testEntriesIdentifier}_VALID_REPORT_TYPE_";
            var expectedGeneratedReportId      = "test generated report Id";
            var expectedReportProcessingStatus = "_DONE_";
            var reportRequestContainer         = GenerateReportContainer(validReportType);

            Setup_RequestReport_Returns_ReportRequestWasGenerated(validReportType);
            Setup_GetReportRequestList_Returns_ReportsGeneratedSuccessfully(expectedGeneratedReportId, expectedReportProcessingStatus);
            Setup_GetReport_Returns_ReportContentStream(expectedGeneratedReportId, "testReportContent");
            Stream actualReportContent = null;
            var    targetEventArgs     = new ReadOnlyDictionary <string, object>(new Dictionary <string, object>());
            var    reportDownloadedEventPublishedCount = 0;

            _easyMwsClient.ReportDownloaded += (s, e) =>
            {
                reportDownloadedEventPublishedCount++;
                actualReportContent = e.ReportContent;
                targetEventArgs     = e.TargetHandlerArgs;
            };

            // act - queue report
            _easyMwsClient.QueueReport(reportRequestContainer, "targetHandlerId", new Dictionary <string, object> {
                { "key1", "value1" }
            });

            var dbEntry = _dbContext.ReportRequestEntries.Where(rre => rre.ReportType == validReportType);

            // assert - null callback data serialization step does not crash
            Assert.NotNull(dbEntry);
            Assert.AreEqual(1, dbEntry.Count());
            var reportRequestEntry = dbEntry.Single();

            Assert.AreEqual("{\"key1\":\"value1\"}", reportRequestEntry.TargetHandlerArgs);

            // act - Poll report request process, in order for the queuedReport delegate to be invoked.
            _easyMwsClient.Poll();

            // assert - null callback data deserialization step does not crash, and callback was invoked successfully
            Assert.AreEqual(1, targetEventArgs.Count());
            Assert.IsNotNull(targetEventArgs.Where(kvp => kvp.Key == "key1"));
            Assert.IsNotNull(targetEventArgs.Where(kvp => kvp.Value == "value1"));
            Assert.NotNull(actualReportContent);
            Assert.AreEqual(1, reportDownloadedEventPublishedCount);
            _mwsClientMock.Verify(mws => mws.RequestReport(It.IsAny <RequestReportRequest>()), Times.Once);
            _mwsClientMock.Verify(mws => mws.GetReportRequestList(It.IsAny <GetReportRequestListRequest>()), Times.Once);
            _mwsClientMock.Verify(mws => mws.GetReport(It.IsAny <GetReportRequest>()), Times.Once);
        }