Exemplo n.º 1
0
        public void SetProperties()
        {
            var builder = new ExcelModelBuilder();

            builder.IgnoreSheetNames();
            var model = builder.Build();

            Assert.AreEqual(true, model.IgnoreSheetNames);
        }
Exemplo n.º 2
0
        public void NullResultFromOnReadSheet_Unnamed()
        {
            var sheet   = workbook.Worksheets.Add("Sheet1");
            var builder = new ExcelModelBuilder();

            builder.IgnoreSheetNames();
            builder.Sheet <Class1>();
            var model = builder.Build();
            var mock  = new Mock <SampleContext>(model);

            mock.Protected().Setup <object>("OnReadSheet", sheet, model.Sheets[0]).Returns(null).Verifiable();
            mock.CallBase = true;
            var context = mock.Object;

            Assert.ThrowsException <InvalidOperationException>(() => {
                var result = context.TestOnReadFile(workbook);
            });
        }
Exemplo n.º 3
0
        public void MultipleIgnoreNames()
        {
            var sheet   = workbook.Worksheets.Add("Sheet1");
            var sheet2  = workbook.Worksheets.Add("Sheet2");
            var builder = new ExcelModelBuilder();

            builder.IgnoreSheetNames();
            builder.Sheet <Class1>();
            builder.Sheet <Class2>();
            var model = builder.Build();
            var mock  = new Mock <SampleContext>(model);

            mock.Protected().Setup <object>("OnReadSheet", sheet, model.Sheets[0]).Returns(new List <Class1>()).Verifiable();
            mock.Protected().Setup <object>("OnReadSheet", sheet2, model.Sheets[1]).Returns(new List <Class2>()).Verifiable();
            mock.CallBase = true;
            var context = mock.Object;
            var result  = context.TestOnReadFile(workbook);

            Assert.IsNotNull(result);
            Assert.AreEqual(2, result.Count);
            Assert.IsInstanceOfType(result[0], typeof(List <Class1>));
            Assert.IsInstanceOfType(result[1], typeof(List <Class2>));
            mock.Verify();
        }