예제 #1
0
        public void ShouldSchduleFacebookJobs()
        {
            // Arrange
            var schedulerJobManagerMock      = new Mock <IScheduleJobManager>();
            var siteSocialAccountServiceMock = new Mock <ISiteSocialAccountService>();
            var facebookAccount = new SiteSocialAccount {
                SiteId = 10000, FacebookPageId = "123"
            };

            siteSocialAccountServiceMock.Setup(t => t.GetFacebookSiteAccountsAsync()).ReturnsAsync(new List <SiteSocialAccount>
            {
                facebookAccount
            });

            SchedulerJob schedulerJob = new SchedulerJob(schedulerJobManagerMock.Object, siteSocialAccountServiceMock.Object);

            var jobExecutionContextMock = new Mock <IJobExecutionContext>();
            var jobDetailMock           = new Mock <IJobDetail>();

            jobDetailMock.Setup(t => t.Key).Returns(new JobKey("TestJobKey"));
            jobExecutionContextMock.Setup(t => t.JobDetail).Returns(jobDetailMock.Object);

            // Act
            schedulerJob.Execute(jobExecutionContextMock.Object);

            // Assert
            schedulerJobManagerMock.Verify(t => t.ScheduleAsync <PullMessagesJob, SiteSocialAccount>(It.IsAny <Action <JobBuilder> >(), It.IsAny <Action <TriggerBuilder> >(), facebookAccount), "Should schedule facebook pull message job.");
            schedulerJobManagerMock.Verify(t => t.ScheduleAsync <PullTaggedVisitorPostsJob, SiteSocialAccount>(It.IsAny <Action <JobBuilder> >(), It.IsAny <Action <TriggerBuilder> >(), facebookAccount), "Should schedule facebook pull tagged visitor post job.");
            schedulerJobManagerMock.Verify(t => t.ScheduleAsync <PullVisitorPostsFromFeedJob, SiteSocialAccount>(It.IsAny <Action <JobBuilder> >(), It.IsAny <Action <TriggerBuilder> >(), facebookAccount), "Should schedule facebook pull feed post job.");
        }
예제 #2
0
        public Startup(IHostingEnvironment env)
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(env.ContentRootPath)
                          //.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
                          //.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
                          .AddEnvironmentVariables();

            if (env.IsDevelopment() || env.IsProduction())
            {
                builder.AddUserSecrets <Startup>();
            }

            Configuration = builder.Build();


            AerisJobParams aerisJobParams = new AerisJobParams();

            aerisJobParams.AerisClientId               = Configuration.GetSection("AerisJobParams:AerisClientID").Value;
            aerisJobParams.AerisClientSecret           = Configuration.GetSection("AerisJobParams:AerisClientSecret").Value;
            aerisJobParams.MyConnectionString          = Configuration.GetSection("AerisJobParams:MyConnectionString").Value;
            aerisJobParams.JitWebData3ConnectionString = Configuration.GetSection("AerisJobParams:JitWebData3ConnectionString").Value;
            aerisJobParams.RealJitWeatherConnection    = Configuration.GetSection("AerisJobParams:RealJitWeatherConnection").Value;

            SchedulerJob.RunAsync(aerisJobParams).GetAwaiter().GetResult();
        }
        public void Handle(ActivateJob command)
        {
            SchedulerJob job = repository.GetById(command.JobId);

            job.Activate();
            repository.Save(job);
        }
예제 #4
0
        public void ShouldSchduleTwitterJobs()
        {
            // Arrange
            var schedulerJobManagerMock      = new Mock <IScheduleJobManager>();
            var siteSocialAccountServiceMock = new Mock <ISiteSocialAccountService>();
            var twitterAccount = new SiteSocialAccount {
                SiteId = 10000, TwitterUserId = "abc"
            };

            siteSocialAccountServiceMock.Setup(t => t.GetTwitterSiteAccountsAsync()).ReturnsAsync(new List <SiteSocialAccount>
            {
                twitterAccount
            });

            SchedulerJob schedulerJob = new SchedulerJob(schedulerJobManagerMock.Object, siteSocialAccountServiceMock.Object);

            var jobExecutionContextMock = new Mock <IJobExecutionContext>();
            var jobDetailMock           = new Mock <IJobDetail>();

            jobDetailMock.Setup(t => t.Key).Returns(new JobKey("TestJobKey"));
            jobExecutionContextMock.Setup(t => t.JobDetail).Returns(jobDetailMock.Object);

            // Act
            schedulerJob.Execute(jobExecutionContextMock.Object);

            // Assert
            schedulerJobManagerMock.Verify(t => t.ScheduleAsync <TwitterUserStreamJob, SiteSocialAccount>(It.IsAny <Action <JobBuilder> >(), It.IsAny <Action <TriggerBuilder> >(), twitterAccount), "Should schedule twitter user stream job.");
            schedulerJobManagerMock.Verify(t => t.ScheduleAsync <TwitterPullTweetsJob, SiteSocialAccount>(It.IsAny <Action <JobBuilder> >(), It.IsAny <Action <TriggerBuilder> >(), twitterAccount), "Should schedule twitter pull tweets job.");
            schedulerJobManagerMock.Verify(t => t.ScheduleAsync <TwitterPullDirectMessagesJob, SiteSocialAccount>(It.IsAny <Action <JobBuilder> >(), It.IsAny <Action <TriggerBuilder> >(), twitterAccount), "Should schedule facebook pull direct message job.");
        }
예제 #5
0
        public async Task UnknownAccountIsNotUsedForTweeting()
        {
            // Arrange
            var job = new SchedulerJob
            {
                AccountIds = new List <ulong> {
                    3
                },
                Text = "test"
            };

            var ctx1 = new Mock <IContextEntry>();

            ctx1.Setup(c => c.UserId).Returns(1);
            ctx1.Setup(c => c.Twitter.Statuses.TweetAsync("test", It.IsAny <IEnumerable <ulong> >(), 0))
            .Returns(Task.FromResult(DummyGenerator.CreateDummyStatus()))
            .Verifiable();

            var contextList = new Mock <ITwitterContextList>();

            contextList.Setup(c => c.Contexts).Returns(new[] { ctx1.Object });

            var config = new Mock <ITwitterConfiguration>();
            var proc   = new CreateStatusProcessor(contextList.Object, config.Object);

            // Act
            await proc.Process(job);

            // Assert
            ctx1.Verify(c => c.Twitter.Statuses.TweetAsync("test", It.IsAny <IEnumerable <ulong> >(), 0), Times.Never());
        }
예제 #6
0
        void TryStartDataFlow(JobType.UpdateInfoType jobType)
        {
            if (bufferBlockLowP == null || lowPriorityReadInfoBlock == null || writeInfoBlock == null)
            {
                return;
            }

            logger.Debug("TryStartDataFlow " + jobType);

            //var allInstancesID = unitOfWork.Instances.GetAll().Where(i => i.IsDeleted == false).Select<Instance, int>(i => i.Id);
            var allInstancesID = unitOfWork.Instances.GetAll().Select <Instance, int>(i => i.Id);
            var curCollecting  = nowCollecting.Where(i => i.Value.JobType == jobType).Select <KeyValuePair <long, SchedulerWorkItem>, int>(i => i.Value.InstanceId);

            var idToStartUpdate = allInstancesID.Except <int>(curCollecting);

            foreach (int id in idToStartUpdate)
            {
                SchedulerJob schedulerJob = new SchedulerJob(id, jobWorkers.GetUpdater(jobType), jobWorkers.GetSaver(jobType), jobType);

                while (!bufferBlockLowP.Post(schedulerJob))
                {
                }

                nowCollecting.TryAdd(unchecked (dictionaryKey++), new SchedulerWorkItem(id, jobType));

                // logger.Debug("post to BufferBlock " + jobType + " instanceID=" + id);
            }
        }
        public void Handle(DisableJob command)
        {
            SchedulerJob job = repository.GetById(command.JobId);

            job.Disable();
            repository.Save(job);
        }
        public void Handle(AddTaskToJob command)
        {
            SchedulerJob job = Repository.GetById(command.JobId);

            if (job != null)
            {
                job.AddTaskToJob(command.TaskId, command.CurrentState, command.DesiredState, command.LockedUntil);
                Repository.Save(job, command.OriginalVersion);
            }
        }
        public void Handle(UpdateTaskContent command)
        {
            SchedulerJob job = Repository.GetById(command.JobId);

            if (job != null)
            {
                job.UpdateTaskContent(command.TaskId, command.Content);
                Repository.Save(job, command.OriginalVersion);
            }
        }
        public void Handle(UpdateTaskLockedUntil command)
        {
            SchedulerJob job = Repository.GetById(command.JobId);

            if (job != null)
            {
                job.UpdateLockedUntil(command.TaskId, command.LockedUntil);
                Repository.Save(job, command.OriginalVersion);
            }
        }
        public void Handle(UpdateTaskDesiredState command)
        {
            SchedulerJob job = Repository.GetById(command.JobId);

            if (job != null)
            {
                job.UpdateDesiredState(command.TaskId, command.DesiredState);
                Repository.Save(job, command.OriginalVersion);
            }
        }
예제 #12
0
        public void RefreshInstance(int id)
        {
            logger.Debug("refresh instance with id=" + id);

            SchedulerJob schedulerJob = new SchedulerJob(id, jobWorkers.GetUpdater(JobType.UpdateInfoType.CheckStatus), jobWorkers.GetSaver(JobType.UpdateInfoType.CheckStatus), JobType.UpdateInfoType.CheckStatus);

            while (!bufferBlockHighP.Post(schedulerJob))
            {
            }

            logger.Debug(" urgentInstanceUpdate=" + id);
        }
예제 #13
0
        private void ScheduleDeletion(List <Tuple <ulong, ulong> > tweetIds)
        {
            var job = new SchedulerJob
            {
                JobType     = SchedulerJobType.DeleteStatus,
                IdsToDelete = tweetIds.Select(t => t.Item1).ToList(),
                AccountIds  = tweetIds.Select(t => t.Item2).ToList(),
                TargetTime  = DeletionDate + DeletionTime.TimeOfDay,
                Text        = Text
            };

            Scheduler.AddJob(job);
        }
예제 #14
0
        public void JobCanBeAdded()
        {
            var fileName = "SchedulerTests.JobCanBeAdded.json";

            try
            {
                // Arrange
                var contextList = new Mock <ITwitterContextList>();
                var config      = new Mock <ITwitterConfiguration>();

                var scheduler = new Scheduler(fileName, contextList.Object, config.Object);

                var job = new SchedulerJob
                {
                    JobType    = SchedulerJobType.Test,
                    AccountIds = new List <ulong> {
                        123
                    },
                    FilesToAttach = new List <string> {
                        "1", "2", "3"
                    },
                    IdsToDelete = new List <ulong> {
                        456
                    },
                    InReplyToStatus = 678,
                    TargetTime      = new DateTime(1, 2, 3, 4, 5, 6),
                    Text            = "hello world"
                };

                // Act
                scheduler.AddJob(job);

                // Assert
                string json    = File.ReadAllText(fileName);
                var    jobList = JsonConvert.DeserializeObject <List <SchedulerJob> >(json);

                Assert.IsNotNull(jobList);
                Assert.AreEqual(1, jobList.Count);
                CollectionAssert.AreEquivalent(job.AccountIds, jobList[0].AccountIds);
                Assert.AreEqual(job.InReplyToStatus, jobList[0].InReplyToStatus);
                Assert.AreEqual(job.TargetTime, jobList[0].TargetTime);
                Assert.AreEqual(job.Text, jobList[0].Text);
                Assert.AreEqual(job.JobType, jobList[0].JobType);
                CollectionAssert.AreEquivalent(job.IdsToDelete, jobList[0].IdsToDelete);
                CollectionAssert.AreEquivalent(job.FilesToAttach, jobList[0].FilesToAttach);
            }
            finally
            {
                File.Delete(fileName);
            }
        }
        public void ScheduleTweet(string text, ulong?inReplyTo, IEnumerable <ulong> accountIds, IEnumerable <string> mediaFileNames)
        {
            var job = new SchedulerJob
            {
                JobType         = SchedulerJobType.CreateStatus,
                Text            = text,
                AccountIds      = accountIds.ToList(),
                TargetTime      = ScheduleDate + ScheduleTime.TimeOfDay,
                InReplyToStatus = inReplyTo ?? 0,
                FilesToAttach   = mediaFileNames.ToList()
            };

            Scheduler.AddJob(job);
        }
예제 #16
0
        private void ScheduleTweet()
        {
            var job = new SchedulerJob
            {
                JobType         = SchedulerJobType.CreateStatus,
                Text            = Text,
                AccountIds      = Accounts.Where(a => a.Use).Select(a => a.Context.UserId).ToList(),
                TargetTime      = ScheduleDate + ScheduleTime.TimeOfDay,
                InReplyToStatus = InReplyTo?.Id ?? 0,
                FilesToAttach   = AttachedMedias.Select(m => m.FileName).ToList()
            };

            Scheduler.AddJob(job);
        }
예제 #17
0
        public override async Task Process(SchedulerJob job)
        {
            for (int i = 0; i < job.IdsToDelete.Count; ++i)
            {
                var statusId  = job.IdsToDelete[i];
                var accountId = job.AccountIds[i];

                var context = ContextList.Contexts.FirstOrDefault(c => c.UserId == accountId);
                if (context == null)
                {
                    LogTo.Warn($"Account with Id ({accountId}) was not found");
                    continue;
                }

                await context.Twitter.Statuses.DeleteTweetAsync(statusId);
            }
        }
예제 #18
0
        public ScheduleItem(SchedulerJob job, UserViewModel user, IScheduler scheduler, IConfig config, IViewServiceRepository viewServices)
            : base(config, viewServices)
        {
            Job          = job;
            User         = user;
            Scheduler    = scheduler;
            ViewServices = viewServices;

            Entities = new Entities
            {
                HashTagEntities     = EntityParser.ExtractHashtags(job.Text),
                MediaEntities       = new List <MediaEntity>(),
                SymbolEntities      = new List <SymbolEntity>(),
                UrlEntities         = new List <UrlEntity>(),
                UserMentionEntities = EntityParser.ExtractMentions(job.Text)
            };
        }
예제 #19
0
        public override async Task <CollectionResult> UpdateJob(SchedulerJob job)
        {
            Instance instance = await unitOfWork.Instances.GetAsync(job.InstanceID);

            if (instance.IsDeleted)
            {
                return(null);
            }

            CollectionResult result = new CollectionResult();

            result.InstanceID = job.InstanceID;

            SqlConnection connection = await connManager.OpenConnection(job.InstanceID, unitOfWork);

            if (connection == null)
            {
                logger.Error("can't open connection inctanceID =  " + job.InstanceID);
                result.InstanceInfo = null;
            }
            else
            {
                result.InstanceInfo = await instanceInfoUpdater.UpdateAsync(job.InstanceID, instanceDataCollector).ConfigureAwait(false);

                connManager.CloseConnection();
            }



            result.JobType = job.JobType;
            // result.Scheduler = job.Scheduler;
            result.JobSaver = job.JobSaver;



            if (result.InstanceInfo == null)
            {
                logger.Error("Job type full update collect error for instance " + job.InstanceID);
            }


            logger.Debug("end collect  full updat  id=" + job.InstanceID);

            return(result);
        }
예제 #20
0
        public void FutureJobIsNotExecuted()
        {
            // Arrange
            var contextList = new Mock <ITwitterContextList>();
            var config      = new Mock <ITwitterConfiguration>();

            var scheduler = new Scheduler("invalid.filename", contextList.Object, config.Object);
            var job       = new SchedulerJob
            {
                TargetTime = DateTime.Now.AddHours(1)
            };

            // Act
            bool processed = scheduler.ProcessJob(job);

            // Assert
            Assert.IsFalse(processed);
        }
예제 #21
0
        public void JobIsExecutedInThread()
        {
            // Arrange
            var contextList = new Mock <ITwitterContextList>();
            var config      = new Mock <ITwitterConfiguration>();

            var waitHandle = new ManualResetEventSlim(false);

            var proc = new Mock <IJobProcessor>();

            proc.Setup(p => p.Process(It.IsAny <SchedulerJob>())).Returns(Task.CompletedTask).Callback(
                () => waitHandle.Set()).Verifiable();

            var scheduler = new Scheduler("SchedulerTests.JobIsExecutedInThread.json", contextList.Object, config.Object,
                                          proc.Object, 20);

            scheduler.Start();
            bool set;

            try
            {
                var job = new SchedulerJob
                {
                    JobType    = SchedulerJobType.Test,
                    TargetTime = DateTime.Now.AddMilliseconds(-1),
                    AccountIds = new List <ulong> {
                        1
                    },
                    Text = "test"
                };
                scheduler.AddJob(job);

                // Act
                set = waitHandle.Wait(2000);
            }
            finally
            {
                scheduler.Stop();
            }

            // Assert
            Assert.IsTrue(set);
            proc.Verify(p => p.Process(It.IsAny <SchedulerJob>()), Times.Once());
        }
예제 #22
0
        public ScheduleItem(SchedulerJob job, UserViewModel user, IScheduler scheduler, IConfig config, IViewServiceRepository viewServices)
            : base(config, viewServices)
        {
            Job          = job;
            User         = user;
            Scheduler    = scheduler;
            ViewServices = viewServices;

            Entities = new Entities
            {
                HashTagEntities     = EntityParser.ExtractHashtags(job.Text),
                MediaEntities       = new List <MediaEntity>(),
                SymbolEntities      = new List <SymbolEntity>(),
                UrlEntities         = new List <UrlEntity>(),
                UserMentionEntities = EntityParser.ExtractMentions(job.Text)
            };

            BlockUserCommand  = new LogMessageCommand("Tried to block user from ScheduleItem", LogLevel.Warn);
            ReportSpamCommand = new LogMessageCommand("Tried to report user from ScheduleItem", LogLevel.Warn);
        }
예제 #23
0
        private async Task <ScheduleItem> CreateViewModel(SchedulerJob job)
        {
            var userId = job.AccountIds.First();
            var user   = await Cache.GetUser(userId);

            if (user == null)
            {
                user = await Context.Twitter.Users.ShowUser(userId, true);

                await Cache.AddUsers(new[]
                {
                    new UserCacheEntry(user)
                });
            }

            var userVm = new UserViewModel(user);
            var item   = new ScheduleItem(job, userVm, Scheduler, Configuration, ViewServiceRepository);

            return(item);
        }
예제 #24
0
        public async override Task <CollectionResult> UpdateJob(SchedulerJob job)
        {
            var instance = await unitOfWork.Instances.GetAsync(job.InstanceID);

            if (instance != null)
            {
                if (instance.IsDeleted && (DateTime.Now - instance.IsDeletedTime).Value.TotalSeconds > TIME_TO_SAVE_DELETED_INSECONDS)
                {
                    logger.Debug("RemoveJobUpdater found instance " + job.InstanceID);

                    CollectionResult result = new CollectionResult();
                    result.InstanceID = job.InstanceID;
                    result.JobType    = job.JobType;
                    result.JobSaver   = job.JobSaver;
                    return(result);
                }
            }


            return(null);
        }
예제 #25
0
        public override async Task Process(SchedulerJob job)
        {
            List <ulong> mediaIds = new List <ulong>();

            foreach (var file in job.FilesToAttach)
            {
                byte[] mediaData = File.ReadAllBytes(file);
                if (mediaData.Length > TwitterConfig.MaxImageSize)
                {
                    LogTo.Warn("Tried to attach image that was too big");
                    continue;
                }

                var usedAccounts     = ContextList.Contexts.Where(c => job.AccountIds.Contains(c.UserId)).ToArray();
                var acc              = usedAccounts.First();
                var additionalOwners = usedAccounts.Skip(1).Select(a => a.UserId);

                string mediaType = TwitterHelper.GetMimeType(file);
                var    media     = await acc.Twitter.UploadMediaAsync(mediaData, mediaType, additionalOwners);

                mediaIds.Add(media.MediaID);
            }

            var taskList = new List <Task>();

            foreach (var accountId in job.AccountIds)
            {
                var context = ContextList.Contexts.FirstOrDefault(c => c.UserId == accountId);
                if (context == null)
                {
                    LogTo.Warn($"Account with Id {accountId} was not found");
                    continue;
                }

                var task = context.Twitter.Statuses.TweetAsync(job.Text, mediaIds, job.InReplyToStatus);
                taskList.Add(task);
            }

            await Task.WhenAll(taskList);
        }
예제 #26
0
        public async Task TweetIsSend()
        {
            // Arrange
            var ctx1 = new Mock <IContextEntry>();

            ctx1.Setup(c => c.UserId).Returns(1);
            ctx1.Setup(c => c.Twitter.Statuses.TweetAsync("hello world", It.IsAny <IEnumerable <ulong> >(), 111))
            .Returns(Task.FromResult(DummyGenerator.CreateDummyStatus()))
            .Verifiable();

            var ctx2 = new Mock <IContextEntry>();

            ctx2.Setup(c => c.UserId).Returns(2);
            ctx2.Setup(c => c.Twitter.Statuses.TweetAsync("hello world", It.IsAny <IEnumerable <ulong> >(), 111))
            .Returns(Task.FromResult(DummyGenerator.CreateDummyStatus()))
            .Verifiable();

            var contextList = new Mock <ITwitterContextList>();

            contextList.Setup(c => c.Contexts).Returns(new[] { ctx1.Object, ctx2.Object });

            var job = new SchedulerJob
            {
                AccountIds = new List <ulong> {
                    1, 2
                },
                Text            = "hello world",
                InReplyToStatus = 111
            };

            var config = new Mock <ITwitterConfiguration>();
            var proc   = new CreateStatusProcessor(contextList.Object, config.Object);

            // Act
            await proc.Process(job);

            // Assert
            ctx1.Verify(c => c.Twitter.Statuses.TweetAsync("hello world", It.IsAny <IEnumerable <ulong> >(), 111), Times.Once());
            ctx2.Verify(c => c.Twitter.Statuses.TweetAsync("hello world", It.IsAny <IEnumerable <ulong> >(), 111), Times.Once());
        }
예제 #27
0
        public override async Task <CollectionResult> UpdateJob(SchedulerJob job)
        {
            // logger.Debug("start collect status job  id=" + job.InstanceID);



            CollectionResult result = new CollectionResult();

            result.InstanceID = job.InstanceID;

            SqlConnection connection = await connManager.OpenConnection(job.InstanceID, unitOfWork);

            if (connection == null)
            {
                logger.Error("can't open connection inctanceID =  " + job.InstanceID);
                result.InstanceInfo = null;
            }
            else
            {
                result.InstanceInfo = await instanceInfoUpdater.UpdateStatusOnlyAsync(job.InstanceID, instanceDataCollector).ConfigureAwait(false);

                connManager.CloseConnection();
            }

            result.JobType = job.JobType;
            //result.Scheduler = job.Scheduler;
            result.JobSaver = job.JobSaver;



            if (result.InstanceInfo == null)
            {
                logger.Error("Job type status update collect error for instance " + job.InstanceID);
            }


            logger.Debug("end collect  status update  id=" + job.InstanceID);

            return(result);
        }
예제 #28
0
        public async Task TooBigImageIsNotUploaded()
        {
            try
            {
                // Arrange
                File.WriteAllBytes("file3.png", new byte[] { 1 });

                var ctx1 = new Mock <IContextEntry>();
                ctx1.Setup(c => c.UserId).Returns(1);
                ctx1.Setup(c => c.Twitter.UploadMediaAsync(It.IsAny <byte[]>(), It.IsAny <string>(), It.IsAny <IEnumerable <ulong> >()))
                .Returns(Task.FromResult(new LinqToTwitter.Media()))
                .Verifiable();

                var config = new Mock <ITwitterConfiguration>();
                config.SetupGet(c => c.MaxImageSize).Returns(0);

                var contextList = new Mock <ITwitterContextList>();
                contextList.Setup(c => c.Contexts).Returns(new[] { ctx1.Object });

                var proc = new CreateStatusProcessor(contextList.Object, config.Object);

                var job = new SchedulerJob
                {
                    FilesToAttach = new List <string> {
                        "file3.png"
                    }
                };

                // Act
                await proc.Process(job);

                // Assert
                ctx1.Verify(c => c.Twitter.UploadMediaAsync(It.IsAny <byte[]>(), It.IsAny <string>(), It.IsAny <IEnumerable <ulong> >()), Times.Never());
            }
            finally
            {
                File.Delete("file3.png");
            }
        }
예제 #29
0
        public void PastJobIsExecuted()
        {
            // Arrange
            var contextList = new Mock <ITwitterContextList>();
            var config      = new Mock <ITwitterConfiguration>();

            var job = new SchedulerJob
            {
                TargetTime = DateTime.Now.AddHours(-1)
            };

            var proc = new Mock <IJobProcessor>();

            proc.Setup(p => p.Process(job)).Verifiable();
            var scheduler = new Scheduler("invalid.filename", contextList.Object, config.Object, proc.Object);

            // Act
            bool processed = scheduler.ProcessJob(job);

            // Assert
            Assert.IsTrue(processed);
            proc.Verify(p => p.Process(job), Times.Once());
        }
예제 #30
0
        public async Task StatusIsDeleteFromCorrectAccount()
        {
            // Arrange
            var job = new SchedulerJob
            {
                JobType     = SchedulerJobType.DeleteStatus,
                IdsToDelete = new List <ulong> {
                    1001, 2001
                },
                AccountIds = new List <ulong> {
                    1, 2
                }
            };

            var ctx1 = new Mock <IContextEntry>();

            ctx1.Setup(c => c.UserId).Returns(1);
            ctx1.Setup(c => c.Twitter.Statuses.DeleteTweetAsync(1001)).Returns(Task.FromResult(DummyGenerator.CreateDummyStatus())).Verifiable();

            var ctx2 = new Mock <IContextEntry>();

            ctx2.Setup(c => c.UserId).Returns(2);
            ctx2.Setup(c => c.Twitter.Statuses.DeleteTweetAsync(2001)).Returns(Task.FromResult(DummyGenerator.CreateDummyStatus())).Verifiable();

            var contextList = new Mock <ITwitterContextList>();

            contextList.Setup(c => c.Contexts).Returns(new[] { ctx1.Object, ctx2.Object });

            var proc = new DeleteStatusProcessor(contextList.Object);

            // Act
            await proc.Process(job);

            // Assert
            ctx1.Verify(c => c.Twitter.Statuses.DeleteTweetAsync(1001), Times.Once());
            ctx2.Verify(c => c.Twitter.Statuses.DeleteTweetAsync(2001), Times.Once());
        }