public void ReturnFalse_WhenNullArgumentIsPassed() { //Arrange var mockedUnitOfWork = new Mock <IUnitOfWork>(); var mockedMapper = new Mock <IMapper>(); var jobOfferService = new JobOfferService(mockedUnitOfWork.Object, mockedMapper.Object); //Act & Assert Assert.IsFalse(jobOfferService.Add(null)); }
public void ReturnFalse_WhenExceptionOccured() { //Arrange var mockedUnitOfWork = new Mock <IUnitOfWork>(); var mockedMapper = new Mock <IMapper>(); var jobOfferService = new JobOfferService(mockedUnitOfWork.Object, mockedMapper.Object); var mockedJobOfferModel = new Mock <JobOfferModel>(); //Act mockedUnitOfWork.Setup(x => x.JobOfferRepository).Throws(new Exception()); //Assert Assert.IsFalse(jobOfferService.Add(mockedJobOfferModel.Object)); }
public void CallMapperMapMethod_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>(); var mockedJobOfferModel = new Mock <JobOfferModel>(); //Act mockedMapper.Setup(x => x.Map <JobOffer>(mockedJobOfferModel.Object)).Returns(mockedJobOffer.Object); jobOfferService.Add(mockedJobOfferModel.Object); //Assert mockedMapper.Verify(x => x.Map <JobOffer>(mockedJobOfferModel.Object), Times.Once); }
public void ExecuteMethodAndReturnTrue_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>(); var mockedJobOfferModel = new Mock <JobOfferModel>(); //Act mockedMapper.Setup(x => x.Map <JobOffer>(mockedJobOfferModel.Object)).Returns(mockedJobOffer.Object); mockedUnitOfWork.Setup(x => x.JobOfferRepository).Returns(mockedJobOfferRepository.Object); mockedJobOfferRepository.Setup(x => x.Update(mockedJobOffer.Object)); mockedUnitOfWork.Setup(x => x.SaveChanges()); //Assert Assert.IsTrue(jobOfferService.Add(mockedJobOfferModel.Object)); }