Beispiel #1
0
        public void Should_call_serializer_with_same_fields_when_fields_passed()
        {
            var parameters = new UsersParametersModel()
            {
                Fields = "id,email"
            };

            _usersController.GetUsers(parameters).GetAwaiter().GetResult();

            _jsonFieldsSerializer.Verify(x => x.Serialize(It.IsAny <UsersRootObject>(), It.IsIn(parameters.Fields), null));
        }
Beispiel #2
0
        public void Should_return_bad_request_when_invalid_page_passed(int invalidPage)
        {
            var parameters = new UsersParametersModel()
            {
                Page = invalidPage
            };

            _jsonFieldsSerializer.Setup(x => x.Serialize(It.IsAny <UsersRootObject>(), It.IsAny <string>(), null))
            .Returns(String.Empty);

            var result     = _usersController.GetUsers(parameters).GetAwaiter().GetResult();
            var statusCode = ActionResultExecutor.ExecuteResult(result);

            Assert.AreEqual(HttpStatusCode.BadRequest, statusCode);
        }
Beispiel #3
0
        public void Should_call_serializer_with_no_users_when_no_users_exist()
        {
            var returnedUsersDtoCollection = new List <UserDto>();
            var parameters = new UsersParametersModel();

            _userApiService
            .Setup(x => x.GetUserDtos(parameters.CreatedAtMin, parameters.CreatedAtMax, parameters.Limit,
                                      parameters.Page, parameters.SinceId, null, null)).Returns(returnedUsersDtoCollection);

            _usersController.GetUsers(parameters).GetAwaiter().GetResult();

            _jsonFieldsSerializer.Verify(x =>
                                         x.Serialize(It.Is <UsersRootObject>(r => r.Users.Count == returnedUsersDtoCollection.Count),
                                                     It.IsIn(parameters.Fields), null));
        }
Beispiel #4
0
        public void Should_call_service_with_same_parameters_when_valid_parameters_passed()
        {
            var parameters = new UsersParametersModel
            {
                SinceId      = Configurations.DefaultSinceId + 1, // some different than default since id
                CreatedAtMin = DateTime.Now,
                CreatedAtMax = DateTime.Now,
                Page         = Configurations.DefaultPageValue + 1, // some different than default page
                Limit        = Configurations.MinLimit + 1,         // some different than default limit
            };

            _usersController.GetUsers(parameters).GetAwaiter().GetResult();

            _userApiService.Verify(x => x.GetUserDtos(parameters.CreatedAtMin, parameters.CreatedAtMax,
                                                      parameters.Limit, parameters.Page, parameters.SinceId, null, null));
        }
Beispiel #5
0
        public async Task <IActionResult> GetUsers(UsersParametersModel parameters)
        {
            if (parameters.Limit < Configurations.MinLimit || parameters.Limit > Configurations.MaxLimit)
            {
                return(await Error(HttpStatusCode.BadRequest, "limit", "Invalid limit parameter"));
            }

            if (parameters.Page < Configurations.DefaultPageValue)
            {
                return(await Error(HttpStatusCode.BadRequest, "page", "Invalid request parameters"));
            }

            var users = _userApiService.GetUserDtos(parameters.CreatedAtMin, parameters.CreatedAtMax, parameters.Limit,
                                                    parameters.Page, parameters.SinceId, parameters.RoleIds, parameters.StoreIds);

            var usersRootObject = new UsersRootObject
            {
                Users = users
            };

            var json = JsonFieldsSerializer.Serialize(usersRootObject, parameters.Fields);

            return(new RawJsonActionResult(json));
        }