public void Should_call_service_with_default_parameters_when_no_parameters_passed() { var defaultParametersModel = new UsersSearchParametersModel(); _usersController.Search(defaultParametersModel).GetAwaiter().GetResult(); _userApiService.Verify(x => x.Search(defaultParametersModel.Query, defaultParametersModel.Order, defaultParametersModel.Page, defaultParametersModel.Limit)); }
public void Should_call_serializer_with_same_fields_when_fields_parameters_passed() { var defaultParametersModel = new UsersSearchParametersModel { Fields = "id, mail" }; _usersController.Search(defaultParametersModel).GetAwaiter().GetResult(); _jsonFieldsSerializer.Verify(x => x.Serialize(It.IsAny <UsersRootObject>(), It.IsIn(defaultParametersModel.Fields), null)); }
public void Should_return_bad_request_when_non_positive_page_passed(int nonPositivePage) { var parametersModel = new UsersSearchParametersModel() { Page = nonPositivePage }; _jsonFieldsSerializer.Setup(x => x.Serialize(It.IsAny <UsersRootObject>(), It.IsAny <string>(), null)) .Returns(String.Empty); var result = _usersController.Search(parametersModel).GetAwaiter().GetResult(); var statusCode = ActionResultExecutor.ExecuteResult(result); Assert.AreEqual(HttpStatusCode.BadRequest, statusCode); }
public void Should_call_serializer_when_no_parameters_passed_and_no_user_exists() { var expectedUsersCollection = new List <UserDto>(); var expectedRootObject = new UsersRootObject { Users = expectedUsersCollection }; var defaultParameters = new UsersSearchParametersModel(); _jsonFieldsSerializer.Setup(x => x.Serialize(expectedRootObject, defaultParameters.Fields, null)); _userApiService.Setup(x => x.Search(null, null, 1, 50)).Returns(expectedUsersCollection); _usersController.Search(defaultParameters).GetAwaiter().GetResult(); _jsonFieldsSerializer.Verify(x => x.Serialize(It.IsAny <UsersRootObject>(), It.IsIn(defaultParameters.Fields), null)); }
public async Task <IActionResult> Search(UsersSearchParametersModel parameters) { if (parameters.Limit <= Configurations.MinLimit || parameters.Limit > Configurations.MaxLimit) { return(await Error(HttpStatusCode.BadRequest, "limit", "Invalid limit parameter")); } if (parameters.Page <= 0) { return(await Error(HttpStatusCode.BadRequest, "page", "Invalid page parameter")); } var usersDto = _userApiService.Search(parameters.Query, parameters.Order, parameters.Page, parameters.Limit); var usersRootObject = new UsersRootObject() { Users = usersDto }; var json = JsonFieldsSerializer.Serialize(usersRootObject, parameters.Fields); return(new RawJsonActionResult(json)); }