Beispiel #1
0
        public void TestAddMergedRegion()
        {
            InternalSheet sheet        = InternalSheet.CreateSheet();
            int           regionsToAdd = 4096;
            int           startRecords = sheet.Records.Count;

            //simple Test that Adds a load of regions
            for (int n = 0; n < regionsToAdd; n++)
            {
                int index = sheet.AddMergedRegion(0, 0, 1, 1);
                Assert.AreEqual(index, n, "Merged region index expected to be " + n + " got " + index);
            }

            //test all the regions were indeed Added
            Assert.AreEqual(sheet.NumMergedRegions, regionsToAdd);

            //test that the regions were spread out over the appropriate number of records
            MergedCellListener mcListener = new MergedCellListener();

            sheet.VisitContainedRecords(mcListener, 0);
            int recordsAdded    = mcListener.Count;
            int recordsExpected = regionsToAdd / 1027;

            if ((regionsToAdd % 1027) != 0)
            {
                recordsExpected++;
            }
            Assert.AreEqual(recordsAdded, recordsExpected, "The " + regionsToAdd + " merged regions should have been spRead out over " + recordsExpected + " records, not " + recordsAdded);
            // Check we can't Add one with invalid date
            try
            {
                sheet.AddMergedRegion(10, 10, 9, 12);
                Assert.Fail("Expected an exception to occur");
            }
            catch (ArgumentException e)
            {
                // occurs during successful Test
                Assert.AreEqual("The 'to' row (9) must not be less than the 'from' row (10)", e.Message);
            }
            try
            {
                sheet.AddMergedRegion(10, 10, 12, 9);
                Assert.Fail("Expected an exception to occur");
            }
            catch (ArgumentException e)
            {
                // occurs during successful Test
                Assert.AreEqual("The 'to' col (9) must not be less than the 'from' col (10)", e.Message);
            }
        }
Beispiel #2
0
        public void TestRemoveMergedRegion()
        {
            InternalSheet sheet        = InternalSheet.CreateSheet();
            int           regionsToAdd = 4096;

            for (int n = 0; n < regionsToAdd; n++)
            {
                sheet.AddMergedRegion(0, 0, 1, 1);
            }

            int nSheetRecords = sheet.Records.Count;

            //remove a third from the beginning
            for (int n = 0; n < regionsToAdd / 3; n++)
            {
                sheet.RemoveMergedRegion(0);
                //assert they have been deleted
                Assert.AreEqual(sheet.NumMergedRegions, regionsToAdd - n - 1, "Num of regions should be " + (regionsToAdd - n - 1) + " not " + sheet.NumMergedRegions);
            }

            // merge records are removed from within the MergedCellsTable,
            // so the sheet record count should not change
            Assert.AreEqual(nSheetRecords, sheet.Records.Count, "Sheet Records");
        }