-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTestDatabase.cs
41 lines (36 loc) · 1.39 KB
/
TestDatabase.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using CuriousGremlin.AzureCosmosDB;
using CuriousGremlin;
using CuriousGremlin.Client;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace CuriousGremlin.UnitTests
{
public class TestDatabase : CosmosDBGraphClient, IDisposable
{
public static readonly string db_name = "test_db";
public TestDatabase(string endpoint, string authKey) : base(endpoint, authKey) { }
private string collection;
public static TestDatabase GetClient(string collection)
{
TestDatabase client = new TestDatabase("https://localhost:8081/",
"C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==");
client.CreateDatabaseIfNotExistsAsync(db_name).Wait();
client.collection = collection;
client.CreateDocumentCollectionIfNotExistsAsync(db_name, collection).Wait();
client.Open(db_name, collection).Wait();
var query = VertexQuery.All().Drop();
client.Execute(query).Wait();
return client;
}
public override void Dispose()
{
var query = VertexQuery.All().Drop();
this.Execute(query).Wait();
this.DeleteCollectionAsync(db_name, collection).Wait();
base.Dispose();
}
}
}