public void Update(FlyOwner owner) { ValideteUpdate(owner); using (var scope = new TransactionScope()) { _ownerRepository.Update(owner); scope.Complete(); } }
public void Insert(FlyOwner owner) { ValidateInsert(owner); using (var scope = new TransactionScope()) { _ownerRepository.Insert(owner); scope.Complete(); } }
private void ValidateInsert(FlyOwner owner) { if(owner == null) throw new ArgumentException("Owner is required!"); if(string.IsNullOrWhiteSpace(owner.Name)) throw new ArgumentException("Name is required!"); if (string.IsNullOrWhiteSpace(owner.NickName)) throw new ArgumentException("Nick is required!"); }
public void Update(FlyOwner owner) { if (owner.Id > 0) { var ownerToUpdate = GetById(owner.Id); if (ownerToUpdate != null) { _context.Entry(ownerToUpdate).CurrentValues.SetValues(owner); } } _context.SaveChanges(); }
private void ValideteUpdate(FlyOwner owner) { if(owner == null) throw new ArgumentException("Owner is required!"); if (string.IsNullOrWhiteSpace(owner.Name)) throw new ArgumentException("Name is required!"); if (string.IsNullOrWhiteSpace(owner.NickName)) throw new ArgumentException("Nick is required!"); if(_ownerRepository.GetById(owner.Id) == null) throw new ArgumentException("Owner not exists!"); }
public void Insert(FlyOwner owner) { _context.FlyOwners.Add(owner); _context.SaveChanges(); }
public void CanUpdate() { var ownerRepository = new Mock<IFlyOwnerRepository>(); ownerRepository.Setup(s => s.GetById(1)).Returns(new FlyOwner { Id = 1, Name = "First Owner", NickName = "Nick" }); var ownerService = new FlyOwnerService(ownerRepository.Object); var owner = new FlyOwner { Id = 1, Name = "Second Owner", NickName = "Nick" }; ownerService.Update(owner); ownerRepository.Verify(v => v.Update(It.IsAny<FlyOwner>()), Times.Once()); }
public void CanNotUpdateAbsentOwner() { var ownerRepository = new Mock<IFlyOwnerRepository>(); ownerRepository.Setup(s => s.GetById(1)).Returns(new FlyOwner { Id = 1, Name = "First Owner", NickName = "Nick" }); var ownerService = new FlyOwnerService(ownerRepository.Object); try { var owner = new FlyOwner { Id = 2, Name = "Second Owner", NickName = "Nick" }; ownerService.Update(owner); Assert.Fail("Validation not Implemented!"); } catch (ArgumentException argex) { Assert.AreEqual("Owner not exists!", argex.Message); ownerRepository.Verify(v => v.Update(It.IsAny<FlyOwner>()), Times.Never()); } }