Esempio n. 1
0
        public void PersonBl_GetById_Should_Return_NewObject()
        {
            // Arrange
            A.CallTo(() => _personRepository.GetById(PersonId)).Returns(null);
            var personBl = new PersonBl(_uow);

            // Act
            var sut = personBl.GetById(PersonId);

            // Assert
            bool isEqual = AreObjectsEqualHelper.IsEqual(sut, _personDto);

            Assert.AreEqual(isEqual, true);
        }
Esempio n. 2
0
        public void PersonBl_GetById_Should_Return_Person()
        {
            // Arrange
            A.CallTo(() => _personRepository.GetById(PersonId)).Returns(_person);
            var personBl = new PersonBl(_uow);

            // Act
            var sut             = personBl.GetById(PersonId);
            var actualPersonDto = personBl.FromEntityToModel(_person);

            // Assert
            bool isEqual = AreObjectsEqualHelper.IsEqual(sut, actualPersonDto);

            Assert.AreEqual(isEqual, true);
        }
        public void DeletePerson(PersonBl personBl)
        {
            if (personBl == null)
            {
                throw new ArgumentException("personBl cannot be null");
            }

            var person = _context.People.SingleOrDefault(p => p.PersonId == personBl.PersonId);

            if (person == null)
            {
                throw new ArgumentException(String.Format("person {0} does not exist", personBl.PersonId));
            }

            _context.People.Remove(person);
            _context.SaveChanges();
        }
        public PersonBl UpdatePerson(PersonBl personBl)
        {
            if (personBl == null)
            {
                throw new ArgumentException("personBl cannot be null");
            }

            var person = _context.People.SingleOrDefault(p => p.PersonId == personBl.PersonId);

            if (person == null)
            {
                throw new ArgumentException(String.Format("person {0} does not exist", personBl.PersonId));
            }

            _mapper.Map(personBl, person);
            _context.SaveChanges();

            return(_mapper.Map <PersonBl>(person));
        }
        public PersonBl AddPerson(PersonBl personBl)
        {
            if (personBl == null)
            {
                throw new ArgumentException("personBl cannot be null");
            }

            if (personBl.PersonId != 0)
            {
                throw new ArgumentException("personBl cannot define it's own id");
            }

            var person = _mapper.Map <Person>(personBl);

            _context.People.Add(person);
            _context.SaveChanges();

            return(_mapper.Map <PersonBl>(person));
        }