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)); }
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)); }
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)); }
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)); }
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); }
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)); }
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)); }
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)); }
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)); }
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); }); }); }
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()); }
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); }
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)); }
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)); }
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); }
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); }
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"); }
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"); }
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); }); }
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); }
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); }); }
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); }
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); }
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); }
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); }); }); }
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); }); }); }
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); }); }); }
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)); }
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)); }
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)); }