Esempio n. 1
0
        public void Test1()
        {
            var original = (DataItem) new JsonParser().FromJson(json1);
            var parsed   = DataItem.FromJson(json1);

            parsed.ToJson().ShouldBe(original.ToJson());
        }
Esempio n. 2
0
        public void TestNewLine()
        {
            var di = new DataItem();

            di.Set("x", "a\r\nB");
            var j = di.ToJson();

            j.ShouldContain("\"x\":\"a\\r\\nB\"");
            di = DataItem.FromJson(j);
            di["x"].Text.ShouldBe("a\r\nB");
        }
Esempio n. 3
0
        public void TestBool()
        {
            var di = new DataItem();

            di.Set("x", false);
            di.Set("y", true);
            var x = di.ToJson();

            x.ShouldContain("\"x\":false");
            var z = DataItem.FromJson(x);

            di["x"].Bool.ShouldBe(false);
            di["y"].Bool.ShouldBe(true);
        }
Esempio n. 4
0
        public void TestReadTheString()
        {
            var x  = @"{
""id"": 1,
""productName"": ""Chai123"",
""supplierID"": 1,
""categoryID"": 1,
""quantityPerUnit"": ""10 boxes x 20 bags"",
""unitPrice"": 18,
""unitsInStock"": 39,
""unitsOnOrder"": 0,
""reorderLevel"": 10,
""discontinued"": ""False""
}";
            var it = DataItem.FromJson(x);

            it["id"].Number.ShouldBe(1);
        }
Esempio n. 5
0
        // Precondition: Categories haveb been added to database, with Misc set as 38
        // Query: http://services.runescape.com/m=itemdb_rs/api/catalogue/detail.json?item=21787
        public async Task <IActionResult> UpdateItem()
        {
            // Get item IDs from static file
            string        rs3itemjson    = System.IO.File.ReadAllText(@"..\investrs\wwwroot\data\items_rs3.json");                              // Items from static list (may need to be updated)
            List <string> itemListString = DataRs3Item.FromJson(rs3itemjson).Where(x => x.Value.Tradeable == true).Select(x => x.Key).ToList(); // tradeable items
            List <int>    itemListIDs    = new List <int>();

            foreach (string i in itemListString)
            {
                itemListIDs.Add(Convert.ToInt32(i));
            }
            // -------

            client.BaseAddress = new Uri("http://services.runescape.com/m=itemdb_rs/api/"); // API Address
            int itemsAddedCounter = 0;                                                      // Number of items added

            // TODO: Check if GE version is current version
            foreach (int itemID in itemListIDs)
            {
                try
                {
                    // To do: Wait here
                    Thread.Sleep(5001);

                    // Query API with itemID
                    var response = await client.GetAsync("catalogue/detail.json?item=" + itemID.ToString()); // Query string

                    response.EnsureSuccessStatusCode();                                                      // Ensure successful response
                    var stringResult = await response.Content.ReadAsStringAsync();                           // Get string from JSON returned

                    DataItem result = DataItem.FromJson(stringResult);                                       // Deserialize JSON string to DataItem object

                    // Create Item class object from JSON
                    Item newItem = new Item()
                    {
                        ApiID         = Convert.ToInt32(result.Item.Id),
                        Description   = result.Item.Description,
                        Icon          = result.Item.Icon,
                        IconLarge     = result.Item.IconLarge,
                        Name          = result.Item.Name,
                        IsMembersItem = bool.Parse(result.Item.Members),
                        CategoryID    = db.Category.Where(x => x.Name == result.Item.Type).FirstOrDefault().Number,
                    };
                    // Check if item exists in database
                    IEnumerable <Item> currentItems = db.Item;                      // Get items in db
                    if (!currentItems.Select(x => x.ApiID).Contains(newItem.ApiID)) // See if newItemID exists
                    {
                        // Add item to database
                        // Validate
                        if (newItem.CategoryID == 0) // Check if the new item is of category "Misc", which has an API ID of 0, but is stored as 38 in this database
                        {
                            newItem.CategoryID = 38; // Chaneg Category ID to 38
                        }
                        // Add
                        db.Item.Add(newItem);
                        db.SaveChanges();

                        itemsAddedCounter++;
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
            ViewBag.DataUpdateItemListCounter = itemsAddedCounter;
            return(View());
        }
Esempio n. 6
0
        public void Test2()
        {
            var parsed = DataItem.FromJson(json);

            parsed.Get("mail").ToString().ShouldBe("*****@*****.**");
        }