示例#1
0
        public void Parse_EqualsExpectedResult(QuarterTestItem <string> quarterTestItem)
        {
            var quarterFromText = Quarter.Parse(quarterTestItem.ExpectedResult); // TODO bad use of Expected result?
            var expectedQuarter = quarterTestItem.Create();

            Assert.AreEqual(expectedQuarter, quarterFromText);
        }
示例#2
0
 public void TestGetQuarterByTestApiKeyDenied()
 {
     // テスト用のAPIキーではゼロイチ銘柄のみデータを取得できる
     var client   = new BuffettCodeClientV2();
     var json     = client.GetQuarter(BuffettCodeTestUtils.GetTestApiKey(), "6502", "2018", "4").Result;
     var quarters = Quarter.Parse("6502", json);
 }
示例#3
0
        public void TestGetQuarter()
        {
            var client   = new BuffettCodeClientV1();
            var json     = client.GetQuarter(BuffettCodeTestUtils.GetValidApiKey(), "6501", "2018", "4").Result;
            var quarters = Quarter.Parse("6501", json);

            Assert.IsFalse(quarters.Count == 0);
            Assert.AreEqual("6501", quarters[0].Ticker);
            Assert.IsNotNull(quarters[0].GetValue("assets")); // 値は変わりうるのでNullかどうかだけチェック
            Assert.IsNull(quarters[0].GetDescription("assets"));
        }
        public void TestGetPropertyNames()
        {
            var json          = File.ReadAllText(@"data\quarter.json");
            var quarters      = Quarter.Parse("2371", json);
            var propertyNames = CSVGenerator.GetPropertyNames(quarters[0]);

            var actual   = string.Join(",", propertyNames);
            var expected = File.ReadAllText(@"data\propertyNames.txt");

            Assert.IsTrue(propertyNames.Count == 77);
            Assert.AreEqual(actual, expected);
        }
        public void TestGenerateAndWrite()
        {
            var json     = File.ReadAllText(@"data\quarter.json");
            var quarters = Quarter.Parse("2371", json);

            using (var stream = new MemoryStream())
            {
                CSVGenerator.GenerateAndWrite(stream, Encoding.UTF8, quarters);
                var actual   = Encoding.UTF8.GetString(stream.ToArray());
                var expected = File.ReadAllText(@"data\csv.txt");
                Assert.AreEqual(actual, expected);
            }
        }
        private IList <Quarter> GetSortedQuarters(string ticker, string from, string to)
        {
            var client   = new BuffettCodeClientV2();
            var quarters = new List <Quarter>();

            foreach (KeyValuePair <string, string> range in SliceRange(from, to))
            {
                Task <string> task = client.GetQuarterRange(apiKey, ticker, range.Key, range.Value, false);
                string        json = task.Result;
                quarters.AddRange(Quarter.Parse(ticker, json));
            }

            var distinct = new List <Quarter>(quarters).Distinct(new IPropertyAggregationComparer()).Cast <Quarter>();
            var sorted   = new List <Quarter>(distinct);

            sorted.Sort((left, right) => { return(left.GetIdentifier().CompareTo(right.GetIdentifier())); });
            return(sorted);
        }
示例#7
0
 public void Parse_WithInvalidText_ThrowsArgumentException(string text)
 {
     Assert.Throws(Is.TypeOf <FormatException>().And
                   .Message.EqualTo($"The string '{text}' was not recognized as a valid Quarter."), () => Quarter.Parse(text));
 }