[Test] public async Task TestAuthenticateSession() { Value createdInstance = await client.Query( Create(await RandomClass(), Obj("credentials", Obj("password", "abcdefg"))) ); Value auth = await client.Query( Login( createdInstance.Get(REF_FIELD), Obj("password", "abcdefg")) ); FaunaClient sessionClient = GetClient(secret: auth.Get(SECRET_FIELD)); Value loggedOut = await sessionClient.Query(Logout(true)); Assert.AreEqual(true, loggedOut.To <bool>().Value); Value identified = await client.Query( Identify(createdInstance.Get(REF_FIELD), "wrong-password") ); Assert.AreEqual(false, identified.To <bool>().Value); }
public async Task TestCreateAComplexInstance() { Value instance = await client.Query( Create(await RandomClass(), Obj("data", Obj("testField", Obj( "array", Arr(1, "2", 3.4, Obj("name", "JR")), "bool", true, "num", 1234, "string", "sup", "float", 1.234) )))); Value testField = instance.Get(DATA).At("testField"); Assert.AreEqual("sup", testField.At("string").To <string>().Value); Assert.AreEqual(1234L, testField.At("num").To <long>().Value); Assert.AreEqual(true, testField.At("bool").To <bool>().Value); Assert.AreEqual(None(), testField.At("bool").To <string>().ToOption); Assert.AreEqual(None(), testField.At("credentials").To <Value>().ToOption); Assert.AreEqual(None(), testField.At("credentials", "password").To <string>().ToOption); Value array = testField.At("array"); Assert.AreEqual(4, array.To <Value[]>().Value.Length); Assert.AreEqual(1L, array.At(0).To <long>().Value); Assert.AreEqual("2", array.At(1).To <string>().Value); Assert.AreEqual(3.4, array.At(2).To <double>().Value); Assert.AreEqual("JR", array.At(3).At("name").To <string>().Value); Assert.AreEqual(None(), array.At(4).To <Value>().ToOption); }
[Test] public async Task TestEvalIfExpression() { Value res = await client.Query( If(true, "was true", "was false") ); Assert.AreEqual("was true", res.To <string>().Value); }
[Test] public async Task TestDealWithSetRef() { Value res = await client.Query( Match(Index("spells_by_element"), "arcane")); IReadOnlyDictionary <string, Value> set = res.To <SetRefV>().Value.Value; Assert.AreEqual("arcane", set["terms"].To <string>().Value); Assert.AreEqual(new IndexV("spells_by_element"), set["match"].To <RefV>().Value); }
[Test] public async Task TestEvalSelectExpression() { Value selected = await client.Query( Select( Path("favorites", "foods").At(1), Obj("favorites", Obj("foods", Arr("crunchings", "munchings", "lunchings"))) ) ); Assert.AreEqual("munchings", selected.To <string>().Value); }
[Test] public async Task TestEvalConcatExpression() { Value simpleConcat = await client.Query(Concat(Arr("Magic", "Missile"))); Assert.AreEqual("MagicMissile", simpleConcat.To <string>().Value); Value concatWithSeparator = await client.Query( Concat(Arr("Magic", "Missile"), " ") ); Assert.AreEqual("Magic Missile", concatWithSeparator.To <string>().Value); }
[Test] public async Task TestDeleteAnInstance() { Value createdInstance = await client.Query( Create(await RandomClass(), Obj("data", Obj("name", "Magic Missile")))); Value @ref = createdInstance.Get(REF_FIELD); await client.Query(Delete(@ref)); Value exists = await client.Query(Exists(@ref)); Assert.AreEqual(false, exists.To <bool>().Value); var ex = Assert.ThrowsAsync <NotFound>(async() => await client.Query(Get(@ref))); AssertErrors(ex, code: "instance not found", description: "Instance not found."); AssertEmptyFailures(ex); AssertPosition(ex, positions: Is.EquivalentTo(new List <string> { })); }
[Test] public async Task TestEvalDateExpression() { Value res = await client.Query(Date("1970-01-02")); Assert.AreEqual(new DateTime(1970, 1, 2), res.To <DateTime>().Value); }
[Test] public async Task TestEvalTimeExpression() { Value res = await client.Query(Time("1970-01-01T00:00:00-04:00")); Assert.AreEqual(new DateTime(1970, 1, 1, 4, 0, 0), res.To <DateTime>().Value); }
[Test] public async Task TestEvalNotExpression() { Value notR = await client.Query(Not(false)); Assert.AreEqual(true, notR.To <bool>().Value); }
[Test] public async Task TestEvalOrExpression() { Value res = await client.Query(Or(true, false)); Assert.AreEqual(true, res.To <bool>().Value); }
[Test] public async Task TestEvalModuloExpression() { Value res = await client.Query(Modulo(101, 10)); Assert.AreEqual(1L, res.To <long>().Value); }
[Test] public async Task TestEvalDivideExpression() { Value res = await client.Query(Divide(100, 10)); Assert.AreEqual(10L, res.To <long>().Value); }
[Test] public async Task TestEvalGTExpression() { Value res = await client.Query(GTE(Arr(3, 2, 2))); Assert.AreEqual(true, res.To <bool>().Value); }
[Test] public async Task TestEvalCasefoldExpression() { Value res = await client.Query(Casefold("Hen Wen")); Assert.AreEqual("hen wen", res.To <string>().Value); }
[Test] public async Task TestEvalEqualsExpression() { Value equals = await client.Query(EqualsFn("fire", "fire")); Assert.AreEqual(true, equals.To <bool>().Value); }
[Test] public async Task TestGetNextId() { Value res = await client.Query(NextId()); Assert.IsNotNull(res.To <string>().Value); }
[Test] public async Task TestEvalMultiplyExpression() { Value res = await client.Query(Multiply(100, 10)); Assert.AreEqual(1000L, res.To <long>().Value); }
[Test] public async Task TestEvalSubtractExpression() { Value res = await client.Query(Subtract(100, 10)); Assert.AreEqual(90L, res.To <long>().Value); }