Beispiel #1
0
        public void DeleteAdvert_ShouldThrowNullReferenceException_IfAdvertIsNull()
        {
            var mockedRepository = new Mock <IRepository <Advert> >();
            var mockedUnitOfWork = new Mock <IUnitOfWork>();
            var advertService    = new AdvertServices(mockedRepository.Object, mockedUnitOfWork.Object);

            Mock <Advert> advertAsNull = null;

            Assert.Throws <NullReferenceException>(() => advertService.DeleteAdvert(advertAsNull.Object));
        }
Beispiel #2
0
        public void DeleteAdvert_Should_BeCalledOnce_IfParamsAreValid()
        {
            var mockedRepository = new Mock <IRepository <Advert> >();
            var mockedUnitOfWork = new Mock <IUnitOfWork>();
            var advertService    = new AdvertServices(mockedRepository.Object, mockedUnitOfWork.Object);

            var advert = new Mock <Advert>();

            advertService.AddAdvert(advert.Object);
            advertService.DeleteAdvert(advert.Object);

            mockedRepository.Verify(rep => rep.Delete(It.IsAny <Advert>()), Times.Once);
        }
Beispiel #3
0
        public void DeleteAdvert_Should_CallSaveChangesTwoTimes_IfAdvertIsValid()
        {
            var mockedRepository = new Mock <IRepository <Advert> >();
            var mockedUnitOfWork = new Mock <IUnitOfWork>();
            var advertService    = new AdvertServices(mockedRepository.Object, mockedUnitOfWork.Object);

            var advert = new Mock <Advert>();

            advertService.AddAdvert(advert.Object);
            advertService.DeleteAdvert(advert.Object);

            mockedUnitOfWork.Verify(u => u.SaveChanges(), Times.Exactly(2));
        }
Beispiel #4
0
        public void DeleteAdvert_Should_BeCalled_IfAdvertIsValid()
        {
            var mockedRepository = new Mock <IRepository <Advert> >();
            var mockedUnitOfWork = new Mock <IUnitOfWork>();
            var advertService    = new AdvertServices(mockedRepository.Object, mockedUnitOfWork.Object);

            var advertToAddAndDelete = new Mock <Advert>();

            advertService.AddAdvert(advertToAddAndDelete.Object);
            advertService.DeleteAdvert(advertToAddAndDelete.Object);

            mockedRepository.Verify(rep => rep.Delete(advertToAddAndDelete.Object));
        }