Ejemplo n.º 1
0
        public void AllHospitalsHttpShouldBeEmptyTest()
        {
            var mockHospitalsService   = new Mock <IHospitalsService>();
            var mockUserManagerService = this.GetUserManagerMock();
            var mockRecipientsService  = new Mock <IRecipientsService>();
            var mockBloodbanksService  = new Mock <IBloodBanksService>();
            var mockUsersService       = new Mock <IUsersService>();
            var viewModel = new AllHospitalsViewModel();

            var controller = new HospitalsController(
                mockHospitalsService.Object,
                mockUserManagerService.Object,
                mockRecipientsService.Object,
                mockBloodbanksService.Object,
                mockUsersService.Object);

            var result = controller.AllHospitals(viewModel);

            Assert.IsType <ViewResult>(result);

            var viewResult = result as ViewResult;

            Assert.IsType <AllHospitalsViewModel>(viewResult.Model);

            viewModel = viewResult.Model as AllHospitalsViewModel;
            var actualResult = viewModel.Hospitals.Count();

            Assert.Equal(0, actualResult);
        }
Ejemplo n.º 2
0
        public IActionResult AllHospitals(AllHospitalsViewModel viewModel, int page = 1)
        {
            viewModel.Hospitals = this.hospitalsService.GetAllHospitals <HospitalInfoViewModel>(take, (int)(page - 1) * take);

            var count = this.hospitalsService.GetAllHospitals <HospitalInfoViewModel>().Count();

            if (!string.IsNullOrEmpty(viewModel.SearchTerm))
            {
                viewModel.Hospitals = this.hospitalsService
                                      .GetAllHospitals <HospitalInfoViewModel>()
                                      .Where(h => h.Name.Contains(viewModel.SearchTerm) ||
                                             h.Location.Country.Contains(viewModel.SearchTerm) ||
                                             h.Location.AdressDescription.Contains(viewModel.SearchTerm));

                count = viewModel.Hospitals.Count();
            }

            viewModel.PagesCount = (int)Math.Ceiling((double)count / take);
            if (viewModel.PagesCount == 0)
            {
                viewModel.PagesCount = 1;
            }

            viewModel.CurrentPage = page;
            return(this.View(viewModel));
        }
Ejemplo n.º 3
0
        public void AllHospitalsShouldReturnCorrectViewModelTest()
        {
            var mockHospitalsService   = new Mock <IHospitalsService>();
            var mockUserManagerService = this.GetUserManagerMock();
            var mockRecipientsService  = new Mock <IRecipientsService>();
            var mockBloodbanksService  = new Mock <IBloodBanksService>();
            var mockUsersService       = new Mock <IUsersService>();
            var viewModel = new AllHospitalsViewModel();

            var controller = new HospitalsController(
                mockHospitalsService.Object,
                mockUserManagerService.Object,
                mockRecipientsService.Object,
                mockBloodbanksService.Object,
                mockUsersService.Object);

            var result = controller.AllHospitals(viewModel);

            Assert.IsType <ViewResult>(result);
        }