public void ResolveTest()
        {
            var quarterDict = new SupportedTierDictionary <FiscalQuarterPeriod>();
            var dayDict     = new SupportedTierDictionary <DayPeriod>();

            quarterDict.Add(company.Ticker, company.SupportedQuarterRanges);
            dayDict.Add(company.Ticker, company.SupportedDailyRanges);
            var resolver = new PeriodSupportedTierResolver(null, null, quarterDict, dayDict);

            // snapshot
            Assert.AreEqual(SupportedTier.FixedTier, resolver.Resolve(ticker, Snapshot.GetInstance(), false, false));

            // relative quarter periods
            Assert.AreEqual(SupportedTier.FixedTier, resolver.Resolve(ticker, RelativeFiscalQuarterPeriod.CreateLatest(), false, false));
            Assert.AreEqual(SupportedTier.FixedTier, resolver.Resolve(ticker, RelativeFiscalQuarterPeriod.Create(5, 1), false, false));
            Assert.AreEqual(SupportedTier.OndemandTier, resolver.Resolve(ticker, RelativeFiscalQuarterPeriod.Create(5, 2), false, false));
            Assert.AreEqual(SupportedTier.OndemandTier, resolver.Resolve(ticker, RelativeFiscalQuarterPeriod.Create(5, 3), false, false));
            Assert.AreEqual(SupportedTier.OndemandTier, resolver.Resolve(ticker, RelativeFiscalQuarterPeriod.Create(11, 2), false, false));
            Assert.AreEqual(SupportedTier.None, resolver.Resolve(ticker, RelativeFiscalQuarterPeriod.Create(11, 3), false, false));
            Assert.AreEqual(SupportedTier.None, resolver.Resolve(ticker, RelativeFiscalQuarterPeriod.Create(11, 4), false, false));

            // latest day
            Assert.AreEqual(SupportedTier.FixedTier, resolver.Resolve(ticker, LatestDayPeriod.GetInstance(), false, false));


            // quarter
            Assert.AreEqual(SupportedTier.FixedTier, resolver.Resolve(ticker, fixedOldestQuarter, false, false));
            Assert.AreEqual(SupportedTier.FixedTier, resolver.Resolve(ticker, fixedOldestQuarter.Next() as FiscalQuarterPeriod, false, false));
            Assert.AreEqual(SupportedTier.FixedTier, resolver.Resolve(ticker, fixedLatestQuarter, false, false));
            Assert.AreEqual(SupportedTier.OndemandTier, resolver.Resolve(ticker, ondemandOldestQuarter, false, false));
            Assert.AreEqual(SupportedTier.OndemandTier, resolver.Resolve(ticker, ondemandOldestQuarter.Next() as FiscalQuarterPeriod, false, false));
            Assert.AreEqual(SupportedTier.FixedTier, resolver.Resolve(ticker, ondemandLatestQuarter, false, false));
            Assert.AreEqual(SupportedTier.None, resolver.Resolve(ticker, ondemandLatestQuarter.Next() as FiscalQuarterPeriod, false, false));

            // day
            Assert.AreEqual(SupportedTier.FixedTier, resolver.Resolve(ticker, ondemandLatestDay, false, false));
            Assert.AreEqual(SupportedTier.FixedTier, resolver.Resolve(ticker, fixedTierLatestDay, false, false));
            Assert.AreEqual(SupportedTier.FixedTier, resolver.Resolve(ticker, fixedTierOldestDay, false, false));
            Assert.AreEqual(SupportedTier.FixedTier, resolver.Resolve(ticker, fixedTierOldestDay.Next(), false, false));
            Assert.AreEqual(SupportedTier.OndemandTier, resolver.Resolve(ticker, fixedTierOldestDay.Prev(), false, false));
            Assert.AreEqual(SupportedTier.OndemandTier, resolver.Resolve(ticker, ondemandOldestDay, false, false));
            Assert.AreEqual(SupportedTier.OndemandTier, resolver.Resolve(ticker, ondemandOldestDay.Next(), false, false));
            Assert.AreEqual(SupportedTier.None, resolver.Resolve(ticker, ondemandOldestDay.Prev(), false, false));
            Assert.AreEqual(SupportedTier.None, resolver.Resolve(ticker, fixedTierLatestDay.Next(), false, false));
            Assert.AreEqual(SupportedTier.None, resolver.Resolve(ticker, ondemandLatestDay.Next(), false, false));
        }
        public ITickerPeriodParameter Build()
        {
            switch (dataType)
            {
            case DataTypeConfig.Indicator:
                return(TickerEmptyPeriodParameter.Create(ticker, Snapshot.GetInstance()));

            case DataTypeConfig.Quarter:
                if (string.IsNullOrWhiteSpace(parameter1) && string.IsNullOrWhiteSpace(parameter2))
                {
                    return(TickerQuarterParameter.Create(ticker, RelativeFiscalQuarterPeriod.CreateLatest()));
                }
                else
                {
                    return(TickerQuarterParameter.Create(ticker, FiscalQuarterPeriod.Create(parameter1, parameter2)));
                }

            case DataTypeConfig.Daily:
                return(TickerDayParameter.Create(ticker, LatestDayPeriod.GetInstance()));

            default:
                throw new NotSupportedDataTypeException($"dataType ={dataType} is not supported.");
            }
        }
 public void CreateLatestTest()
 {
     Assert.AreEqual(RelativeFiscalQuarterPeriod.Create(0, 0), RelativeFiscalQuarterPeriod.CreateLatest());
 }
        public void FindAvailableTierTest()
        {
            var tierResolver = CreatTierResolver();
            var helper       = new ApiTaskHelper(tierResolver);

            // enable ondemand endpoint
            // quarter
            Assert.AreEqual(SupportedTier.FixedTier, helper.FindAvailableTier(DataTypeConfig.Quarter, ticker, fixedOldestQuarter, true, true, true));
            Assert.AreEqual(SupportedTier.FixedTier, helper.FindAvailableTier(DataTypeConfig.Quarter, ticker, fixedOldestQuarter.Next() as FiscalQuarterPeriod, true, true, true));
            Assert.AreEqual(SupportedTier.FixedTier, helper.FindAvailableTier(DataTypeConfig.Quarter, ticker, fixedLatestQuarter, true, true, true));
            Assert.AreEqual(SupportedTier.OndemandTier, helper.FindAvailableTier(DataTypeConfig.Quarter, ticker, ondemandOldestQuarter, true, true, true));
            Assert.AreEqual(SupportedTier.OndemandTier, helper.FindAvailableTier(DataTypeConfig.Quarter, ticker, ondemandOldestQuarter.Next() as FiscalQuarterPeriod, true, true, true));
            Assert.AreEqual(SupportedTier.OndemandTier, helper.FindAvailableTier(DataTypeConfig.Quarter, ticker, ondemandLatestQuarter, true, true, true));
            Assert.AreEqual(SupportedTier.FixedTier, helper.FindAvailableTier(DataTypeConfig.Quarter, ticker, RelativeFiscalQuarterPeriod.CreateLatest(), true, true, true));

            Assert.ThrowsException <NotSupportedTierException>(() => helper.FindAvailableTier(DataTypeConfig.Quarter, ticker, ondemandLatestQuarter.Next() as FiscalQuarterPeriod, true, true, true));

            // daily
            Assert.AreEqual(SupportedTier.FixedTier, helper.FindAvailableTier(DataTypeConfig.Daily, ticker, fixedTierOldestDay, true, true, true));
            Assert.AreEqual(SupportedTier.FixedTier, helper.FindAvailableTier(DataTypeConfig.Daily, ticker, fixedTierOldestDay.Next() as DayPeriod, true, true, true));
            Assert.AreEqual(SupportedTier.FixedTier, helper.FindAvailableTier(DataTypeConfig.Daily, ticker, fixedTierLatestDay, true, true, true));
            Assert.AreEqual(SupportedTier.OndemandTier, helper.FindAvailableTier(DataTypeConfig.Daily, ticker, ondemandOldestDay, true, true, true));
            Assert.AreEqual(SupportedTier.OndemandTier, helper.FindAvailableTier(DataTypeConfig.Daily, ticker, ondemandOldestDay.Next() as DayPeriod, true, true, true));
            Assert.AreEqual(SupportedTier.OndemandTier, helper.FindAvailableTier(DataTypeConfig.Daily, ticker, ondemandLatestDay, true, true, true));
            Assert.AreEqual(SupportedTier.FixedTier, helper.FindAvailableTier(DataTypeConfig.Daily, ticker, LatestDayPeriod.GetInstance(), true, true, true));
            Assert.ThrowsException <NotSupportedTierException>(() => helper.FindAvailableTier(DataTypeConfig.Daily, ticker, ondemandLatestDay.Next() as DayPeriod, true, true, true));


            // disabled ondemand endpoint
            // quarter
            Assert.AreEqual(SupportedTier.FixedTier, helper.FindAvailableTier(DataTypeConfig.Quarter, ticker, fixedOldestQuarter, false, true, true));
            Assert.AreEqual(SupportedTier.FixedTier, helper.FindAvailableTier(DataTypeConfig.Quarter, ticker, fixedOldestQuarter.Next() as FiscalQuarterPeriod, false, true, true));
            Assert.AreEqual(SupportedTier.FixedTier, helper.FindAvailableTier(DataTypeConfig.Quarter, ticker, fixedLatestQuarter, false, true, true));
            Assert.ThrowsException <NotSupportedTierException>(() => helper.FindAvailableTier(DataTypeConfig.Quarter, ticker, ondemandOldestQuarter, false, true, true));
            Assert.ThrowsException <NotSupportedTierException>(() => helper.FindAvailableTier(DataTypeConfig.Quarter, ticker, ondemandOldestQuarter.Next() as FiscalQuarterPeriod, false, true, true));
            Assert.ThrowsException <NotSupportedTierException>(() => helper.FindAvailableTier(DataTypeConfig.Quarter, ticker, ondemandLatestQuarter, false, true, true));
            Assert.ThrowsException <NotSupportedTierException>(() => helper.FindAvailableTier(DataTypeConfig.Quarter, ticker, ondemandLatestQuarter.Next() as FiscalQuarterPeriod, false, true, true));
            Assert.AreEqual(SupportedTier.FixedTier, helper.FindAvailableTier(DataTypeConfig.Quarter, ticker, RelativeFiscalQuarterPeriod.CreateLatest(), false, true, true));

            // daily
            Assert.AreEqual(SupportedTier.FixedTier, helper.FindAvailableTier(DataTypeConfig.Daily, ticker, fixedTierOldestDay, false, true, true));
            Assert.AreEqual(SupportedTier.FixedTier, helper.FindAvailableTier(DataTypeConfig.Daily, ticker, fixedTierOldestDay.Next() as DayPeriod, false, true, true));
            Assert.AreEqual(SupportedTier.FixedTier, helper.FindAvailableTier(DataTypeConfig.Daily, ticker, fixedTierLatestDay, false, true, true));
            Assert.ThrowsException <NotSupportedTierException>(() => helper.FindAvailableTier(DataTypeConfig.Daily, ticker, ondemandLatestDay, false, true, true));
            Assert.ThrowsException <NotSupportedTierException>(() => helper.FindAvailableTier(DataTypeConfig.Daily, ticker, ondemandLatestDay.Next() as DayPeriod, false, true, true));
            Assert.ThrowsException <NotSupportedTierException>(() => helper.FindAvailableTier(DataTypeConfig.Daily, ticker, ondemandLatestDay, false, true, true));
            Assert.AreEqual(SupportedTier.FixedTier, helper.FindAvailableTier(DataTypeConfig.Daily, ticker, LatestDayPeriod.GetInstance(), false, true, true));
            Assert.ThrowsException <NotSupportedTierException>(() => helper.FindAvailableTier(DataTypeConfig.Daily, ticker, ondemandLatestDay.Next() as DayPeriod, false, true, true));

            // company is always fixed tier
            Assert.AreEqual(SupportedTier.FixedTier, helper.FindAvailableTier(DataTypeConfig.Company, ticker, Snapshot.GetInstance(), true, true, true));
            Assert.AreEqual(SupportedTier.FixedTier, helper.FindAvailableTier(DataTypeConfig.Company, ticker, Snapshot.GetInstance(), false, true, true));

            // indicator is always fixed tier
            Assert.AreEqual(SupportedTier.FixedTier, helper.FindAvailableTier(DataTypeConfig.Indicator, ticker, Snapshot.GetInstance(), true, true, true));
            Assert.AreEqual(SupportedTier.FixedTier, helper.FindAvailableTier(DataTypeConfig.Indicator, ticker, Snapshot.GetInstance(), false, true, true));
        }