示例#1
0
        public void Update_ShouldUpdateDoc()
        {
            // Arrange
            int   id            = _rnd.Next(2, _docs.Count());
            var   newName       = "NewUpdate";
            var   newTypeId     = _docs[0].Type.Id;
            short newNumOfPages = 9;
            var   newForm       = 9.0f;

            var newDocRequest = new DocUpdateRequest
            {
                Name       = newName,
                TypeId     = newTypeId,
                NumOfPages = newNumOfPages,
                Form       = newForm,
            };

            // Act
            _service.Update(id, newDocRequest);

            // Assert
            _repository.Verify(mock => mock.Update(It.IsAny <Doc>()), Times.Once);
            Assert.Equal(newTypeId, _docs.SingleOrDefault(v => v.Id == id).Type.Id);
            Assert.Equal(newName, _docs.SingleOrDefault(v => v.Id == id).Name);
            Assert.Equal(newNumOfPages, _docs.SingleOrDefault(v => v.Id == id).NumOfPages);
            Assert.Equal(newForm, _docs.SingleOrDefault(v => v.Id == id).Form);
        }
示例#2
0
 public ActionResult Update(int id, [FromBody] DocUpdateRequest docRequest)
 {
     if (!docRequest.Validate())
     {
         return(BadRequest());
     }
     try
     {
         _service.Update(id, docRequest);
     }
     catch (ArgumentNullException)
     {
         return(NotFound());
     }
     return(NoContent());
 }