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_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_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); }
static SectionCellLocatorTest() { ConstructorArgumentValidationTestScenarios .RemoveAllScenarios() .AddScenario(() => new ConstructorArgumentValidationTestScenario <SectionCellLocator> { Name = "constructor should throw ArgumentNullException when parameter 'cellId' is null scenario", ConstructionFunc = () => { var referenceObject = A.Dummy <SectionCellLocator>(); var result = new SectionCellLocator( null, referenceObject.SlotId, referenceObject.SlotSelectionStrategy); return(result); }, ExpectedExceptionType = typeof(ArgumentNullException), ExpectedExceptionMessageContains = new[] { "cellId", }, }) .AddScenario(() => new ConstructorArgumentValidationTestScenario <SectionCellLocator> { Name = "constructor should throw ArgumentException when parameter 'cellId' is white space scenario", ConstructionFunc = () => { var referenceObject = A.Dummy <SectionCellLocator>(); var result = new SectionCellLocator( Invariant($" {Environment.NewLine} "), referenceObject.SlotId, referenceObject.SlotSelectionStrategy); return(result); }, ExpectedExceptionType = typeof(ArgumentException), ExpectedExceptionMessageContains = new[] { "cellId", "white space", }, }) .AddScenario(() => new ConstructorArgumentValidationTestScenario <SectionCellLocator> { Name = "constructor should throw ArgumentOutOfRangeException when parameter 'slotSelectionStrategy' is SlotSelectionStrategy.Unknown", ConstructionFunc = () => { var referenceObject = A.Dummy <SectionCellLocator>(); var result = new SectionCellLocator( referenceObject.CellId, referenceObject.SlotId, SlotSelectionStrategy.Unknown); return(result); }, ExpectedExceptionType = typeof(ArgumentOutOfRangeException), ExpectedExceptionMessageContains = new[] { "slotSelectionStrategy", "Unknown", }, }); }
public static void ToString___Should_return_string_representation_of_exception___When_cellLocator_is_not_null() { // Arrange var cellLocator = new SectionCellLocator("cell-id"); var systemUnderTest = new CellValueMissingException("my-message", new Exception("my-inner-exception"), cellLocator); var expected = Invariant($"The cell that was found using the following locator does not yet have a value: OBeautifulCode.DataStructure.SectionCellLocator: CellId = cell-id, SlotId = <null>, SlotSelectionStrategy = ThrowIfSlotIdNotSpecified.{Environment.NewLine}OBeautifulCode.DataStructure.CellValueMissingException: my-message ---> System.Exception: my-inner-exception{Environment.NewLine} --- End of inner exception stack trace ---"); // Act var actual = systemUnderTest.ToString(); // 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_sectionCellLocator___Should_return_cell___When_cell_is_not_slotted() { // Arrange var report = A.Dummy <Report>(); var section = report.Sections.First(); var allCells = section.TreeTable.GetAllCells(); var expected = section.TreeTable.GetAllCells().First(_ => _ is INotSlottedCell); var currentCell = allCells.First(_ => !_.Equals(expected)); var sectionCellLocator = new SectionCellLocator(expected.Id); 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_cell_with_specified_id_is_not_found() { // Arrange var report = A.Dummy <Report>(); var section = report.Sections.First(); var currentCell = section.TreeTable.GetAllCells().First(); var sectionCellLocator = new SectionCellLocator(A.Dummy <string>()); var systemUnderTest = new ReportCache(report); var expectedReportCellLocator = new ReportCellLocator(section.Id, sectionCellLocator.CellId); // Act var actual = Record.Exception(() => systemUnderTest.GetCell(sectionCellLocator, currentCell)); // Assert actual.AsTest().Must().BeOfType <CellNotFoundException>(); actual.Message.AsTest().Must().ContainString(Invariant($"There is no cell with id '{sectionCellLocator.CellId}' in section '{section.Id}'.")); ((CellNotFoundException)actual).CellLocator.AsTest().Must().BeEqualTo((CellLocatorBase)expectedReportCellLocator); }