Skip to content
This repository has been archived by the owner on Dec 18, 2023. It is now read-only.

Added Relate and Graph Semantics tests #83

Merged
merged 3 commits into from
Oct 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions tests/Driver.Tests/Queries/QueryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,38 @@ public async Task SimpleSelectFromWhereValueQueryTest(TKey key, TValue value) =>
}
);

[Theory]
[MemberData("KeyAndValuePairs")]
public async Task SimpleRelateAndGraphSemanticsQueryTest(TKey key, TValue value) => await DbHandle<T>.WithDatabase(
async db => {
TestObject<TKey, TValue> expectedObject = new(key, value);

Thing thing1 = Thing.From("object1", expectedObject.Key!.ToString());
await db.Create(thing1, expectedObject);

Thing thing2 = Thing.From("object2", expectedObject.Key!.ToString());
await db.Create(thing2, expectedObject);

var relateSql = "RELATE ($thing1)->hasOtherThing->($thing2)";
var vars = new Dictionary<string, object>
{
{"thing1", thing1},
{"thing2", thing2},
};
var relateResponse = await db.Query(relateSql, vars);
Assert.NotNull(relateResponse);
TestHelper.AssertOk(relateResponse);

var thing2Sql = "SELECT ->hasOtherThing->object2.* AS field FROM $thing1";
var thing2Response = await db.Query(thing2Sql, vars);
Assert.NotNull(thing2Response);
TestHelper.AssertOk(thing2Response);
Assert.True(thing2Response.TryGetResult(out Result thing2Result));
Field<TestObject<TKey, TValue>>? thing2Doc = thing2Result.GetObject<Field<TestObject<TKey, TValue>>>();
thing2Doc.field.First().Should().BeEquivalentTo(expectedObject);
}
);

[DebuggerStepThrough]
protected static string Serialize<V>(in V value) {
return JsonSerializer.Serialize(value, SerializerOptions.Shared);
Expand Down
14 changes: 12 additions & 2 deletions tests/Shared/TestObjects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,24 @@ public ExtendedTestObject(TKey key, TValue value, TValue mergeValue) : base (key
public TValue MergeValue { get; set; }
}

public record struct IdScopeAuth(
public readonly record struct IdScopeAuth(
string id,
string user,
string pass,
string NS,
string DB,
string SC) : IAuth;

public record struct User(
public readonly record struct User(
string id,
string email);

public class Temperature {
public string location;
public DateTime date;
public float temperature;
}

public class Field<T> {
public List<T> field { get; set; }
}