public async Task GetAllReturnTwoEtc() { // arrange var repo = new Mock <IRepository <Patient> >(); repo .Setup(x => x.GetAllAsync()) .Returns(Task.FromResult(new List <Patient>() { new Patient(), new Patient() }.AsEnumerable())); var mapper = new Mock <IMapper>(); mapper .Setup(x => x.Map <IEnumerable <PatientDto> >(It.IsAny <IEnumerable <Patient> >())) .Returns(new List <PatientDto>() { new PatientDto(), new PatientDto() }.AsEnumerable()); var service = new GenericService <Patient, PatientDto>(repo.Object, mapper.Object, new Mock <IUnitOfWork>().Object); // act var result = await service.GetAllAsync(); // assert Assert.NotEmpty(result); Assert.IsAssignableFrom <IEnumerable <PatientDto> >(result); Assert.Equal(2, result.Count()); }
public async Task <IActionResult> Get() { try { return(Ok(await _service.GetAllAsync())); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async Task GetAllReturnEmpty() { // arrange var mapper = new Mock <IMapper>(); var repo = new Mock <IRepository <Patient> >(); repo .Setup(x => x.GetAllAsync()) .Returns(Task.FromResult(Enumerable.Empty <Patient>())); var service = new GenericService <Patient, PatientDto>(repo.Object, mapper.Object, new Mock <IUnitOfWork>().Object); // act var result = await service.GetAllAsync(); // assert Assert.Empty(result); Assert.IsAssignableFrom <IEnumerable <PatientDto> >(result); }
public async Task <List <MenuTest> > Get() { // admin_tms thì load hết, ko thì kiểm tra trong token, lấy ra ds MenuCode ! ClaimsPrincipal claimPrincipal = HttpContext.User; if (claimPrincipal.Identity.IsAuthenticated) { var userId = UserClaim.UserId ?? "anonymous"; if (userId.Equals("admin_tms", StringComparison.OrdinalIgnoreCase)) { return(await _serviceMenuTest.GetAllAsync()); } else { var arrMenuCode = claimPrincipal.FindFirst(StaticVar.ClaimArrMenu).Value; if (!String.IsNullOrEmpty(arrMenuCode)) { return(await _serviceMenuTest.SearchMatchArray("Code", arrMenuCode.Split(",").ToList())); } } } return(null); //return await _serviceMenuTest.GetAllAsync(); }
public async Task <List <UserTest> > Get() { return(await _serviceUserTest.GetAllAsync()); }
public void GetAllAsync_Should_InvokeGenericRepositoryGetAllAsync_Once() { var returnValue = _genericService.GetAllAsync(); _mockGenericRepository.Verify(x => x.GetAllAsync(It.IsAny <bool>()), Times.Once); }
public async Task <List <Category> > Get() { return(await _serviceCategory.GetAllAsync()); }
public virtual async Task <IEnumerable <TModel> > GetAllAsync() { return(await _service.GetAllAsync()); }
public async Task <List <GroupTest> > Get() { return(await _serviceGroupTest.GetAllAsync()); }
public async Task <List <SystemFunctionTest> > Get() { return(await _serviceSysFuctionTest.GetAllAsync()); }