Kinetica   C#   API  Version 7.2.3.1
AsyncTypeManagementTests.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.Threading.Tasks;
4 using Xunit;
6 using kinetica;
7 
9 {
14  [Trait("Category", "Integration")]
15  [Trait("Category", "Async")]
17  {
18  [Fact]
19  public async Task TestCreateTypeBasicAsync()
20  {
21  using var ctx = new TestContext("async_type_basic");
22 
23  var typeDef = @"{""type"":""record"",""name"":""simple"",""fields"":[{""name"":""id"",""type"":""int""},{""name"":""name"",""type"":""string""}]}";
24 
25  var resp = await ctx.Kinetica.CreateTypeAsync(typeDef, "simple_type", new Dictionary<string, IList<string>>(), new Dictionary<string, string>());
26 
27  Assert.False(string.IsNullOrEmpty(resp.type_id));
28  Assert.Equal("simple_type", resp.label);
29  }
30 
31  [Fact]
33  {
34  using var ctx = new TestContext("async_type_pk");
35 
36  var typeDef = @"{""type"":""record"",""name"":""pk_type"",""fields"":[{""name"":""id"",""type"":""int""},{""name"":""value"",""type"":""double""}]}";
37 
38  var properties = new Dictionary<string, IList<string>>
39  {
40  { "id", new List<string> { "int", "primary_key" } }
41  };
42 
43  var resp = await ctx.Kinetica.CreateTypeAsync(typeDef, "pk_type", properties, new Dictionary<string, string>());
44 
45  Assert.False(string.IsNullOrEmpty(resp.type_id));
46  }
47 
48  [Fact]
50  {
51  using var ctx = new TestContext("async_type_props");
52 
53  var typeDef = @"{""type"":""record"",""name"":""multi_props"",""fields"":[{""name"":""id"",""type"":""int""},{""name"":""x"",""type"":""double""},{""name"":""name"",""type"":""string""}]}";
54 
55  var properties = new Dictionary<string, IList<string>>
56  {
57  { "id", new List<string> { "int", "primary_key" } },
58  { "x", new List<string> { "data" } },
59  { "name", new List<string> { "char32" } }
60  };
61 
62  var resp = await ctx.Kinetica.CreateTypeAsync(typeDef, "multi_prop_type", properties, new Dictionary<string, string>());
63 
64  Assert.False(string.IsNullOrEmpty(resp.type_id));
65  }
66 
67  [Fact]
69  {
70  using var ctx = new TestContext("async_type_complex");
71 
72  var typeDef = @"{""type"":""record"",""name"":""complex_type"",""fields"":[{""name"":""id"",""type"":""int""},{""name"":""timestamp"",""type"":""long""},{""name"":""value"",""type"":""double""},{""name"":""name"",""type"":""string""},{""name"":""active"",""type"":""int""},{""name"":""score"",""type"":""float""}]}";
73 
74  var properties = new Dictionary<string, IList<string>>
75  {
76  { "id", new List<string> { "int", "primary_key" } }
77  };
78 
79  var resp = await ctx.Kinetica.CreateTypeAsync(typeDef, "complex_type", properties, new Dictionary<string, string>());
80 
81  Assert.False(string.IsNullOrEmpty(resp.type_id));
82  }
83 
84  [Fact]
85  public async Task TestHasTypeExistsAsync()
86  {
87  using var ctx = new TestContext("async_has_type_exists");
88 
89  // Create a type first
90  var typeDef = @"{""type"":""record"",""name"":""test"",""fields"":[{""name"":""id"",""type"":""int""}]}";
91  var createResp = await ctx.Kinetica.CreateTypeAsync(typeDef, "test_type", new Dictionary<string, IList<string>>(), new Dictionary<string, string>());
92 
93  // Check it exists
94  var hasResp = await ctx.Kinetica.HasTypeAsync(createResp.type_id, new Dictionary<string, string>());
95 
96  Assert.True(hasResp.type_exists);
97  }
98 
99  [Fact]
100  public async Task TestHasTypeNotExistsAsync()
101  {
102  using var ctx = new TestContext("async_has_type_not");
103 
104  var hasResp = await ctx.Kinetica.HasTypeAsync("nonexistent_type_async_12345", new Dictionary<string, string>());
105 
106  Assert.False(hasResp.type_exists);
107  }
108 
109  [Fact]
111  {
112  using var ctx = new TestContext("async_type_string");
113 
114  // Simple type with string field (strings are nullable by default in Kinetica)
115  var typeDef = @"{""type"":""record"",""name"":""string_type"",""fields"":[{""name"":""id"",""type"":""int""},{""name"":""name"",""type"":""string""}]}";
116 
117  var resp = await ctx.Kinetica.CreateTypeAsync(typeDef, "string_type", new Dictionary<string, IList<string>>(), new Dictionary<string, string>());
118 
119  Assert.False(string.IsNullOrEmpty(resp.type_id));
120  }
121  }
122 }
Async tests for type management endpoints (create_type, has_type).
Test context that manages schema and cleanup for integration tests.
Definition: TestContext.cs:11