コード例 #1
0
        public void MappingTest()
        {
            //Arrange
            var dataStorage = new Mock <IDataStorage>();
            var entity      = new Question {
                Id       = 1,
                DataType = QuestionDataType.Integer,
                Value    = "2",
                File     = null
            };
            var updatedEntity = new Question {
                Id       = 1,
                DataType = QuestionDataType.Integer,
                Value    = "3",
                File     = new Attachment()
            };
            var repository = new QuestionRepository(dataStorage.Object);

            dataStorage.Setup(ds => ds.GetData <Question>()).Returns(new List <Question> {
                entity
            });
            //Act
            repository.Edit(updatedEntity);
            //Assert
            //Values are equal
            Assert.That(entity.DataType, Is.EqualTo(updatedEntity.DataType));
            Assert.That(entity.Value, Is.EqualTo(updatedEntity.Value));
            Assert.That(entity.File, Is.EqualTo(updatedEntity.File));
        }
コード例 #2
0
        public void MappingTest()
        {
            //Arrange
            var dataStorage = new Mock<IDataStorage>();
            var entity = new Question {
                Id = 1,
                DataType = QuestionDataType.Integer,
                Value = "2",
                File = null
            };
            var updatedEntity = new Question {
                Id = 1,
                DataType = QuestionDataType.Integer,
                Value = "3",
                File = new Attachment()
            };
            var repository = new QuestionRepository(dataStorage.Object);

            dataStorage.Setup(ds => ds.GetData<Question>()).Returns(new List<Question> {entity});
            //Act
            repository.Edit(updatedEntity);
            //Assert
            //Values are equal
            Assert.That(entity.DataType, Is.EqualTo(updatedEntity.DataType));
            Assert.That(entity.Value, Is.EqualTo(updatedEntity.Value));
            Assert.That(entity.File, Is.EqualTo(updatedEntity.File));
        }
コード例 #3
0
        public IActionResult Edit([FromBody] QuestionViewModel questionViewModel, long id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            else if (_questionRepository.GetById(id) == null)
            {
                return(NotFound());
            }
            var question = new QuestionModel
            {
                Id             = questionViewModel.Id,
                Question       = questionViewModel.Question,
                Answer         = questionViewModel.Answer,
                Correct_answer = questionViewModel.Correct_answer,
                Level          = questionViewModel.Level
            };

            _questionRepository.Edit(question);
            return(Ok());
        }
コード例 #4
0
 public bool UpdateQuestion(Question question)
 {
     return(_questionRepository.Edit(question));
 }