Exemple #1
0
        public void SaveEvents()
        {
            // use alternate table def for methods that alter data during testing
            var opts = IQ.GetQueryOptions(tableName: tempTable);

            var dog = new EventDog();
            dog.Name = "SomeDog";
            dog.Age = 10;
            IQ.Save(dog,opts);

            Assert.AreEqual(4,dog.Events.Count,"4 events found before/on save/insert");

            // verify event sequence
            IQEventType[] types = dog.Events.Select(item => item.EventType).ToArray();
            Assert.AreEqual(new IQEventType[] {IQEventType.BeforeSave, IQEventType.BeforeInsert, IQEventType.OnInsert, IQEventType.OnSave},
                types, "Event handler worked.");

            dog.Events.Clear();
            dog.Age = 11;
            // try out extension method
            dog.Save(opts);

            types = dog.Events.Select(item => item.EventType).ToArray();
            Assert.AreEqual(new IQEventType[] { IQEventType.BeforeSave, IQEventType.BeforeUpdate, IQEventType.OnUpdate, IQEventType.OnSave },
                types, "Event handler worked.");
        }
Exemple #2
0
        public void SaveEvents()
        {
            // use alternate table def for methods that alter data during testing
            var opts = IQ.GetQueryOptions(tableName: tempTable);

            var dog = new EventDog();

            dog.Name = "SomeDog";
            dog.Age  = 10;
            IQ.Save(dog, opts);


            Assert.AreEqual(4, dog.Events.Count, "4 events found before/on save/insert");

            // verify event sequence
            IQEventType[] types = dog.Events.Select(item => item.EventType).ToArray();
            Assert.AreEqual(new IQEventType[] { IQEventType.BeforeSave, IQEventType.BeforeInsert, IQEventType.OnInsert, IQEventType.OnSave },
                            types, "Event handler worked.");

            dog.Events.Clear();
            dog.Age = 11;
            // try out extension method
            dog.Save(opts);

            types = dog.Events.Select(item => item.EventType).ToArray();
            Assert.AreEqual(new IQEventType[] { IQEventType.BeforeSave, IQEventType.BeforeUpdate, IQEventType.OnUpdate, IQEventType.OnSave },
                            types, "Event handler worked.");
        }
Exemple #3
0
        public void DeleteEvents()
        {
            // use alternate table def for methods that alter data during testing
            var opts = IQ.GetQueryOptions(tableName: tempTable);

            var dog = new EventDog();

            dog.Name = "SomeDog";
            dog.Age  = 10;
            IQ.Save(dog, opts);

            var id = dog.PK;

            dog.Events.Clear();
            bool deleted = dog.Delete(opts);

            Assert.IsTrue(deleted);
            Assert.AreEqual(2, dog.Events.Count, "Two events on delete");

            Assert.Throws <InvalidOperationException>(() =>
            {
                dog.Delete();
            }, "Can't delete with zero-valued primary key");



            dog.Save(opts);
            Assert.AreEqual(id + 1, dog.PK, "ID incremented by one for a new save");

            dog.RejectNextEvent = IQEventType.BeforeDelete;
            deleted             = dog.Delete(opts);

            Assert.IsFalse(deleted, "Was not actually deleted");
            dog.RejectNextEvent = IQEventType.OnDelete;
            Assert.Throws <InvalidOperationException>(() =>
            {
                dog.Delete();
            }, "Rejecting the after-delete event throws an exception");
        }
Exemple #4
0
        public void DeleteEvents()
        {
            // use alternate table def for methods that alter data during testing
            var opts = IQ.GetQueryOptions(tableName: tempTable);

            var dog = new EventDog();
            dog.Name = "SomeDog";
            dog.Age = 10;
            IQ.Save(dog,opts);

            var id = dog.PK;

            dog.Events.Clear();
            bool deleted = dog.Delete(opts);

            Assert.IsTrue(deleted);
            Assert.AreEqual(2, dog.Events.Count, "Two events on delete");

            Assert.Throws<InvalidOperationException>(() =>
            {
                dog.Delete();

            }, "Can't delete with zero-valued primary key");

            dog.Save(opts);
            Assert.AreEqual(id + 1, dog.PK, "ID incremented by one for a new save");

            dog.RejectNextEvent = IQEventType.BeforeDelete;
            deleted = dog.Delete(opts);

            Assert.IsFalse(deleted, "Was not actually deleted");
            dog.RejectNextEvent = IQEventType.OnDelete;
            Assert.Throws<InvalidOperationException>(() =>
            {
                dog.Delete();
            }, "Rejecting the after-delete event throws an exception");
        }