public void Update(Fly fly) { ValidateUpdate(fly); using (var scope = new TransactionScope()) { _flyRepository.Update(fly); scope.Complete(); } }
public void Insert(Fly fly) { ValidadeInsert(fly); using (var scope = new TransactionScope()) { _flyRepository.Insert(fly); scope.Complete(); } }
public void Update(Fly fly) { var flyToUpdate = GetById(fly.Id); if (flyToUpdate != null) { _context.Entry(flyToUpdate).CurrentValues.SetValues(fly); } _context.SaveChanges(); }
private void ValidateUpdate(Fly fly) { if (fly == null) throw new ArgumentException("Fly is required!"); if(_flyRepository.GetById(fly.Id) == null) throw new ArgumentException("Fly not exists!"); if(string.IsNullOrWhiteSpace(fly.Description)) throw new ArgumentException("Description is required!"); }
private void ValidadeInsert(Fly fly) { if (fly == null) throw new ArgumentException("Fly is required!"); if (string.IsNullOrWhiteSpace(fly.Description)) throw new ArgumentException("Description is required!"); if (fly.Owner == null) throw new ArgumentException("Owner is required!"); }
public void CanInsert() { var flyRepository = new Mock<IFlyRepository>(); var flyService = new FlyService(flyRepository.Object); var fly = new Fly { DateOfFly = DateTime.Now, Description = "First fly", Owner = new FlyOwner { Id = 1, Name = "Owner 1" } }; flyService.Insert(fly); flyRepository.Verify(v => v.Insert(It.IsAny<Fly>()), Times.Once()); }
public void Insert(Fly fly) { _context.Flys.Add(fly); _context.SaveChanges(); }
public void CanUpdate() { var flyRepository = new Mock<IFlyRepository>(); flyRepository.Setup(s => s.GetById(It.IsAny<int>())).Returns( new Fly { Id = 1, DateOfFly = DateTime.Now, Description="First Fly" , Owner = new FlyOwner { Id = 1, Name = "Owner 1" } }); var flyService = new FlyService(flyRepository.Object); var fly = new Fly { Id = 1, DateOfFly = DateTime.Now, Description="First Fly Update", Owner = new FlyOwner { Id = 2, Name = "Update Owner 1" } }; flyService.Update(fly); flyRepository.Verify(v => v.Update(It.IsAny<Fly>()), Times.Once()); }
public void CanNotInsertWithoutOwner() { var flyRepository = new Mock<IFlyRepository>(); var flyService = new FlyService(flyRepository.Object); var fly = new Fly { DateOfFly = DateTime.Now, Description = "First fly" }; try { flyService.Insert(fly); Assert.Fail("Validation not implemented!"); } catch (ArgumentException argex) { Assert.AreEqual("Owner is required!", argex.Message); flyRepository.Verify(v => v.Insert(It.IsAny<Fly>()), Times.Never()); } }