예제 #1
0
        public void TestSelectBlobTriggerWithNoBlobContent()
        {
            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 adoDelegate = new StdAdoDelegate();

            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);

            var conn = new ConnectionAndTransactionHolder(connection, transaction);

            // 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.TriggerTypeBlob);

            IOperableTrigger trigger = adoDelegate.SelectTrigger(conn, new TriggerKey("test"));
            Assert.That(trigger, Is.Null);
        }
예제 #2
0
        public void TestSerializeJobData()
        {
            var args = new DelegateInitializationArgs();
            args.Logger = LogManager.GetLogger(GetType());
            args.TablePrefix = "QRTZ_";
            args.InstanceName = "TESTSCHED";
            args.InstanceId = "INSTANCE";
            args.DbProvider = new DbProvider("SqlServer-20", "");
            args.TypeLoadHelper = new SimpleTypeLoadHelper();
            args.ObjectSerializer = new DefaultObjectSerializer();

            var del = new StdAdoDelegate();
            del.Initialize(args);

            var jdm = new JobDataMap();
            del.SerializeJobData(jdm);

            jdm.Clear();
            jdm.Put("key", "value");
            jdm.Put("key2", null);
            del.SerializeJobData(jdm);

            jdm.Clear();
            jdm.Put("key1", "value");
            jdm.Put("key2", null);
            jdm.Put("key3", new NonSerializableTestClass());

            try
            {
                del.SerializeJobData(jdm);
                Assert.Fail();
            }
            catch (SerializationException e)
            {
                Assert.IsTrue(e.Message.IndexOf("key3") >= 0);
            }
        }
예제 #3
0
        public void CronTrigger_AfterTriggerUpdate_Retains_Cron_Type()
        {
            //Arrange
            var cronTriggerImpl = new CronTriggerImpl("Trigger", "Trigger.Group", "JobName", "JobGroup", "0 15 23 * * ?");
            cronTriggerImpl.CalendarName = "calName";
            cronTriggerImpl.MisfireInstruction = 1;
            cronTriggerImpl.Description = "Description";
            cronTriggerImpl.SetPreviousFireTimeUtc(new DateTimeOffset(new DateTime(2010,1,1)));
            cronTriggerImpl.SetNextFireTimeUtc(new DateTimeOffset(new DateTime(2010, 2, 1)));
            cronTriggerImpl.JobKey = new JobKey("JobKey","JobKeyGroup");
            cronTriggerImpl.Priority = 1;

            var dbProvider = MockRepository.GenerateStub<IDbProvider>();
            var dbCommand = MockRepository.GenerateStub<IDbCommand>();
            var dataParameterCollection = MockRepository.GenerateStub<IDataParameterCollection>();
            dbProvider.Stub(d => d.CreateCommand()).Return(dbCommand).Repeat.Any();
            Func<StubDataParameter> dataParam = () => new StubDataParameter();
            dbProvider.Stub(d => d.CreateParameter()).Do(dataParam);
            dbCommand.Stub(c => c.CreateParameter()).Do(dataParam);

            var dataParameterCollectionOutputs = new List<object>();

            Func<object, int> dataParameterFunc = x =>
                                                      {
                                                          dataParameterCollectionOutputs.Add(x);
                                                          return 1;
                                                      };

            dataParameterCollection.Stub(d => d.Add(Arg<object>.Is.Anything)).Do(dataParameterFunc);

            dbCommand.Stub(c => c.Parameters).Return(dataParameterCollection);
            var metaData = MockRepository.GenerateStub<DbMetadata>();
            dbProvider.Stub(d => d.Metadata).Return(metaData);
            
            Func<string, string> paramFunc = x => x;
            metaData.Stub(m => m.GetParameterName(Arg<string>.Is.Anything)).Do(paramFunc);

            DelegateInitializationArgs args = new DelegateInitializationArgs();
            args.Logger = LogManager.GetLogger(GetType());
            args.TablePrefix = "QRTZ_";
            args.InstanceName = "TESTSCHED";
            args.InstanceId = "INSTANCE";
            args.DbProvider = dbProvider;
            args.TypeLoadHelper = new SimpleTypeLoadHelper();

            var adoDelegate = new StdAdoDelegate();
            adoDelegate.Initialize(args);

            var dbConnection = new StubConnection();
            var conn = new ConnectionAndTransactionHolder(dbConnection, null);
            var jobDetail = MockRepository.GenerateMock<IJobDetail>();
            var jobDataMap = new JobDataMap();
            jobDataMap.ClearDirtyFlag();
            cronTriggerImpl.JobDataMap = jobDataMap;
            
            //Act
            adoDelegate.UpdateTrigger(conn, cronTriggerImpl, "state", jobDetail);

            //Assert
            var resultDataParameters = dataParameterCollectionOutputs.Select(x => x as IDataParameter).Where(x => x.ParameterName == "triggerType").FirstOrDefault();
            Assert.AreEqual("CRON",resultDataParameters.Value);
        }
예제 #4
0
        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));
        }
예제 #5
0
        public void ShouldSupportAssemblyQualifiedTriggerPersistenceDelegates()
        {
            StdAdoDelegate adoDelegate = new TestStdAdoDelegate(new SimpleTriggerPersistenceDelegate());

            var delegateInitializationArgs = new DelegateInitializationArgs
            {
                TablePrefix = "QRTZ_",
                InstanceId = "TESTSCHED",
                InstanceName = "INSTANCE",
                TypeLoadHelper = new SimpleTypeLoadHelper(),
                UseProperties = false,
                InitString = "triggerPersistenceDelegateClasses=" + typeof(TestTriggerPersistenceDelegate).AssemblyQualifiedName + ";" + typeof(TestTriggerPersistenceDelegate).AssemblyQualifiedName,
                Logger = LogManager.GetLogger(GetType()),
                DbProvider = MockRepository.GenerateMock<IDbProvider>()
            };
            adoDelegate.Initialize(delegateInitializationArgs);
        }