public void GetCrossRangePositions_CanGetGetTopRightCrossRangePositions() { /* * A B C D E * 1 * 2 * 3 . x x * 4 . x x * 5 * 6 . . * */ var C6D6 = ExcelMocker.CreateMockRange(3, 6, 4, 6); var A3A4 = ExcelMocker.CreateMockRange(1, 3, 1, 4); var result1 = SourceReaderHelper.GetCrossRangePositions(C6D6.Object, A3A4.Object); var result2 = SourceReaderHelper.GetCrossRangePositions(A3A4.Object, C6D6.Object); Assert.That(result1.Count, Is.EqualTo(4)); Assert.That(result1.Count(x => x.Row == 3 && x.Column == 3), Is.EqualTo(1)); Assert.That(result1.Count(x => x.Row == 3 && x.Column == 4), Is.EqualTo(1)); Assert.That(result1.Count(x => x.Row == 4 && x.Column == 3), Is.EqualTo(1)); Assert.That(result1.Count(x => x.Row == 4 && x.Column == 4), Is.EqualTo(1)); Assert.That(result2.Count, Is.EqualTo(4)); Assert.That(result2.Count(x => x.Row == 3 && x.Column == 3), Is.EqualTo(1)); Assert.That(result2.Count(x => x.Row == 3 && x.Column == 4), Is.EqualTo(1)); Assert.That(result2.Count(x => x.Row == 4 && x.Column == 3), Is.EqualTo(1)); Assert.That(result2.Count(x => x.Row == 4 && x.Column == 4), Is.EqualTo(1)); }
public void GetCrossRangePositions_WillFailIfSpansAreMoreThanOneCellWideBothWays() { var C1D1_Thin = ExcelMocker.CreateMockRange(3, 1, 4, 1); var A3A4_Thin = ExcelMocker.CreateMockRange(1, 3, 1, 4); var C1D2_Wide = ExcelMocker.CreateMockRange(3, 1, 4, 2); var A3B4_Wide = ExcelMocker.CreateMockRange(1, 3, 2, 4); Assert.Throws(typeof(Exception), () => { SourceReaderHelper.GetCrossRangePositions(C1D1_Thin.Object, A3B4_Wide.Object); }); Assert.Throws(typeof(Exception), () => { SourceReaderHelper.GetCrossRangePositions(A3A4_Thin.Object, C1D2_Wide.Object); }); Assert.Throws(typeof(Exception), () => { SourceReaderHelper.GetCrossRangePositions(C1D2_Wide.Object, C1D1_Thin.Object); }); Assert.Throws(typeof(Exception), () => { SourceReaderHelper.GetCrossRangePositions(A3B4_Wide.Object, A3A4_Thin.Object); }); }
public void CanGetTitlePositionForValuePosition() { // GetTitleValueForReservation /* * A B C D E * 1 . . * 2 * 3 . C3 D3 * 4 . C4 D4 * 5 * */ var C1D1 = ExcelMocker.CreateMockRange(3, 1, 4, 1); var A3A4 = ExcelMocker.CreateMockRange(1, 3, 1, 4); var title_for_C = SourceReaderHelper.GetTitlePositionForValuePosition( new CellPosition() { Column = 3, Row = 3 }, C1D1.Object); var title_for_D = SourceReaderHelper.GetTitlePositionForValuePosition( new CellPosition() { Column = 4, Row = 4 }, C1D1.Object); var title_for_3 = SourceReaderHelper.GetTitlePositionForValuePosition( new CellPosition() { Column = 4, Row = 3 }, A3A4.Object); var title_for_4 = SourceReaderHelper.GetTitlePositionForValuePosition( new CellPosition() { Column = 3, Row = 4 }, A3A4.Object); Assert.That(title_for_C.Row, Is.EqualTo(1)); Assert.That(title_for_C.Column, Is.EqualTo(3)); Assert.That(title_for_D.Row, Is.EqualTo(1)); Assert.That(title_for_D.Column, Is.EqualTo(4)); Assert.That(title_for_3.Row, Is.EqualTo(3)); Assert.That(title_for_3.Column, Is.EqualTo(1)); Assert.That(title_for_4.Row, Is.EqualTo(4)); Assert.That(title_for_4.Column, Is.EqualTo(1)); }
public void BackgroundWillChangeIfValueIsValidXLAddressOrNot() { var outside_helper = new Mock <IOutsideWindowHelper>(); var highlight_worker = new Mock <IHighlightWorker>(); var workbook = new Mock <IXLWorkbook>(); var worksheets = new Mock <IXLWorksheets>(); var worksheet1 = new Mock <IXLWorksheet>(); var range = ExcelMocker.CreateMockRange(1, 1, 1, 1); workbook.Setup(x => x.Worksheets).Returns(worksheets.Object); worksheets.Setup(x => x.GetEnumerator()).Returns((new List <IXLWorksheet>() { worksheet1.Object }).GetEnumerator()); workbook.Setup(x => x.Worksheet(It.IsAny <int>())).Returns(worksheet1.Object); worksheet1.Setup(x => x.Range(It.IsAny <string>())).Returns(range.Object); outside_helper.Setup(x => x.GetXLWorkbook(It.IsAny <string>())).Returns(workbook.Object); string selected_file_path = "h:\\henrik.xlsx"; outside_helper.Setup(x => x.ShowLoadFileDialog(It.IsAny <string>(), out selected_file_path)); outside_helper.Setup(x => x.GetXLWorkbook(It.IsAny <string>())).Returns(workbook.Object); var cell = ExcelMocker.CreateMockCell("", 1, 1); worksheet1.Setup(x => x.LastCellUsed()).Returns(cell.Object); worksheet1.Setup(x => x.Cell(It.IsAny <int>(), It.IsAny <int>())).Returns(cell.Object); var logic = new MainWindowLogic(outside_helper.Object, highlight_worker.Object); logic.SelectInputFile.Execute(null); // ElementIdSpan Assert.That(logic.ElementIdSpanText, Is.Empty); Assert.That(logic.ElementIdSpanBackground.Color.ToString(), Is.EqualTo(Colors.White.ToString())); logic.ElementIdSpanText = "A"; Assert.That(logic.ElementIdSpanBackground.Color.ToString(), Is.EqualTo(Colors.LightPink.ToString())); logic.ElementIdSpanText = "A1:C5"; Assert.That(logic.ElementIdSpanBackground.Color.ToString(), Is.EqualTo(Colors.LightGreen.ToString())); // BuyersNamesSpan Assert.That(logic.BuyersNamesSpanText, Is.Empty); Assert.That(logic.BuyersNamesSpanBackground.Color.ToString(), Is.EqualTo(Colors.White.ToString())); logic.BuyersNamesSpanText = "A"; Assert.That(logic.BuyersNamesSpanBackground.Color.ToString(), Is.EqualTo(Colors.LightPink.ToString())); logic.BuyersNamesSpanText = "A1:C5"; Assert.That(logic.BuyersNamesSpanBackground.Color.ToString(), Is.EqualTo(Colors.LightGreen.ToString())); // BlDescSpan Assert.That(logic.BlDescSpanText, Is.Empty); Assert.That(logic.BlDescSpanBackground.Color.ToString(), Is.EqualTo(Colors.White.ToString())); logic.BlDescSpanText = "A"; Assert.That(logic.BlDescSpanBackground.Color.ToString(), Is.EqualTo(Colors.LightPink.ToString())); logic.BlDescSpanText = "A1:C5"; Assert.That(logic.BlDescSpanBackground.Color.ToString(), Is.EqualTo(Colors.LightGreen.ToString())); // BlColorSpan Assert.That(logic.BlColorSpanText, Is.Empty); Assert.That(logic.BlColorSpanBackground.Color.ToString(), Is.EqualTo(Colors.White.ToString())); logic.BlColorSpanText = "A"; Assert.That(logic.BlColorSpanBackground.Color.ToString(), Is.EqualTo(Colors.LightPink.ToString())); logic.BlColorSpanText = "A1:C5"; Assert.That(logic.BlColorSpanBackground.Color.ToString(), Is.EqualTo(Colors.LightGreen.ToString())); // TlgColorSpan Assert.That(logic.TlgColorSpanText, Is.Empty); Assert.That(logic.TlgColorSpanBackground.Color.ToString(), Is.EqualTo(Colors.White.ToString())); logic.TlgColorSpanText = "A"; Assert.That(logic.TlgColorSpanBackground.Color.ToString(), Is.EqualTo(Colors.LightPink.ToString())); logic.TlgColorSpanText = "A1:C5"; Assert.That(logic.TlgColorSpanBackground.Color.ToString(), Is.EqualTo(Colors.LightGreen.ToString())); }