示例#1
0
        public void ReturnFalse_WhenExceptionOccuresByMethodExecution()
        {
            //Arrange
            var mockedUnitOfWork = new Mock <IUnitOfWork>();
            var mockedMapper     = new Mock <IMapper>();
            var jobOfferService  = new JobOfferService(mockedUnitOfWork.Object, mockedMapper.Object);

            //Act
            mockedUnitOfWork.Setup(x => x.JobOfferRepository).Throws(new Exception());

            //Assert
            Assert.IsFalse(jobOfferService.DeleteById(1));
        }
示例#2
0
        public void CallInheritedGetByIdMethod_WhenInvokedWithValidArgs()
        {
            //Arrange
            var mockedUnitOfWork         = new Mock <IUnitOfWork>();
            var mockedMapper             = new Mock <IMapper>();
            var jobOfferService          = new JobOfferService(mockedUnitOfWork.Object, mockedMapper.Object);
            var mockedJobOfferRepository = new Mock <IJobOfferRepository>();
            var mockedJobOffer           = new Mock <JobOffer>();

            //Act
            mockedUnitOfWork.Setup(x => x.JobOfferRepository).Returns(mockedJobOfferRepository.Object);
            mockedJobOfferRepository.Setup(x => x.GetById(It.IsAny <int>())).Returns(mockedJobOffer.Object);
            jobOfferService.DeleteById(1);

            //Assert
            mockedJobOfferRepository.Verify(x => x.GetById(1), Times.Once);
        }