public void Update_ShouldFailWithNull_WhenWrongValues()
        {
            // Arrange
            int id             = _markGeneralDataPoints[0].Id;
            int markId         = _markGeneralDataPoints[0].Mark.Id;
            int sectionId      = _markGeneralDataPoints[0].Section.Id;
            var newStringValue = "NewUpdate";

            var newMarkGeneralDataPointRequest = new MarkGeneralDataPointUpdateRequest
            {
                Text = newStringValue,
            };

            // Act & Assert
            Assert.Throws <ArgumentNullException>(() => _service.Update(
                                                      id, markId, sectionId, null));
            Assert.Throws <ArgumentNullException>(() => _service.Update(
                                                      999, markId, sectionId, newMarkGeneralDataPointRequest));
            Assert.Throws <ArgumentNullException>(() => _service.Update(
                                                      id, 999, sectionId, newMarkGeneralDataPointRequest));
            Assert.Throws <ArgumentNullException>(() => _service.Update(
                                                      id, markId, 999, newMarkGeneralDataPointRequest));


            _repository.Verify(mock => mock.Update(It.IsAny <MarkGeneralDataPoint>()), Times.Never);
        }
Esempio n. 2
0
 public ActionResult Update(int markId, int sectionId, int id,
                            [FromBody] MarkGeneralDataPointUpdateRequest markGeneralDataPointRequest)
 {
     if (!markGeneralDataPointRequest.Validate())
     {
         return(BadRequest());
     }
     try
     {
         _service.Update(id, markId, sectionId, markGeneralDataPointRequest);
     }
     catch (ArgumentNullException)
     {
         return(NotFound());
     }
     return(NoContent());
 }
        public void Update_ShouldFailWithConflict_WhenConflictValues()
        {
            // Arrange
            int id        = _markGeneralDataPoints[0].Id;
            int markId    = _markGeneralDataPoints[0].Mark.Id;
            int sectionId = _markGeneralDataPoints[0].Section.Id;

            var newMarkGeneralDataPointRequest = new MarkGeneralDataPointUpdateRequest
            {
                Text = _markGeneralDataPoints[6].Text,
            };

            // Act & Assert
            Assert.Throws <ConflictException>(() => _service.Update(
                                                  id, markId, sectionId, newMarkGeneralDataPointRequest));

            _repository.Verify(mock => mock.Update(It.IsAny <MarkGeneralDataPoint>()), Times.Never);
        }
        public void Update_ShouldUpdatemarkGeneralDataPoint()
        {
            // Arrange
            int id             = _markGeneralDataPoints[0].Id;
            int markId         = _markGeneralDataPoints[0].Mark.Id;
            int sectionId      = _markGeneralDataPoints[0].Section.Id;
            var newStringValue = "NewUpdate";

            var newMarkGeneralDataPointRequest = new MarkGeneralDataPointUpdateRequest
            {
                Text = newStringValue,
            };

            // Act
            _service.Update(
                id, markId, sectionId, newMarkGeneralDataPointRequest);

            // Assert
            _repository.Verify(mock => mock.Update(It.IsAny <MarkGeneralDataPoint>()), Times.Once);
            var v = _markGeneralDataPoints.SingleOrDefault(v => v.Id == id);

            Assert.Equal(newStringValue, v.Text);
        }
Esempio n. 5
0
        public void Update(
            int id, int markId, int sectionId,
            MarkGeneralDataPointUpdateRequest markGeneralDataPoint)
        {
            if (markGeneralDataPoint == null)
            {
                throw new ArgumentNullException(nameof(markGeneralDataPoint));
            }
            var foundMarkGeneralDataPoint = _repository.GetById(id);

            if (foundMarkGeneralDataPoint == null)
            {
                throw new ArgumentNullException(nameof(foundMarkGeneralDataPoint));
            }
            var foundMark = _markRepo.GetById(markId);

            if (foundMark == null)
            {
                throw new ArgumentNullException(nameof(foundMark));
            }
            var foundSection = _generalDataSectionRepo.GetById(sectionId);

            if (foundSection == null)
            {
                throw new ArgumentNullException(nameof(foundSection));
            }

            if (markGeneralDataPoint.Text != null)
            {
                var uniqueConstraintViolationCheck = _repository.GetByUniqueKey(
                    foundMarkGeneralDataPoint.Mark.Id,
                    foundMarkGeneralDataPoint.Section.Id,
                    markGeneralDataPoint.Text);
                if (uniqueConstraintViolationCheck != null && uniqueConstraintViolationCheck.Id != id)
                {
                    throw new ConflictException(uniqueConstraintViolationCheck.Id.ToString());
                }
                foundMarkGeneralDataPoint.Text = markGeneralDataPoint.Text;
            }
            if (markGeneralDataPoint.OrderNum != null)
            {
                var orderNum = markGeneralDataPoint.OrderNum.GetValueOrDefault();
                foundMarkGeneralDataPoint.OrderNum = orderNum;
                short num = 1;
                foreach (var p in _repository.GetAllByMarkAndSectionId(markId, sectionId))
                {
                    if (p.Id == id)
                    {
                        continue;
                    }
                    if (num == markGeneralDataPoint.OrderNum)
                    {
                        num        = (Int16)(num + 1);
                        p.OrderNum = num;
                        _repository.Update(p);
                        num = (Int16)(num + 1);
                        continue;
                    }
                    p.OrderNum = num;
                    _repository.Update(p);
                    num = (Int16)(num + 1);
                }
            }

            _repository.Update(foundMarkGeneralDataPoint);

            foundMark.EditedDate = DateTime.Now;
            _markRepo.Update(foundMark);
        }