public void RangesRemoveAllWithoutDispose()
        {
            var ws     = new XLWorkbook().Worksheets.Add("Sheet1");
            var ranges = new XLRanges();

            ranges.Add(ws.Range("A1:A2"));
            ranges.Add(ws.Range("B1:B2"));
            var rangesCopy = ranges.ToList();

            ranges.RemoveAll(null, false);
            ws.FirstColumn().InsertColumnsBefore(1);

            Assert.AreEqual(0, ranges.Count);
            // if ranges were not disposed they addresses should change
            Assert.AreEqual("B1:B2", rangesCopy.First().RangeAddress.ToString());
            Assert.AreEqual("C1:C2", rangesCopy.Last().RangeAddress.ToString());
        }
        public void XLRangesReturnsRangesInDeterministicOrder()
        {
            var wb  = new XLWorkbook();
            var ws1 = wb.Worksheets.Add("Sheet1");
            var ws2 = wb.Worksheets.Add("Another sheet");

            var ranges = new XLRanges();

            ranges.Add(ws2.Range("F1:F12"));
            ranges.Add(ws1.Range("F12:F16"));
            ranges.Add(ws1.Range("B1:F2"));
            ranges.Add(ws2.Range("A13:B14"));
            ranges.Add(ws2.Range("E1:E2"));
            ranges.Add(ws1.Range("E1:H2"));
            ranges.Add(ws1.Range("G2:G13"));
            ranges.Add(ws1.Range("G20:G20"));

            var expectedRanges = new List <IXLRange>
            {
                ws1.Range("B1:F2"),
                ws1.Range("E1:H2"),
                ws1.Range("G2:G13"),
                ws1.Range("F12:F16"),
                ws1.Range("G20:G20"),

                ws2.Range("E1:E2"),
                ws2.Range("F1:F12"),
                ws2.Range("A13:B14"),
            };

            var actualRanges = ranges.ToList();

            Assert.AreEqual(expectedRanges.Count, actualRanges.Count);
            for (int i = 0; i < actualRanges.Count; i++)
            {
                Assert.AreEqual(expectedRanges[i], actualRanges[i]);
            }
        }