Exemplo n.º 1
0
        public void LookupFromOtherSheetByProductIdTest_SheetAAAWithA123_Gid888__SheetBBBWithB123_Gid999()
        {
            var excelHandler = Substitute.For <IExcelHandler>();

            excelHandler.GetAllColumnTitle(1).Returns(new Dictionary <int, string> {
                { 1, "AAA" }, { 2, "BBB" }, { 3, "CCC" }
            });
            excelHandler.GetSpecifiedColumnAllCellValue(1, "商品主號")
            .Returns(new Dictionary <int, string> {
                { 2, "A123" }, { 3, "B123" }
            });
            excelHandler.ExistSheet("AAA").Returns(true);
            excelHandler.ExistSheet("BBB").Returns(true);
            excelHandler.ExistSheet("CCC").Returns(false);
            excelHandler.GetSpecifiedColumnAllCellValue("AAA", "商品主號").Returns(new Dictionary <int, string> {
                { 2, "A123" }
            });
            excelHandler.GetSpecifiedColumnAllCellValue("BBB", "商品主號").Returns(new Dictionary <int, string> {
                { 2, "B123" }
            });
            excelHandler.GetSpecifiedCellValue("AAA", 2, 1).Returns("888");
            excelHandler.GetSpecifiedCellValue("BBB", 2, 1).Returns("999");

            var target = new WorkSheetHandler(excelHandler);

            target.LookupFromOtherSheetByProductId();

            Received.InOrder(() =>
            {
                excelHandler.Received(1).SetCellValue(1, 1, 2, ",888");
                excelHandler.Received(1).SetCellValue(1, 2, 3, ",999");
            });
        }
Exemplo n.º 2
0
        public void AddConcatenateAheadColumnTest()
        {
            var excelHandler = Substitute.For <IExcelHandler>();
            var target       = new WorkSheetHandler(excelHandler);

            target.AddConcatenateAheadColumn(0, 0, 0);
            Received.InOrder(() =>
            {
                excelHandler.Received(1).AddConcatenateAheadColumn(0, 0, 0);
                excelHandler.Received(1).Save();
            });
        }
Exemplo n.º 3
0
        public void GroupTenItemsTest_TwoGroups()
        {
            var excelHandler = Substitute.For <IExcelHandler>();

            excelHandler.AddWorksheet("完整", "活動設定").Returns(2);
            excelHandler.GetSpecifiedColumnAllCellValue("完整", "pid").Returns(new Dictionary <int, string> {
                { 2, "777" }, { 3, "888" }, { 4, "999" }
            });
            excelHandler.GetSpecifiedColumnAllCellValue("完整", "活動名稱").Returns(new Dictionary <int, string> {
                { 2, "GOGOGOA" }, { 3, "GOGOGOA" }, { 4, "GOGOGOB" }
            });
            excelHandler.GetSpecifiedColumnAllCellValue("完整", "rank").Returns(new Dictionary <int, string> {
                { 2, "111" }, { 3, "111" }, { 4, "222" }
            });
            excelHandler.GetSpecifiedColumnAllCellValue("完整", "商品名稱").Returns(new Dictionary <int, string> {
                { 2, "ProductA" }, { 3, "ProductB" }, { 4, "ProductC" }
            });

            excelHandler.GetSpecifiedCellValue(2, 3, 2).Returns("GOGOGOA");
            excelHandler.GetSpecifiedCellValue(2, 3, 3).Returns("GOGOGOA");
            excelHandler.GetSpecifiedCellValue(2, 3, 4).Returns("GOGOGOB");
            excelHandler.GetSpecifiedCellValue(2, 4, 2).Returns("777");
            excelHandler.GetSpecifiedCellValue(2, 4, 3).Returns("888");
            excelHandler.GetSpecifiedCellValue(2, 4, 4).Returns("999");
            excelHandler.GetSpecifiedCellValue(2, 5, 2).Returns((string)null);
            excelHandler.GetSpecifiedCellValue(2, 5, 3).Returns("777,888");

            var target = new WorkSheetHandler(excelHandler);

            target.GroupTenItemsViaPid("完整", "活動設定");

            excelHandler.Received().SetCellValue(2, 1, 2, "ProductA");
            excelHandler.Received().SetCellValue(2, 1, 3, "ProductB");
            excelHandler.Received().SetCellValue(2, 1, 4, "ProductC");
            excelHandler.Received().SetCellValue(2, 2, 2, "111");
            excelHandler.Received().SetCellValue(2, 2, 3, "111");
            excelHandler.Received().SetCellValue(2, 2, 4, "222");
            excelHandler.Received().SetCellValue(2, 3, 2, "GOGOGOA");
            excelHandler.Received().SetCellValue(2, 3, 3, "GOGOGOA");
            excelHandler.Received().SetCellValue(2, 3, 4, "GOGOGOB");
            excelHandler.Received().SetCellValue(2, 4, 2, "777");
            excelHandler.Received().SetCellValue(2, 4, 3, "888");
            excelHandler.Received().SetCellValue(2, 4, 4, "999");
            excelHandler.Received().SetCellValue(2, 5, 3, "777,888");
            excelHandler.Received().SetCellValue(2, 5, 4, "999");
        }
Exemplo n.º 4
0
        public void GenerateColumnsViaSheetNameTest_2Sheets()
        {
            var excelHandler = Substitute.For <IExcelHandler>();

            excelHandler.GetWorkSheetNamesExceptFirst().Returns(new List <string> {
                "AAA", "BBB"
            });
            var target = new WorkSheetHandler(excelHandler);

            target.GenerateColumnsViaSheetName();

            Received.InOrder(() =>
            {
                excelHandler.Received(1).CreateColumnAhead("BBB");
                excelHandler.Received(1).CreateColumnAhead("AAA");
            });
        }
Exemplo n.º 5
0
        public void GroupTenItemsTest_OneBigGroup()
        {
            var excelHandler = Substitute.For <IExcelHandler>();

            excelHandler.AddWorksheet("完整", "活動設定").Returns(2);
            excelHandler.GetSpecifiedColumnAllCellValue("完整", "pid").Returns(new Dictionary <int, string> {
                { 2, "1" }, { 3, "2" }, { 4, "3" }, { 5, "4" }, { 6, "5" }, { 7, "6" }, { 8, "7" }, { 9, "8" }, { 10, "9" }, { 11, "10" }, { 12, "11" }
            });
            excelHandler.GetSpecifiedColumnAllCellValue("完整", "活動名稱").Returns(new Dictionary <int, string> {
                { 2, "GOGOGOA" }, { 3, "GOGOGOA" }, { 4, "GOGOGOA" }, { 5, "GOGOGOA" }, { 6, "GOGOGOA" }, { 7, "GOGOGOA" }, { 8, "GOGOGOA" }, { 9, "GOGOGOA" }, { 10, "GOGOGOA" }, { 11, "GOGOGOA" }, { 12, "GOGOGOA" }
            });
            excelHandler.GetSpecifiedColumnAllCellValue("完整", "rank").Returns(new Dictionary <int, string> {
                { 2, "111" }, { 3, "111" }, { 4, "111" }, { 5, "111" }, { 6, "111" }, { 7, "111" }, { 8, "111" }, { 9, "111" }, { 10, "111" }, { 11, "111" }, { 12, "111" }
            });
            excelHandler.GetSpecifiedColumnAllCellValue("完整", "商品名稱").Returns(new Dictionary <int, string> {
                { 2, "GOGOGOA" }, { 3, "GOGOGOA" }, { 4, "GOGOGOA" }, { 5, "GOGOGOA" }, { 6, "GOGOGOA" }, { 7, "GOGOGOA" }, { 8, "GOGOGOA" }, { 9, "GOGOGOA" }, { 10, "GOGOGOA" }, { 11, "GOGOGOA" }, { 12, "GOGOGOA" }
            });

            excelHandler.GetSpecifiedCellValue(2, 2, 2).Returns("GOGOGOA");
            excelHandler.GetSpecifiedCellValue(2, 2, 3).Returns("GOGOGOA");
            excelHandler.GetSpecifiedCellValue(2, 2, 4).Returns("GOGOGOA");
            excelHandler.GetSpecifiedCellValue(2, 2, 5).Returns("GOGOGOA");
            excelHandler.GetSpecifiedCellValue(2, 2, 6).Returns("GOGOGOA");
            excelHandler.GetSpecifiedCellValue(2, 2, 7).Returns("GOGOGOA");
            excelHandler.GetSpecifiedCellValue(2, 2, 8).Returns("GOGOGOA");
            excelHandler.GetSpecifiedCellValue(2, 2, 9).Returns("GOGOGOA");
            excelHandler.GetSpecifiedCellValue(2, 2, 10).Returns("GOGOGOA");
            excelHandler.GetSpecifiedCellValue(2, 2, 11).Returns("GOGOGOA");
            excelHandler.GetSpecifiedCellValue(2, 2, 12).Returns("GOGOGOA");

            excelHandler.GetSpecifiedCellValue(2, 3, 2).Returns("111");
            excelHandler.GetSpecifiedCellValue(2, 3, 3).Returns("111");
            excelHandler.GetSpecifiedCellValue(2, 3, 4).Returns("111");
            excelHandler.GetSpecifiedCellValue(2, 3, 5).Returns("111");
            excelHandler.GetSpecifiedCellValue(2, 3, 6).Returns("111");
            excelHandler.GetSpecifiedCellValue(2, 3, 7).Returns("111");
            excelHandler.GetSpecifiedCellValue(2, 3, 8).Returns("111");
            excelHandler.GetSpecifiedCellValue(2, 3, 9).Returns("111");
            excelHandler.GetSpecifiedCellValue(2, 3, 10).Returns("111");
            excelHandler.GetSpecifiedCellValue(2, 3, 11).Returns("111");
            excelHandler.GetSpecifiedCellValue(2, 3, 12).Returns("111");

            excelHandler.GetSpecifiedCellValue(2, 4, 2).Returns("1");
            excelHandler.GetSpecifiedCellValue(2, 4, 3).Returns("2");
            excelHandler.GetSpecifiedCellValue(2, 4, 4).Returns("3");
            excelHandler.GetSpecifiedCellValue(2, 4, 5).Returns("4");
            excelHandler.GetSpecifiedCellValue(2, 4, 6).Returns("5");
            excelHandler.GetSpecifiedCellValue(2, 4, 7).Returns("6");
            excelHandler.GetSpecifiedCellValue(2, 4, 8).Returns("7");
            excelHandler.GetSpecifiedCellValue(2, 4, 9).Returns("8");
            excelHandler.GetSpecifiedCellValue(2, 4, 10).Returns("9");
            excelHandler.GetSpecifiedCellValue(2, 4, 11).Returns("10");
            excelHandler.GetSpecifiedCellValue(2, 4, 12).Returns("11");

            excelHandler.GetSpecifiedCellValue(2, 5, 11).Returns("1,2,3,4,5,6,7,8,9,10");

            var target = new WorkSheetHandler(excelHandler);

            target.GroupTenItemsViaPid("完整", "活動設定");

            excelHandler.Received().SetCellValue(2, 5, 11, "1,2,3,4,5,6,7,8,9,10");
            excelHandler.Received().SetCellValue(2, 5, 12, "11");
        }