public IActionResult AllocateUsers(AllocateUsersRequest request)
        {
            _logger.LogDebug(
                "AllocateUsers No. of UserTypes: {count} Application: {application}", request.UserTypes.Count, request.Application);

            lock (AllocationLock)
            {
                var responses = new List <UserDetailsResponse>();

                foreach (var userType in request.UserTypes)
                {
                    var allocateRequest = new AllocateUserRequest()
                    {
                        AllocatedBy     = request.AllocatedBy,
                        Application     = request.Application,
                        ExpiryInMinutes = request.ExpiryInMinutes,
                        IsEjud          = request.IsEjud,
                        IsProdUser      = request.IsProdUser,
                        TestType        = request.TestType,
                        UserType        = userType
                    };

                    var user = Allocate(allocateRequest);
                    _logger.LogDebug("User '{username}' successfully allocated", user.Result.Username);
                    responses.Add(UserToDetailsResponseMapper.MapToResponse(user.Result));
                }

                _logger.LogInformation("Allocated {count} user(s)", responses.Count);

                return(Ok(responses));
            }
        }
        public void Should_map_all_properties()
        {
            var user = new UserBuilder(EmailData.FAKE_EMAIL_STEM, 1)
                       .WithUserType(UserType.Individual)
                       .ForApplication(Application.TestApi)
                       .BuildUserDto();

            var response = UserToDetailsResponseMapper.MapToResponse(user);

            response.Should().BeEquivalentTo(user);
        }
        public IActionResult AllocateSingleUser(AllocateUserRequest request)
        {
            _logger.LogDebug("AllocateSingleUser {userType} {application}", request.UserType, request.Application);

            lock (AllocationLock)
            {
                var user = Allocate(request);
                _logger.LogDebug("User '{username}' successfully allocated", user.Result.Username);

                var response = UserToDetailsResponseMapper.MapToResponse(user.Result);
                return(Ok(response));
            }
        }
        public async Task <IActionResult> GetUserDetailsByUsername(string username)
        {
            _logger.LogDebug("GetUserDetailsByUsername {username}", username);

            var user = await _queryHandler.Handle <GetUserByUsernameQuery, UserDto>(new GetUserByUsernameQuery(username));

            if (user == null)
            {
                return(NotFound());
            }

            var response = UserToDetailsResponseMapper.MapToResponse(user);

            return(Ok(response));
        }