Example #1
0
        public void ToQuestionInfoShouldSplitTags()
        {
            Question target = new Question { Date = new DateTime(2010, 06,23), Id = 1, QuestionId = 45, Site = "site", TagsList="tag1,tag2"};
            QuestionInfo expected = new QuestionInfo { CreationDate = new DateTime(2010, 06, 23), Id = 45, Tags = new System.Collections.Generic.List<string> { "tag1", "tag2"} };

            var actual = target.ToQuestionInfo();
            Assert.AreEqual(expected, actual);
        }
Example #2
0
        public void ToQuestionInfoShouldReturnEmptyTagsForNullTagsList()
        {
            Question target = new Question { Date = new DateTime(2010, 06, 23), Id = 1, QuestionId = 45, Site = "site", TagsList = null };
            QuestionInfo expected = new QuestionInfo { CreationDate = new DateTime(2010, 06, 23), Id = 45, Tags = new System.Collections.Generic.List<string> { } };

            var actual = target.ToQuestionInfo();
            Assert.AreEqual(expected, actual);
        }
Example #3
0
        public void SetFromQuestionInfoTest()
        {
            Question expected = new Question { Date = new DateTime(2010, 06, 23),QuestionId = 45, Site="site1", TagsList = "tag1,tag2" };
            QuestionInfo qInfo = new QuestionInfo { CreationDate = new DateTime(2010, 06, 23), Id = 45, Tags = new System.Collections.Generic.List<string> { "tag1", "tag2" } };
            var target = new Question();
            target.SetFromQuestionInfo("site1", qInfo);

            Assert.AreEqual(expected, target);
        }
        public void SaveQuestionsShouldAddOnlyNonExistentQuestions()
        {
            QuestionsRepository target = new QuestionsRepository(m_EntitiesMock.Object);
            List<QuestionInfo> questionInfos = new List<QuestionInfo> {
                new QuestionInfo{CreationDate = new DateTime(2010, 06, 23), Id = 34, Tags= new List<string>{"tag1", "tag2"}},
                new QuestionInfo{CreationDate = new DateTime(2010, 06, 23), Id = 12, Tags= new List<string>{"tag1", "tag2"}}
            };

            var result = new Question();
            m_EntitiesMock.Setup(e => e.CreateQuestion()).Returns(result);
            m_EntitiesMock.Setup(e=>e.Questions).Returns(new MockObjectSet<Question>(new []{
                new Question{QuestionId = 12, Site = "site1"}
            }));

            target.SaveQuestions("site1", questionInfos);

            m_EntitiesMock.Verify(e => e.AddQuestion(result), Times.Once());
            m_EntitiesMock.Verify(e => e.AddQuestion(It.IsAny<Question>()), Times.Once());
        }
        public void SaveQuestionsShouldCreateAndAddQuestion()
        {
            QuestionsRepository target = new QuestionsRepository(m_EntitiesMock.Object);
            List<QuestionInfo> questionInfos = new List<QuestionInfo> {
                new QuestionInfo{CreationDate = new DateTime(2010, 06, 23), Id = 34, Tags= new List<string>{"tag1", "tag2"}}
            };

            var result = new Question();
            m_EntitiesMock.Setup(e => e.Questions).Returns(new MockObjectSet<Question>(new Question[0]));
            m_EntitiesMock.Setup(e => e.CreateQuestion()).Returns(result);
            m_EntitiesMock.Setup(e => e.AddQuestion(result));
            m_EntitiesMock.Setup(e => e.SaveChanges());
            target.SaveQuestions("site1", questionInfos);
            m_EntitiesMock.VerifyAll();
        }
Example #6
0
 public void AddQuestion(Question item)
 {
     m_Questions.AddObject(item);
 }