public void GetAllRoutesUnhandledException() { var request = new CollectionRequestModel(); var mocker = new RouteServiceMocker(); RouteInfoEntity entity = new RouteInfoEntity(); mocker.RepoMock.Setup(r => r.Search(It.IsAny <SearchQuery <RouteInfoEntity> >())).Throws(new Exception("testexception")); IRouteBLService service = mocker.GetService(); var result = service.GetAllRoutes(request); Assert.Equal(ErrorStatus.InternalServer, result.Result.Error.Status); Assert.Equal("testexception", result.Result.Error.Message); }
public void GetAllRoutesValidResult() { var request = new CollectionRequestModel(); var mocker = new RouteServiceMocker(); RouteInfoEntity entity = new RouteInfoEntity(); mocker.RepoMock.Setup(r => r.Search(It.IsAny <SearchQuery <RouteInfoEntity> >())) .Returns(() => Task.FromResult(new PagingResult <RouteInfoEntity>() { Count = 2, HasNext = false, Results = new List <RouteInfoEntity>() { new RouteInfoEntity() { Difficulty = 2, ID = 1, Name = "First" }, new RouteInfoEntity() { Difficulty = 3, ID = 2, Name = "Second" } } })); IRouteBLService service = mocker.GetService(); var result = service.GetAllRoutes(request); Assert.Equal(true, result.Result.IsOk); Assert.Equal(2, result.Result.Content.Count); Assert.Equal(false, result.Result.Content.HasNext); }
public async Task <IActionResult> Get([FromQuery] string filter, [FromQuery] string sort, [FromQuery] int?page, [FromQuery] int?pagesize) { var result = await _routeService.GetAllRoutes(new CollectionRequestModel(page, pagesize, sort, filter)); return(WrapResponse(result, HttpStatusCode.OK)); }