コード例 #1
0
        private static void SerializationFailureTest_Run(IDbContext context, ref Expr lastQuery)
        {
            var model1 = new UnmappedModel {
                TestString = "test"
            };

            Assert.Throws <InvalidMappingException>(() => context.ToFaunaObj(model1));
            Assert.Throws <InvalidMappingException>(() => context.Decode(JObject.Parse(JsonConvert.SerializeObject(model1)), model1.GetType()));

            var model2 = new ReferenceModel {
                Indexed1 = null, Indexed2 = "test"
            };
            var manual2 = Obj("indexed1", null, "indexed2", "test");

            Assert.Equal(JsonConvert.SerializeObject(manual2), JsonConvert.SerializeObject(context.ToFaunaObj(model2)));

            var model3 = new ModelWithUnmappedReference {
                Model = new UnmappedModel()
            };

            Assert.Throws <InvalidMappingException>(() => context.ToFaunaObj(model3));

            Assert.Throws <JsonSerializationException>(() => context.Decode(JObject.Parse("{\"data\": {custom_collection: [null, null, null]}}"), typeof(UnsupportedCustomCollectionModel)));
            Assert.Throws <InvalidMappingException>(() => context.Decode(JObject.Parse("{\"data\": {custom_collection: [null, null, null]}}"), typeof(UnsupportedCustomCollectionModel2)));
            Assert.Throws <InvalidMappingException>(() => context.Decode(JObject.Parse("{\"data\": {custom_collection: [null, null, null]}}"), typeof(UnsupportedCustomCollectionModel3)));
        }
コード例 #2
0
        private static void TestQuery_Run(IDbContext context, ref Expr lastQuery)
        {
            var query  = context.Query <ReferenceModel>(a => a.Indexed1 == "test1");
            var result = query.Provider.Execute <ReferenceModel>(query.Expression);
            var model  = new ReferenceModel {
                Indexed1 = "test1", Indexed2 = "test2"
            };                                                                         // Indexed1: name attr "indexed1" | Indexed2: default name

            Assert.Equal(model, result);
        }
コード例 #3
0
        private void SimpleDecodeTest_Run(IDbContext context, ref Expr lastQuery)
        {
            var model = new ReferenceModel {
                Indexed1 = "test1", Indexed2 = "test2"
            };

            var result = context.Get <ReferenceModel>("testRef").Result;

            Assert.Equal(model, result);
        }
コード例 #4
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = (Id != null ? Id.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (ReferenceModel != null ? ReferenceModel.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (ReferenceModels1 != null ? ReferenceModels1.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (ReferenceModels2 != null ? ReferenceModels2.GetHashCode() : 0);
         return(hashCode);
     }
 }
コード例 #5
0
        private static void DeleteTest_Run(IDbContext client, ref Expr lastQuery)
        {
            var model = new ReferenceModel {
                Id = "testId", Indexed1 = "test1", Indexed2 = "test2"
            };
            var q = client.Delete(model);

            var manual = Delete(Ref(model.Id));

            Assert.Equal(JsonConvert.SerializeObject(lastQuery), JsonConvert.SerializeObject(manual));
        }
コード例 #6
0
        private static void CreateTest_Run(IDbContext client, ref Expr lastQuery)
        {
            var model = new ReferenceModel {
                Indexed1 = "test1", Indexed2 = "test2"
            };
            var q = client.Create(model).Result;

            var manual = Create(Class("reference_model"), Obj("data", Obj("indexed1", "test1", "indexed2", "test2")));

            Assert.Equal(JsonConvert.SerializeObject(lastQuery), JsonConvert.SerializeObject(manual));
        }
コード例 #7
0
        private static void BasicReferenceTypeSerializationTest_Run(IDbContext context, ref Expr lastQuery)
        {
            var model = new ReferenceModel {
                Indexed1 = "test1", Indexed2 = "test2"
            };                                                                         // Indexed1: name attr "indexed1" | Indexed2: default name

            var manual = Obj("indexed1", "test1", "indexed2", "test2");

            var auto = context.ToFaunaObj(model);

            Assert.Equal(JsonConvert.SerializeObject(manual), JsonConvert.SerializeObject(auto));
        }
コード例 #8
0
        private static void UpsertTest_Run(IDbContext client, ref Expr lastQuery)
        {
            var model = new ReferenceModel {
                Id = "testId", Indexed1 = "test1", Indexed2 = "test2"
            };
            var q = client.Upsert(model);

            var manual = If(Exists(Ref(model.Id)), Update(Ref(model.Id), Obj("indexed1", "test1", "indexed2", "test2")),
                            Create(Class("reference_model"), Obj("indexed1", "test1", "indexed2", "test2")));

            Assert.Equal(JsonConvert.SerializeObject(lastQuery), JsonConvert.SerializeObject(manual));
        }
コード例 #9
0
        private static void UpsertCompositeIndexWithArgsTest_Run(IDbContext client, ref Expr lastQuery)
        {
            var model = new ReferenceModel {
                Indexed1 = "test1", Indexed2 = "test2"
            };
            var q = client.Upsert(model, a => a.CompositeIndex, "test1", "test2");

            var obj       = Obj("indexed1", "test1", "indexed2", "test2");
            var matchExpr = Match(Index("composite_index"), "test1", "test2");
            var manual    = If(Exists(matchExpr), Map(matchExpr, Lambda("arg0", Update(Var("arg0"), obj))), Create(Class("reference_model"), obj));

            Assert.Equal(JsonConvert.SerializeObject(lastQuery), JsonConvert.SerializeObject(manual));
        }
コード例 #10
0
 protected bool Equals(ReferenceModel other)
 {
     return(string.Equals(Indexed1, other.Indexed1) && string.Equals(Indexed2, other.Indexed2));
 }