Пример #1
0
        /// <summary>
        /// Method of generically converting datatable to 
        /// </summary>
        /// <param name="dataTable"></param>
        /// <returns></returns>
        public static GeckoDataset ConvertToDataset(this DataTable dataTable)
        {
            var retVal = new GeckoDataset();

            var fields = new Dictionary<string, IDatasetField>();
            foreach (DataColumn dataTableColumn in dataTable.Columns)
            {
                fields.Add(dataTableColumn.ColumnName.ToLowerInvariant(), new DatasetField(GetDatasetFieldType(dataTableColumn.DataType), dataTableColumn.ColumnName));
            }
            retVal.Fields = fields;

            List<Dictionary<string, object>> data = new List<Dictionary<string, object>>();
            foreach (DataRow dataTableRow in dataTable.Rows)
            {
                Dictionary<string, object> rowData = new Dictionary<string, object>();
                for (int i = 0; i < dataTable.Columns.Count; i++)
                {
                    var dataToInsert = dataTableRow[dataTable.Columns[i]];
                    rowData.Add(dataTable.Columns[i].ColumnName.ToLowerInvariant(), dataToInsert);
                }
                data.Add(rowData);
            }
            retVal.Data = data;

            return retVal;
        }
Пример #2
0
        public void Live_Create_Dataset()
        {
            // Arrange
            var client = new GeckoConnect();
            var obj = new GeckoDataset()
            {
                Fields = new Dictionary<string, IDatasetField>()
                {
                    {"amount", new DatasetField(DatasetFieldType.number, "Amount")},
                    {"timestamp", new DatasetField(DatasetFieldType.datetime, "Date")}
                },
                UniqueBy = new List<string>() { "timestamp" }
            };
            var datasetName = $"test_{Guid.NewGuid().ToString()}";

            // Act
            Assert.AreNotEqual("<api key here>", this.apiKey);
            var result = client.CreateDataset(obj, datasetName, this.apiKey);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(datasetName, result.Id);
            Assert.IsTrue(DateTime.Now > result.CreatedAt);
            Assert.IsTrue(DateTime.Now > result.UpdatedAt);

            client.DeleteDataset(datasetName, this.apiKey);
        }
Пример #3
0
        public void Can_Serialize_Dataset()
        {
            var obj = new GeckoDataset()
            {
                Fields = new Dictionary<string, IDatasetField>()
                {
                    {"amount", new DatasetField(DatasetFieldType.number, "Amount")},
                    {"timestamp", new DatasetField(DatasetFieldType.datetime, "Date")}
                },
                UniqueBy = new List<string>() { "timestamp" }
            };

            // Act
            var result = JsonConvert.SerializeObject(obj, Formatting.Indented);

            // Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(!string.IsNullOrWhiteSpace(result));
        }
Пример #4
0
        public void Live_Replace_Data_In_Dataset()
        {
            // Arrange
            var client = new GeckoConnect();
            var obj = new GeckoDataset()
            {
                Data = new List<Dictionary<string, object>>()
                {
                    new Dictionary<string, object>()
                    {
                        { "timestamp", "2016-01-01T12:00:00Z" },
                        { "amount", 819 }
                    },
                    new Dictionary<string, object>()
                    {
                        { "timestamp", "2016-01-02T12:00:00Z" },
                        { "amount", 409 }
                    },
                    new Dictionary<string, object>()
                    {
                        { "timestamp", "2016-01-03T12:00:00Z" },
                        { "amount", 164 }
                    }
                }
            };
            var datasetName = "test";

            // Act
            Assert.AreNotEqual("<api key here>", this.apiKey);
            var result = client.UpdateDataset(obj, datasetName, this.apiKey);

            // Assert
            Assert.IsNotNull(result);
        }