Ejemplo n.º 1
0
        public void Update(Fly fly)
        {
            ValidateUpdate(fly);

            using (var scope = new TransactionScope())
            {
                _flyRepository.Update(fly);
                scope.Complete();
            }
        }
Ejemplo n.º 2
0
        public void Insert(Fly fly)
        {
            ValidadeInsert(fly);

            using (var scope = new TransactionScope())
            {
                _flyRepository.Insert(fly);
                scope.Complete();
            }
        }
Ejemplo n.º 3
0
        public void Update(Fly fly)
        {
            var flyToUpdate = GetById(fly.Id);

            if (flyToUpdate != null)
            {
                _context.Entry(flyToUpdate).CurrentValues.SetValues(fly);
            }

            _context.SaveChanges();
        }
Ejemplo n.º 4
0
        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!");
        }
Ejemplo n.º 5
0
        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!");
        }
Ejemplo n.º 6
0
        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());
        }
Ejemplo n.º 7
0
 public void Insert(Fly fly)
 {
     _context.Flys.Add(fly);
     _context.SaveChanges();
 }
Ejemplo n.º 8
0
        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());
        }
Ejemplo n.º 9
0
        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());
            }
        }