Esempio n. 1
0
        public ActionResult Create(
            int specificationId,
            [FromBody] ConstructionCreateRequest constructionRequest)
        {
            var constructionModel = _mapper.Map <Construction>(constructionRequest);

            try
            {
                _service.Create(
                    constructionModel,
                    specificationId,
                    constructionRequest.TypeId,
                    constructionRequest.SubtypeId,
                    constructionRequest.WeldingControlId);
            }
            catch (ArgumentNullException)
            {
                return(NotFound());
            }
            catch (ConflictException)
            {
                return(Conflict());
            }
            return(Created($"constructions/{constructionModel.Id}", null));
        }
        public void Create_ShouldCreateConstruction()
        {
            // Arrange
            int specificationId  = _rnd.Next(1, _specifications.Count());
            int typeId           = _rnd.Next(1, _constructionTypes.Count());
            int subtypeId        = _rnd.Next(1, _constructionSubtypes.Count());
            int weldingControlId = _rnd.Next(1, _weldingControl.Count());

            var newConstruction = new Construction
            {
                Name      = "NewCreate",
                Valuation = "NewCreate",
                NumOfStandardConstructions = 0,
                HasEdgeBlunting            = true,
                HasDynamicLoad             = false,
                HasFlangedConnections      = true,
                PaintworkCoeff             = 2,
            };

            // Act
            _service.Create(
                newConstruction,
                specificationId,
                typeId,
                subtypeId,
                weldingControlId);

            // Assert
            _repository.Verify(mock => mock.Add(It.IsAny <Construction>()), Times.Once);
            Assert.NotNull(newConstruction.Specification);
        }