public void GetList_Valid()
        {
            var jobseekerID = 1;
            var searchType  = ReferralHistoryItemType.All;

            var request = new GetListRequest {
                JobseekerId = jobseekerID, SearchType = searchType.GetFlag()
            };
            var response = new GetListResponse
            {
                FirstGivenName = "firstname",
                ListItems      = new[] { new ListItem {
                                             Type = "A", DisSiteCode = "site"
                                         } },
                ExecutionResult = new ExecutionResult {
                    Status = ExecuteStatus.Success
                }
            };
            var outModel = MappingEngine.Map <ReferralHistoryModel>(response);

            mockUserService.Setup(m => m.Roles).Returns(new[] { "DAD" });
            mockMappingEngine.Setup(m => m.Map <ReferralHistoryModel>(response)).Returns(outModel);
            mockReferralHistoryWcf.Setup(m => m.GetList(It.IsAny <GetListRequest>())).Returns(response);

            var result = SystemUnderTest().GetList(jobseekerID, searchType);

            Assert.IsTrue(result.JobseekerID == jobseekerID);
            Assert.IsTrue(result.JobseekerFirstName == outModel.JobseekerFirstName);
            Assert.IsTrue(result.List.Count() == outModel.List.Count());
            Assert.IsTrue(result.List.First().Site == outModel.List.First().Site);
            mockReferralHistoryWcf.Verify(m => m.GetList(It.IsAny <GetListRequest>()), Times.Once());
            mockMappingEngine.Verify(m => m.Map <ReferralHistoryModel>(response), Times.Once());
        }
Beispiel #2
0
        public IEnumerable <RecordModel> RecordList(GetListRequest request)
        {
            IEnumerable <RecordModel> result = _context.Records.Include(record => record.Patient);

            return(Sort(result, request.Sort, request.SortDirection)
                   .Skip((request.PageIndex - 1) * request.PageSize).Take(request.PageSize));
        }
        public async Task <ActionResult <IEnumerable <ItemList> > > GetItemLists([FromQuery] GetListRequest request)
        {
            var itemList = await _context.ItemLists.Where(il => il.AccessCode == request.AccessCode).FirstAsync();

            itemList.Items = await _context.Items.Where(i => i.ListId == itemList.Id).ToListAsync();

            var items     = itemList.Items.Select(i => new { i.Id, i.Name, i.IsDone });
            var isStarred = false;

            try
            {
                var userId = UserIdGetter.getIdFromToken(Request, _context);
                isStarred = _context.UserLists.Where(ul => ul.ListId == itemList.Id)
                            .Select(ul => ul.UserId)
                            .Contains(userId);
            }
            catch {
            }
            if (itemList.IsPublic || itemList.ListPassword == request.ListPassword)
            {
                return(Ok(new SuccessfulGetListResponse()
                {
                    Name = itemList.Name,
                    AccessCode = itemList.AccessCode,
                    IsPublic = itemList.IsPublic,
                    Items = items,
                    IsStarred = isStarred
                }));
            }
            return(BadRequest("Wrong list access code or password"));
        }
Beispiel #4
0
        public async Task <IActionResult> Get(string status, string type, string clientName)
        {
            var request = new GetListRequest(status, type, clientName);
            var result  = await _mediator.Send(request);

            return(result != null?Ok(result) : NotFound());
        }
Beispiel #5
0
        public async Task ValidationErrorsAreAddedToException()
        {
            const string USER       = "******";
            var          validators = new List <IValidator <GetListRequest> >
            {
                new GetListValidator()
            };

            var request             = new GetListRequest(string.Empty, USER);
            var validationBehaviour = new ValidationBehaviour <GetListRequest, ListDTO>(validators);

            var handlerMock = new Mock <RequestHandlerDelegate <ListDTO> >();

            try
            {
                await validationBehaviour.Handle(request, CancellationToken.None, handlerMock.Object);

                // an exception is expected, if we got here the test failed
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.IsInstanceOfType(e, typeof(RequestValidationFailedException));
                Assert.AreEqual(1, (e as RequestValidationFailedException).Failures.Count);
            }
        }
Beispiel #6
0
        public async Task <ActionResult <RecordListReadDtoModel> > GetRecordList([FromQuery] GetListRequest request)
        {
            Int64 TotalRecord = _recordRepository.GetCount();

            // we can use auto mapper to map internal model to dto
            RecordListReadDtoModel result = new RecordListReadDtoModel()
            {
                TotalRecord = TotalRecord,
                Items       = _recordRepository.RecordList(request).Select(x => new RecordListReadDtoItem
                {
                    RecordId    = x.RecordId,
                    TimeOfEntry = x.TimeOfEntry,
                    Bill        = x.Bill,
                    Description = x.Description,
                    DiseaseName = x.DiseaseName,
                    PatientId   = x.PatientId,
                    PatientName = x.Patient.PatientName
                })
            };

            if (result.Items.Count() == 0)
            {
                return(NotFound());
            }

            return(Ok(result));
        }
Beispiel #7
0
        public async Task ReturnsListDTOForListIgnoresIdCase()
        {
            const string ID   = "id";
            const string USER = "******";

            var(context, mapper, config) = CreateDeps();
            using (context)
            {
                // seed DB
                context.Lists.Add(new List
                {
                    Id = ID
                });

                context.SaveChanges();

                var request = new GetListRequest(ID.ToLower(), USER);
                var handler = new GetListHandler(context, mapper, config);
                var result  = await handler.Handle(request, CancellationToken.None);

                // only check it's the right one, let the mapping tests check the properties
                Assert.IsNotNull(result);
                Assert.AreEqual(ID, result.Id);
            }
        }
Beispiel #8
0
        public async Task DoesNotAddListContributorRecordForUserAndListIfAlreadyExists()
        {
            const string ID = "id", USER = "******";

            var(context, mapper, config) = CreateDeps();
            using (context)
            {
                // seed DB
                context.Lists.Add(new List
                {
                    Id = ID
                });

                context.ListContributors.Add(new ListContributor
                {
                    ListId    = ID,
                    UserIdent = USER
                });

                context.SaveChanges();

                var request = new GetListRequest(ID, USER);
                var handler = new GetListHandler(context, mapper, config);
                await handler.Handle(request, CancellationToken.None);

                Assert.AreEqual(1, context.ListContributors.Count());
                Assert.AreEqual(ID, context.ListContributors.First().ListId);
                Assert.AreEqual(USER, context.ListContributors.First().UserIdent);
            }
        }
Beispiel #9
0
        public async Task DoesNotThrowIfUserReachedMaxAfterContributing()
        {
            const string ID   = "id";
            const string USER = "******";

            var(context, mapper, config) = CreateDeps(0);
            using (context)
            {
                // seed DB
                context.Lists.Add(new List
                {
                    Id = ID
                });

                context.ListContributors.Add(new ListContributor
                {
                    ListId    = ID,
                    UserIdent = USER
                });

                context.SaveChanges();

                var request = new GetListRequest(ID, USER);
                var handler = new GetListHandler(context, mapper, config);

                var result = await handler.Handle(request, CancellationToken.None);

                Assert.IsNotNull(result);
            }
        }
Beispiel #10
0
        public async Task ThrowsIfUserReachedMaxBeforeContributing()
        {
            const string ID   = "id";
            const string USER = "******";

            var(context, mapper, config) = CreateDeps(0);
            using (context)
            {
                // seed DB
                context.Lists.Add(new List
                {
                    Id = ID
                });

                context.SaveChanges();

                var request = new GetListRequest(ID, USER);
                var handler = new GetListHandler(context, mapper, config);

                try
                {
                    await handler.Handle(request, CancellationToken.None);

                    Assert.Fail("exception was not thrown");
                }
                catch (RequestFailedException e)
                {
                    Assert.AreEqual(HttpStatusCode.Forbidden, e.Code);
                }
                catch (Exception)
                {
                    Assert.Fail("didn't throw correct exception");
                }
            }
        }
        public void PassesOnSetUserId()
        {
            const string USER      = "******";
            var          request   = new GetListRequest("a", USER);
            var          validator = new GetListValidator();

            validator.ShouldNotHaveValidationErrorFor(r => r.UserIdent, request);
        }
Beispiel #12
0
        public IEnumerable <TEntity> GetData(GetListRequest request)
        {
            IEnumerable <TEntity> result = _context.Set <TEntity>();

            result = Sort(result, request.Sort, request.SortDirection)
                     .Skip((request.PageIndex - 1) * request.PageSize).Take(request.PageSize);;
            return(result);
        }
        public void FailsOnEmptyUserId()
        {
            var request   = new GetListRequest("", "");
            var validator = new GetListValidator();
            var failures  = validator.ShouldHaveValidationErrorFor(r => r.UserIdent, request);

            Assert.AreEqual(1, failures.Count());
            Assert.AreEqual("UserId not set", failures.First().ErrorMessage);
        }
Beispiel #14
0
        public IEnumerable <PatientModel> PatientList(GetListRequest request)
        {
            IEnumerable <PatientModel> result = _context.Set <PatientModel>()
                                                .Include(patient => patient.MetaData)
                                                .Include(patient => patient.Records);

            return(Sort(result, request.Sort, request.SortDirection)
                   .Skip((request.PageIndex - 1) * request.PageSize).Take(request.PageSize));
        }
        public void FailsOnEmptyId()
        {
            const string USER      = "******";
            var          request   = new GetListRequest("", USER);
            var          validator = new GetListValidator();
            var          failures  = validator.ShouldHaveValidationErrorFor(r => r.Id, request);

            Assert.AreEqual(1, failures.Count());
            Assert.AreEqual("Id not set", failures.First().ErrorMessage);
        }
Beispiel #16
0
        private async Task CheckForAdvisor()
        {
            var request = new GetListRequest(20, 0);

            var userInfo = await App.UserManager.GetAsync($"{JsonConvert.DeserializeObject<User>(Settings.CurrentUser).Id}/advisor");

            Settings.AdvisorContact = AdvisorContact = userInfo != null ? userInfo.Phone : string.Empty;

            Settings.AdvisorEmail = userInfo != null ? userInfo.Email : string.Empty;
        }
        public async Task <object> GetImageList(GetListRequest req)
        {
            var user = HttpContext.GetUser();
            var list = await ImagesService.GetInfoList(req);

            if ((int)user.Role <= (int)UserRole.User)
            {
                list.Data = list.Data.Where(l => l.IsPublic || l.Owner == user.UserName);
            }
            return(list);
        }
        public async Task <object> GetFilesList(GetListRequest req)
        {
            var user       = HttpContext.GetUser();
            var dataResult = await FilesService.GetInfoList(req);

            dataResult.Data = dataResult.Data.OrderByDescending(f => f.IsFolder);
            if ((int)user.Role <= (int)UserRole.User)
            {
                dataResult.Data = dataResult.Data.Where(l => l.IsPublic || l.Owner == user.UserName);
            }
            return(dataResult);
        }
Beispiel #19
0
        public async Task ThrowsIfNoListFound()
        {
            const string ID   = "id";
            const string USER = "******";

            var(context, mapper, config) = CreateDeps();
            using (context)
            {
                var request = new GetListRequest(ID, USER);
                var handler = new GetListHandler(context, mapper, config);
                await Assert.ThrowsExceptionAsync <RequestFailedException>(() => handler.Handle(request, CancellationToken.None));
            }
        }
Beispiel #20
0
        public static object GetList <Type>(GetListRequest req)
        {
            StringBuilder sb = new StringBuilder(
                @"<soap:getList>           
            <user>
                <login>").
                               Append(req.user.login).Append(@"</login><pass>").
                               Append(req.user.pass).Append(@"</pass>
            </user>
</soap:getList>");

            return(Action <Type>(createRequestBody(sb.ToString())));
        }
Beispiel #21
0
        private async Task DownlaodDocuments()
        {
            if (App.IsConnected())
            {
                var request   = new GetListRequest(200, 0);
                var documents =
                    new ObservableCollection <Document>((await App.DocumentsManager.GetListAsync(request)).rows);

                //Updating records in local cache
                await new StorageService <Document>().InvalidateSyncedItems();
                await new StorageService <Document>().AddManyAsync(documents.ToList());
            }
        }
Beispiel #22
0
        public RepeatedField <User.UserHdr> GetList(uint deviceID)
        {
            var request = new GetListRequest {
                DeviceID = deviceID
            };

            try {
                var response = userClient.GetList(request);

                return(response.Hdrs);
            } catch (RpcException e) {
                Console.WriteLine("Cannot get the user list {0}: {1}", deviceID, e);
                throw;
            }
        }
        public List <string> getList()
        {
            GetListRequest req = new GetListRequest();

            req.user       = new User();
            req.user.login = conf.Login;
            req.user.pass  = Utils.GetMD5String(conf.Soap_pass);
            GetListResponse resp = (GetListResponse)Soap.GetList <GetListResponse>(req);

            if (resp.errorCode != 0)
            {
                throw new Exception(resp.errorMessage);
            }
            return(resp.list);
        }
Beispiel #24
0
        public async Task ThrowsErrorIfAValidationErrorOccurs()
        {
            const string USER       = "******";
            var          validators = new List <IValidator <GetListRequest> >
            {
                new GetListValidator()
            };

            var request             = new GetListRequest(string.Empty, USER);
            var validationBehaviour = new ValidationBehaviour <GetListRequest, ListDTO>(validators);

            var handlerMock = new Mock <RequestHandlerDelegate <ListDTO> >();

            await Assert.ThrowsExceptionAsync <RequestValidationFailedException>(
                () => validationBehaviour.Handle(request, CancellationToken.None, handlerMock.Object));
        }
Beispiel #25
0
        private async Task DownlaodDocuments()
        {
            if (App.IsConnected())
            {
                var request = new GetListRequest(10, 0);

                var documents = await App.DocumentsManager.GetListAsync(request);

                documents = await App.DocumentsManager.GetListAsync(new GetListRequest(documents.total, 0));

                //Updating records in local cache
                if (documents != null && documents.rows != null)
                {
                    await new StorageService <Document>().InvalidateSyncedItems();
                }

                await new StorageService <Document>().AddManyAsync(documents.rows);
            }
        }
        public async Task <List <Transaction> > Handle(GetListRequest request, CancellationToken cancellationToken)
        {
            IQueryable <Transaction> transactions = _db.Transactions;

            if (!string.IsNullOrEmpty(request.Type))                                                //Filter by type
            {
                transactions = transactions.Where(i => i.Type.Contains(request.Type));
            }
            if (!string.IsNullOrEmpty(request.Status))                                              //Filter by status
            {
                transactions = transactions.Where(i => i.Status.Contains(request.Status));
            }
            if (!string.IsNullOrEmpty(request.ClientName))                                          //Filter by client name
            {
                transactions = transactions.Where(i => i.ClientName.Contains(request.ClientName));
            }

            return(await transactions.ToListAsync());                                                //Final response
        }
        public virtual async Task <PaginationResponse <TModel> > GetListAsync(GetListRequest request)
        {
            var res = new PaginationResponse <TModel>()
            {
                rows = new System.Collections.Generic.List <TModel>()
            };

            if (Device.RuntimePlatform == Device.Android)
            {
                res.rows = new System.Collections.Generic.List <TModel>();
            }

            try
            {
                res = (await _restService.GetAllDataAsyncWithParameters(
                           request.Limit,
                           request.Page,
                           request.SearchValue,
                           request.SearchFields,
                           request.SortField,
                           request.SortDirection));
            }
            catch (UnauthorizedAccessException)
            {
                if (!_firstAuthFail)
                {
                    return(res);
                }

                _firstAuthFail = !_firstAuthFail;

                if (await RegenerateLoginToken())
                {
                    res = await GetListAsync(request);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(@"				ERROR {0}", e.Message);
            }

            return(res);
        }
        public void TestGetList()
        {
            string remoteFileName = "TestGetList.doc";

            this.UploadFileToStorage(
                remoteDataFolder + "/" + remoteFileName,
                null,
                null,
                File.ReadAllBytes(LocalTestDataFolder + localFile)
                );

            var request = new GetListRequest(
                name: remoteFileName,
                listId: 1,
                folder: remoteDataFolder
                );
            var actual = this.WordsApi.GetList(request);

            Assert.NotNull(actual.List);
            Assert.AreEqual(1, actual.List.ListId);
        }
Beispiel #29
0
        public async Task CallsNextIfNoValidationErrorsOccur()
        {
            const string LIST_ID = "id";
            const string USER    = "******";

            var validators = new List <IValidator <GetListRequest> >
            {
                new GetListValidator()
            };

            var request             = new GetListRequest(LIST_ID, USER);
            var validationBehaviour = new ValidationBehaviour <GetListRequest, ListDTO>(validators);
            var handlerMock         = new Mock <RequestHandlerDelegate <ListDTO> >();
            var mockReturned        = new ListDTO();

            handlerMock.Setup(m => m.Invoke()).ReturnsAsync(mockReturned);

            var result = await validationBehaviour.Handle(request, CancellationToken.None, handlerMock.Object);

            Assert.AreSame(mockReturned, result);
            handlerMock.Verify(m => m.Invoke(), Times.Once);
        }
Beispiel #30
0
        public async Task ReturnsListDTOWithOrderedItems()
        {
            const string ID            = "id";
            const string ORDER_ONE_ID  = "1";
            const string ORDER_ZERO_ID = "0";
            const string USER          = "******";

            var(context, mapper, config) = CreateDeps();
            using (context)
            {
                // seed DB
                context.Lists.Add(new List
                {
                    Id    = ID,
                    Items = new List <ListItem>
                    {
                        new ListItem
                        {
                            Id    = ORDER_ONE_ID,
                            Order = 1
                        },
                        new ListItem
                        {
                            Id    = ORDER_ZERO_ID,
                            Order = 0
                        }
                    }
                });

                context.SaveChanges();

                var request = new GetListRequest(ID, USER);
                var handler = new GetListHandler(context, mapper, config);
                var result  = await handler.Handle(request, CancellationToken.None);

                Assert.AreEqual(ORDER_ZERO_ID, result.Items.First().Id);
                Assert.AreEqual(ORDER_ONE_ID, result.Items.ToList()[1].Id);
            }
        }