コード例 #1
0
        public async void CanGetResourceNotFoundWhenUnavilableTopicIdIsPassedWhileAddQuestion()
        {
            var mockResults = new DataEntity.Question();

            _questionDataAccessMock.Setup(p => p.AddAsync(mockResults))
            .ReturnsAsync(string.Empty)
            .Verifiable();

            var result = await _questionController.Add(
                new ResponseData.QuestionIgnoreId {
                TopicId = "mcokTopicId"
            });

            var actualResult = Assert.IsType <NotFoundObjectResult>(result);

            Assert.Equal((int)HttpStatusCode.NotFound, actualResult.StatusCode.Value);
        }
コード例 #2
0
        public async void CanUpdateQuestion()
        {
            // Arrange
            const string topicId     = "5782a3fa50f5fea2822f21cf";
            const string description = "update Questions";
            const string notes       = "testing question udpate";

            // Mock data entity
            var questionEntityReturnVal = new DataEntity.Question
            {
                TopicId     = topicId,
                Description = description,
                Notes       = notes
            };
            var topicEntityReturnVal = new DataEntity.Topic
            {
                Id          = topicId,
                Description = "topic description",
                Notes       = "topic notes"
            };


            // mongoDB
            var mockMongoDBTopic = MockMongoDatabase <DataEntity.Topic>(topicEntityReturnVal,
                                                                        new List <DataEntity.Topic> {
                new DataEntity.Topic()
            });

            var mockMongoDBQuestion = MockMongoDatabase <DataEntity.Question>(questionEntityReturnVal, new List <DataEntity.Question> {
                new DataEntity.Question()
            });


            var dataAccessTopicObject    = new QuizDataAccess.QuizDataAccess <DataEntity.Topic>(mockMongoDBTopic.Object);
            var dataAccessQuestionObject = new QuizDataAccess.QuizDataAccess <DataEntity.Question>(mockMongoDBQuestion.Object);

            // Cache
            MockQuestionCache(new List <DataEntity.Question> {
                new DataEntity.Question()
            });
            MockTopicCache(new List <DataEntity.Topic> {
                new DataEntity.Topic()
            });

            // Repository's
            var topicRepository    = new TopicRepository(dataAccessTopicObject, _topicCacheMock.Object);
            var questionRepository = new QuestionRepository(dataAccessQuestionObject, _questionsCacheMock.Object);

            var manager            = new QuizManager.QuizManager(topicRepository, questionRepository, null);
            var questionController = new QuestionController(manager);

            // Act
            var result = await questionController.Update("5883a3fa50f5fea2822f21cf",
                                                         new ResponseData.QuestionIgnoreId
            {
                TopicId     = topicId,
                Description = description,
                Notes       = notes
            });

            // Assert
            var statusCode = Assert.IsType <NoContentResult>(result);

            statusCode.Should().NotBeNull("Expected a valid status code");
            statusCode.StatusCode.Should().Be((int)HttpStatusCode.NoContent);
        }