示例#1
0
        public void Validate_Error_ValueList()
        {
            var person = new DynamicDoc(Schema.GetForTypedDoc(typeof(Person)));

            person["ID"]             = "POP1";
            person["FirstName"]      = "Oleg";
            person["LastName"]       = "Popov";
            person["DOB"]            = new DateTime(1981, 2, 12);
            person["YearsInSpace"]   = 45;
            person["Amount"]         = 100;
            person["Description"]    = "0123";
            person["Classification"] = "INVALID";

            var error = person.Validate();

            error?.Message.See();
            Aver.IsTrue(error is FieldValidationException);
            Aver.AreEqual("Classification", ((FieldValidationException)error).FieldName);
            Aver.IsTrue(error.Message.Contains("list of allowed"));

            person["Classification"] = "good";
            Aver.IsNull(person.Validate());
            person["Classification"] = "bad";
            Aver.IsNull(person.Validate());
            person["Classification"] = "ugly";
            Aver.IsNull(person.Validate());
        }
示例#2
0
文件: TestLogic.cs 项目: kozimir/azos
        public static void ASYNC_QueryInsertQuery(ICRUDDataStore store)
        {
            var query = new Query("CRUD.Queries.Patient.List")
            {
                new Query.Param("LN", "%loff")
            };
            var task = store.LoadAsync(query);

            Aver.AreEqual(1, task.Result.Count);
            var rowset = task.Result[0];

            Aver.AreEqual(0, rowset.Count);

            var row = new DynamicDoc(rowset.Schema);

            row["ssn"]        = "999-88-9012";
            row["First_Name"] = "Jack";
            row["Last_Name"]  = "Kozloff";
            row["DOB"]        = new DateTime(1980, 1, 12);

            Aver.IsNull(row.Validate());

            store.InsertAsync(row).Wait();


            task = store.LoadAsync(query);

            Aver.AreEqual(1, task.Result.Count);
            rowset = task.Result[0];

            Aver.AreEqual(1, rowset.Count);
            Aver.AreObjectsEqual("Jack", rowset[0]["First_Name"]);
        }
示例#3
0
        public void Validate_Error_DateTimeMinMax_DifferentTarget()
        {
            var person = new DynamicDoc(Schema.GetForTypedDoc(typeof(Person)));

            person["ID"]           = "POP1";
            person["FirstName"]    = "Oleg";
            person["LastName"]     = "Popov";
            person["DOB"]          = new DateTime(1899, 12, 10);
            person["YearsInSpace"] = 45;
            person["Amount"]       = 100;

            var error = person.Validate("sparta_system");

            Aver.IsNull(error);
        }
示例#4
0
        public void Validate_Error_NullableIntRequired()
        {
            var person = new DynamicDoc(Schema.GetForTypedDoc(typeof(Person)));

            person["ID"]        = "POP1";
            person["FirstName"] = "Oleg";
            person["LastName"]  = "Popov";
            person["DOB"]       = new DateTime(1953, 12, 10);
            // person["YearsInSpace"] = 12;  NOT SET!!!

            var error = person.Validate();

            error?.Message.See();
            Aver.IsTrue(error is FieldValidationException);
            Aver.AreEqual("YearsInSpace", ((FieldValidationException)error).FieldName);
        }
示例#5
0
        public void Validate_Error_StringRequired()
        {
            var person = new DynamicDoc(Schema.GetForTypedDoc(typeof(Person)));

            person["ID"]           = "POP1";
            person["FirstName"]    = "Oleg";
            person["LastName"]     = null;
            person["DOB"]          = new DateTime(1953, 12, 10);
            person["YearsInSpace"] = 12;

            var error = person.Validate();

            Console.WriteLine(error);
            Aver.IsTrue(error is FieldValidationException);
            Aver.AreEqual("LastName", ((FieldValidationException)error).FieldName);
        }
示例#6
0
        public void Validate_Error_DateTimeMinMax_1()
        {
            var person = new DynamicDoc(Schema.GetForTypedDoc(typeof(Person)));

            person["ID"]           = "POP1";
            person["FirstName"]    = "Oleg";
            person["LastName"]     = "Popov";
            person["DOB"]          = new DateTime(1899, 12, 10);
            person["YearsInSpace"] = 45;
            person["Amount"]       = 100;

            var error = person.Validate();

            error?.Message.See();
            Aver.IsTrue(error is FieldValidationException);
            Aver.AreEqual("DOB", ((FieldValidationException)error).FieldName);
            Aver.IsTrue(error.Message.Contains("is below"));
        }
示例#7
0
        public void Validate_Error_DecimalMinMax_2()
        {
            var person = new DynamicDoc(Schema.GetForTypedDoc(typeof(Person)));

            person["ID"]           = "POP1";
            person["FirstName"]    = "Oleg";
            person["LastName"]     = "Popov";
            person["DOB"]          = new DateTime(1953, 12, 10);
            person["YearsInSpace"] = 45;
            person["Amount"]       = 2000000;

            var error = person.Validate();

            Console.WriteLine(error);
            Aver.IsTrue(error is FieldValidationException);
            Aver.AreEqual("Amount", ((FieldValidationException)error).FieldName);
            Aver.IsTrue(error.Message.Contains("is above"));
        }
示例#8
0
        public void Validate_Error_MaxLength()
        {
            var person = new DynamicDoc(Schema.GetForTypedDoc(typeof(Person)));

            person["ID"]           = "POP1";
            person["FirstName"]    = "Oleg";
            person["LastName"]     = "Popov";
            person["DOB"]          = new DateTime(1981, 2, 12);
            person["YearsInSpace"] = 45;
            person["Amount"]       = 100;
            person["Description"]  = "0123456789012345678901234567890";

            var error = person.Validate();

            error?.Message.See();
            Aver.IsTrue(error is FieldValidationException);
            Aver.AreEqual("Description", ((FieldValidationException)error).FieldName);
            Aver.IsTrue(error.Message.Contains("exceeds max length"));
        }
示例#9
0
        public void SetGetAndValidate_NoError()
        {
            var person = new DynamicDoc(Schema.GetForTypedDoc(typeof(Person)));

            person["ID"]           = "POP1";
            person["FirstName"]    = "Oleg";
            person["LastName"]     = "Popov";
            person["DOB"]          = new DateTime(1953, 12, 10);
            person["YearsInSpace"] = 12;

            var error = person.Validate();

            Aver.IsNull(error);

            Aver.AreObjectsEqual("POP1", person["ID"]);
            Aver.AreObjectsEqual("Oleg", person["FirstName"]);
            Aver.AreObjectsEqual("Popov", person["LastName"]);
            Aver.AreObjectsEqual(new DateTime(1953, 12, 10), person["DOB"]);
            Aver.AreObjectsEqual(12, person["YearsInSpace"]);
        }