示例#1
0
        public void GetTimePeriod_WithKnownDateTime_ReturnsCorrectPeriodId(string period1, string period2, int expectedPeriodIdDiff)
        {
            var result1 = TimePeriodHelper.GetTimePeriod(DateTime.Parse(period1), (60 * 60));
            var result2 = TimePeriodHelper.GetTimePeriod(DateTime.Parse(period2), (60 * 60));

            Assert.AreEqual(expectedPeriodIdDiff, result2.PeriodId - result1.PeriodId);
        }
示例#2
0
        public void GetTimePeriod_WithKnownDateTime_ReturnsCorrectPeriodId()
        {
            var result1 = TimePeriodHelper.GetTimePeriod(DateTime.Parse("01 January 2013 03:14:23"), (60 * 60));
            var result2 = TimePeriodHelper.GetTimePeriod(DateTime.Parse("01 January 2013 04:44:23"), (60 * 60));

            Assert.AreEqual(1, result2 - result1);
        }
        public void GivenIAddTheTimePeriodParameterThatIsDaysInTheFuture(int days)
        {
            var dateStart = DateTime.UtcNow.AddDays(days);
            var dateEnd   = dateStart.AddDays(1);
            var val       = TimePeriodHelper.GetTimePeriod(dateStart.ToString("yyyy-MM-dd"), dateEnd.ToString("yyyy-MM-dd"));

            Given($"I add the parameter \"start\" with the value \"{FhirConst.Prefixs.kGreaterThanOrEqualTo}{val.Start}\"");
            Given($"I add the parameter \"end\" with the value \"{FhirConst.Prefixs.kLessThanOrEqualTo}{val.End}\"");
        }
示例#4
0
        public void GetTimePeriod_WithKnownDateTime_ReturnsCorrectDates()
        {
            var result1 = TimePeriodHelper.GetTimePeriod(DateTime.Parse("09 June 2013 03:14:23"));

            Assert.AreEqual(9, result1.From.Day, "From Day");
            Assert.AreEqual(6, result1.From.Month, "From Month");
            Assert.AreEqual(2013, result1.From.Year, "From Month");

            Assert.AreEqual(9, result1.To.Day, "To Day");
            Assert.AreEqual(6, result1.To.Month, "To Month");
            Assert.AreEqual(2013, result1.To.Year, "To Month");
        }
        public List <Entities.StockPrice> GetStockPrices()
        {
            var timePeriod = TimePeriodHelper.GetTimePeriod(DateTime.UtcNow);

            var stockPrices = new List <StockPrice>();

            Parallel.ForEach <string>(GetPageUrls(), url =>
            {
                var stock = ReadStockPrices(url, timePeriod);

                if (stock != null)
                {
                    lock (stockPrices)
                    {
                        stockPrices.Add(stock);
                    }
                }
            });

            return(stockPrices);
        }
        private StockPrice ExtractStockData(string content)
        {
            var nameExp = "(?ismx)" +
                          "<h2[^>]*?class\\s?=\\s?[\\\"\\']title[\\\"\\'][^>]*?>[^<]*?" +
                          "(?:<a[^>]*?>)?" +
                          "\\s*(?<val>[^<]*?)\\s*<";

            var name = Regex.Match(content, nameExp).Groups["val"].Value;

            var symExp = "(?ismx)" +
                         "symbol[^<]*?" +
                         "<span[^>]*?class\\s?=\\s?[\\\"\\']shares_one[^>]*?>\\s*" +
                         "(?:<a[^>]*?>[^<]*?)?" +
                         "(?<val>[^<]*?)\\s*<";

            var symb = Regex.Match(content, symExp).Groups["val"].Value;

            var midExp = "(?ismx)" +
                         "share\\sprice[^<]*?" +
                         "<span[^>]*?class\\s?=\\s?[\\\"\\']shares_one[^>]*?>\\s*" +
                         "(?<val>[\\d\\,\\.]+)";

            var mid = Regex.Match(content, midExp).Groups["val"].Value;

            var valExp = "(?ismx)" +
                         "<th[^>]*?>[^<]*?{0}[^<]*?</\\s?th>[^<]*?" +
                         "<td[^>]*?>\\s*(?:<a[^>]*?>)?(?<value>.*?)\\s*</\\s?(?:a|td)>";

            var bid      = Regex.Match(content, string.Format(valExp, "bid")).Groups["value"].Value;
            var offer    = Regex.Match(content, string.Format(valExp, "offer")).Groups["value"].Value;
            var security = Regex.Match(content, string.Format(valExp, "security")).Groups["value"].Value;

            var changeDateExp = "(?ismx)" +
                                "<th[^>]*?>\\s*last\\schange[^<]*</\\s?th>[^<]*?<td[^>]*?>" +
                                "(?<month>\\d+)\\s*.\\s*" +
                                "(?<day>\\d+)\\s*.\\s*" +
                                "(?<hour>\\d+)\\s*.\\s*" +
                                "(?<min>\\d+)";

            var changeDateMatch = Regex.Match(content, changeDateExp);
            var dateTime        = new DateTime(DateTime.Now.Year,
                                               int.Parse(changeDateMatch.Groups["month"].Value),
                                               int.Parse(changeDateMatch.Groups["day"].Value),
                                               int.Parse(changeDateMatch.Groups["hour"].Value),
                                               int.Parse(changeDateMatch.Groups["min"].Value),
                                               0);

            var period = TimePeriodHelper.GetTimePeriod(dateTime);

            var stock = new Stock {
                Identifier = symb, Name = name, Security = security
            };

            return(new StockPrice
            {
                Period = period,
                UpdatedAt = DateTime.UtcNow,
                Stock = stock,
                Price = new Price
                {
                    Bid = decimal.Parse(bid),
                    Offer = decimal.Parse(offer),
                    UpdatedAt = DateTime.Now
                }
            });
        }
示例#7
0
 public void AddATimePeriodParameterWithStartDateAndEndDate(string startDate, string endDate)
 {
     _httpContext.HttpRequestConfiguration.BodyParameters.Add(FhirConst.GetCareRecordParams.kTimePeriod, TimePeriodHelper.GetTimePeriod(startDate, endDate));
 }