예제 #1
0
        public void DataValidationHasWorksheetAndRangesWhenCreated()
        {
            using (var wb = new XLWorkbook())
            {
                var ws    = wb.AddWorksheet();
                var range = ws.Range("A1:A3");

                var dv = new XLDataValidation(range);

                Assert.AreSame(ws, dv.Worksheet);
                Assert.AreSame(range, dv.Ranges.Single());
            }
        }
예제 #2
0
        public void RemoveNonExistingRangeDoesNotFireEvent()
        {
            using (var wb = new XLWorkbook())
            {
                var ws     = wb.AddWorksheet();
                var range1 = ws.Range("A1:A3");
                var range2 = ws.Range("C1:C3");
                var dv     = new XLDataValidation(range1);

                dv.RangeRemoved += (s, e) => Assert.Fail("Expected not to fire event");

                dv.RemoveRange(range2);
            }
        }
예제 #3
0
        public void CanAddRangeFromAnotherWorksheet()
        {
            using (var wb = new XLWorkbook())
            {
                var ws1    = wb.AddWorksheet();
                var ws2    = wb.AddWorksheet();
                var range1 = ws1.Range("A1:A3");
                var range2 = ws2.Range("C1:C3");
                var dv     = new XLDataValidation(range1);

                dv.AddRange(range2);

                Assert.IsTrue(dv.Ranges.Any(r => r != range2 && r.RangeAddress.ToString() == range2.RangeAddress.ToString()));
            }
        }
예제 #4
0
        public void RemovingExistingRangeDoesNoFail()
        {
            using (var wb = new XLWorkbook())
            {
                var ws     = wb.AddWorksheet();
                var range1 = ws.Range("A1:A3");
                var range2 = ws.Range("C1:C3");

                var dv = new XLDataValidation(range1);

                dv.RemoveRange(range2);
                dv.RemoveRange(null);

                Assert.AreSame(range1, dv.Ranges.Single());
            }
        }
예제 #5
0
        public void RemoveRangeFiresEvent()
        {
            using (var wb = new XLWorkbook())
            {
                var ws     = wb.AddWorksheet();
                var range1 = ws.Range("A1:A3");
                var range2 = ws.Range("C1:C3");
                var dv     = new XLDataValidation(range1);
                dv.AddRange(range2);
                IXLRange removedRange = null;
                dv.RangeRemoved += (s, e) => removedRange = e.Range;

                dv.RemoveRange(range2);

                Assert.AreSame(range2, removedRange);
            }
        }
예제 #6
0
        public void CanClearRanges()
        {
            using (var wb = new XLWorkbook())
            {
                var ws      = wb.AddWorksheet();
                var range1  = ws.Range("A1:A3");
                var range2  = ws.Range("C1:C3");
                var ranges3 = ws.Ranges("D1:D3,F1:F3");
                var dv      = new XLDataValidation(range1);
                dv.AddRange(range2);
                dv.AddRanges(ranges3);

                dv.ClearRanges();

                Assert.IsEmpty(dv.Ranges);
            }
        }
예제 #7
0
        public void AddRangesFiresMultipleEvents()
        {
            using (var wb = new XLWorkbook())
            {
                var ws     = wb.AddWorksheet();
                var range1 = ws.Range("A1:A3");
                var ranges = ws.Ranges("D1:D3,F1:F3");
                var dv     = new XLDataValidation(range1);

                var addedRanges = new List <IXLRange>();

                dv.RangeAdded += (s, e) => addedRanges.Add(e.Range);

                dv.AddRanges(ranges);

                Assert.AreEqual(2, addedRanges.Count);
            }
        }
예제 #8
0
        public void ClearRangesFiresMultipleEvents()
        {
            using (var wb = new XLWorkbook())
            {
                var ws     = wb.AddWorksheet();
                var range1 = ws.Range("A1:A3");
                var range2 = ws.Range("C1:C3");
                var dv     = new XLDataValidation(range1);
                dv.AddRange(range2);

                var removedRanges = new List <IXLRange>();

                dv.RangeRemoved += (s, e) => removedRanges.Add(e.Range);

                dv.ClearRanges();

                Assert.AreEqual(2, removedRanges.Count);
            }
        }
예제 #9
0
        public void CanAddRangeFromSameWorksheet()
        {
            using (var wb = new XLWorkbook())
            {
                var ws      = wb.AddWorksheet();
                var range1  = ws.Range("A1:A3");
                var range2  = ws.Range("C1:C3");
                var ranges3 = ws.Ranges("D1:D3,F1:F3");
                var dv      = new XLDataValidation(range1);

                dv.AddRange(range2);
                dv.AddRanges(ranges3);

                Assert.IsTrue(dv.Ranges.Any(r => r == range1));
                Assert.IsTrue(dv.Ranges.Any(r => r == range2));
                Assert.IsTrue(dv.Ranges.Any(r => r == ranges3.First()));
                Assert.IsTrue(dv.Ranges.Any(r => r == ranges3.Last()));
            }
        }