public void SourceReader_WillIgnoreNegativeNumbers() { /* * * A B C D * 1 Henrik Alice Simpson * 2 222222 100 50 * 3 333333 0 100 200 * 4 444444 150 -10 300 * */ var parameters = new InputParameters(); parameters.ElementIdSpan = "A2A4"; parameters.BuyersSpan = "B1D1"; // Reusing columns to simplify test parameters.BrickLinkDescriptionSpan = "A2A4"; parameters.BrickLinkIdSpan = "A2A4"; parameters.BrickLinkColorSpan = "A2A4"; parameters.TlgColorSpan = "A2A4"; var sheet = new Mock <IXLWorksheet>(); ExcelMocker.AddMockRange(sheet, "A2A4"); ExcelMocker.AddMockRange(sheet, "B1D1"); ExcelMocker.CreateMockCell("Henrik", 1, 2, sheet); ExcelMocker.CreateMockCell("Alice", 1, 3, sheet); ExcelMocker.CreateMockCell("Simpson", 1, 4, sheet); ExcelMocker.CreateMockCell("222222", 2, 1, sheet); ExcelMocker.CreateMockCell("333333", 3, 1, sheet); ExcelMocker.CreateMockCell("444444", 4, 1, sheet); ExcelMocker.CreateMockCell("100", 2, 2, sheet); ExcelMocker.CreateMockCell("0", 3, 2, sheet); ExcelMocker.CreateMockCell("150", 4, 2, sheet); ExcelMocker.CreateMockCell("50", 2, 3, sheet); ExcelMocker.CreateMockCell("100", 3, 3, sheet); ExcelMocker.CreateMockCell("-10", 4, 3, sheet); ExcelMocker.CreateMockCell("", 2, 4, sheet); ExcelMocker.CreateMockCell("200", 3, 4, sheet); ExcelMocker.CreateMockCell("300", 4, 4, sheet); var reader = new SourceReader(sheet.Object, parameters); var result = reader.GetReservations(); Assert.That(result.Count, Is.EqualTo(6)); Assert.True(result.Any(x => x.Element.ElementID == "222222" && x.Buyer.Name == "Henrik" && x.Amount == 100)); Assert.True(result.Any(x => x.Element.ElementID == "444444" && x.Buyer.Name == "Henrik" && x.Amount == 150)); Assert.True(result.Any(x => x.Element.ElementID == "222222" && x.Buyer.Name == "Alice" && x.Amount == 50)); Assert.True(result.Any(x => x.Element.ElementID == "333333" && x.Buyer.Name == "Alice" && x.Amount == 100)); Assert.True(result.Any(x => x.Element.ElementID == "333333" && x.Buyer.Name == "Simpson" && x.Amount == 200)); Assert.True(result.Any(x => x.Element.ElementID == "444444" && x.Buyer.Name == "Simpson" && x.Amount == 300)); }
public void SourceReader_CanGetBuyersWithAReservations() { /* * _ Henrik Alice Simpson * 111 1 0 1 * 222 1 - 0 * 333 0 */ var parameters = new InputParameters(); parameters.ElementIdSpan = "A2A4"; parameters.BuyersSpan = "B1D1"; // Reusing columns to simplify test parameters.BrickLinkDescriptionSpan = "A2A4"; parameters.BrickLinkIdSpan = "A2A4"; parameters.BrickLinkColorSpan = "A2A4"; parameters.TlgColorSpan = "A2A4"; var sheet = new Mock <IXLWorksheet>(); ExcelMocker.AddMockRange(sheet, "A2A4"); ExcelMocker.AddMockRange(sheet, "B1D1"); ExcelMocker.CreateMockCell("Henrik", 1, 2, sheet); ExcelMocker.CreateMockCell("Alice", 1, 3, sheet); ExcelMocker.CreateMockCell("Simpson", 1, 4, sheet); ExcelMocker.CreateMockCell("111", 2, 1, sheet); ExcelMocker.CreateMockCell("222", 3, 1, sheet); ExcelMocker.CreateMockCell("333", 4, 1, sheet); ExcelMocker.CreateMockCell("1", 2, 2, sheet); ExcelMocker.CreateMockCell("1", 3, 2, sheet); ExcelMocker.CreateMockCell("", 4, 2, sheet); ExcelMocker.CreateMockCell("0", 2, 3, sheet); ExcelMocker.CreateMockCell("-", 3, 3, sheet); ExcelMocker.CreateMockCell("", 4, 3, sheet); ExcelMocker.CreateMockCell("1", 2, 4, sheet); ExcelMocker.CreateMockCell("0", 3, 4, sheet); ExcelMocker.CreateMockCell("0", 4, 4, sheet); var reader = new SourceReader(sheet.Object, parameters); var result = reader.GetBuyers(); Assert.That(result.Count, Is.EqualTo(2)); Assert.That(result.Count(x => x.Name == "Henrik"), Is.EqualTo(1)); Assert.That(result.Count(x => x.Name == "Simpson"), Is.EqualTo(1)); Assert.That(result.Count(x => x.Id == 100), Is.EqualTo(1)); Assert.That(result.Count(x => x.Id == 101), Is.EqualTo(1)); }
public void CanGetValuesForTitlePosition_Pivoted() { /* * A B C D * 1 BB CC * 2 22 B2 C2 * 3 33 B3 C3 * 4 44 B4 C4 * 5 */ var title_pos_1 = new CellPosition() { Row = 1, Column = 2 }; var title_pos_2 = new CellPosition() { Row = 2, Column = 1 }; var values_start_pos = new CellPosition() { Row = 2, Column = 2 }; var values_end_pos = new CellPosition() { Row = 4, Column = 3 }; var work_sheet = new Mock <IXLWorksheet>(); ExcelMocker.CreateMockCell("B2", 2, 2, work_sheet); ExcelMocker.CreateMockCell("B3", 3, 2, work_sheet); ExcelMocker.CreateMockCell("B4", 4, 2, work_sheet); ExcelMocker.CreateMockCell("C2", 2, 3, work_sheet); ExcelMocker.CreateMockCell("C3", 3, 3, work_sheet); ExcelMocker.CreateMockCell("C4", 4, 3, work_sheet); var result1 = SourceReaderHelper.GetValuesForTitlePosition(title_pos_1, values_start_pos, values_end_pos, work_sheet.Object); var result2 = SourceReaderHelper.GetValuesForTitlePosition(title_pos_2, values_start_pos, values_end_pos, work_sheet.Object); Assert.That(result1.Count, Is.EqualTo(3)); Assert.That(result1.Count(x => x == "B2"), Is.EqualTo(1)); Assert.That(result1.Count(x => x == "B3"), Is.EqualTo(1)); Assert.That(result1.Count(x => x == "B4"), Is.EqualTo(1)); Assert.That(result2.Count, Is.EqualTo(2)); Assert.That(result2.Count(x => x == "B2"), Is.EqualTo(1)); Assert.That(result2.Count(x => x == "C2"), Is.EqualTo(1)); }
public void SourceReader_BuyerIdsWillFollowAlphabetically() { /* * _ Henrik Alice Simpson * 111 1 0 1 * 222 1 1 0 * 222 0 1 0 */ var parameters = new InputParameters(); parameters.ElementIdSpan = "A2A4"; parameters.BuyersSpan = "B1D1"; var sheet = new Mock <IXLWorksheet>(); ExcelMocker.AddMockRange(sheet, "A2A4"); ExcelMocker.AddMockRange(sheet, "B1D1"); ExcelMocker.CreateMockCell("Henrik", 1, 2, sheet); ExcelMocker.CreateMockCell("Alice", 1, 3, sheet); ExcelMocker.CreateMockCell("Simpson", 1, 4, sheet); ExcelMocker.CreateMockCell("1", 2, 2, sheet); ExcelMocker.CreateMockCell("0", 2, 3, sheet); ExcelMocker.CreateMockCell("1", 2, 4, sheet); ExcelMocker.CreateMockCell("1", 3, 2, sheet); ExcelMocker.CreateMockCell("1", 3, 3, sheet); ExcelMocker.CreateMockCell("0", 3, 4, sheet); ExcelMocker.CreateMockCell("0", 4, 2, sheet); ExcelMocker.CreateMockCell("1", 4, 3, sheet); ExcelMocker.CreateMockCell("0", 4, 4, sheet); var reader = new SourceReader(sheet.Object, parameters); var result = reader.GetBuyers(); Assert.That(result.Count, Is.EqualTo(3)); Assert.That(result[0].Name, Is.EqualTo("Alice")); Assert.That(result[1].Name, Is.EqualTo("Henrik")); Assert.That(result[2].Name, Is.EqualTo("Simpson")); Assert.That(result[0].Id, Is.EqualTo(100)); Assert.That(result[1].Id, Is.EqualTo(101)); Assert.That(result[2].Id, Is.EqualTo(102)); }
public void SourceReader_WillIgnoreElementsNotOrdered() { /* * ElementID BL Desc BL Id BL Color TLG Color Henrik Alice Simpson * 111 Brick1 BB1 Red Real Read 1 1 1 * 222 Brick2 BB2 Blue Bright Blue 0 0 0 * 333 Brick3 BB3 Green Dark Green 1 1 1 */ var parameters = new InputParameters(); parameters.ElementIdSpan = "A2A4"; parameters.BrickLinkDescriptionSpan = "B2B4"; parameters.BrickLinkIdSpan = "C2C4"; parameters.BrickLinkColorSpan = "D2D4"; parameters.TlgColorSpan = "E2E4"; parameters.BuyersSpan = "F1H1"; var sheet = new Mock <IXLWorksheet>(); ExcelMocker.AddMockRange(sheet, "A2A4"); ExcelMocker.AddMockRange(sheet, "B2B4"); ExcelMocker.AddMockRange(sheet, "C2C4"); ExcelMocker.AddMockRange(sheet, "D2D4"); ExcelMocker.AddMockRange(sheet, "E2E4"); ExcelMocker.AddMockRange(sheet, "F1H1"); ExcelMocker.CreateMockCell("111", 2, 1, sheet); ExcelMocker.CreateMockCell("222", 3, 1, sheet); ExcelMocker.CreateMockCell("333", 4, 1, sheet); ExcelMocker.CreateMockCell("Brick1", 2, 2, sheet); ExcelMocker.CreateMockCell("Brick2", 3, 2, sheet); ExcelMocker.CreateMockCell("Brick3", 4, 2, sheet); ExcelMocker.CreateMockCell("BB1", 2, 3, sheet); ExcelMocker.CreateMockCell("BB2", 3, 3, sheet); ExcelMocker.CreateMockCell("BB3", 4, 3, sheet); ExcelMocker.CreateMockCell("Red", 2, 4, sheet); ExcelMocker.CreateMockCell("Blue", 3, 4, sheet); ExcelMocker.CreateMockCell("Green", 4, 4, sheet); ExcelMocker.CreateMockCell("Real Red", 2, 5, sheet); ExcelMocker.CreateMockCell("Bright Blue", 3, 5, sheet); ExcelMocker.CreateMockCell("Dark Green", 4, 5, sheet); ExcelMocker.CreateMockCell("Henrik", 1, 6, sheet); ExcelMocker.CreateMockCell("Alice", 1, 7, sheet); ExcelMocker.CreateMockCell("Simpson", 1, 8, sheet); ExcelMocker.CreateMockCell("1", 2, 6, sheet); ExcelMocker.CreateMockCell("1", 2, 7, sheet); ExcelMocker.CreateMockCell("1", 2, 8, sheet); ExcelMocker.CreateMockCell("0", 3, 6, sheet); ExcelMocker.CreateMockCell("", 3, 7, sheet); ExcelMocker.CreateMockCell("-1", 3, 8, sheet); ExcelMocker.CreateMockCell("1", 4, 6, sheet); ExcelMocker.CreateMockCell("1", 4, 7, sheet); ExcelMocker.CreateMockCell("1", 4, 8, sheet); var reader = new SourceReader(sheet.Object, parameters); var result = reader.GetElements(); Assert.That(result.Count, Is.EqualTo(2)); Assert.That(result[0].ElementID, Is.EqualTo("111")); Assert.That(result[0].BricklinkDescription, Is.EqualTo("Brick1")); Assert.That(result[0].BricklinkId, Is.EqualTo("BB1")); Assert.That(result[0].BricklinkColor, Is.EqualTo("Red")); Assert.That(result[0].MaterialColor, Is.EqualTo("Real Red")); Assert.That(result[1].ElementID, Is.EqualTo("333")); Assert.That(result[1].BricklinkDescription, Is.EqualTo("Brick3")); Assert.That(result[1].BricklinkId, Is.EqualTo("BB3")); Assert.That(result[1].BricklinkColor, Is.EqualTo("Green")); Assert.That(result[1].MaterialColor, Is.EqualTo("Dark Green")); }
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())); }