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); var adoDelegate = new StdAdoDelegate(LogManager.GetLogger(GetType()), "QRTZ_", "TESTSCHED", "INSTANCE", dbProvider, new SimpleTypeLoadHelper()); 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); }
public async Task 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 = A.Fake <IDbProvider>(); var dbCommand = A.Fake <DbCommand>(); var dataParameterCollection = A.Fake <DbParameterCollection>(); A.CallTo(() => dbProvider.CreateCommand()).Returns(dbCommand); Func <DbParameter> dataParam = () => new SqlParameter(); A.CallTo(dbProvider) .Where(x => x.Method.Name == "CreateDbParameter") .WithReturnType <DbParameter>() .ReturnsLazily(dataParam); A.CallTo(dbCommand) .Where(x => x.Method.Name == "CreateDbParameter") .WithReturnType <DbParameter>() .ReturnsLazily(dataParam); var dataParameterCollectionOutputs = new List <object>(); A.CallTo(() => dataParameterCollection.Add(A <object> ._)).Invokes(x => { dataParameterCollectionOutputs.Add(x.Arguments.Single()); }); A.CallTo(dbCommand) .Where(x => x.Method.Name == "get_DbParameterCollection") .WithReturnType <DbParameterCollection>() .Returns(dataParameterCollection); var metaData = A.Fake <DbMetadata>(); A.CallTo(() => dbProvider.Metadata).Returns(metaData); Func <string, string> paramFunc = x => x; A.CallTo(() => metaData.GetParameterName(A <string> .Ignored)).ReturnsLazily(paramFunc); DelegateInitializationArgs args = new DelegateInitializationArgs(); args.Logger = LogProvider.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 = A.Fake <IJobDetail>(); var jobDataMap = new JobDataMap(); jobDataMap.ClearDirtyFlag(); cronTriggerImpl.JobDataMap = jobDataMap; //Act await 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); }
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); }