DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
TriggerListenTests.cs
Go to the documentation of this file.
1 //
2 // Copyright 2010-2014 Deveel
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 using System;
16 
17 using Deveel.Data.Sql.Tables;
18 using Deveel.Data.Types;
19 
20 using NUnit.Framework;
21 
22 namespace Deveel.Data.Sql.Triggers {
23  [TestFixture]
24  public sealed class TriggerListenTests : ContextBasedTest {
25  private static readonly ObjectName TestTableName = ObjectName.Parse("APP.test_table");
26 
27  protected override IQuery CreateQuery(ISession session) {
28  var query = base.CreateQuery(session);
29 
30  var tableInfo = new TableInfo(TestTableName);
31  tableInfo.AddColumn("id", PrimitiveTypes.Integer(), true);
32  tableInfo.AddColumn("first_name", PrimitiveTypes.String());
33  tableInfo.AddColumn("last_name", PrimitiveTypes.String());
34 
35  query.CreateTable(tableInfo);
36 
37  return query;
38  }
39 
42 
43  protected override ISystem CreateSystem() {
44  var system = base.CreateSystem();
45  system.Context.ListenTriggers(trigger => {
46  if ((trigger.TriggerEventType & TriggerEventType.After) != 0) {
47  afterEvent = trigger;
48  } else if ((trigger.TriggerEventType & TriggerEventType.Before) != 0) {
49  beforeEvent = trigger;
50  }
51  });
52 
53  return system;
54  }
55 
56  protected override void OnSetUp(string testName) {
57  if (!testName.EndsWith("_NoTriggers")) {
58  // TODO: Create triggers
59  }
60 
61  base.OnSetUp(testName);
62  }
63 
64  [Test]
65  public void Insert_NoTriggers() {
66  var table = Query.GetMutableTable(TestTableName);
67 
68  Assert.IsNotNull(table);
69 
70  var row = table.NewRow();
71  row.SetValue(0, 1);
72  row.SetValue(1, "Antonello");
73  row.SetValue(2, "Provenzano");
74 
75  Assert.DoesNotThrow(() => table.AddRow(row));
76  Assert.DoesNotThrow(() => Query.Commit());
77 
78  Assert.IsNull(beforeEvent);
79  Assert.IsNull(afterEvent);
80  }
81  }
82 }
Provides some helper functions for resolving and creating SqlType instances that are primitive to the...
static ObjectName Parse(string s)
Parses the given string into a ObjectName object.
Definition: ObjectName.cs:139
new ISystemContext Context
Definition: ISystem.cs:27
TriggerEventType
The different types of high layer trigger events.
Describes the name of an object within a database.
Definition: ObjectName.cs:44
An isolated session to a given database for a given user, encapsulating the transaction for operation...
Definition: ISession.cs:30
override IQuery CreateQuery(ISession session)
override void OnSetUp(string testName)
Defines the metadata properties of a table existing within a database.
Definition: TableInfo.cs:41