Esempio n. 1
0
        public void Create_ShouldCreateDoc()
        {
            // Arrange
            int markId      = _rnd.Next(1, TestData.marks.Count());
            int docTypeId   = _rnd.Next(1, TestData.docTypes.Count());
            int creatorId   = _rnd.Next(1, TestData.employees.Count());
            int inspectorId = _rnd.Next(1, TestData.employees.Count());
            int normContrId = _rnd.Next(1, TestData.employees.Count());

            var newDoc = new Doc
            {
                Name       = "NewCreate",
                NumOfPages = 1,
                Form       = 1.0f,
            };

            // Act
            _service.Create(
                newDoc, markId, docTypeId, creatorId, inspectorId, normContrId);

            // Assert
            _repository.Verify(mock => mock.Add(It.IsAny <Doc>()), Times.Once);
            Assert.NotNull(newDoc.Mark);
            Assert.NotNull(newDoc.Type);
            Assert.NotNull(newDoc.Creator);
            Assert.NotNull(newDoc.Inspector);
            Assert.NotNull(newDoc.NormContr);
        }
 public IActionResult Post([FromBody] DocCreateModel doc)
 {
     try
     {
         return(Created("Post", docService.Create(mapper.Map <Doc>(doc))));
     }
     catch (Exception ex)
     {
         logger.LogError(ex.Message);
         return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
     }
 }
Esempio n. 3
0
        public ActionResult Create(
            int markId, [FromBody] DocCreateRequest docRequest)
        {
            var docModel = _mapper.Map <Doc>(docRequest);

            try
            {
                _service.Create(
                    docModel,
                    markId,
                    docRequest.TypeId,
                    docRequest.CreatorId,
                    docRequest.InspectorId,
                    docRequest.NormContrId);
            }
            catch (ArgumentNullException)
            {
                return(NotFound());
            }
            return(Created(
                       $"docs/{docModel.Id}", null));
        }