コード例 #1
0
        public IActionResult PutDocument(int id, [FromBody] DocumentCategoryEditModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            DocumentCategoryDto documentCategoryDto = new DocumentCategoryDto()
            {
                DocumentCategoryId    = model.DocumentCategoryId,
                DocumentCategoryTitle = model.DocumentCategoryTitle,
                CustomerId            = model.CustomerId,
                DateCreated           = DateTime.Now,
                DateModified          = DateTime.Now
            };

            try
            {
                var documentCategory = adminRepository.EditDocumentCategory(id, documentCategoryDto);
                if (documentCategory)
                {
                    return(Ok(documentCategory));
                }
                else
                {
                    return(NoContent());
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
コード例 #2
0
        public void UpdateDocumentCategoryTest()
        {
            NSI.REST.Models.DocumentCategoryCreateModel documentCategoryPost = new DocumentCategoryCreateModel()
            {
                DocumentCategoryTitle = "firstDocument",
                IsDeleted             = false,
                CustomerId            = 1,
                DateCreated           = DateTime.Now,
                DateModified          = DateTime.Now
            };

            NSI.REST.Models.DocumentCategoryEditModel documentCategoryPut = new DocumentCategoryEditModel()
            {
                DocumentCategoryId    = 10,
                DocumentCategoryTitle = "firstDocument",
                IsDeleted             = false,
                CustomerId            = 1,
                DateCreated           = DateTime.Now,
                DateModified          = DateTime.Now
            };

            var documentCategory = new DocumentCategoryDto()
            {
                DocumentCategoryId    = 10,
                DocumentCategoryTitle = "firstDocument",
                IsDeleted             = false,
                CustomerId            = 1,
                DateCreated           = DateTime.Now,
                DateModified          = DateTime.Now
            };

            var mockRepo = new Mock <IAdminManipulation>();

            mockRepo.Setup(x => x.CreateDocumentCategory(It.IsAny <DocumentCategoryDto>())).Returns(documentCategory);
            var controller = new AdminController(mockRepo.Object);

            controller.PostDocument(documentCategoryPost);

            //No content Result

            documentCategoryPut.DocumentCategoryTitle = "NewName";
            var result = controller.PutDocument(1, documentCategoryPut);

            Assert.IsType <NoContentResult>(result);

            //Bad Case Model
            controller.ModelState.AddModelError("error", "some error");

            result = controller.PutDocument(30, model: null);
            Assert.IsType <BadRequestObjectResult>(result);
        }
コード例 #3
0
        public void UpdateDocumentCategoryNoContentTest()
        {
            NSI.REST.Models.DocumentCategoryEditModel documentCategoryPut = new DocumentCategoryEditModel()
            {
                DocumentCategoryTitle = "firstDocument",
                IsDeleted             = false,
                CustomerId            = 1,
                DateCreated           = DateTime.Now,
                DateModified          = DateTime.Now
            };

            var mockRepo = new Mock <IAdminRepository>();

            mockRepo.Setup(x => x.EditCaseCategory(It.IsAny <int>(), It.IsAny <CaseCategoryDto>()));
            var adminManipulation = new AdminManipulation(mockRepo.Object);
            var controller        = new AdminController(adminManipulation);
            var result            = controller.PutDocument(10, documentCategoryPut);

            Assert.IsType <NoContentResult>(result);
        }