[Test] public void Get_WhenCalled_ShouldReturnList() { //Arrange IEnumerable <EventModel> expectedList = TestsFacade.EventsFacade.BuildEventModelList(); var repositoryMock = _mock.Mock <IGenericRepository <EventModel> >(); repositoryMock .Setup(items => items.Get(null, null, "")) .Returns(() => expectedList); GenericService <EventModel> service = _mock.Create <GenericService <EventModel> >(); //Act ResultService <IEnumerable <EventModel> > result = service.Get(null, null, ""); //Assert Assert.IsNotNull(result); Assert.IsInstanceOf <ResultService <IEnumerable <EventModel> > >(result); Assert.IsTrue(result.Success); Assert.IsInstanceOf <IEnumerable <EventModel> >(result.Value); IEnumerable <EventModel> resultList = result.Value; Assert.IsNotNull(resultList); Assert.AreEqual(resultList.Count(), expectedList.Count()); Assert.AreEqual(resultList.First().GetHashCode(), expectedList.First().GetHashCode()); }
[Test] public void Get_WhenCalledWithOrder_ShouldReturnList() { //Arrange IEnumerable <EventModel> expectedList = TestsFacade.EventsFacade.BuildEventModelList(10); OrderByStatement <EventModel> orderByStatement = TestsFacade.OrderBytatementFacade.BuildOrderByStatement <EventModel>(); var repositoryMock = _mock.Mock <IGenericRepository <EventModel> >(); repositoryMock .Setup(items => items.Get(null, It.IsAny <Func <IQueryable <EventModel>, IOrderedQueryable <EventModel> > >(), "")) .Returns(() => expectedList); GenericService <EventModel> service = _mock.Create <GenericService <EventModel> >(); //Act ResultService <IEnumerable <EventModel> > result = service.Get(null, orderByStatement, ""); //Assert Assert.IsNotNull(result); Assert.IsInstanceOf <ResultService <IEnumerable <EventModel> > >(result); Assert.IsTrue(result.Success); Assert.IsInstanceOf <IEnumerable <EventModel> >(result.Value); IEnumerable <EventModel> resultList = result.Value; Assert.IsNotNull(resultList); Assert.AreEqual(resultList.Count(), expectedList.Count()); Assert.AreEqual(resultList, expectedList); }
public IActionResult View(int Id) { var deleteBooking = service.Get(Id); if (deleteBooking == null) { return(NotFound()); } return(View(deleteBooking)); }
public ActionResult Index(int?page) { int pageSize = 5; int pageNumber = (page ?? 1); var result = Units.Get().ToList().Map <List <UnitsViewModel> >(); return(View(new UnitsViewModel() { Units = result.ToPagedList(pageNumber, pageSize) })); }
public ActionResult Index(int?page) { int pageSize = 5; int pageNumber = (page ?? 1); var result = Types.Get().ToList().Map <List <TypeServicesViewModel> >(); return(View(new TypeServicesViewModel() { Types = result.ToPagedList(pageNumber, pageSize) })); }
public ActionResult Create() { var dentists = UserManager.Users.Where(x => x.TypeUser == UserType.Dentist).Select(t => new SelectListItem { Text = t.FirstName + " " + t.LastName + " " + t.MiddleName, Value = t.Id }).ToList(); var patients = Patients.Get().Select(s => new SelectListItem { Text = s.LastName + " " + s.FirstName + " " + s.MiddleName, Value = Convert.ToString(s.PatientsId) }).ToList(); var model = new AppointmentCreateViewModel { Users = dentists, Patients = patients }; return(View(model)); }
public ActionResult Create() { var services = Services.Get().Select(s => new SelectListItem { Text = s.Name, Value = Convert.ToString(s.ServicesId) }).ToList(); var model = new PriceCreateViewModel { Service = services }; return(View(model)); }
public void PrepareViewModel(ServicesCreateViewModel model) { var units = Units.Get().Select(s => new SelectListItem { Text = s.Name, Value = Convert.ToString(s.UnitsId) }).ToList(); var types = Types.Get().Select(s => new SelectListItem { Text = s.Name, Value = Convert.ToString(s.TypeServicesId) }).ToList(); model.Types = types; model.Units = units; }
[Test] public void Get_WhenRepositoryThrowException_ShouldReturnError() { //Arrange Exception expectedException = new Exception(Guid.NewGuid().ToString()); var repositoryMock = _mock.Mock <IGenericRepository <EventModel> >(); repositoryMock .Setup(items => items.Get(null, null, "")) .Throws(expectedException); GenericService <EventModel> service = _mock.Create <GenericService <EventModel> >(); //Act ResultService <IEnumerable <EventModel> > result = service.Get(null, null, ""); //Assert AssertResultServiceException <IEnumerable <EventModel> >(result, expectedException); }
[Test] public void Get_WhenRepositoryReturnsNull_ShouldReturnNotFound() { //Arrange var repositoryMock = _mock.Mock <IGenericRepository <EventModel> >(); repositoryMock .Setup(items => items.Get(null, null, "")) .Returns(() => null); GenericService <EventModel> service = _mock.Create <GenericService <EventModel> >(); //Act ResultService <IEnumerable <EventModel> > result = service.Get(null, null, ""); //Assert Assert.IsNotNull(result); Assert.IsFalse(result.Success); Assert.IsNull(result.Value); Assert.IsTrue(result.ErrorCode == ErrorCode.NotFound); }