Exemplo n.º 1
5
 public void NowFunctionShouldReturnNow()
 {
     var startTime = DateTime.Now;
     Thread.Sleep(1);
     var func = new Now();
     var args = new FunctionArgument[0];
     var result = func.Execute(args, _parsingContext);
     Thread.Sleep(1);
     var endTime = DateTime.Now;
     var resultDate = DateTime.FromOADate((double)result.Result);
     Assert.IsTrue(resultDate > startTime && resultDate < endTime);
 }
Exemplo n.º 2
0
 /// <summary>
 /// if the supplied <paramref name="arg">argument</paramref> contains an Excel error
 /// an <see cref="ExcelErrorValueException"/> with that errorcode will be thrown
 /// </summary>
 /// <param name="arg"></param>
 /// <exception cref="ExcelErrorValueException"></exception>
 protected void CheckForAndHandleExcelError(FunctionArgument arg)
 {
     if (arg.ValueIsExcelError)
     {
         throw (new ExcelErrorValueException(arg.ValueAsExcelErrorValue));
     }
 }
        protected virtual IEnumerable <double> ArgsToDoubleEnumerableZeroPadded(bool ignoreHiddenCells, ExcelDataProvider.IRangeInfo rangeInfo, ParsingContext context)
        {
            var startRow = rangeInfo.Address.Start.Row;
            var endRow   = rangeInfo.Address.End.Row;
            var funcArg  = new FunctionArgument(rangeInfo);
            var result   = ArgsToDoubleEnumerable(ignoreHiddenCells, new List <FunctionArgument> {
                funcArg
            }, context);
            var dict = new Dictionary <int, double>();

            result.ToList().ForEach(x => dict.Add(x.CellRow.Value, x.Value));
            var resultList = new List <double>();

            for (var row = startRow; row <= endRow; row++)
            {
                if (dict.ContainsKey(row))
                {
                    resultList.Add(dict[row]);
                }
                else
                {
                    resultList.Add(0d);
                }
            }
            return(resultList);
        }
 protected bool ShouldIgnore(FunctionArgument arg)
 {
     if (IgnoreHiddenValues && arg.ExcelStateFlagIsSet(ExcelCellState.HiddenCell))
     {
         return(true);
     }
     return(false);
 }
Exemplo n.º 5
0
 public void TodayFunctionShouldReturnTodaysDate()
 {
     var func = new Today();
     var args = new FunctionArgument[0];
     var result = func.Execute(args, _parsingContext);
     var resultDate = DateTime.FromOADate((double)result.Result);
     Assert.AreEqual(DateTime.Now.Date, resultDate);
 }
Exemplo n.º 6
0
 /// <summary>
 /// If the argument is a collection, its first value will be returned.
 /// If the argument is not a collection, the argument will be returned.
 /// </summary>
 /// <param name="argument"></param>
 /// <returns></returns>
 protected FunctionArgument GetFirstArgument(FunctionArgument argument)
 {
     if (argument.Value is IEnumerable <FunctionArgument> enumerableArgument)
     {
         return(enumerableArgument.First());
     }
     return(argument);
 }
 protected bool ShouldIgnore(FunctionArgument arg)
 {
     if (IgnoreHiddenValues && arg.ExcelStateFlagIsSet(ExcelCellState.HiddenCell))
     {
         return true;
     }
     return false;
 }
Exemplo n.º 8
0
 public override CompileResult Compile(IEnumerable<Expression> children, ParsingContext context)
 {
     var args = new List<FunctionArgument>();
     Function.BeforeInvoke(context);
     foreach (var child in children)
     {
         var compileResult = child.Compile();
         if (compileResult.IsResultOfSubtotal)
         {
             var arg = new FunctionArgument(compileResult.Result);
             arg.SetExcelStateFlag(ExcelCellState.IsResultOfSubtotal);
             args.Add(arg);
         }
         else
         {
             BuildFunctionArguments(compileResult.Result, args);     
         }
     }
     return Function.Execute(args, context);
 }
Exemplo n.º 9
0
 /// <summary>
 /// if the supplied <paramref name="arg">argument</paramref> contains an Excel error
 /// an <see cref="ExcelErrorValueException"/> with that errorcode will be thrown
 /// </summary>
 /// <param name="arg"></param>
 /// <exception cref="ExcelErrorValueException"></exception>
 protected void CheckForAndHandleExcelError(FunctionArgument arg)
 {
     if (arg.ValueIsExcelError)
     {
         throw (new ExcelErrorValueException(arg.ValueAsExcelErrorValue));
     }
 }
Exemplo n.º 10
0
 internal static bool ShouldIgnore(bool ignoreHiddenValues, FunctionArgument arg, ParsingContext context)
 {
     return(ignoreHiddenValues && arg.ExcelStateFlagIsSet(ExcelCellState.HiddenCell));
 }
Exemplo n.º 11
0
 internal static bool ShouldIgnore(bool ignoreHiddenValues, FunctionArgument arg, ParsingContext context)
 {
     return (ignoreHiddenValues && arg.ExcelStateFlagIsSet(ExcelCellState.HiddenCell));
 }
Exemplo n.º 12
0
 public void ExcelStateFlagIsSetShouldReturnFalseWhenNotSet()
 {
     var arg = new FunctionArgument(2);
     Assert.IsFalse(arg.ExcelStateFlagIsSet(ExcelCellState.HiddenCell));
 }
Exemplo n.º 13
0
 public void ShouldSetExcelState()
 {
     var arg = new FunctionArgument(2);
     arg.SetExcelStateFlag(ExcelCellState.HiddenCell);
     Assert.IsTrue(arg.ExcelStateFlagIsSet(ExcelCellState.HiddenCell));
 }
Exemplo n.º 14
0
 public void RandShouldReturnAValueBetween0and1()
 {
     var func = new Rand();
     var args = new FunctionArgument[0];
     var result1 = func.Execute(args, _parsingContext);
     Assert.IsTrue(((double)result1.Result) > 0 && ((double) result1.Result) < 1);
     var result2 = func.Execute(args, _parsingContext);
     Assert.AreNotEqual(result1.Result, result2.Result, "The two numbers were the same");
     Assert.IsTrue(((double)result2.Result) > 0 && ((double)result2.Result) < 1);
 }
Exemplo n.º 15
0
        public void AverageShouldThrowDivByZeroExcelErrorValueIfEmptyArgs()
        {
            eErrorType errorType = eErrorType.Value;

            var func = new Average();
            var args = new FunctionArgument[0];
            try
            {
                func.Execute(args, _parsingContext);
            }
            catch (ExcelErrorValueException e)
            {
                errorType = e.ErrorValue.Type;
            }
            Assert.AreEqual(eErrorType.Div0, errorType);
        }
Exemplo n.º 16
0
 /// <summary>
 /// If the specified <paramref name="argument"/>'s value is a boolean value its value will be returned.
 /// If the specified <paramref name="argument"/>'s value is an integer value, true will be returned if its
 /// value is not 0, otherwise false.
 /// </summary>
 /// <param name="argument">The argument to parse to a boolean value.</param>
 /// <returns>True if the <paramref name="argument"/>'s value coalesces to true, false otherwise.</returns>
 protected bool ArgToBool(FunctionArgument argument)
 {
     return(this.ArgToBool(argument.Value));
 }