public static void GetCell_sectionCellLocator___Should_throw_CellNotFoundException___When_addressing_slotted_cell_and_SlotId_not_specified_and_SlotSelectionStrategy_is_ThrowIfSlotIdNotSpecified()
        {
            // Arrange
            var report = A.Dummy <Report>().Whose(_ => _.Sections.Any(s => s.TreeTable.GetAllCells().Any(c => c is ISlottedCell)));

            var section = report.Sections.First(_ => _.TreeTable.GetAllCells().Any(c => c is ISlottedCell));

            var allCells = section.TreeTable.GetAllCells();

            var cell = allCells.First(_ => _ is ISlottedCell);

            var currentCell = allCells.First(_ => !_.Equals(cell));

            var sectionCellLocator = new SectionCellLocator(cell.Id, null, SlotSelectionStrategy.ThrowIfSlotIdNotSpecified);

            var expectedReportCellLocator = new ReportCellLocator(section.Id, sectionCellLocator.CellId, sectionCellLocator.SlotId);

            var systemUnderTest = new ReportCache(report);

            // Act
            var actual = Record.Exception(() => systemUnderTest.GetCell(sectionCellLocator, currentCell));

            // Assert
            actual.AsTest().Must().BeOfType <CellNotFoundException>();
            actual.Message.AsTest().Must().ContainString(Invariant($"The operation addresses an {nameof(ISlottedCell)} (and not a slot within that cell) and {nameof(SlotSelectionStrategy)} is {nameof(SlotSelectionStrategy.ThrowIfSlotIdNotSpecified)}."));
            ((CellNotFoundException)actual).CellLocator.AsTest().Must().BeEqualTo((CellLocatorBase)expectedReportCellLocator);
        }
        public static void GetCell_sectionCellLocator___Should_return_cell_in_specified_slot___When_addressing_slot_within_slotted_cell()
        {
            // Arrange
            var report = A.Dummy <Report>().Whose(_ => _.Sections.Any(s => s.TreeTable.GetAllCells().OfType <ISlottedCell>().Any(c => c.SlotIdToCellMap.Count > 1)));

            var section = report.Sections.First(_ => _.TreeTable.GetAllCells().Any(c => c is ISlottedCell));

            var allCells = section.TreeTable.GetAllCells();

            var cell = allCells.OfType <ISlottedCell>().First(_ => _.SlotIdToCellMap.Count > 1);

            var currentCell = allCells.First(_ => !_.Equals(cell));

            var slotId = cell.SlotIdToCellMap.First(_ => _.Key != cell.DefaultSlotId).Key;

            var expected = (ICell)cell.SlotIdToCellMap[slotId];

            var sectionCellLocator = new SectionCellLocator(cell.Id, slotId, SlotSelectionStrategy.ThrowIfSlotIdNotSpecified);

            var systemUnderTest = new ReportCache(report);

            // Act
            var actual = systemUnderTest.GetCell(sectionCellLocator, currentCell);

            // Assert
            actual.AsTest().Must().BeSameReferenceAs(expected);
        }
        public static void GetCell_sectionCellLocator___Should_throw_CellNotFoundException___When_addressing_slotted_cell_but_there_is_no_slot_having_slotId()
        {
            // Arrange
            var report = A.Dummy <Report>().Whose(_ => _.Sections.Any(s => s.TreeTable.GetAllCells().Any(c => c is ISlottedCell)));

            var section = report.Sections.First(_ => _.TreeTable.GetAllCells().Any(c => c is ISlottedCell));

            var allCells = section.TreeTable.GetAllCells();

            var cell = allCells.First(_ => _ is ISlottedCell);

            var currentCell = allCells.First(_ => !_.Equals(cell));

            var sectionCellLocator = new SectionCellLocator(cell.Id, A.Dummy <string>());

            var expectedReportCellLocator = new ReportCellLocator(section.Id, sectionCellLocator.CellId, sectionCellLocator.SlotId);

            var systemUnderTest = new ReportCache(report);

            // Act
            var actual = Record.Exception(() => systemUnderTest.GetCell(sectionCellLocator, currentCell));

            // Assert
            actual.AsTest().Must().BeOfType <CellNotFoundException>();
            actual.Message.AsTest().Must().ContainString(Invariant($"Slot id '{sectionCellLocator.SlotId}' was specified, but the addressed cell '{cell.Id}' in section '{section.Id}' does not contain a slot having that id."));
            ((CellNotFoundException)actual).CellLocator.AsTest().Must().BeEqualTo((CellLocatorBase)expectedReportCellLocator);
        }
        public static void GetCell_sectionCellLocator___Should_throw_ArgumentNullException___When_parameter_currentCell_is_null()
        {
            // Arrange
            var systemUnderTest = new ReportCache(A.Dummy <Report>());

            // Act
            var actual = Record.Exception(() => systemUnderTest.GetCell(A.Dummy <SectionCellLocator>(), null));

            // Assert
            actual.AsTest().Must().BeOfType <ArgumentNullException>();
            actual.Message.AsTest().Must().ContainString("currentCell");
        }
        public static void AvailabilityCheckCells___Should_return_all_availability_check_cells___When_getting()
        {
            // Arrange
            var report = A.Dummy <Report>();

            var systemUnderTest = new ReportCache(report);

            IReadOnlyCollection <IAvailabilityCheckCell> expected = report.Sections.SelectMany(_ => _.TreeTable.GetAllCells()).OfType <IAvailabilityCheckCell>().ToList();

            // Act
            var actual = systemUnderTest.AvailabilityCheckCells;

            // Assert
            actual.AsTest().Must().BeEqualTo(expected);
        }
        public static void GetCell_sectionCellLocator___Should_throw_ArgumentNullException___When_currentCell_is_not_a_cell_in_the_report()
        {
            // Arrange
            var report = A.Dummy <Report>();

            var systemUnderTest = new ReportCache(report);

            var sectionCellLocator = new SectionCellLocator(report.Sections.First().TreeTable.GetAllCells().First().Id);

            // Act
            var actual = Record.Exception(() => systemUnderTest.GetCell(sectionCellLocator, A.Dummy <ICell>()));

            // Assert
            actual.AsTest().Must().BeOfType <CellNotFoundException>();
            actual.Message.AsTest().Must().ContainString("currentCell is not a cell in the report.");
            ((CellNotFoundException)actual).CellLocator.AsTest().Must().BeEqualTo((CellLocatorBase)sectionCellLocator);
        }
        public static void GetCell_reportCellLocator___Should_throw_CellNotFoundException___When_section_is_not_found()
        {
            // Arrange
            var report = A.Dummy <Report>();

            var reportCellLocator = new ReportCellLocator(A.Dummy <string>(), report.Sections.First().TreeTable.GetAllCells().First().Id);

            var systemUnderTest = new ReportCache(report);

            // Act
            var actual = Record.Exception(() => systemUnderTest.GetCell(reportCellLocator));

            // Assert
            actual.AsTest().Must().BeOfType <CellNotFoundException>();
            actual.Message.AsTest().Must().ContainString(Invariant($"There is no section with id '{reportCellLocator.SectionId}'."));
            ((CellNotFoundException)actual).CellLocator.AsTest().Must().BeEqualTo((CellLocatorBase)reportCellLocator);
        }
        public static void GetCell_reportCellLocator___Should_return_cell___When_cell_is_not_slotted()
        {
            // Arrange
            var report = A.Dummy <Report>();

            var section = report.Sections.First();

            var expected = section.TreeTable.GetAllCells().First(_ => _ is INotSlottedCell);

            var reportCellLocator = new ReportCellLocator(section.Id, expected.Id);

            var systemUnderTest = new ReportCache(report);

            // Act
            var actual = systemUnderTest.GetCell(reportCellLocator);

            // Assert
            actual.AsTest().Must().BeSameReferenceAs(expected);
        }
        public static void GetCell_reportCellLocator___Should_throw_CellNotFoundException___When_cell_with_specified_id_is_not_found()
        {
            // Arrange
            var report = A.Dummy <Report>();

            var section = report.Sections.First();

            var reportCellLocator = new ReportCellLocator(section.Id, A.Dummy <string>());

            var systemUnderTest = new ReportCache(report);

            // Act
            var actual = Record.Exception(() => systemUnderTest.GetCell(reportCellLocator));

            // Assert
            actual.AsTest().Must().BeOfType <CellNotFoundException>();
            actual.Message.AsTest().Must().ContainString(Invariant($"There is no cell with id '{reportCellLocator.CellId}' in section '{section.Id}'."));
            ((CellNotFoundException)actual).CellLocator.AsTest().Must().BeEqualTo((CellLocatorBase)reportCellLocator);
        }
        public static void GetCell_reportCellLocator___Should_return_cell_in_default_slot___When_addressing_slotted_cell_and_SlotSelectionStrategy_is_DefaultSlot()
        {
            // Arrange
            var report = A.Dummy <Report>().Whose(_ => _.Sections.Any(s => s.TreeTable.GetAllCells().Any(c => c is ISlottedCell)));

            var section = report.Sections.First(_ => _.TreeTable.GetAllCells().Any(c => c is ISlottedCell));

            var cell = section.TreeTable.GetAllCells().OfType <ISlottedCell>().First();

            var expected = (ICell)cell.SlotIdToCellMap[cell.DefaultSlotId];

            var reportCellLocator = new ReportCellLocator(section.Id, cell.Id, null, SlotSelectionStrategy.DefaultSlot);

            var systemUnderTest = new ReportCache(report);

            // Act
            var actual = systemUnderTest.GetCell(reportCellLocator);

            // Assert
            actual.AsTest().Must().BeSameReferenceAs(expected);
        }
        public static void GetCell_reportCellLocator___Should_throw_CellNotFoundException___When_slotId_specified_for_cell_that_is_not_slotted()
        {
            // Arrange
            var report = A.Dummy <Report>();

            var section = report.Sections.First();

            var cell = section.TreeTable.GetAllCells().First(_ => _ is INotSlottedCell);

            var reportCellLocator = new ReportCellLocator(section.Id, cell.Id, A.Dummy <string>());

            var systemUnderTest = new ReportCache(report);

            // Act
            var actual = Record.Exception(() => systemUnderTest.GetCell(reportCellLocator));

            // Assert
            actual.AsTest().Must().BeOfType <CellNotFoundException>();
            actual.Message.AsTest().Must().ContainString(Invariant($"Slot id '{reportCellLocator.SlotId}' was specified, but the addressed cell '{cell.Id}' in section '{section.Id}' is not a slotted cell"));
            ((CellNotFoundException)actual).CellLocator.AsTest().Must().BeEqualTo((CellLocatorBase)reportCellLocator);
        }
Пример #12
0
 public void SetUp()
 {
     cache = new ReportCache <PopularServer>(cacheTime);
 }
Пример #13
0
        public void waitForComplete(string ReportRequestId, string ReportType, Dictionary <string, string> parms, int timeoutMS, Func <ReportCache, string> callWhenDone, bool usePrior)
        {
            if (timeoutMS < 10000)
            {
                timeoutMS = 10000;
            }
            string GeneratedReportId = "";

            DateTime startTime = DateTime.Now;
            long     genId     = 0;

            while (!long.TryParse(GeneratedReportId, out genId) && (DateTime.Now - startTime).TotalMilliseconds < timeoutMS)
            {
                Log.Info(_acct.AmazonAccountId, $"Waiting for report requestid {ReportRequestId}");

                Thread.Sleep(timeoutMS / 10);
                GeneratedReportId = getCompletedReportId(ReportRequestId, ReportType, false);
                if (GeneratedReportId == "_CANCELLED_")
                {
                    Log.Warn(_acct.AmazonAccountId, $"Report request {ReportRequestId} Cancelled");
                    GeneratedReportId = "";
                    break;
                }
            }



            if (!long.TryParse(GeneratedReportId, out genId) && usePrior)
            {
                Log.Warn(_acct.AmazonAccountId, "Did not get a report back, getting prior version if possible");

                GeneratedReportId = getCompletedReportId(ReportRequestId, ReportType, true);
                if (String.IsNullOrEmpty(GeneratedReportId))
                {
                    Log.Warn(_acct.AmazonAccountId, $"Never got a completed report back for {ReportType} id= {ReportRequestId}");
                    return;
                }
            }

            if (long.TryParse(GeneratedReportId, out genId))
            {
                Log.Info(_acct.AmazonAccountId, "Requesting Completed Report " + GeneratedReportId);

                IDictionary <string, string> r1 = new Dictionary <string, String>();

                r1["Action"]        = "GetReport";
                r1["SellerId"]      = _acct.SellerId;
                r1["MarketplaceId"] = _acct.MarketplaceId;


                r1["ReportId"] = GeneratedReportId;
                r1["Version"]  = "2009-01-01";

                String serviceURL = "https://mws.amazonservices.com";

                AMZNWebResponse wr = new AMZNWebResponse(_acct);
                string          s  = wr.getResponse(serviceURL, r1, false);
                Log.Info(_acct.AmazonAccountId, "Completed Getting Report " + GeneratedReportId + ", calling processing function");

                var rc = ReportCache.fromTSV(ReportType, s, parms, _acct);


                callWhenDone(rc);
            }
        }