Kinetica   C#   API  Version 7.2.3.1
BasicTests.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using Xunit;
4 using Kinetica.Tests.Common;
5 using kinetica;
6 
8 {
13  [Trait("Category", "Integration")]
14  public class BasicTests
15  {
16  [Fact]
17  public void TestHasType()
18  {
19  using var ctx = new TestContext("has_type");
20 
21  // Create a simple type
22  var typeDefinition = @"{
23  ""type"": ""record"",
24  ""name"": ""test_record"",
25  ""fields"": [
26  {""name"": ""id"", ""type"": ""int""},
27  {""name"": ""name"", ""type"": ""string""}
28  ]
29  }";
30 
31  var properties = new Dictionary<string, IList<string>>
32  {
33  { "id", new List<string> { "int", "primary_key" } }
34  };
35 
36  // Create the type
37  var createResponse = ctx.Kinetica.createType(typeDefinition, "test_type", properties, new Dictionary<string, string>());
38  var typeId = createResponse.type_id;
39 
40  // Verify type exists using has_type
41  var hasTypeResponse = ctx.Kinetica.hasType(typeId, new Dictionary<string, string>());
42  Assert.True(hasTypeResponse.type_exists, "Type should exist");
43 
44  // Verify non-existent type returns false
45  var hasTypeResponseNonexistent = ctx.Kinetica.hasType("nonexistent_type_12345", new Dictionary<string, string>());
46  Assert.False(hasTypeResponseNonexistent.type_exists, "Non-existent type should not exist");
47  }
48 
49  [Fact]
50  public void TestHasTable()
51  {
52  using var ctx = new TestContext("has_table");
53 
54  // Create a type
55  var typeDefinition = @"{
56  ""type"": ""record"",
57  ""name"": ""test_record"",
58  ""fields"": [
59  {""name"": ""id"", ""type"": ""int""},
60  {""name"": ""value"", ""type"": ""double""}
61  ]
62  }";
63 
64  var properties = new Dictionary<string, IList<string>>
65  {
66  { "id", new List<string> { "int", "primary_key" } }
67  };
68 
69  var typeResponse = ctx.Kinetica.createType(typeDefinition, "has_table_type", properties, new Dictionary<string, string>());
70 
71  // Create a table
72  var tableName = ctx.QualifiedTable("test_table");
73  ctx.Kinetica.createTable(tableName, typeResponse.type_id, new Dictionary<string, string>());
74 
75  // Verify table exists
76  var hasTableResponse = ctx.Kinetica.hasTable(tableName, new Dictionary<string, string>());
77  Assert.True(hasTableResponse.table_exists, "Table should exist");
78  Assert.Equal(tableName, hasTableResponse.table_name);
79 
80  // Verify non-existent table returns false
81  var nonexistentTable = ctx.QualifiedTable("nonexistent_table");
82  var hasTableResponseNonexistent = ctx.Kinetica.hasTable(nonexistentTable, new Dictionary<string, string>());
83  Assert.False(hasTableResponseNonexistent.table_exists, "Non-existent table should not exist");
84  }
85 
86  [Fact]
88  {
89  using var ctx = new TestContext("create_clear");
90 
91  // Create type
92  var typeDefinition = @"{
93  ""type"": ""record"",
94  ""name"": ""simple_record"",
95  ""fields"": [
96  {""name"": ""id"", ""type"": ""int""}
97  ]
98  }";
99 
100  var properties = new Dictionary<string, IList<string>>
101  {
102  { "id", new List<string> { "int", "primary_key" } }
103  };
104 
105  var typeResponse = ctx.Kinetica.createType(typeDefinition, "simple_type", properties, new Dictionary<string, string>());
106 
107  // Create table
108  var tableName = ctx.QualifiedTable("simple_table");
109  var createTableResponse = ctx.Kinetica.createTable(tableName, typeResponse.type_id, new Dictionary<string, string>());
110  Assert.Equal(tableName, createTableResponse.table_name);
111 
112  // Verify table exists
113  var hasTableResponse = ctx.Kinetica.hasTable(tableName, new Dictionary<string, string>());
114  Assert.True(hasTableResponse.table_exists);
115 
116  // Clear table
117  var clearResponse = ctx.Kinetica.clearTable(tableName, null, new Dictionary<string, string>());
118  Assert.Equal(tableName, clearResponse.table_name);
119 
120  // Table should no longer exist after clear
121  var hasTableResponseAfter = ctx.Kinetica.hasTable(tableName, new Dictionary<string, string>());
122  Assert.False(hasTableResponseAfter.table_exists, "Table should not exist after clear");
123  }
124 
125  [Fact]
126  public void TestSchemaIsolation()
127  {
128  // Verify that schemas don't interfere with each other
129  using var ctx1 = new TestContext("isolation_1");
130  using var ctx2 = new TestContext("isolation_2");
131 
132  Assert.NotEqual(ctx1.SchemaName, ctx2.SchemaName);
133  }
134 
135  [Fact]
136  public void TestContextCreation()
137  {
138  using var ctx = new TestContext("context_test");
139  Assert.Equal("test_context_test", ctx.SchemaName);
140  Assert.Equal("test_context_test.my_table", ctx.QualifiedTable("my_table"));
141  }
142  }
143 }
Basic integration tests for core API functionality.
Definition: BasicTests.cs:14
Test context that manages schema and cleanup for integration tests.
Definition: TestContext.cs:11