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_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_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 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);
        }