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); }
public void HLookupWithInvalidArgumentReturnsPoundValue() { var func = new HLookup(); var parsingContext = ParsingContext.Create(); var args = FunctionsHelper.CreateArgs(); var result = func.Execute(args, parsingContext); Assert.AreEqual(eErrorType.Value, ((ExcelErrorValue)result.Result).Type); }
public void HLookupShouldThrowIfNoMatchingRecordIsFoundWhenRangeLookupIsTrue() { var func = new HLookup(); var args = FunctionsHelper.CreateArgs(1, "A1:B2", 2, true); var parsingContext = ParsingContext.Create(); var provider = MockRepository.GenerateStub <ExcelDataProvider>(); provider.Stub(x => x.GetCellValue(0, 0)).Return(new ExcelCell(2, null, 0, 0)); provider.Stub(x => x.GetCellValue(0, 1)).Return(new ExcelCell(3, null, 0, 0)); provider.Stub(x => x.GetCellValue(1, 0)).Return(new ExcelCell(3, null, 0, 0)); provider.Stub(x => x.GetCellValue(1, 1)).Return(new ExcelCell(5, null, 0, 0)); parsingContext.ExcelDataProvider = provider; var result = func.Execute(args, parsingContext); }
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); }
public void HLookupShouldReturnResultFromMatchingRow() { var func = new HLookup(); var args = FunctionsHelper.CreateArgs(1, "A1:B2", 2); var parsingContext = ParsingContext.Create(); var provider = MockRepository.GenerateStub <ExcelDataProvider>(); provider.Stub(x => x.GetCellValue(0, 0)).Return(new ExcelCell(3, null, 0, 0)); provider.Stub(x => x.GetCellValue(0, 1)).Return(new ExcelCell(1, null, 0, 0)); provider.Stub(x => x.GetCellValue(1, 0)).Return(new ExcelCell(2, null, 0, 0)); provider.Stub(x => x.GetCellValue(1, 1)).Return(new ExcelCell(5, null, 0, 0)); parsingContext.ExcelDataProvider = provider; var result = func.Execute(args, parsingContext); Assert.AreEqual(5, result.Result); }
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); }
public void HLookupShouldReturnErrorIfNoMatchingRecordIsFoundWhenRangeLookupIsTrue() { var func = new HLookup(); var args = FunctionsHelper.CreateArgs(1, "A1:B2", 2, true); var parsingContext = ParsingContext.Create(); parsingContext.Scopes.NewScope(RangeAddress.Empty); var provider = A.Fake <ExcelDataProvider>(); A.CallTo(() => provider.GetCellValue(WorksheetName, 1, 1)).Returns(2); A.CallTo(() => provider.GetCellValue(WorksheetName, 1, 2)).Returns(3); A.CallTo(() => provider.GetCellValue(WorksheetName, 2, 1)).Returns(3); A.CallTo(() => provider.GetCellValue(WorksheetName, 2, 2)).Returns(5); parsingContext.ExcelDataProvider = provider; var result = func.Execute(args, parsingContext); Assert.AreEqual(result.DataType, DataType.ExcelError); }
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 = A.Fake <ExcelDataProvider>(); A.CallTo(() => provider.GetCellValue(WorksheetName, 1, 1)).Returns(1); A.CallTo(() => provider.GetCellValue(WorksheetName, 1, 2)).Returns(1); A.CallTo(() => provider.GetCellValue(WorksheetName, 2, 1)).Returns(2); A.CallTo(() => provider.GetCellValue(WorksheetName, 2, 2)).Returns(5); parsingContext.ExcelDataProvider = provider; var result = func.Execute(args, parsingContext); Assert.AreEqual(5, result.Result); }