Beispiel #1
0
        public void Callback()
        {
            var tableName = ObjectName.Parse("APP.test_table");

            AdminQuery.Access().CreateCallbackTrigger("callback1", tableName, TriggerEventTime.After, TriggerEventType.Insert);

            var reset = new AutoResetEvent(false);

            TriggerEvent firedEvent = null;

            AdminQuery.Context.RouteImmediate <TriggerEvent>(e => {
                firedEvent = e;
                reset.Set();
            }, e => e.TriggerType == TriggerType.Callback &&
                                                             e.TriggerName.Name.Equals("callback1"));

            AdminQuery.Insert(tableName, new[] { "id", "name" },
                              new SqlExpression[] { SqlExpression.Constant(2), SqlExpression.Constant("The Name") });

            reset.WaitOne(300);

            Assert.IsNotNull(firedEvent);
            Assert.AreEqual(TriggerEventTime.After, firedEvent.EventTime);
            Assert.AreEqual(TriggerEventType.Insert, firedEvent.EventType);
        }
        public void OneValueWithLob()
        {
            const string testBio = "A simple test string that can span several characters, " +
                                   "that is trying to be the longest possible, just to prove" +
                                   "the capacity of a LONG VARCHAR to handle very long strings. " +
                                   "Anyway it is virtually impossible to reach the maximum size " +
                                   "of a long object, that is organized in 64k byte pages and " +
                                   "spans within the local system without any constraint of size. " +
                                   "For sake of memory anyway, the maximum size of the test object " +
                                   "is set to just 2048 bytes.";

            var tableName = ObjectName.Parse("APP.test_table");
            var columns   = new[] { "first_name", "last_name", "active", "bio" };
            var bio       = CreateBio(testBio);

            var values = new List <SqlExpression[]> {
                new[] {
                    SqlExpression.Constant("Antonello"),
                    SqlExpression.Constant("Provenzano"),
                    SqlExpression.Constant(true),
                    SqlExpression.Constant(bio)
                },
            };

            var count = AdminQuery.Insert(tableName, columns, values.ToArray());

            Assert.AreEqual(1, count);

            var table = AdminQuery.Access().GetTable(tableName);

            Assert.IsNotNull(table);
            Assert.AreEqual(1, table.RowCount);
        }
        public void InsertWithUserType()
        {
            var tableName = ObjectName.Parse("APP.test_table");
            var columns   = new[] { "first_name", "last_name", "active", "user_obj" };
            var values    = new List <SqlExpression[]> {
                new SqlExpression[] {
                    SqlExpression.Constant("Antonello"),
                    SqlExpression.Constant("Provenzano"),
                    SqlExpression.Constant(true),
                    SqlExpression.FunctionCall("type1", new SqlExpression[] {
                        SqlExpression.Constant("test1"),
                        SqlExpression.Constant(1),
                    })
                },
                new SqlExpression[] {
                    SqlExpression.Constant("Mart"),
                    SqlExpression.Constant("Roosmaa"),
                    SqlExpression.Constant(false),
                    SqlExpression.FunctionCall("type1", new SqlExpression[] {
                        SqlExpression.Constant("test2"),
                        SqlExpression.Constant(3),
                    })
                }
            };

            var count = AdminQuery.Insert(tableName, columns, values.ToArray());


            Assert.AreEqual(2, count);

            var table = AdminQuery.Access().GetTable(tableName);

            Assert.IsNotNull(table);
            Assert.AreEqual(2, table.RowCount);
        }
        public void TwoValues_NoColumnes()
        {
            var tableName = ObjectName.Parse("APP.test_table");
            var values    = new List <SqlExpression[]> {
                new SqlExpression[] {
                    SqlExpression.Constant("Antonello"),
                    SqlExpression.Constant("Provenzano"),
                    SqlExpression.Constant(true)
                },
                new SqlExpression[] {
                    SqlExpression.Constant("Mart"),
                    SqlExpression.Constant("Roosmaa"),
                    SqlExpression.Constant(false)
                }
            };

            var count = AdminQuery.Insert(tableName, values.ToArray());


            Assert.AreEqual(2, count);

            var table = AdminQuery.Access().GetTable(tableName);

            Assert.IsNotNull(table);
            Assert.AreEqual(2, table.RowCount);
        }
        public void NotNullColumnViolation()
        {
            var expected = Is.InstanceOf <ConstraintViolationException>()
                           .And.TypeOf <NotNullColumnViolationException>()
                           .And.Property("TableName").EqualTo(ObjectName.Parse("APP.test_table"))
                           .And.Property("ColumnName").EqualTo("active");

            Assert.Throws(expected, () => AdminQuery.Insert(new ObjectName("test_table"),
                                                            new[] { "first_name", "last_name", "birth_date", "active" },
                                                            new SqlExpression[] {
                SqlExpression.Constant("Antonello"),
                SqlExpression.Constant("Provenzano"),
                SqlExpression.Constant(new SqlDateTime(1980, 06, 04)),
                SqlExpression.Constant(Field.Null())
            }));
        }
Beispiel #6
0
        public void BeforeInsert()
        {
            var tableName = ObjectName.Parse("APP.test_table");

            var reset = new AutoResetEvent(false);

            TriggerEvent firedEvent = null;

            AdminQuery.Context.RouteImmediate <TriggerEvent>(e => {
                firedEvent = e;
                reset.Set();
            }, e => e.TriggerType == TriggerType.Procedural &&
                                                             e.TriggerName.FullName.Equals("APP.trigger1"));

            AdminQuery.Insert(tableName, new[] { "id", "name" },
                              new SqlExpression[] { SqlExpression.Constant(2), SqlExpression.Constant("The Name") });

            reset.WaitOne(500);

            Assert.IsNotNull(firedEvent);
        }