コード例 #1
0
ファイル: GetByIdTests.cs プロジェクト: KristiyanVachev/Leaf
        public void GetById_ShouldReturnNull_WhenQuestionIsNotFound(int id)
        {
            //Arrange
            var mockQuestionRepository = new Mock <IRepository <Question> >();
            var mockCategoryRepository = new Mock <IRepository <Category> >();
            var mockQuestionFactory    = new Mock <IQuestionFactory>();
            var mockUnitOfWork         = new Mock <IUnitOfWork>();

            var utility = new QuestionUtility(mockQuestionRepository.Object,
                                              mockCategoryRepository.Object,
                                              mockQuestionFactory.Object,
                                              mockUnitOfWork.Object
                                              );

            //Act
            var question = utility.GetById(id);

            //Assert
            Assert.IsNull(question);
        }
コード例 #2
0
ファイル: GetByIdTests.cs プロジェクト: KristiyanVachev/Leaf
        public void GetById_ShouldReturnQuestion_WhenFound(int id)
        {
            //Arrange
            var mockQuestionRepository = new Mock <IRepository <Question> >();
            var mockCategoryRepository = new Mock <IRepository <Category> >();
            var mockQuestionFactory    = new Mock <IQuestionFactory>();
            var mockUnitOfWork         = new Mock <IUnitOfWork>();

            var utility = new QuestionUtility(mockQuestionRepository.Object,
                                              mockCategoryRepository.Object,
                                              mockQuestionFactory.Object,
                                              mockUnitOfWork.Object
                                              );

            mockQuestionRepository.Setup(x => x.GetById(id)).Returns(new Mock <Question>().Object);

            //Act
            var question = utility.GetById(id);

            //Assert
            Assert.IsInstanceOf <Question>(question);
        }