public void Update_ShouldUpdateConstructionElement() { // Arrange int id = _rnd.Next(1, _updateConstructionElements.Count()); int profileId = _rnd.Next(1, _profiles.Count()); short steelId = (Int16)(_rnd.Next(1, _steel.Count())); var newFloatValue = 9.0f; var newConstructionElementRequest = new ConstructionElementUpdateRequest { ProfileId = profileId, SteelId = steelId, Length = newFloatValue, }; // Act _updateService.Update(id, newConstructionElementRequest); // Assert _updateRepository.Verify(mock => mock.Update(It.IsAny <ConstructionElement>()), Times.Once); Assert.Equal(_profiles.SingleOrDefault(v => v.Id == profileId), _updateConstructionElements.SingleOrDefault( v => v.Id == id).Profile); Assert.Equal(_steel.SingleOrDefault(v => v.Id == steelId), _updateConstructionElements.SingleOrDefault( v => v.Id == id).Steel); Assert.Equal(newFloatValue, _updateConstructionElements.SingleOrDefault( v => v.Id == id).Length); }
public ActionResult Update( int id, [FromBody] ConstructionElementUpdateRequest constructionElementRequest) { if (!constructionElementRequest.Validate()) { return(BadRequest()); } try { _service.Update(id, constructionElementRequest); } catch (ArgumentNullException) { return(NotFound()); } catch (ConflictException) { return(Conflict()); } return(NoContent()); }