public async Task TestSelectSimpleTriggerWithDeleteBeforeSelectExtendedProps()
        {
            var dbProvider  = A.Fake <IDbProvider>();
            var connection  = A.Fake <DbConnection>();
            var transaction = A.Fake <DbTransaction>();
            var command     = (DbCommand)A.Fake <StubCommand>();
            var dbMetadata  = new DbMetadata();

            A.CallTo(() => dbProvider.Metadata).Returns(dbMetadata);

            A.CallTo(() => dbProvider.CreateCommand()).Returns(command);

            var dataReader = A.Fake <DbDataReader>();

            A.CallTo(command).Where(x => x.Method.Name == "ExecuteDbDataReaderAsync")
            .WithReturnType <Task <DbDataReader> >()
            .Returns(Task.FromResult(dataReader));

            A.CallTo(command).Where(x => x.Method.Name == "get_DbParameterCollection")
            .WithReturnType <DbParameterCollection>()
            .Returns(new StubParameterCollection());

            A.CallTo(() => command.CommandText).Returns("");

            A.CallTo(command).Where(x => x.Method.Name == "CreateDbParameter")
            .WithReturnType <DbParameter>()
            .Returns(new SqlParameter());

            var persistenceDelegate = A.Fake <ITriggerPersistenceDelegate>();
            var exception           = new InvalidOperationException();

            A.CallTo(() => persistenceDelegate.LoadExtendedTriggerProperties(A <ConnectionAndTransactionHolder> .Ignored, A <TriggerKey> .Ignored, CancellationToken.None)).Throws(exception);

            StdAdoDelegate adoDelegate = new TestStdAdoDelegate(persistenceDelegate);

            var delegateInitializationArgs = new DelegateInitializationArgs
            {
                TablePrefix    = "QRTZ_",
                InstanceId     = "TESTSCHED",
                InstanceName   = "INSTANCE",
                TypeLoadHelper = new SimpleTypeLoadHelper(),
                UseProperties  = false,
                InitString     = "",
                DbProvider     = dbProvider
            };

            adoDelegate.Initialize(delegateInitializationArgs);

            // First result set has results, second has none
            A.CallTo(() => dataReader.ReadAsync(CancellationToken.None)).Returns(true).Once();
            A.CallTo(() => dataReader[AdoConstants.ColumnTriggerType]).Returns(AdoConstants.TriggerTypeSimple);
            A.CallTo(() => dataReader[A <string> ._]).Returns("1");

            var conn = new ConnectionAndTransactionHolder(connection, transaction);
            IOperableTrigger trigger = await adoDelegate.SelectTrigger(conn, new TriggerKey("test"));

            Assert.That(trigger, Is.Null);

            A.CallTo(() => persistenceDelegate.LoadExtendedTriggerProperties(A <ConnectionAndTransactionHolder> .Ignored, A <TriggerKey> .Ignored, CancellationToken.None)).MustHaveHappened();
        }
        public void TestSelectSimpleTriggerWithExceptionWithExtendedProps()
        {
            var dbProvider  = MockRepository.GenerateMock <IDbProvider>();
            var connection  = MockRepository.GenerateMock <IDbConnection>();
            var transaction = MockRepository.GenerateMock <IDbTransaction>();
            var command     = (IDbCommand)MockRepository.GenerateMock <StubCommand>();
            var dbMetadata  = new DbMetadata();

            dbProvider.Stub(x => x.Metadata).Repeat.Any().Return(dbMetadata);

            dbProvider.Stub(x => x.CreateCommand()).Return(command);

            var dataReader = MockRepository.GenerateMock <IDataReader>();

            command.Stub(x => x.ExecuteReader()).Return(dataReader);
            command.Stub(x => x.Parameters).Repeat.Any().Return(new StubParameterCollection());
            command.Stub(x => x.CommandText).Return("").Repeat.Any();
            command.Stub(x => x.CreateParameter()).Repeat.Any().Return(new StubDataParameter());

            var persistenceDelegate = MockRepository.GenerateMock <ITriggerPersistenceDelegate>();
            var exception           = new InvalidOperationException();

            persistenceDelegate.Stub(x => x.LoadExtendedTriggerProperties(Arg <ConnectionAndTransactionHolder> .Is.Anything, Arg <TriggerKey> .Is.Anything)).Throw(exception);


            StdAdoDelegate adoDelegate = new TestStdAdoDelegate(persistenceDelegate);

            var delegateInitializationArgs = new DelegateInitializationArgs
            {
                TablePrefix    = "QRTZ_",
                InstanceId     = "TESTSCHED",
                InstanceName   = "INSTANCE",
                TypeLoadHelper = new SimpleTypeLoadHelper(),
                UseProperties  = false,
                InitString     = "",
                Logger         = LogManager.GetLogger(GetType()),
                DbProvider     = dbProvider
            };

            adoDelegate.Initialize(delegateInitializationArgs);

            // Mock basic trigger data
            dataReader.Stub(x => x.Read()).Return(true).Repeat.Any();
            dataReader.Stub(x => x[AdoConstants.ColumnTriggerType]).Return(AdoConstants.TriggerTypeSimple);

            try
            {
                var conn = new ConnectionAndTransactionHolder(connection, transaction);
                adoDelegate.SelectTrigger(conn, new TriggerKey("test"));
                Assert.Fail("Trigger selection should result in exception");
            }
            catch (InvalidOperationException e)
            {
                Assert.That(e, Is.SameAs(exception));
            }

            persistenceDelegate.AssertWasCalled(x => x.LoadExtendedTriggerProperties(Arg <ConnectionAndTransactionHolder> .Is.Anything, Arg <TriggerKey> .Is.Anything));
        }
Example #3
0
        public void TestSelectSimpleTriggerWithDeleteBeforeSelectExtendedProps()
        {
            var dbProvider = MockRepository.GenerateMock<IDbProvider>();
            var connection = MockRepository.GenerateMock<IDbConnection>();
            var transaction = MockRepository.GenerateMock<IDbTransaction>();
            var command = (IDbCommand)MockRepository.GenerateMock<StubCommand>();
            var dbMetadata = new DbMetadata();
            dbProvider.Stub(x => x.Metadata).Repeat.Any().Return(dbMetadata);

            dbProvider.Stub(x => x.CreateCommand()).Return(command);

            var dataReader = MockRepository.GenerateMock<IDataReader>();
            command.Stub(x => x.ExecuteReader()).Return(dataReader);
            command.Stub(x => x.Parameters).Repeat.Any().Return(new StubParameterCollection());
            command.Stub(x => x.CommandText).Return("").Repeat.Any();
            command.Stub(x => x.CreateParameter()).Repeat.Any().Return(new StubDataParameter());

            var persistenceDelegate = MockRepository.GenerateMock<ITriggerPersistenceDelegate>();
            var exception = new InvalidOperationException();
            persistenceDelegate.Stub(x => x.LoadExtendedTriggerProperties(Arg<ConnectionAndTransactionHolder>.Is.Anything, Arg<TriggerKey>.Is.Anything)).Throw(exception);

            StdAdoDelegate adoDelegate = new TestStdAdoDelegate(persistenceDelegate);

            var delegateInitializationArgs = new DelegateInitializationArgs
            {
                TablePrefix = "QRTZ_",
                InstanceId = "TESTSCHED",
                InstanceName = "INSTANCE",
                TypeLoadHelper = new SimpleTypeLoadHelper(),
                UseProperties = false,
                InitString = "",
                Logger = LogManager.GetLogger(GetType()),
                DbProvider = dbProvider
            };
            adoDelegate.Initialize(delegateInitializationArgs);

            // First result set has results, second has none
            dataReader.Stub(x => x.Read()).Return(true).Repeat.Once();
            dataReader.Stub(x => x.Read()).Return(false);
            dataReader.Stub(x => x[AdoConstants.ColumnTriggerType]).Return(AdoConstants.TriggerTypeSimple);

            var conn = new ConnectionAndTransactionHolder(connection, transaction);
            IOperableTrigger trigger = adoDelegate.SelectTrigger(conn, new TriggerKey("test"));
            Assert.That(trigger, Is.Null);

            persistenceDelegate.AssertWasCalled(x => x.LoadExtendedTriggerProperties(Arg<ConnectionAndTransactionHolder>.Is.Anything, Arg<TriggerKey>.Is.Anything));
        }