public async Task <ActionResult> Index(int?pageNumber, string currentFilter, bool isMapView = false) { if (!string.IsNullOrEmpty(currentFilter)) { ViewData["CurrentFilter"] = currentFilter; } return(View(await _service.GetDestinations(pageNumber, currentFilter, isMapView))); }
public void BeCalled_WhenParamsAreValid() { //Arrange var mockedRepository = new Mock <IEFRepository <Destination> >(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var destinationService = new DestinationService(mockedRepository.Object, mockedUnitOfWork.Object); //Act destinationService.GetDestinations(1, 2); //Assert mockedRepository.Verify(repository => repository.All(), Times.Once); }
public void ThrowException_WhenNullDestination() { //Arrange var mockedRepository = new Mock <IEFRepository <Destination> >(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var destinationService = new DestinationService(mockedRepository.Object, mockedUnitOfWork.Object); //Act IEnumerable <Destination> result = null; mockedRepository.Setup(repository => repository.All()).Returns(() => result.AsQueryable()); //Assert Assert.Throws <ArgumentNullException>(() => destinationService.GetDestinations(0, 1)); }
public void ReturnEmptyCollection_WhenNoDestinations() { //Arrange var mockedRepository = new Mock <IEFRepository <Destination> >(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var destinationService = new DestinationService(mockedRepository.Object, mockedUnitOfWork.Object); //Act IEnumerable <Destination> result = new List <Destination>(); mockedRepository.Setup(repository => repository.Entities).Returns(() => result.AsQueryable()); //Assert Assert.IsEmpty(destinationService.GetDestinations(0, 1)); }
public void WorksProperly_WhenInvoked() { //Arrange var mockedRepository = new Mock <IEFRepository <Destination> >(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var destinationService = new DestinationService(mockedRepository.Object, mockedUnitOfWork.Object); //Act IEnumerable <Destination> result = new List <Destination>() { new Destination(), new Destination() }; mockedRepository.Setup(repository => repository.All()).Returns(() => result.AsQueryable()); //Assert Assert.AreEqual(destinationService.GetDestinations(0, 2), result); }
public void ReturnIQueryable_WhenInvoked() { //Arrange var mockedRepository = new Mock <IEFRepository <Destination> >(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var destinationService = new DestinationService(mockedRepository.Object, mockedUnitOfWork.Object); //Act IEnumerable <Destination> result = new List <Destination>() { new Destination(), new Destination(), new Destination() }; mockedRepository.Setup(repository => repository.Entities).Returns(() => result.AsQueryable()); //Assert Assert.IsInstanceOf <IQueryable <Destination> >(destinationService.GetDestinations(0, 3)); }
public void ShouldReturnDestinations() { var destList = new List <Destination>() { new Destination() { Id = 1, CountryId = 1, Country = new Country() { Id = 1, Name = "country", SubsistanceAllowenceId = 1 }, Name = "x", CreatedDateTime = DateTime.Now }, new Destination() { Id = 2, CountryId = 1, Country = new Country() { Id = 1, Name = "country", SubsistanceAllowenceId = 1 }, Name = "y", CreatedDateTime = DateTime.Now }, new Destination() { Id = 3, CountryId = 1, Country = new Country() { Id = 1, Name = "country", SubsistanceAllowenceId = 1 }, Name = "z", CreatedDateTime = DateTime.Now } }; var config = new MapperConfiguration(cfg => { cfg.AddProfile(new MappingProfile()); }); var mapper = config.CreateMapper(); var destRepo = new Mock <IDestinationRepository>(); destRepo.Setup(d => d.GetDestinations()).Returns(destList.AsQueryable()); var destServ = new DestinationService(destRepo.Object, mapper); var resultList = destServ.GetDestinations(); resultList.Should().NotBeNull(); resultList.Should().AllBeOfType(typeof(DestinationTypeVm)); resultList.Should().HaveCount(3); resultList.Should().OnlyHaveUniqueItems(d => d.Id); }