public void TypedDoc_2()
        {
            var doc = new Doc1 {
            };                    //nothing is required

            Aver.IsNull(doc.Validate());
        }
        public void TypedDoc_7()
        {
            var doc = new Doc1 {
                Field2 = "a"
            };                            //In list

            Aver.IsNull(doc.Validate());
            doc.Field2 = "ap";
            Aver.IsNull(doc.Validate());
            doc.Field2 = "azz";
            Aver.IsNotNull(doc.Validate());

            doc.Field2 = "b";
            Aver.IsNull(doc.Validate());
            doc.Field2 = "ba";
            Aver.IsNull(doc.Validate());
            doc.Field2 = "bazz";
            Aver.IsNotNull(doc.Validate());

            doc.Field2 = "c";
            Aver.IsNull(doc.Validate());
            doc.Field2 = "ch";
            Aver.IsNull(doc.Validate());

            doc.Field2 = "d";
            Aver.IsNull(doc.Validate());
            doc.Field2 = "dy";
            Aver.IsNull(doc.Validate());
            doc.Field2 = "di";
            Aver.IsNull(doc.Validate());
        }
        public void FullCycle_doc3()
        {
            var comparer = new DocLogicalComparer();

            var d1 = new Doc3
            {
                D1 = new Doc1 {
                    S1 = "asdf"
                },
                D2 = new Doc2()
                {
                    S1 = "in d1", B1 = true, I1 = 1234, DT1 = new DateTime(1980, 09, 15, 0, 0, 0, DateTimeKind.Utc), NI1 = null, NL1 = 9_000_000_000L, S2 = null, NDT1 = null
                }
            };

            var json = d1.ToJson(JsonWritingOptions.PrettyPrintRowsAsMap);

            var d2 = JsonReader.ToDoc <Doc3>(json);

            json.See("JSON");

            var diff = comparer.Compare(d1, d2);

            diff.See();
            Aver.IsTrue(diff.AreSame);
        }
        public void demonstration()
        {
            using (var store = DocumentStore.For(_ =>
            {
                _.Connection(ConnectionSource.ConnectionString);
                _.AutoCreateSchemaObjects = AutoCreate.All;
                _.Listeners.Add(new TimestampListener());
            }))
            {
                var doc1s = new Doc1[] {new Doc1(), new Doc1(), };
                var doc2s = new Doc2[] {new Doc2(), new Doc2(), };
                var doc3s = new Doc3[] {new Doc3(), new Doc3(), };

                using (var session = store.OpenSession())
                {
                    session.Store(doc1s);
                    session.Store(doc2s);
                    session.Store(doc3s);

                    session.SaveChanges();
                }

                doc1s.Each(x => x.Timestamp.ShouldNotBeNull());
                doc2s.Each(x => x.Timestamp.ShouldNotBeNull());
                doc3s.Each(x => x.Timestamp.ShouldNotBeNull());
            }
        }
Example #5
0
        public void Test01_Batch()
        {
            var doc1 = new Doc1 {
                S1 = "shr", S2 = "none", I1 = 120
            };
            var got = doc1.Validate(new ValidState(null, ValidErrorMode.Batch));

            got.See();

            Aver.IsTrue(got.IsAssigned);
            Aver.IsTrue(got.HasErrors);
            Aver.IsFalse(got.NoErrors);
            Aver.AreEqual(3, got.ErrorCount);
            Aver.IsTrue(got.ShouldContinue);
            Aver.IsFalse(got.ShouldStop);
            Aver.IsNotNull(got.Error);

            var batch = got.Error as ValidationBatchException;

            Aver.IsNotNull(batch);
            Aver.IsNotNull(batch.Batch);
            Aver.AreEqual(3, batch.Batch.Count);

            Aver.IsTrue(batch.Batch.OfType <FieldValidationException>().Any(e => e.FieldName == "I1"));
            Aver.IsTrue(batch.Batch.OfType <FieldValidationException>().Any(e => e.FieldName == "S1"));
            Aver.IsTrue(batch.Batch.OfType <FieldValidationException>().Any(e => e.FieldName == "S2"));

            Aver.IsTrue(batch.Batch.Any(e => e.Message.Contains("length of 5")));
            Aver.IsTrue(batch.Batch.Any(e => e.Message.Contains("list of allowed")));
            Aver.IsTrue(batch.Batch.Any(e => e.Message.Contains("max bound")));
        }
Example #6
0
        public void demonstration()
        {
            using (var store = DocumentStore.For(_ =>
            {
                _.DatabaseSchemaName = "setting_timestamp";
                _.Connection(ConnectionSource.ConnectionString);
                _.AutoCreateSchemaObjects = AutoCreate.All;
                _.Listeners.Add(new TimestampListener());
            }))
            {
                var doc1s = new Doc1[] { new Doc1(), new Doc1(), };
                var doc2s = new Doc2[] { new Doc2(), new Doc2(), };
                var doc3s = new Doc3[] { new Doc3(), new Doc3(), };

                using (var session = store.OpenSession())
                {
                    session.Store(doc1s);
                    session.Store(doc2s);
                    session.Store(doc3s);

                    session.SaveChanges();
                }

                doc1s.Each(x => x.Timestamp.ShouldNotBeNull());
                doc2s.Each(x => x.Timestamp.ShouldNotBeNull());
                doc3s.Each(x => x.Timestamp.ShouldNotBeNull());
            }
        }
        public void TypedDoc_3()
        {
            var doc = new Doc1 {
                Field1 = "a"
            };                           //In list

            Aver.IsNull(doc.Validate());
            doc.Field1 = "d";
            Aver.IsNull(doc.Validate());
        }
Example #8
0
        public void FlatTest()
        {
            var d1 = new Doc1 {
                ID = 1234, CustomerName = "Snake Lam"
            };
            var json = d1.Schema.ToJson(JsonWritingOptions.PrettyPrint);

            Console.WriteLine(json);
//todo This needs to be redesigned per Schema JSOn writable re-design
        }
        public void TypedDoc_5()
        {
            var doc = new Doc1 {
                Field3 = "a"
            };                            //In list

            Aver.IsNull(doc.Validate());
            doc.Field3 = "b";
            Aver.IsNull(doc.Validate());
            doc.Field3 = "n";
            Aver.IsNull(doc.Validate());
        }
Example #10
0
        public void TypedDoc_6()
        {
            var doc = new Doc1 {
                Field3 = "I can not be here"
            };                                            //NOT In list
            var ve = doc.Validate() as FieldValidationException;

            Aver.IsNotNull(ve);
            Conout.WriteLine(ve.ToMessageWithType());
            Aver.AreEqual("Field3", ve.FieldName);
            doc.Field3 = "n";//'Nancy' obtained from dynamic imperative call
            Aver.IsNull(doc.Validate());
        }
Example #11
0
        public void TypedDoc_4()
        {
            var doc = new Doc1 {
                Field1 = "Z"
            };                            //NOT In list
            var ve = doc.Validate() as FieldValidationException;

            Aver.IsNotNull(ve);
            Conout.WriteLine(ve.ToMessageWithType());
            Aver.AreEqual("Field1", ve.FieldName);
            doc.Field1 = "c";
            Aver.IsNull(doc.Validate());
        }
Example #12
0
        public void JSON03()
        {
            var d1 = new Doc1 {
                V1 = EntityId.Parse("abc@def::12:15:178"), V2 = EntityId.Parse("lic::i9973od")
            };
            var json = d1.ToJson(JsonWritingOptions.PrettyPrintRowsAsMap);

            json.See();
            var got = JsonReader.ToDoc <Doc1>(json);

            got.See();

            Aver.AreEqual(d1.V1, got.V1);
            Aver.AreEqual(d1.V2, got.V2);
        }
Example #13
0
        public void JSON04()
        {
            var d1 = new Doc1 {
                V1 = EntityId.Parse("abc@def::abc@def::456"), V2 = EntityId.Parse("lic:::::")
            };
            var json = d1.ToJson(JsonWritingOptions.PrettyPrintRowsAsMap);

            json.See();
            var got = JsonReader.ToDoc <Doc1>(json);

            got.See();

            Aver.AreEqual("abc@def::456", got.V1.Address);
            Aver.AreEqual(":::", got.V2.Value.Address);
        }
        public void TwoEmpty()
        {
            var comparer = new DocLogicalComparer();

            var d1 = new Doc1()
            {
            };
            var d2 = new Doc1()
            {
            };

            var diff = comparer.Compare(d1, d2);

            diff.See();
            Aver.IsTrue(diff.AreSame);
            Aver.IsFalse(diff.AreDifferent);
        }
        public void OneField_d2_Different()
        {
            var comparer = new DocLogicalComparer();

            var d1 = new Doc1()
            {
            };
            var d2 = new Doc1()
            {
                S1 = "abc"
            };

            var diff = comparer.Compare(d1, d2);

            diff.See();
            Aver.IsFalse(diff.AreSame);
            Aver.IsTrue(diff.AreDifferent);
        }
Example #16
0
        public void JSON06()
        {
            var d1 = new Doc1 {
                V1 = EntityId.Parse("abc.int@sys1::address1"), V2 = null
            };
            var json = d1.ToJson(JsonWritingOptions.PrettyPrintRowsAsMap);

            json.See();
            var got = JsonReader.ToDoc <Doc1>(json);

            got.See();

            Aver.AreEqual("sys1", got.V1.System.Value);
            Aver.AreEqual("int", got.V1.Schema.Value);
            Aver.AreEqual("address1", got.V1.Address);

            Aver.IsTrue(got.V2 == null);
        }
Example #17
0
        public void Test001()
        {
            var doc = new Doc1 {
                F1 = "one"
            };

            Aver.AreEqual("one+two", doc.F2);

            doc.Schema.See();

            var json = doc.ToJson();

            json.See();

            var doc2 = JsonReader.ToDoc <Doc1>(json);

            doc2.See();
        }
        public void FullCycle_doc1()
        {
            var comparer = new DocLogicalComparer();

            var d1 = new Doc1()
            {
                S1 = "in d1"
            };

            var json = d1.ToJson(JsonWritingOptions.PrettyPrintRowsAsMap);

            var d2 = JsonReader.ToDoc <Doc1>(json);

            d1.See("d1");
            json.See("JSON");
            d2.See("d2");

            var diff = comparer.Compare(d1, d2);

            diff.See();
            Aver.IsTrue(diff.AreSame);
        }
Example #19
0
        public void Test02_Batch()
        {
            var doc1 = new Doc1 {
                S1 = "shr", S2 = "01", I1 = 15
            };
            var got = doc1.Validate(new ValidState(null, ValidErrorMode.Batch));

            got.See();

            Aver.IsTrue(got.IsAssigned);
            Aver.IsTrue(got.HasErrors);
            Aver.IsFalse(got.NoErrors);
            Aver.AreEqual(1, got.ErrorCount);
            Aver.IsTrue(got.ShouldContinue);
            Aver.IsFalse(got.ShouldStop);
            Aver.IsNotNull(got.Error);

            var fve = got.Error as FieldValidationException;

            Aver.IsNotNull(fve);
            Aver.IsTrue(fve.Message.Contains("length of 5"));
        }