Exemplo n.º 1
0
        public void HLookupShouldReturnNaErrorIfNoMatchingRecordIsFoundWhenRangeLookupIsFalse()
        {
            var func = new HLookup();
            var args = FunctionsHelper.CreateArgs(2, "A1:B2", 2, false);
            var parsingContext = ParsingContext.Create();
            parsingContext.Scopes.NewScope(RangeAddress.Empty);

            var provider = MockRepository.GenerateStub<ExcelDataProvider>();

            provider.Stub(x => x.GetCellValue(WorksheetName, 1, 1)).Return(3);
            provider.Stub(x => x.GetCellValue(WorksheetName, 1, 2)).Return(1);
            provider.Stub(x => x.GetCellValue(WorksheetName, 2, 1)).Return(2);
            provider.Stub(x => x.GetCellValue(WorksheetName, 2, 2)).Return(5);

            parsingContext.ExcelDataProvider = provider;
            var result = func.Execute(args, parsingContext);
            var expectedResult = ExcelErrorValue.Create(eErrorType.NA);
            Assert.AreEqual(expectedResult, result.Result);
        }
Exemplo n.º 2
0
        public void HLookupShouldThrowIfNoMatchingRecordIsFoundWhenRangeLookupIsTrue()
        {
            var func = new HLookup();
            var args = FunctionsHelper.CreateArgs(1, "A1:B2", 2, true);
            var parsingContext = ParsingContext.Create();
            parsingContext.Scopes.NewScope(RangeAddress.Empty);

            var provider = MockRepository.GenerateStub<ExcelDataProvider>();

            provider.Stub(x => x.GetCellValue(WorksheetName, 1, 1)).Return(2);
            provider.Stub(x => x.GetCellValue(WorksheetName, 1, 2)).Return(3);
            provider.Stub(x => x.GetCellValue(WorksheetName, 2, 1)).Return(3);
            provider.Stub(x => x.GetCellValue(WorksheetName, 2, 2)).Return(5);

            parsingContext.ExcelDataProvider = provider;
            var result = func.Execute(args, parsingContext);
        }
Exemplo n.º 3
0
        public void HLookupShouldReturnResultFromMatchingRow()
        {
            var func = new HLookup();
            var args = FunctionsHelper.CreateArgs(2, "A1:B2", 2);
            var parsingContext = ParsingContext.Create();
            parsingContext.Scopes.NewScope(RangeAddress.Empty);

            var provider = MockRepository.GenerateStub<ExcelDataProvider>();
            //provider.Stub(x => x.GetCellValue(WorksheetName,0, 0)).Return(new ExcelCell(3, null, 0, 0));
            //provider.Stub(x => x.GetCellValue(WorksheetName,0, 1)).Return(new ExcelCell(1, null, 0, 0));
            //provider.Stub(x => x.GetCellValue(WorksheetName,1, 0)).Return(new ExcelCell(2, null, 0, 0));
            //provider.Stub(x => x.GetCellValue(WorksheetName,1, 1)).Return(new ExcelCell(5, null, 0, 0));

            provider.Stub(x => x.GetCellValue(WorksheetName, 1, 1)).Return(1);
            provider.Stub(x => x.GetCellValue(WorksheetName, 1, 2)).Return(1);
            provider.Stub(x => x.GetCellValue(WorksheetName, 2, 1)).Return(2);
            provider.Stub(x => x.GetCellValue(WorksheetName, 2, 2)).Return(5);

            parsingContext.ExcelDataProvider = provider;
            var result = func.Execute(args, parsingContext);
            Assert.AreEqual(5, result.Result);
        }