public void GetById_Should_NotBeCalled_IfNotCalledYolo() { var mockedRepository = new Mock <IRepository <Advert> >(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var advertService = new AdvertServices(mockedRepository.Object, mockedUnitOfWork.Object); mockedRepository.Verify(rep => rep.GetById(1), Times.Never); }
public void Constructor_Should_CreateAdvertServices_IfParamsAreValid() { var mockedRepository = new Mock <IRepository <Advert> >(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var advertService = new AdvertServices(mockedRepository.Object, mockedUnitOfWork.Object); Assert.That(advertService, Is.InstanceOf <AdvertServices>()); }
public void GetAllAdverts_Should_NotBeCalled_IfItIsNeverCalled() { var mockedRepository = new Mock <IRepository <Advert> >(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var advertService = new AdvertServices(mockedRepository.Object, mockedUnitOfWork.Object); mockedRepository.Verify(rep => rep.All(), Times.Never); }
public void DeleteAdvert_Should_NotCallSaveChanges_IfAdvertIsNotDelete() { var mockedRepository = new Mock <IRepository <Advert> >(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var advertService = new AdvertServices(mockedRepository.Object, mockedUnitOfWork.Object); var advertThatIsNotAdded = new Mock <Advert>(); mockedUnitOfWork.Verify(u => u.SaveChanges(), Times.Never); }
public void GetAllAdverts_Should_BeCalled_IfParamsAreValid() { var mockedRepository = new Mock <IRepository <Advert> >(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var advertService = new AdvertServices(mockedRepository.Object, mockedUnitOfWork.Object); advertService.GetAllAdverts(); mockedRepository.Verify(rep => rep.All(), Times.Once); }
public void DeleteAdvert_Should_NotDeleteAdvertThatIsNeverAddedInTheFirstPlace() { var mockedRepository = new Mock <IRepository <Advert> >(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var advertService = new AdvertServices(mockedRepository.Object, mockedUnitOfWork.Object); var advertThatIsNotAdded = new Mock <Advert>(); mockedRepository.Verify(rep => rep.Delete(advertThatIsNotAdded.Object), Times.Never); }
public void GetById_ShouldThrowNullReferenceException_IfAdvertIsNull() { var mockedRepository = new Mock <IRepository <Advert> >(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var advertService = new AdvertServices(mockedRepository.Object, mockedUnitOfWork.Object); Mock <Advert> advertThatIsNull = null; Assert.Throws <NullReferenceException>(() => advertService.GetById(advertThatIsNull.Object.Id)); }
public void GetById_Should_NotReturnAdvert_IfThereIsNoAdvertYolo() { var mockedRepository = new Mock <IRepository <Advert> >(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var advertService = new AdvertServices(mockedRepository.Object, mockedUnitOfWork.Object); mockedRepository.Setup(rep => rep.GetById(0)).Returns(() => null); Assert.IsNull(advertService.GetById(0)); }
public void AddAdvert_ShouldThrowNullReferenceException_IfPassedAdvertIsNull() { var mockedRepository = new Mock <IRepository <Advert> >(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var advertService = new AdvertServices(mockedRepository.Object, mockedUnitOfWork.Object); Mock <Advert> advertToAdd = null; Assert.Throws <NullReferenceException>(() => advertService.AddAdvert(advertToAdd.Object)); }
public void Count_Should_ReturnZero_IfThereAreNoAdverts() { var mockedRepository = new Mock <IRepository <Advert> >(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var advertService = new AdvertServices(mockedRepository.Object, mockedUnitOfWork.Object); IEnumerable <Advert> expectedResult = new List <Advert>(); mockedRepository.Setup(rep => rep.All()).Returns(() => expectedResult.AsQueryable()); Assert.AreEqual(0, advertService.Count()); }
public void GetById_Should_ReturnTheProperAdvertWithId_IfCalled() { var mockedRepository = new Mock <IRepository <Advert> >(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var advertService = new AdvertServices(mockedRepository.Object, mockedUnitOfWork.Object); var advertWithId = new Mock <Advert>(); mockedRepository.Setup(rep => rep.GetById(advertWithId.Object.Id)).Returns(() => advertWithId.Object); Assert.IsInstanceOf <Advert>(advertService.GetById(advertWithId.Object.Id)); }
public void AddAdvert_Should_CallSaveChanges_IfAdvertIsValid() { var mockedRepository = new Mock <IRepository <Advert> >(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var advertService = new AdvertServices(mockedRepository.Object, mockedUnitOfWork.Object); var advertToAdd = new Mock <Advert>(); advertService.AddAdvert(advertToAdd.Object); mockedUnitOfWork.Verify(u => u.SaveChanges(), Times.Once); }
public void AddAdvert_Should_BeCalledOnce_IfAdvertIsValid() { var mockedRepository = new Mock <IRepository <Advert> >(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var advertService = new AdvertServices(mockedRepository.Object, mockedUnitOfWork.Object); var advertToAdd = new Mock <Advert>(); advertService.AddAdvert(advertToAdd.Object); mockedRepository.Verify(rep => rep.Add(It.IsAny <Advert>()), Times.Once); }
public void Count_Should_NeverBeCalled_IfNotCalled() { var mockedRepository = new Mock <IRepository <Advert> >(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var advertService = new AdvertServices(mockedRepository.Object, mockedUnitOfWork.Object); var advertToAdd = new Mock <Advert>(); advertService.AddAdvert(advertToAdd.Object); mockedRepository.Verify(rep => rep.All(), Times.Never); }
public void GetAllAdverts_Should_ThrowArgumentNullException_IfPassedAdvertsAreNull() { var mockedRepository = new Mock <IRepository <Advert> >(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var advertService = new AdvertServices(mockedRepository.Object, mockedUnitOfWork.Object); IEnumerable <Advert> expectedAdvertsResult = null; mockedRepository.Setup(rep => rep.All()).Returns(() => expectedAdvertsResult.AsQueryable()); Assert.Throws <ArgumentNullException>(() => advertService.GetAllAdverts()); }
public void GetById_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.GetById(advert.Object.Id); mockedRepository.Verify(rep => rep.GetById(advert.Object.Id), Times.Once); }
public void GetAllAdverts_Should_ReturnEmptyCollection_IfThereAreNoAdvertsAdded() { var mockedRepository = new Mock <IRepository <Advert> >(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var advertService = new AdvertServices(mockedRepository.Object, mockedUnitOfWork.Object); IEnumerable <Advert> expectedAdvertsResult = new List <Advert>(); mockedRepository.Setup(rep => rep.All()).Returns(() => expectedAdvertsResult.AsQueryable()); Assert.IsEmpty(advertService.GetAllAdverts()); }
public void GetById_Should_Work_IfCalledWithValidParams() { var mockedRepository = new Mock <IRepository <Advert> >(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var advertService = new AdvertServices(mockedRepository.Object, mockedUnitOfWork.Object); var advertWithId = new Mock <Advert>(); mockedRepository.Setup(rep => rep.GetById(advertWithId.Object.Id)).Returns(() => advertWithId.Object); Assert.AreEqual(advertService.GetById(advertWithId.Object.Id), advertWithId.Object); }
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)); }
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)); }
public void DeleteAdvertById_Should_CallSaveChanges_IfParamsAreValid() { var mockedRepository = new Mock <IRepository <Advert> >(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var advertService = new AdvertServices(mockedRepository.Object, mockedUnitOfWork.Object); var advertWithId = new Mock <Advert>(); advertService.AddAdvert(advertWithId.Object); advertService.DeleteAdvertById(advertWithId.Object.Id); mockedUnitOfWork.Verify(u => u.SaveChanges(), Times.Exactly(2)); }
public void GetById_Should_ReturnTheCorrectAdvert_IfCalled() { var mockedRepository = new Mock <IRepository <Advert> >(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var advertService = new AdvertServices(mockedRepository.Object, mockedUnitOfWork.Object); var advert = new Mock <Advert>(); var secondAdvert = new Mock <Advert>(); mockedRepository.Setup(rep => rep.GetById(advert.Object.Id)).Returns(() => advert.Object); Assert.AreNotEqual(advertService.GetById(advert.Object.Id), secondAdvert.Object); }
public void DeleteAdvertById_Should_BeCalledOnce_IfAdvertToDeleteIsValid() { var mockedRepository = new Mock <IRepository <Advert> >(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var advertService = new AdvertServices(mockedRepository.Object, mockedUnitOfWork.Object); var advertToDeleteWithId = new Mock <Advert>(); advertService.AddAdvert(advertToDeleteWithId.Object); advertService.DeleteAdvertById(advertToDeleteWithId.Object.Id); mockedRepository.Verify(rep => rep.Delete(advertToDeleteWithId.Object.Id), Times.Once); }
public void Count_Should_ReturnExactNumberOfAdverts_IfParamsAreValid() { var mockedRepository = new Mock <IRepository <Advert> >(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var advertService = new AdvertServices(mockedRepository.Object, mockedUnitOfWork.Object); IEnumerable <Advert> expectedResult = new List <Advert>() { new Advert(), new Advert() }; mockedRepository.Setup(rep => rep.All()).Returns(() => expectedResult.AsQueryable()); Assert.AreEqual(2, advertService.Count()); }
public void GetAllAdverts_Should_DoItsJobCorrectly_IfCalled() { var mockedRepository = new Mock <IRepository <Advert> >(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var advertService = new AdvertServices(mockedRepository.Object, mockedUnitOfWork.Object); IEnumerable <Advert> expectedAdvertsResult = new List <Advert>() { new Advert(), new Advert() }; mockedRepository.Setup(rep => rep.All()).Returns(() => expectedAdvertsResult.AsQueryable()); Assert.AreEqual(advertService.GetAllAdverts(), expectedAdvertsResult); }
public void ReturnCorrectAdverts_WhenCorrectParameters() { int vehicleModelId = 1; int cityId = 1; int minPrice = 1; int maxPrice = 4; int yearFrom = 1958; int yearTo = 3000; var mockedRepository = new Mock <IRepository <Advert> >(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var advertService = new AdvertServices(mockedRepository.Object, mockedUnitOfWork.Object); var advert = new Mock <Advert>(); var secondAdvert = new Mock <Advert>(); mockedRepository.Setup(rep => rep.All()).Returns(() => new List <Advert>() { new Advert { Id = 1, VehicleModelId = 1, CityId = 1, Price = 2, Year = 2000 }, new Advert { Id = 2, VehicleModelId = 1, CityId = 1, Price = 2, Year = 2000 }, new Advert { Id = 3, VehicleModelId = 1, CityId = 1, Price = 2, Year = 2000 }, new Advert { Id = 4, VehicleModelId = 2, CityId = 1, Price = 2, Year = 2000 } }.AsQueryable()); // Act var result = advertService.GetAdvertsByMultipleParameters(vehicleModelId, cityId, minPrice, maxPrice, yearFrom, yearTo).ToList(); Assert.AreEqual(3, result.Count); }