예제 #1
0
        public async void FindHelp_Should_Call_IBittnService_FindHelp()
        {
            var request = new FindHelpApiRequest
            {
                ConditionId    = 1,
                Severity       = 2,
                Page           = 3,
                SortField      = "field",
                SortDescending = true
            };

            var             service = Substitute.For <IBittnService>();
            FindHelpRequest arg     = null;

            service.FindHelp(Arg.Do <FindHelpRequest>(a => arg = a)).Returns(new FindHelpResponse());

            await _controller.FindHelp(request, service);

            await service.Received(1).FindHelp(Arg.Any <FindHelpRequest>());

            arg.ConditionId.Should().Be(request.ConditionId);
            arg.SeverityLevel.Should().Be(request.Severity);
            arg.PageIndex.Should().Be(request.Page);
            arg.SortField.Should().Be(request.SortField);
            arg.SortDescending.Should().Be(request.SortDescending);
        }
예제 #2
0
        public async Task <FindHelpResponse> FindHelp(FindHelpRequest request)
        {
            var hospitals = await _hospitalRepository.SearchHospitals(new SearchHospitalsRequest());

            var help   = BittnServiceHelper.GetHelpDetails(hospitals.Data, request.ConditionId, request.SeverityLevel);
            var sorted = help.Sort(request.SortField, request.SortDescending);
            var paged  = sorted.GetPage(DEFAULT_ITEMS_PER_PAGE, request.PageIndex);

            var lastPageIndex = help.Count() / DEFAULT_ITEMS_PER_PAGE;
            var currentIndex  = request.PageIndex ?? 0;
            var prevIndex     = currentIndex > 0 ? currentIndex - 1 : (int?)null;
            var nextIndex     = currentIndex < lastPageIndex ? currentIndex + 1 : (int?)null;

            return(new FindHelpResponse
            {
                Data = paged,
                PrevPageIndex = prevIndex,
                NextPageIndex = nextIndex
            });
        }
예제 #3
0
        public async void FindHelp_Should_Return_Correctly()
        {
            var hospitalId = 111;
            var painLevel  = 1;
            var response   = new SearchHospitalsResponse
            {
                CurrentPageIndex = 123,
                NextPageIndex    = 456,
                PrevPageIndex    = 789,
                Data             = new []
                {
                    new HospitalDetails
                    {
                        Id    = hospitalId,
                        Queue = new []
                        {
                            new QueueDetails {
                                PainLevel = painLevel
                            }
                        }
                    }
                }
            };

            _hospitalRepository.SearchHospitals(Arg.Any <SearchHospitalsRequest>()).Returns(response);

            var request = new FindHelpRequest {
                SeverityLevel = painLevel
            };
            var actual = await _service.FindHelp(request);

            actual.PrevPageIndex.Should().Be(null);
            actual.NextPageIndex.Should().Be(null);
            actual.Data.Should().HaveCount(1);
            actual.Data.First().Id.Should().Be(hospitalId);
        }
예제 #4
0
        public async void FindHelp_Should_Call_IHospitalRepository_SearchHospitals()
        {
            SearchHospitalsRequest arg = null;

            _hospitalRepository
            .SearchHospitals(Arg.Do <SearchHospitalsRequest>(a => arg = a))
            .Returns(new SearchHospitalsResponse
            {
                Data = new HospitalDetails[0]
            });

            var request = new FindHelpRequest
            {
                PageIndex = 123
            };

            await _service.FindHelp(request);

            await _hospitalRepository.Received(1).SearchHospitals(Arg.Any <SearchHospitalsRequest>());

            arg.ItemsPerPage.Should().BeNull();
            arg.HospitalName.Should().BeNull();
            arg.PageIndex.Should().BeNull();
        }