Ejemplo n.º 1
0
        public async void CanUpdateTopicEntity()
        {
            // Arrange
            DataEntity.Topic returnVal = new DataEntity.Topic {
                Description = "mockUpdateDescription",
                Notes       = "mockUpdateNotes"
            };

            var mockMongoDBCollection = MongoHelper <DataEntity.Topic> .GetMockMongoCollection();

            mockMongoDBCollection.Setup(c =>
                                        c.FindOneAndUpdateAsync <DataEntity.Topic>(
                                            It.IsAny <MongoDB.Driver.FilterDefinition <DataEntity.Topic> >(),
                                            It.IsAny <MongoDB.Driver.UpdateDefinition <DataEntity.Topic> >(),
                                            It.IsAny <FindOneAndUpdateOptions <DataEntity.Topic, DataEntity.Topic> >(),
                                            It.IsAny <CancellationToken>()))
            .ReturnsAsync(returnVal);

            var mockMongoDatabase = MongoHelper <DataEntity.Topic> .GetMockMongoDBInstance();

            mockMongoDatabase.Setup(mdb =>
                                    mdb.GetCollection <DataEntity.Topic>(It.IsAny <string>(),
                                                                         It.IsAny <MongoCollectionSettings>())).Returns(mockMongoDBCollection.Object);

            var dataAccess      = new QuizDataAccess.QuizDataAccess <DataEntity.Topic>(mockMongoDatabase.Object);
            var topicRep        = new TopicRepository(dataAccess, _topicCacheMock.Object);
            var topicController = new TopicController.TopicController(new QuizManager.QuizManager(topicRep, null, null), null);

            var entity = new ResponseData.Topic {
                Description = "mockDescription",
                Notes       = "mockNotes"
            };

            // Act
            var result = await topicController.Update("58e5db28e40cc200151a5ba4", new ResponseData.TopicIgnoreUniqId {
                Description = entity.Description,
                Notes       = entity.Notes
            });

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

            statusCode.StatusCode.Should().Be(204, "Should return status code as modified");
        }
Ejemplo n.º 2
0
        public async void UpdateCanHandleUnavilableResource()
        {
            // Arrange
            DataEntity.Topic returnVal = null;
            var mockMongoDBCollection  = MongoHelper <DataEntity.Topic> .GetMockMongoCollection();

            mockMongoDBCollection.Setup(c =>
                                        c.FindOneAndUpdateAsync <DataEntity.Topic>(
                                            It.IsAny <MongoDB.Driver.FilterDefinition <DataEntity.Topic> >(),
                                            It.IsAny <MongoDB.Driver.UpdateDefinition <DataEntity.Topic> >(),
                                            It.IsAny <FindOneAndUpdateOptions <DataEntity.Topic, DataEntity.Topic> >(),
                                            It.IsAny <CancellationToken>()))
            .ReturnsAsync(returnVal);

            var mockMongoDatabase = MongoHelper <DataEntity.Topic> .GetMockMongoDBInstance();

            mockMongoDatabase.Setup(mdb =>
                                    mdb.GetCollection <DataEntity.Topic>(It.IsAny <string>(),
                                                                         It.IsAny <MongoCollectionSettings>())).Returns(mockMongoDBCollection.Object);

            var dataAccess = new QuizDataAccess.QuizDataAccess <DataEntity.Topic>(mockMongoDatabase.Object);

            MockTopicCache(new DataEntity.Topic {
                Id          = "5883a3fa50f5fea2822f21cf",
                Description = "mockedDescription",
                Notes       = "mockNotes"
            });

            var topicRep         = new TopicRepository(dataAccess, _topicCacheMock.Object);
            var topicController  = new TopicController.TopicController(new QuizManager.QuizManager(topicRep, null, null), null);
            var jsonPatchRequest = new JsonPatchDocument <ResponseData.TopicIgnoreUniqId>();

            jsonPatchRequest.Add((q) => q.Description, "mockDescriptionToUpdate");

            // Act
            var result = await topicController.UpdateTopic("58e5db28e40cc200151a5ba4", jsonPatchRequest);

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

            statusCode.StatusCode.Should().Be(304, "Should return status code as modified");
        }
Ejemplo n.º 3
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);
        }