//[Fact] public async Task Describe_schema() { HDBClient client = new HDBClient(); // Dictionary<string, string> jsonBody = new Dictionary<string, string>(); // jsonBody.Add("operation", @""); // jsonBody.Add("sql", @"{select * from mycos.employees where id = '69c185dc-2392-45ab-b758-f7c51d1f3338'}"); string query = @"{ ""operation"":""describe_schema"",""schema"":""northnwd"" }"; Console.Out.WriteLine("Request: " + query); var response = await client.PostAsync(HDBConfig.HDBServer, new StringContent(query, Encoding.UTF8, "application/json")); response.EnsureSuccessStatusCode(); var content = await response.Content.ReadAsStringAsync(); dynamic schema = JsonConvert.DeserializeObject(content); Console.Out.WriteLine("Response: " + schema); // Assert.True(schema.) //Assert.NotNull(content); // Assert.False(content.Contains("Invalid")); // Assert.Equal("Test response", content); // Assert.False(response.Headers.Contains("Server"), "Should not contain server header"); }
//[Fact] public async Task CreateSchemaAndTable() { HDBClient client = new HDBClient(); string query = @"{ ""operation"":""create_schema"", ""schema"": ""sql"" }"; Console.Out.WriteLine("Request: " + query); var result = await client.PostAsync(HDBConfig.HDBServer, new StringContent(query, Encoding.UTF8, "application/json")); String responseContent = await result.Content.ReadAsStringAsync(); dynamic responseJson = JsonConvert.DeserializeObject(responseContent); Console.Out.WriteLine("ResponseJson: " + responseJson); if (responseContent.Contains("created")) { string tableQuery = @"{ ""operation"":""create_table"", ""schema"": ""sql"", ""table"":""dog"", ""hash_attribute"":""id"" }"; Console.Out.WriteLine("Request: " + query); var tableResult = await client.PostAsync(HDBConfig.HDBServer, new StringContent(tableQuery, Encoding.UTF8, "application/json")); String tableResponseContent = await tableResult.Content.ReadAsStringAsync(); Console.Out.WriteLine("ResponseJson: " + tableResponseContent); } else { Console.Out.WriteLine("ResponseJson: The schema was created!!!"); } }
//[Fact] public async Task Delete_data() { HDBClient client = new HDBClient(); string query = @"{ ""operation"":""sql"", ""sql"": ""DELETE FROM sql.dog WHERE name = 'Hugo'"" }"; Console.Out.WriteLine("Request: " + query); var result = await client.PostAsync(HDBConfig.HDBServer, new StringContent(query, Encoding.UTF8, "application/json")); String responseContent = await result.Content.ReadAsStringAsync(); dynamic responseJson = JsonConvert.DeserializeObject(responseContent); Console.Out.WriteLine("ResponseJson: " + responseJson); }
//[Fact] public async Task Insert_data() { HDBClient client = new HDBClient(); string query = @"{ ""operation"":""sql"", ""sql"": ""INSERT INTO sql.dog (id, name) VALUES(1, 'Simon')"" }"; Console.Out.WriteLine("Request: " + query); var result = await client.PostAsync(HDBConfig.HDBServer, new StringContent(query, Encoding.UTF8, "application/json")); String responseContent = await result.Content.ReadAsStringAsync(); dynamic responseJson = JsonConvert.DeserializeObject(responseContent); Console.Out.WriteLine("ResponseJson: " + responseJson); }
//[Fact] public async Task Update_Data() { var dir = Directory.GetCurrentDirectory(); dynamic query = JsonConvert.DeserializeObject <dynamic>(File.ReadAllText(dir + Path.DirectorySeparatorChar + @"/tests/schema/dog_update.json")); HDBClient client = new HDBClient(); Console.Out.WriteLine("Request: " + query); var result = await client.PostAsync(HDBConfig.HDBServer, new StringContent(query.ToString(), Encoding.UTF8, "application/json")); String responseContent = await result.Content.ReadAsStringAsync(); dynamic responseJson = JsonConvert.DeserializeObject(responseContent); Console.Out.WriteLine("ResponseJson: " + responseJson); //Assert.Equal("Item not found!", responseJson.error); }
//[Fact] public async Task Describe_table() { HDBClient client = new HDBClient(); string query = @"{ ""operation"":""describe_table"", ""table"":""dog"",""schema"": ""root"" }"; Console.Out.WriteLine("Request: " + query); var result = await client.PostAsync(HDBConfig.HDBServer, new StringContent(query, Encoding.UTF8, "application/json")); String responseContent = await result.Content.ReadAsStringAsync(); dynamic responseJson = JsonConvert.DeserializeObject(responseContent); Console.Out.WriteLine("Response: " + responseJson); //Assert.Equal("Item not found!", responseJson.error); }
public async Task sql(string sql) { HDBClient client = new HDBClient(); sql = "\"" + sql + "\""; string query = @"{""operation"":""sql"",""sql"":" + sql + "}"; Console.Out.WriteLine("Request Body: " + query); var result = await client.PostAsync(HDBConfig.HDBServer, new StringContent(query, Encoding.UTF8, "application/json")); String responseContent = await result.Content.ReadAsStringAsync(); dynamic responseJson = JsonConvert.DeserializeObject(responseContent); Console.Out.WriteLine("ResponseJson: " + responseJson); }
//[Fact] public async Task DropSchemaAndTable() { HDBClient client = new HDBClient(); string query = @"{ ""operation"":""drop_schema"", ""schema"": ""jsonTests"" }"; Console.Out.WriteLine("Request Body: " + query); var result = await client.PostAsync(HDBConfig.HDBServer, new StringContent(query, Encoding.UTF8, "application/json")); String responseContent = await result.Content.ReadAsStringAsync(); dynamic responseJson = JsonConvert.DeserializeObject(responseContent); Console.Out.WriteLine("ResponseJson: " + responseJson); }
//[Fact] public async Task select_data_subdistrict() { HDBClient client = new HDBClient(); string query = @"{""operation"":""sql"",""sql"":""select * from thailand.subdistrict""}"; Console.Out.WriteLine("Request Body: " + query); var result = await client.PostAsync(HDBConfig.HDBServer, new StringContent(query, Encoding.UTF8, "application/json")); String responseContent = await result.Content.ReadAsStringAsync(); dynamic responseJson = JsonConvert.DeserializeObject(responseContent); Console.Out.WriteLine("ResponseJson: " + responseJson); //Assert.Equal("Item not found!", responseJson.error); }
//[Fact] public async Task import_csvdata_customers() { HDBClient client = new HDBClient(); string query = @"{""operation"":""csv_file_load"",""schema"":""northnwd"",""table"":""customers"",""file_path"": ""/home/code/databases/Customers.csv""}"; Console.Out.WriteLine("Request Body: " + query); var result = await client.PostAsync(HDBConfig.HDBServer, new StringContent(query, Encoding.UTF8, "application/json")); String responseContent = await result.Content.ReadAsStringAsync(); dynamic responseJson = JsonConvert.DeserializeObject(responseContent); Console.Out.WriteLine("ResponseJson: " + responseJson); //Assert.Equal("Item not found!", responseJson.error); }
public async Task create_table_customers() { HDBClient client = new HDBClient(); string query = @"{""operation"":""create_table"",""schema"":""northnwd"",""table"":""customers"",""hash_attribute"": ""id""}"; Console.Out.WriteLine("Request Body: " + query); var result = await client.PostAsync(HDBConfig.HDBServer, new StringContent(query, Encoding.UTF8, "application/json")); String responseContent = await result.Content.ReadAsStringAsync(); dynamic responseJson = JsonConvert.DeserializeObject(responseContent); Console.Out.WriteLine("ResponseJson: " + responseJson); //Assert.Equal("Item not found!", responseJson); }
//[Fact] public async Task AddSimpleJson() { CreateSchemaAndTable().Wait(); var dir = Directory.GetCurrentDirectory(); dynamic json = JsonConvert.DeserializeObject <dynamic>(File.ReadAllText(dir + Path.DirectorySeparatorChar + @"basicjson.json")); HDBClient client = new HDBClient(); var response = await client.PostAsync(HDBConfig.HDBServer, new StringContent(json.ToString(), Encoding.UTF8, "application/json")); response.EnsureSuccessStatusCode(); var content = await response.Content.ReadAsStringAsync(); Console.Out.WriteLine(content); DropSchemaAndTable().Wait(); // Assert.Equal("Test response", content); // Assert.False(response.Headers.Contains("Server"), "Should not contain server header"); }