public void Create( AttachedDoc attachedDoc, int markId) { if (attachedDoc == null) { throw new ArgumentNullException(nameof(attachedDoc)); } var foundMark = _markRepo.GetById(markId); if (foundMark == null) { throw new ArgumentNullException(nameof(foundMark)); } var uniqueConstraintViolationCheck = _repository.GetByUniqueKey( markId, attachedDoc.Designation); if (uniqueConstraintViolationCheck != null) { throw new ConflictException( uniqueConstraintViolationCheck.Id.ToString()); } attachedDoc.Mark = foundMark; _repository.Add(attachedDoc); foundMark.EditedDate = DateTime.Now; _markRepo.Update(foundMark); }
public void Create_ShouldFailWithConflict_WhenConflictValues() { // Arrange var conflictMarkId = _attachedDocs[0].Mark.Id; var conflictDesignation = _attachedDocs[0].Designation; var newAttachedDoc = new AttachedDoc { Designation = conflictDesignation, Name = "NewCreate", }; // Act & Assert Assert.Throws <ConflictException>(() => _service.Create(newAttachedDoc, conflictMarkId)); _repository.Verify(mock => mock.Add(It.IsAny <AttachedDoc>()), Times.Never); }
public void Create_ShouldFailWithNull_WhenWrongValues() { // Arrange int markId = _rnd.Next(1, TestData.marks.Count()); var newAttachedDoc = new AttachedDoc { Designation = "NewCreate", Name = "NewCreate", }; // Act & Assert Assert.Throws <ArgumentNullException>(() => _service.Create(null, markId)); Assert.Throws <ArgumentNullException>(() => _service.Create(newAttachedDoc, 999)); _repository.Verify(mock => mock.Add(It.IsAny <AttachedDoc>()), Times.Never); }
public void Create_ShouldCreateAttachedDoc() { // Arrange int markId = _rnd.Next(1, TestData.marks.Count()); var newAttachedDoc = new AttachedDoc { Designation = "NewCreate", Name = "NewCreate", }; // Act _service.Create(newAttachedDoc, markId); // Assert _repository.Verify(mock => mock.Add(It.IsAny <AttachedDoc>()), Times.Once); Assert.NotNull(newAttachedDoc.Mark); }
public void Add_ShouldAddAttachedDoc() { // Arrange var context = GetContext(TestData.attachedDocs); var repo = new SqlAttachedDocRepo(context); int markId = _rnd.Next(1, TestData.marks.Count()); var attachedDoc = new AttachedDoc { Mark = TestData.marks.SingleOrDefault(v => v.Id == markId), Designation = "NewCreate", Name = "NewCreate", }; // Act repo.Add(attachedDoc); // Assert Assert.NotNull(repo.GetById(attachedDoc.Id)); context.Database.EnsureDeleted(); context.Dispose(); }
public void Delete(AttachedDoc attachedDoc) { _context.AttachedDocs.Remove(attachedDoc); _context.SaveChanges(); }
public void Update(AttachedDoc attachedDoc) { _context.Entry(attachedDoc).State = EntityState.Modified; _context.SaveChanges(); }
public void Add(AttachedDoc attachedDoc) { _context.AttachedDocs.Add(attachedDoc); _context.SaveChanges(); }