コード例 #1
0
ファイル: TwitterTest.cs プロジェクト: pgava/FlowTasks
        public void Process_Tweets_When_No_Tweets_To_Process()
        {
            var mockTweet = new Mock <ITweet>();
            var mockTask  = new Mock <IFlowTasksService>();

            DateTime             last   = new DateTime(2012, 5, 30);
            List <TwitterStatus> tweets = new List <TwitterStatus>();

            mockTweet.Setup(tweet => tweet.GetLatestTwitterForWorkflow(out last))
            .Returns(tweets);
            mockTweet.Setup(tweet => tweet.SetLastTweetData(last));

            var resp = new StartWorkflowResponse
            {
                WorkflowId = Guid.NewGuid().ToString()
            };

            mockTask.Setup(task => task.StartWorkflow(Moq.It.IsAny <StartWorkflowRequest>()))
            .Returns(resp);

            var sut = new ProcessTweet(mockTweet.Object, mockTask.Object);

            sut.DoProcess();

            mockTweet.Verify(tweet => tweet.SetLastTweetData(new DateTime(2012, 5, 30)));
            mockTask.Verify(task => task.StartWorkflow(Moq.It.IsAny <StartWorkflowRequest>()), Times.Never());
        }
コード例 #2
0
ファイル: TwitterTest.cs プロジェクト: pgava/FlowTasks
        public void Process_Only_First_Tweet()
        {
            var mockTweet = new Mock <ITweet>();
            var mockTask  = new Mock <IFlowTasksService>();

            DateTime             last   = new DateTime(2012, 5, 30);
            List <TwitterStatus> tweets = new List <TwitterStatus>();

            tweets.Add(new TwitterStatus
            {
                CreatedDate = new DateTime(2012, 5, 1),
                Text        = "Tweet 1",
            });
            tweets.Add(new TwitterStatus
            {
                CreatedDate = new DateTime(2012, 5, 2),
                Text        = "Tweet 2",
            });

            mockTweet.Setup(tweet => tweet.GetLatestTwitterForWorkflow(out last))
            .Returns(tweets);
            mockTweet.Setup(tweet => tweet.SetLastTweetData(last));

            var resp = new StartWorkflowResponse
            {
                WorkflowId = Guid.NewGuid().ToString()
            };

            mockTask.Setup(task => task.StartWorkflow(Moq.It.IsAny <StartWorkflowRequest>()))
            .Returns(() => resp)
            .Callback(() => resp = new StartWorkflowResponse {
                WorkflowId = Guid.Empty.ToString()
            });

            var sut = new ProcessTweet(mockTweet.Object, mockTask.Object);

            sut.DoProcess();

            mockTweet.Verify(tweet => tweet.SetLastTweetData(new DateTime(2012, 5, 1)));
        }