コード例 #1
0
ファイル: SummarizerTest.cs プロジェクト: izevaka/stacktagz
        public void GetTimeSeriesShouldProcessComments()
        {
            Summarizer target = new Summarizer(m_questionRepo.Object, m_answerRepo.Object, m_PersistQuestionsRepo.Object, null, m_commentsRepositoryMock.Object, m_commentsProcessorMock.Object);
            int userId = 0;

            m_commentsProcessorMock.Setup(cp => cp.ConvertAnswersToQuestions(It.IsAny<string>(), It.IsAny<IEnumerable<CommentInfo>>()))
                .Returns(new[] {
                    new CommentInfo { CreationDate = new DateTime(2010, 07, 01), Id = 9876, IsQuestion = true } ,
                    new CommentInfo { CreationDate = new DateTime(2010, 07, 02), Id = 9875, IsQuestion = true }
                });

            m_questionRepo.Setup(ar => ar.Get(It.IsAny<string>(), It.Is<IEnumerable<int>>(arr => arr.IsEqual(new[] { 9876, 9875 }))))
                .Returns(new List<QuestionInfo> {
                    new QuestionInfo { CreationDate = new DateTime(2010, 06, 30), Id = 9876, Tags = new List<string> { "tag1", "tag3" } } ,
                    new QuestionInfo { CreationDate = new DateTime(2010, 06, 29), Id = 9875, Tags = new List<string> { "tag3", "tag4" } }
                });

            m_PersistQuestionsRepo.Setup(qpr => qpr.Get(It.IsAny<string>(), It.Is<IEnumerable<int>>(arr => arr.IsEqual(new[] { 9876, 9875 })))).Returns(new List<QuestionInfo> { });

            var actual = target.RequestTimeSeries("", userId, null,null, Rollup.Weekly);

            CollectionAssert.AreEquivalent(new[] { "tag1", "tag2", "tag3", "tag4" }, actual.Timeseries.Keys);
            Assert.IsTrue(actual.Timeseries["tag1"].IsEqual(new Dictionary<DateTime, TimeseriesPeriod> { { new DateTime(2009, 06, 21), new TimeseriesPeriod(1, 2, 0) }, { new DateTime(2010, 06, 27), new TimeseriesPeriod(0, 0, 1) } }));
            Assert.IsTrue(actual.Timeseries["tag2"].IsEqual(new Dictionary<DateTime, TimeseriesPeriod> { { new DateTime(2009, 06, 21), new TimeseriesPeriod(2, 1, 0) }}));
            Assert.IsTrue(actual.Timeseries["tag3"].IsEqual(new Dictionary<DateTime, TimeseriesPeriod> { { new DateTime(2009, 06, 21), new TimeseriesPeriod(1, 0, 0) }, { new DateTime(2010, 06, 27), new TimeseriesPeriod(0, 0, 2) } }));
            Assert.IsTrue(actual.Timeseries["tag4"].IsEqual(new Dictionary<DateTime, TimeseriesPeriod> { { new DateTime(2009, 06, 21), new TimeseriesPeriod(0, 1, 0) }, { new DateTime(2010, 06, 27), new TimeseriesPeriod(0, 0, 1) } }));
        }
コード例 #2
0
ファイル: SummarizerTest.cs プロジェクト: izevaka/stacktagz
        public void RequestTimeSeriesShouldSaveQuestions()
        {
            Summarizer target = new Summarizer(m_questionRepo.Object, m_answerRepo.Object, m_PersistQuestionsRepo.Object, null, m_commentsRepositoryMock.Object, m_commentsProcessorMock.Object);
            string site = string.Empty;
            int userId = 0;
            Nullable<DateTime> start = new Nullable<DateTime>();
            Nullable<DateTime> end = new Nullable<DateTime>();
            TimeseriesResult actual;
            actual = target.RequestTimeSeries(site, userId, start, end, Rollup.Weekly);

            m_PersistQuestionsRepo.Verify(r => r.SaveQuestions(site, m_UserQuestionData), Times.Once());
        }
コード例 #3
0
ファイル: SummarizerTest.cs プロジェクト: izevaka/stacktagz
 public void RequestTimeSeriesShouldRequestUnknownQuestionIds()
 {
     Summarizer target = new Summarizer(m_questionRepo.Object, m_answerRepo.Object, m_PersistQuestionsRepo.Object, null, m_commentsRepositoryMock.Object, m_commentsProcessorMock.Object);
     string site = string.Empty;
     int userId = 0;
     Nullable<DateTime> start = new Nullable<DateTime>();
     Nullable<DateTime> end = new Nullable<DateTime>();
     TimeseriesResult actual;
     actual = target.RequestTimeSeries(site, userId, start, end, Rollup.Weekly);
     m_questionRepo.Verify(q => q.Get(It.IsAny<string>(), It.Is<IEnumerable<int>>(v => v.IsEqual(new[] { 2345 }))), Times.Exactly(1));
 }
コード例 #4
0
ファイル: SummarizerTest.cs プロジェクト: izevaka/stacktagz
        public void RequestTimeSeriesShouldReturnQuestionAndAnswers()
        {
            Summarizer target = new Summarizer(m_questionRepo.Object, m_answerRepo.Object, m_PersistQuestionsRepo.Object, null, m_commentsRepositoryMock.Object, m_commentsProcessorMock.Object);
            string site = string.Empty;
            int userId = 0;
            Nullable<DateTime> start = new Nullable<DateTime>();
            Nullable<DateTime> end = new Nullable<DateTime>();
            TimeseriesResult actual;
            actual = target.RequestTimeSeries(site, userId, start, end, Rollup.Weekly);

            CollectionAssert.AreEqual(new []{"tag1", "tag2", "tag3", "tag4"}, actual.Timeseries.Keys);
            Assert.IsTrue(actual.Timeseries["tag1"].IsEqual(new Dictionary<DateTime, TimeseriesPeriod> { { new DateTime(2009, 06, 21), new TimeseriesPeriod(1, 2, 0) } }));
            Assert.IsTrue(actual.Timeseries["tag2"].IsEqual(new Dictionary<DateTime, TimeseriesPeriod> { { new DateTime(2009, 06, 21), new TimeseriesPeriod(2, 1, 0) } }));
            Assert.IsTrue(actual.Timeseries["tag3"].IsEqual(new Dictionary<DateTime, TimeseriesPeriod> { { new DateTime(2009, 06, 21), new TimeseriesPeriod(1, 0, 0) } }));
            Assert.IsTrue(actual.Timeseries["tag4"].IsEqual(new Dictionary<DateTime, TimeseriesPeriod> { { new DateTime(2009, 06, 21), new TimeseriesPeriod(0, 1, 0) } }));
        }
コード例 #5
0
ファイル: SummarizerTest.cs プロジェクト: izevaka/stacktagz
        public void RequestTimeSeriesShouldNotCallQuestionRepoIfNoAnswers()
        {
            m_answerRepo = new Mock<IAnswersRepository>();
            m_answerRepo.Setup(q => q.Get(It.IsAny<string>(), It.IsAny<int>())).Returns(new List<AnswerInfo>());

            Summarizer target = new Summarizer(m_questionRepo.Object, m_answerRepo.Object, m_PersistQuestionsRepo.Object, null, m_commentsRepositoryMock.Object, m_commentsProcessorMock.Object);
            string site = string.Empty;
            int userId = 0;
            Nullable<DateTime> start = new Nullable<DateTime>();
            Nullable<DateTime> end = new Nullable<DateTime>();
            TimeseriesResult actual;
            actual = target.RequestTimeSeries(site, userId, start, end, Rollup.Weekly);
            m_questionRepo.Verify(q => q.Get(It.IsAny<string>(), It.IsAny<IEnumerable<int>>()), Times.Never());
        }