Пример #1
0
        public void Parse_Filter_LessOrEqualTo()
        {
            Storm storm = new Storm();

            storm.EditSchema(SampleSchema);
            var compiler = new SqlServerCompiler();
            var con      = storm.OpenConnection(new EmptyConnection());

            var cmd1 = con.Get(Model_1)
                       .Where(e => e["data"].LessOrEqualTo.Val("data1"));

            cmd1.ParseSQL();
            SqlResult result1 = compiler.Compile(cmd1.query);
            string    sql1    = result1.Sql;

            // Previusly Calculated check sum integrity
            Assert.Equal("5D7050823EE2EC6956E201D0400DA419", Helpers.Checksum(sql1));

            var cmd2 = con.Get(Model_1)
                       .Where(e => e["data"].LessOrEqualTo.Ref("Child_2.data"));

            cmd2.ParseSQL();
            SqlResult result2 = compiler.Compile(cmd2.query);
            string    sql2    = result2.Sql;

            // Previusly Calculated check sum integrity
            Assert.Equal("05069F883119759EB2718B153F573D1A", Helpers.Checksum(sql2));
        }
Пример #2
0
        public void Parse_Filter_EqualTo()
        {
            Storm storm = new Storm();

            storm.EditSchema(SampleSchema);
            var compiler = new SqlServerCompiler();
            var con      = storm.OpenConnection(new EmptyConnection());

            var cmd1 = con.Get(Model_1)
                       .Where(e => e["data"].EqualTo.Val("data1"));

            cmd1.ParseSQL();
            SqlResult result1 = compiler.Compile(cmd1.query);
            string    sql1    = result1.Sql;

            // Previusly Calculated check sum integrity
            Assert.Equal("4E0A97FDD8410E7E2B981D76CE1FC8C9", Helpers.Checksum(sql1));

            var cmd2 = con.Get(Model_1)
                       .Where(e => e["data"].EqualTo.Ref("Child_2.data"));

            cmd2.ParseSQL();
            SqlResult result2 = compiler.Compile(cmd2.query);
            string    sql2    = result2.Sql;

            // Previusly Calculated check sum integrity
            Assert.Equal("D44B3E75EA1EEAAC343E96981603CD43", Helpers.Checksum(sql2));
        }
Пример #3
0
        public void Parse_Filter_NotLike()
        {
            Storm storm = new Storm();

            storm.EditSchema(SampleSchema);
            var compiler = new SqlServerCompiler();
            var con      = storm.OpenConnection(new EmptyConnection());

            var cmd1 = con.Get(Model_1)
                       .Where(e => e["data"].NotLike.Val("data1"));

            cmd1.ParseSQL();
            SqlResult result1 = compiler.Compile(cmd1.query);
            string    sql1    = result1.Sql;

            // Previusly Calculated check sum integrity
            Assert.Equal("40DD56CBBD7FB9B8F6B8475CC9FECB26", Helpers.Checksum(sql1));

            var cmd2 = con.Get(Model_1)
                       .Where(e => e["data"].NotLike.Ref("Child_2.data"));

            cmd2.ParseSQL();
            SqlResult result2 = compiler.Compile(cmd2.query);
            string    sql2    = result2.Sql;

            // Previusly Calculated check sum integrity
            Assert.Equal("33D480C67D31B5769AA65E4CA87403C2", Helpers.Checksum(sql2));
        }
Пример #4
0
        public void Parse_Filter_NotEqualTo()
        {
            Storm storm = new Storm();

            storm.EditSchema(SampleSchema);
            var compiler = new SqlServerCompiler();
            var con      = storm.OpenConnection(new EmptyConnection());

            var cmd1 = con.Get(Model_1)
                       .Where(e => e["data"].NotEqualTo.Val("data1"));

            cmd1.ParseSQL();
            SqlResult result1 = compiler.Compile(cmd1.query);
            string    sql1    = result1.Sql;

            // Previusly Calculated check sum integrity
            Assert.Equal("0E80502056208D5E9BD4A68A47059921", Helpers.Checksum(sql1));

            var cmd2 = con.Get(Model_1)
                       .Where(e => e["data"].NotEqualTo.Ref("Child_2.data"));

            cmd2.ParseSQL();
            SqlResult result2 = compiler.Compile(cmd2.query);
            string    sql2    = result2.Sql;

            // Previusly Calculated check sum integrity
            Assert.Equal("296C9F346FD332C7E5ECBA70C5FEAFFA", Helpers.Checksum(sql2));
        }
Пример #5
0
        public void Assert_Navigation_Keep_Schema_Version()
        {
            Storm storm = new Storm();

            storm.EditSchema(e => e.Add <TestModel>("TestModel1", "TABTest"));

            var nav = storm.schema.GetNavigator();

            storm.EditSchema(e => e.Add <TestModel>("TestModel2", "TABTest"));

            var x = nav.GetEntity("TestModel1");
            var y = nav.GetEntity("TestModel2");

            Assert.NotNull(x);
            Assert.Null(y);
        }
Пример #6
0
        public void Parse_Filter_GreaterOrEqualTo()
        {
            Storm storm = new Storm();

            storm.EditSchema(SampleSchema);
            var compiler = new SqlServerCompiler();
            var con      = storm.OpenConnection(new EmptyConnection());

            var cmd1 = con.Get(Model_1)
                       .Where(e => e["data"].GreaterOrEqualTo.Val("data1"));

            cmd1.ParseSQL();
            SqlResult result1 = compiler.Compile(cmd1.query);
            string    sql1    = result1.Sql;

            // Previusly Calculated check sum integrity
            Assert.Equal("34AABBD1AE39782F004A906AE1B2AB72", Helpers.Checksum(sql1));

            var cmd2 = con.Get(Model_1)
                       .Where(e => e["data"].GreaterOrEqualTo.Ref("Child_2.data"));

            cmd2.ParseSQL();
            SqlResult result2 = compiler.Compile(cmd2.query);
            string    sql2    = result2.Sql;

            // Previusly Calculated check sum integrity
            Assert.Equal("B3F599E6750A4CEE5E467FA1A902F705", Helpers.Checksum(sql2));
        }
Пример #7
0
        public void Parse_SetCommand_Update()
        {
            Storm storm = new Storm();

            storm.EditSchema(SampleSchema);
            var compiler = new SqlServerCompiler();
            var con      = storm.OpenConnection(new EmptyConnection());

            var cmd1 = con.Set(Model_0, 12)
                       .Value(new Dictionary <string, object>()
            {
                { "ID", "asd" },  //<= this shold not take in consideration because it's primary key of the entity
                { "Model1ID", "1" },
                { "Field1", "value1" },
                { "Field2", "value2" },
                { "Field3", "value3" },
                { "Field4", "value4" },
                { "Field5", "value5" },
                { "NotExistingField", "some value" }   // <= this shold not take in consideration because it's not a field of the entity
            });

            cmd1.ParseSQL();
            SqlResult result1 = compiler.Compile(cmd1.query);
            string    sql1    = result1.Sql;

            // Previusly Calculated check sum integrity
            Assert.Equal("ADD301250F02D5AF0240ACE77079032E", Helpers.Checksum(sql1));
        }
Пример #8
0
        public void Parse_Filter_Like()
        {
            Storm storm = new Storm();

            storm.EditSchema(SampleSchema);
            var compiler = new SqlServerCompiler();
            var con      = storm.OpenConnection(new EmptyConnection());

            var cmd1 = con.Get(Model_1)
                       .Where(e => e["data"].Like.Val("data1"));

            cmd1.ParseSQL();
            SqlResult result1 = compiler.Compile(cmd1.query);
            string    sql1    = result1.Sql;

            // Previusly Calculated check sum integrity
            Assert.Equal("DE63F4F1988F9EE29ABD22F382A210D3", Helpers.Checksum(sql1));

            var cmd2 = con.Get(Model_1)
                       .Where(e => e["data"].Like.Ref("Child_2.data"));

            cmd2.ParseSQL();
            SqlResult result2 = compiler.Compile(cmd2.query);
            string    sql2    = result2.Sql;

            // Previusly Calculated check sum integrity
            Assert.Equal("461335C8133CF486EB72CC7A2B7B5606", Helpers.Checksum(sql2));
        }
Пример #9
0
        public void Parse_SetCommand_Update_UsingModel()
        {
            Storm storm = new Storm();

            storm.EditSchema(SampleSchema);
            var compiler = new SqlServerCompiler();
            var con      = storm.OpenConnection(new EmptyConnection());

            var cmd1 = con.Set(Model_0, 12)
                       .Value(new Model_0()
            {
                ID       = 12, //<= this shold not take in consideration because it's primary key of the entity
                Model1ID = 1,
                Field1   = "value1",
                Field2   = "value2",
                Field3   = "value3",
                Field4   = "value4",
                Field5   = "value5",
            });


            cmd1.ParseSQL();
            SqlResult result1 = compiler.Compile(cmd1.query);
            string    sql1    = result1.Sql;

            // Previusly Calculated check sum integrity
            Assert.Equal("ADD301250F02D5AF0240ACE77079032E", Helpers.Checksum(sql1));
        }
Пример #10
0
        public void Throw_If_Connection_With_Same_ID_Exists()
        {
            Storm storm = new Storm();

            Assert.Throws <ArgumentException>(() =>
            {
                storm.EditSchema(e =>
                {
                    e.Add <TestModel>("TestModel", "TABTest");
                    e.Add("SomeDynModel", "Table", b =>
                    {
                        b.Add(new FieldConfig()
                        {
                            CodeName = "ID", IsPrimary = true, CodeType = typeof(int)
                        });
                        b.Add(new FieldConfig()
                        {
                            CodeName = "TestModelID", CodeType = typeof(int)
                        });
                        return(b);
                    });

                    e.Connect("TestModel", "SomeDynModel", "TestModel", "TestModelID", "ID");
                    e.Connect("TestModel", "SomeDynModel", "TestModel", "TestModelID", "ID");
                    return(e);
                });
            });
        }
Пример #11
0
        public void CreateSchemaWithEditor()
        {
            var s = new Storm();

            s.EditSchema(e => {
                return(e.Add <Appointment>("Appointment", "Appointments")
                       .Add <Contact>("Contact", "Contacts")
                       .Add <User>("User", "Users")
                       .Add <Organization>("Organization", "Organizations")
                       .Add <Language>("Language", "Languages")
                       .Add("AppointmentCf", "AppointmentCustomFields", AppointmentCustomFields));
            });

            var n = s.schema.GetNavigator();

            //-------------------- APPOINTMENT ---------------------
            var appointment = n.GetEntity("Appointment");

            Assert.Equal("Appointments", appointment.DBName);
            Assert.Equal(typeof(Appointment), appointment.TModel);
            Assert.Equal("Appointment", appointment.ID);
            Assert.Equal(9, appointment.entityFields.Count());


            //------------------- APPOINTMENT CF -------------------
            var appointmentCf = n.GetEntity("AppointmentCf");

            Assert.Equal("AppointmentCustomFields", appointmentCf.DBName);
            Assert.Null(appointmentCf.TModel);
            Assert.Equal("AppointmentCf", appointmentCf.ID);
            Assert.Equal(5, appointmentCf.entityFields.Count());
        }
Пример #12
0
        public void Assert_Add_Connection_Between_Enties()
        {
            Storm storm = new Storm();

            storm.EditSchema(e =>
            {
                e.Add <TestModel>("TestModel", "TABTest");
                e.Add("SomeDynModel", "Table", b =>
                {
                    b.Add(new FieldConfig()
                    {
                        CodeName = "ID", IsPrimary = true, CodeType = typeof(int)
                    });
                    b.Add(new FieldConfig()
                    {
                        CodeName = "TestModelID", CodeType = typeof(int)
                    });
                    return(b);
                });

                e.Connect("TestModel", "SomeDynModel", "TestModel", "TestModelID", "ID");
                return(e);
            });

            var nav = storm.schema.GetNavigator();
            var s   = nav.GetEntity("SomeDynModel");
            var t   = nav.GetEntity("TestModel");
            var x   = nav.GetEdge("SomeDynModel.TestModel");

            Assert.Equal(s.ID, x.SourceID);
            Assert.Equal(t.ID, x.TargetID);
            Assert.Equal("TestModelID", x.On.Item1);
            Assert.Equal("ID", x.On.Item2);
        }
Пример #13
0
        public void Parse_Filter_LessTo()
        {
            Storm storm = new Storm();

            storm.EditSchema(SampleSchema);
            var compiler = new SqlServerCompiler();
            var con      = storm.OpenConnection(new EmptyConnection());

            var cmd1 = con.Get(Model_1)
                       .Where(e => e["data"].LessTo.Val("data1"));

            cmd1.ParseSQL();
            SqlResult result1 = compiler.Compile(cmd1.query);
            string    sql1    = result1.Sql;

            // Previusly Calculated check sum integrity
            Assert.Equal("8C816D6911AF6D3456AF68589502AFFE", Helpers.Checksum(sql1));

            var cmd2 = con.Get(Model_1)
                       .Where(e => e["data"].LessTo.Ref("Child_2.data"));

            cmd2.ParseSQL();
            SqlResult result2 = compiler.Compile(cmd2.query);
            string    sql2    = result2.Sql;

            // Previusly Calculated check sum integrity
            Assert.Equal("09864DD8F14F77517975BFDBBC9CE637", Helpers.Checksum(sql2));
        }
Пример #14
0
        public void Parse_Filter_GreaterTo()
        {
            Storm storm = new Storm();

            storm.EditSchema(SampleSchema);
            var compiler = new SqlServerCompiler();
            var con      = storm.OpenConnection(new EmptyConnection());

            var cmd1 = con.Get(Model_1)
                       .Where(e => e["data"].GreaterTo.Val("data1"));

            cmd1.ParseSQL();
            SqlResult result1 = compiler.Compile(cmd1.query);
            string    sql1    = result1.Sql;

            // Previusly Calculated check sum integrity
            Assert.Equal("3AFF85B634EC75196A52F423A4308A30", Helpers.Checksum(sql1));

            var cmd2 = con.Get(Model_1)
                       .Where(e => e["data"].GreaterTo.Ref("Child_2.data"));

            cmd2.ParseSQL();
            SqlResult result2 = compiler.Compile(cmd2.query);
            string    sql2    = result2.Sql;

            // Previusly Calculated check sum integrity
            Assert.Equal("A69ECA081ECE81EF542FD3CF164F914E", Helpers.Checksum(sql2));
        }
Пример #15
0
        public void Assert_It_Read_Attr_StormDefaultIfNull_TypedModel()
        {
            Storm storm = new Storm();

            storm.EditSchema(e => e.Add <TestModel>("TestModel", "TABTest"));
            var nav = storm.schema.GetNavigator();
            var x   = nav.GetEntity("TestModel");

            Assert.Equal("Some Default Value", x.entityFields.First(y => y.CodeName == "DefaultedField").DefaultIfNull);
        }
Пример #16
0
        public void Assert_It_Read_Attr_StormColumnName_TypedModel()
        {
            Storm storm = new Storm();

            storm.EditSchema(e => e.Add <TestModel>("TestModel", "TABTest"));
            var nav = storm.schema.GetNavigator();
            var x   = nav.GetEntity("TestModel");

            Assert.Equal("DifferentName", x.entityFields.First(y => y.CodeName == "SomeName").DBName);
        }
Пример #17
0
        public void Assert_It_Read_Attr_StormIgnore_TypedModel()
        {
            Storm storm = new Storm();

            storm.EditSchema(e => e.Add <TestModel>("TestModel", "TABTest"));
            var nav = storm.schema.GetNavigator();
            var x   = nav.GetEntity("TestModel");

            Assert.DoesNotContain(x.entityFields, y => y.CodeName == "IgnorableField");
        }
Пример #18
0
        public void Assert_It_Read_Property_Of_TypedModel()
        {
            Storm storm = new Storm();

            storm.EditSchema(e => e.Add <TestModel>("TestModel", "TABTest"));
            var nav = storm.schema.GetNavigator();
            var x   = nav.GetEntity("TestModel");

            Assert.Contains(x.entityFields, y => y.CodeName == "SomeProperty");
        }
Пример #19
0
        public void Assert_Editor_Creation()
        {
            Storm storm = new Storm();

            storm.EditSchema(e =>
            {
                Assert.NotNull(e);
                Assert.True(DateTime.Now.Ticks > e.ticks && e.ticks != 0);
                return(e);
            });
        }
Пример #20
0
        public void Assert_It_Read_Attr_StormColumnType_TypedModel()
        {
            Storm storm = new Storm();

            storm.EditSchema(e => e.Add <TestModel>("TestModel", "TABTest"));
            var nav = storm.schema.GetNavigator();
            var x   = nav.GetEntity("TestModel");

            Assert.Equal(System.Data.DbType.String, x.entityFields.First(y => y.CodeName == "SpecifiedType").DBType);
            Assert.Equal(50, x.entityFields.First(y => y.CodeName == "SpecifiedType").Size);
        }
Пример #21
0
        public void Throw_If_Editor_OutOfDate()
        {
            Storm storm = new Storm();

            Task.Factory.StartNew(() =>
            {
                Assert.Throws <SchemaOutOfDateException>(() =>
                {
                    storm.EditSchema(e =>
                    {
                        System.Threading.Thread.Sleep(10);
                        return(e);
                    });
                });
            });

            storm.EditSchema(e =>
            {
                return(e);
            });
        }
Пример #22
0
        public void Assert_It_Read_Attr_StormColumnAccess_TypedModel()
        {
            Storm storm = new Storm();

            storm.EditSchema(e => e.Add <TestModel>("TestModel", "TABTest"));
            var nav = storm.schema.GetNavigator();
            var x   = nav.GetEntity("TestModel");

            Assert.Equal(ColumnAccess.ReadOnly, x.entityFields.First(y => y.CodeName == "ReadOnlyField").ColumnAccess);
            Assert.Equal(ColumnAccess.CanInsert, x.entityFields.First(y => y.CodeName == "InsertOnly").ColumnAccess);
            Assert.Equal(ColumnAccess.Full, x.entityFields.First(y => y.CodeName == "FullControl").ColumnAccess);
        }
Пример #23
0
        public void Assert_Add_TypedModel()
        {
            Storm storm = new Storm();

            storm.EditSchema(e => e.Add <TestModel>("TestModel", "TABTest"));
            var nav = storm.schema.GetNavigator();
            var x   = nav.GetEntity("TestModel");

            Assert.Equal("TABTest", x.DBName);
            Assert.Equal("TestModel", x.ID);
            Assert.Equal("ID", x.PrimaryKey.CodeName);
            Assert.Equal(typeof(TestModel), x.TModel);
        }
Пример #24
0
        static public Storm PrepareStorm()
        {
            var s = new Storm(SQLEngine.SQLite);

            Schema.SchemaEditor editor(Schema.SchemaEditor e)
            {
                return(e.Add <User>("User", "Users")
                       .Add <Task>("Task", "Tasks")
                       .Connect("User", "Task", "User", "UserID", "ID")
                       .Add("TaskInfo", "TaskInfos", builder =>
                {
                    return builder.Add(new Schema.FieldConfig()
                    {
                        CodeName = "ID",
                        CodeType = typeof(Int32),
                        DBName = "ID",
                        DBType = DbType.Int32,
                        IsPrimary = true
                    }).Add(new Schema.FieldConfig()
                    {
                        CodeName = "Field1",
                        CodeType = typeof(string),
                        DBName = "Field1",
                        DBType = DbType.String,
                    }).Add(new Schema.FieldConfig()
                    {
                        CodeName = "Field2",
                        CodeType = typeof(Int32),
                        DBName = "Field2",
                        DBType = DbType.Int32,
                    }).Add(new Schema.FieldConfig()
                    {
                        CodeName = "Field3",
                        CodeType = typeof(bool),
                        DBName = "Field3",
                        DBType = DbType.Boolean,
                    }).Add(new Schema.FieldConfig()
                    {
                        CodeName = "Field4",
                        CodeType = typeof(string),
                        DBName = "Field4",
                        DBType = DbType.String,
                    });
                }).Connect("Info", "Task", "TaskInfo", "ID", "ID"));
            };

            s.EditSchema(editor);

            return(s);
        }
Пример #25
0
        public void Throw_If_Entity_With_Same_ID_Exists()
        {
            Storm storm = new Storm();

            Assert.Throws <ArgumentException>(() =>
            {
                storm.EditSchema(e =>
                {
                    e.Add <TestModel>("TestModel", "TABTest");
                    e.Add <TestModel>("TestModel", "TABTest2");
                    return(e);
                });
            });
        }
Пример #26
0
        public void Throw_If_Connected_Entity_Not_Exists()
        {
            Storm storm = new Storm();

            Assert.Throws <ArgumentException>(() =>
            {
                storm.EditSchema(e =>
                {
                    e.Add <TestModel>("TestModel", "TABTest");
                    e.Connect("TestModel", "SomeDynModel", "TestModel", "TestModelID", "ID");
                    return(e);
                });
            });
        }
Пример #27
0
        public void Throw_If_No_PrimaryKey_In_DynamicModel()
        {
            Storm storm = new Storm();

            Assert.Throws <NoPrimaryKeySpecifiedException>(() =>
            {
                storm.EditSchema(e =>
                {
                    e.Add("SomeDynModel", "Table", b => b.Add(new FieldConfig()
                    {
                        CodeName = "ID", CodeType = typeof(int)
                    }));
                    return(e);
                });
            });
        }
Пример #28
0
        public void Parse_DeleteCommand_SimpleFilter()
        {
            Storm storm = new Storm();

            storm.EditSchema(SampleSchema);
            var compiler = new SqlServerCompiler();
            var con      = storm.OpenConnection(new EmptyConnection());

            var cmd1 = con.Delete(Model_0).Where(x => x["Field1"].IsNotNull * x["Field2"].GreaterTo.Val(100));

            cmd1.ParseSQL();
            SqlResult result1 = compiler.Compile(cmd1.query);
            string    sql1    = result1.Sql;

            // Previusly Calculated check sum integrity
            Assert.Equal("4EAAE38C3FD27E0728FE85D172227FD7", Helpers.Checksum(sql1));
        }
Пример #29
0
        public void Parse_DeleteCommand_NoFilter()
        {
            Storm storm = new Storm();

            storm.EditSchema(SampleSchema);
            var compiler = new SqlServerCompiler();
            var con      = storm.OpenConnection(new EmptyConnection());

            var cmd1 = con.Delete(Model_0);

            cmd1.ParseSQL();
            SqlResult result1 = compiler.Compile(cmd1.query);
            string    sql1    = result1.Sql;

            // Previusly Calculated check sum integrity
            Assert.Equal("3671297C80C511F80B64CF061D91CA6F", Helpers.Checksum(sql1));
        }
Пример #30
0
        public void Parse_GetObject_With_Relation_ShortPathed()
        {
            Storm storm = new Storm();

            storm.EditSchema(SampleSchema);
            var con = storm.OpenConnection(new EmptyConnection());

            var cmd = con.Get(Model_1).With("Child_2");

            cmd.ParseSQL();
            var       compiler = new SqlServerCompiler();
            SqlResult result   = compiler.Compile(cmd.query);
            string    sql      = result.Sql;

            // Previusly Calculated check sum integrity
            Assert.Equal("D5E28B7FC534053BA010A747D97002F1", Helpers.Checksum(sql));
        }