Пример #1
0
        public void Update(FlyOwner owner)
        {
            ValideteUpdate(owner);

            using (var scope = new TransactionScope())
            {
                _ownerRepository.Update(owner);
                scope.Complete();
            }
        }
Пример #2
0
        public void Insert(FlyOwner owner)
        {
            ValidateInsert(owner);

            using (var scope = new TransactionScope())
            {
                _ownerRepository.Insert(owner);
                scope.Complete();
            }
        }
Пример #3
0
        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!");
        }
Пример #4
0
        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();
        }
Пример #5
0
        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!");
        }
Пример #6
0
 public void Insert(FlyOwner owner)
 {
     _context.FlyOwners.Add(owner);
     _context.SaveChanges();
 }
Пример #7
0
        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());
        }
Пример #8
0
        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());
            }
        }