Esempio n. 1
0
        public ActionResult Get([FromBody] UserControllerRootGet payload)
        {
            // Check if payload is present
            if (payload == null)
            {
                return(BadRequest("UserController (GET) - Missing payload."));
            }

            try
            {
                // Get user from user service and return it
                var user = _userService.GetUser(payload);
                if (user == null)
                {
                    return(NotFound("UserController (GET) - User not found."));
                }

                return(Content(JsonConvert.SerializeObject(user)));
            }
            catch (InvalidCastException e)
            {
                // Return 422 if we can't parse the user identifier as GUID
                return(UnprocessableEntity(e.Message));
            }
            catch (InvalidDataException e)
            {
                // Return 400 if the user identifier is ambiguous
                return(BadRequest(e.Message));
            }
            catch (Exception e)
            {
                // Return 500 if any other exception occurred
                return(Problem(e.Message, e.Source, 500, "UserController (GET)", e.GetType().ToString()));
            }
        }
Esempio n. 2
0
        public User GetUser(UserControllerRootGet payload)
        {
            // Validate Payload
            DataValidator.ValidateField(nameof(payload.UserIdentifier), payload.UserIdentifier);
            DataValidator.ValidateGuid(payload.UserIdentifier);

            // Get User
            return(_storageService.GetUser(payload.UserIdentifier));
        }
Esempio n. 3
0
        public async Task ShouldGetUser()
        {
            // Arrange
            var userIdentifier = Guid.NewGuid().ToString();
            var payload        = new UserControllerRootGet
            {
                UserIdentifier = userIdentifier
            };

            // Act

            // Create User first
            await Shared.CreateUser(Client, payload);

            // Get User
            var getUserResponse = await Shared.GetUser(Client, payload);

            // Assert
            var user = JsonConvert.DeserializeObject <User>(await getUserResponse.Content.ReadAsStringAsync());

            Assert.Equal(HttpStatusCode.OK, getUserResponse.StatusCode);
            Assert.Equal(user.UserIdentifier, payload.UserIdentifier);
        }