Пример #1
0
        public void Test_Execution_Expect_Calculation_For_Input()
        {
            List<DateTimeRangeCalculatorBase> calculators = new List<DateTimeRangeCalculatorBase>
            {
                new MockImplementationTodayCalculator
                {
                    DateTimeProvider = _mockDateTimeProvider.Object
                }
            };

            _mockDateTimeProvider
                .SetupGet(expression: m => m.Today)
                .Returns(value: new DateTime(year: 1986, month: 4, day: 11));

            DateTimeRangeParser rangeExtractor2 = new DateTimeRangeParser(
                dateTimeProvider: _mockDateTimeProvider.Object,
                calculators: calculators);

            DateTimeRange actual = rangeExtractor2.Parse(input: "Today");

            DateTimeRange expected = new DateTimeRange
            {
                Start = new DateTime(year: 1986, month: 4, day: 11),
                End = new DateTime(year: 1986, month: 4, day: 11)
            };

            Assert.Equal(
                expected: expected,
                actual: actual);
        }
Пример #2
0
        public static void Main(string[] args)
        {
            DateTimeRangeParser parser = new DateTimeRangeParser();

            foreach (var item in parser.ImplementedCalculations)
            {
                Console.WriteLine(item);
                if (item.Examples != null)
                {
                    foreach (CalculationExample example in item.Examples)
                    {
                        Console.WriteLine($" - Input: \"{example.InputString}\" results value: {parser.Parse(input: example.InputString)}");
                    }
                }
            }
        }
Пример #3
0
        public void Test_Execution_Expect_SelectorNames()
        {
            List<DateTimeRangeCalculatorBase> calculators = new List<DateTimeRangeCalculatorBase>
            {
                new MockImplementationTodayCalculator
                {
                    DateTimeProvider = _mockDateTimeProvider.Object
                }
            };

            _mockDateTimeProvider
                .SetupGet(expression: m => m.Today)
                .Returns(value: new DateTime(year: 1986, month: 4, day: 11));

            DateTimeRangeParser rangeExtractor2 = new DateTimeRangeParser(
                dateTimeProvider: _mockDateTimeProvider.Object,
                calculators: calculators);

            ReadOnlyCollection<string> expectedSelectorNames = new List<string> { "Today" }.AsReadOnly();
            Assert.Equal(
                expected: expectedSelectorNames,
                actual: rangeExtractor2.ImplementedCalculatorNames);
        }
Пример #4
0
 public static DateTimeRangeParser EnableCaching(this DateTimeRangeParser dateTimeRangeParser)
 {
     dateTimeRangeParser.CachingEnabled = true;
     return(dateTimeRangeParser);
 }