Пример #1
0
        public void WeekdayShouldReturnCorrectResultForASundayWhenReturnTypeIs3()
        {
            var func   = new Weekday();
            var result = func.Execute(FunctionsHelper.CreateArgs(new DateTime(2012, 4, 1).ToOADate(), 3), _parsingContext);

            Assert.AreEqual(6, result.Result);
        }
Пример #2
0
        public void WeekdayWithDateAsDoubleInStringReturnsCorrectResult()
        {
            var func   = new Weekday();
            var args   = FunctionsHelper.CreateArgs("8.5");
            var result = func.Execute(args, this.ParsingContext);

            Assert.AreEqual(1, result.Result);
        }
Пример #3
0
        public void WeekdayWithDateAsNegativeIntegerReturnsPoundNum()
        {
            var func   = new Weekday();
            var args   = FunctionsHelper.CreateArgs(-1);
            var result = func.Execute(args, this.ParsingContext);

            Assert.AreEqual(eErrorType.Num, ((ExcelErrorValue)result.Result).Type);
        }
Пример #4
0
        public void WeekdayNonNumericDateAndNegativeReturnTypeReturnsPoundValue()
        {
            var func   = new Weekday();
            var args   = FunctionsHelper.CreateArgs("word", -1);
            var result = func.Execute(args, this.ParsingContext);

            Assert.AreEqual(eErrorType.Value, ((ExcelErrorValue)result.Result).Type);
        }
Пример #5
0
        public void WeekdayWithNullDateReturnsCorrectResult()
        {
            var func   = new Weekday();
            var args   = FunctionsHelper.CreateArgs(null, 1);
            var result = func.Execute(args, this.ParsingContext);

            Assert.AreEqual(7, result.Result);
        }
Пример #6
0
        public void WeekdayWithBothParametersNullReturnsPoundNum()
        {
            var func   = new Weekday();
            var args   = FunctionsHelper.CreateArgs(null, null);
            var result = func.Execute(args, this.ParsingContext);

            Assert.AreEqual(eErrorType.Num, ((ExcelErrorValue)result.Result).Type);
        }
Пример #7
0
        public void WeekdayWithDateAs1March1900ReturnsCorrectResult()
        {
            var func   = new Weekday();
            var args   = FunctionsHelper.CreateArgs("3/1/1900");
            var result = func.Execute(args, this.ParsingContext);

            Assert.AreEqual(5, result.Result);
        }
Пример #8
0
        public void WeekdayWithInvalidArgumentReturnsPoundValue()
        {
            var func   = new Weekday();
            var args   = FunctionsHelper.CreateArgs();
            var result = func.Execute(args, this.ParsingContext);

            Assert.AreEqual(eErrorType.Value, ((ExcelErrorValue)result.Result).Type);
        }
Пример #9
0
        public void WeekdayShouldReturnCorrectResultForASundayWhenReturnTypeIs17()
        {
            // A return type of 17 requests the weekday as a 1-indexed value where
            // the week starts on Sunday.
            var func   = new Weekday();
            var result = func.Execute(FunctionsHelper.CreateArgs(new DateTime(2012, 4, 1).ToOADate(), 17), this.ParsingContext);

            Assert.AreEqual(1, result.Result);
        }
Пример #10
0
        public void WeekdayWithDateAsFractionInStringReturnsCorrectResult()
        {
            // Note that Excel treats the OADate 0 as a special date with special output.
            var func   = new Weekday();
            var args   = FunctionsHelper.CreateArgs("0.5");
            var result = func.Execute(args, this.ParsingContext);

            Assert.AreEqual(7, result.Result);
        }
Пример #11
0
        public void WeekdayWithDateAsIntegerReturnsCorrectResult()
        {
            // Note that an omitted return_type is equivalent to using the
            // WEEKDAY function with a return_type of 1.
            var func   = new Weekday();
            var args   = FunctionsHelper.CreateArgs(8);
            var result = func.Execute(args, this.ParsingContext);

            Assert.AreEqual(1, result.Result);
        }
Пример #12
0
        public void WeekdayWithNonEnumeratedReturnTypeReturnsPoundNum()
        {
            // Note that the WEEKDAY function only accepts 1-3 and 11-17
            // as valid return_type values.
            var func   = new Weekday();
            var args   = FunctionsHelper.CreateArgs(new DateTime(2017, 5, 14), 4);
            var result = func.Execute(args, this.ParsingContext);

            Assert.AreEqual(eErrorType.Num, ((ExcelErrorValue)result.Result).Type);
        }
Пример #13
0
        public void WeekdayWithDateAs28February1900ReturnsCorrectResult()
        {
            // Note that System.DateTime dates before 3/1/1900 have their OADates off by one
            // from the Excel OADates due to Excel's inclusion of the non-existent day 2/29/1900
            // as a valid day.
            var func   = new Weekday();
            var args   = FunctionsHelper.CreateArgs("2/28/1900");
            var result = func.Execute(args, this.ParsingContext);

            Assert.AreEqual(3, result.Result);
        }
Пример #14
0
        public void WeekdayWithDateAsStringWithCommasReturnsCorrectResult()
        {
            // Note that Excel does not consider "5,17,2017" as a valid date format under the
            // US culture, but System.DateTime does. In this regard, EPPlus is not completely replicating
            // Excel's handling of specifically formatted dates. Properly handling this specific case
            // is currently considered too much work for too little value.
            var func   = new Weekday();
            var args   = FunctionsHelper.CreateArgs("5,17,2017");
            var result = func.Execute(args, this.ParsingContext);

            Assert.AreEqual(4, result.Result);
        }
Пример #15
0
        public void WeekNumWithItalianhDateAsStringWithPeriodsReturnsCorrectResult()
        {
            // Test case where the culture has been changed to Italian to test the
            // Italian date format.
            var currentCulture = Thread.CurrentThread.CurrentCulture;

            try
            {
                Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("it-IT");
                var function = new Weekday();
                var args     = FunctionsHelper.CreateArgs("3.5.2017");
                var result   = function.Execute(args, this.ParsingContext);
                Assert.AreEqual(4, result.Result);
            }
            finally
            {
                Thread.CurrentThread.CurrentCulture = currentCulture;
            }
        }
Пример #16
0
        public void WeekdayFunctionWithErrorValuesAsInputReturnsTheInputErrorValue()
        {
            var func        = new Weekday();
            var argNA       = FunctionsHelper.CreateArgs(ExcelErrorValue.Create(eErrorType.NA));
            var argNAME     = FunctionsHelper.CreateArgs(ExcelErrorValue.Create(eErrorType.Name));
            var argVALUE    = FunctionsHelper.CreateArgs(ExcelErrorValue.Create(eErrorType.Value));
            var argNUM      = FunctionsHelper.CreateArgs(ExcelErrorValue.Create(eErrorType.Num));
            var argDIV0     = FunctionsHelper.CreateArgs(ExcelErrorValue.Create(eErrorType.Div0));
            var argREF      = FunctionsHelper.CreateArgs(ExcelErrorValue.Create(eErrorType.Ref));
            var resultNA    = func.Execute(argNA, this.ParsingContext);
            var resultNAME  = func.Execute(argNAME, this.ParsingContext);
            var resultVALUE = func.Execute(argVALUE, this.ParsingContext);
            var resultNUM   = func.Execute(argNUM, this.ParsingContext);
            var resultDIV0  = func.Execute(argDIV0, this.ParsingContext);
            var resultREF   = func.Execute(argREF, this.ParsingContext);

            Assert.AreEqual(eErrorType.NA, ((ExcelErrorValue)resultNA.Result).Type);
            Assert.AreEqual(eErrorType.Name, ((ExcelErrorValue)resultNAME.Result).Type);
            Assert.AreEqual(eErrorType.Value, ((ExcelErrorValue)resultVALUE.Result).Type);
            Assert.AreEqual(eErrorType.Num, ((ExcelErrorValue)resultNUM.Result).Type);
            Assert.AreEqual(eErrorType.Div0, ((ExcelErrorValue)resultDIV0.Result).Type);
            Assert.AreEqual(eErrorType.Ref, ((ExcelErrorValue)resultREF.Result).Type);
        }