コード例 #1
0
        public async Task <CreateUserProfileResponse> UpdateUserProfile(UpdateUserProfileRequest user)
        {
            string url         = $"/users/update";
            var    requestBody = await Task.Run(() => JsonConvert.SerializeObject(user));

            using (HttpClient httpClient = new HttpClient())
            {
                CreateUserProfileResponse data = new CreateUserProfileResponse();
                try
                {
                    var authHeader = new AuthenticationHeaderValue("Bearer", await SecureStorage.GetAsync("auth_token"));
                    httpClient.DefaultRequestHeaders.Authorization = authHeader;
                    httpClient.BaseAddress = new Uri(Constants.BaseUrl);
                    StringContent       content = new StringContent(requestBody, Encoding.UTF8, "application/json");
                    HttpResponseMessage result  = await httpClient.PostAsync(url, content);

                    string response = await result.Content.ReadAsStringAsync();

                    data = JsonConvert.DeserializeObject <CreateUserProfileResponse>(response);

                    if (result.IsSuccessStatusCode && result.StatusCode == HttpStatusCode.OK)
                    {
                        return(data);
                    }

                    return(null);
                }
                catch (Exception exp)
                {
                    return(null);
                }
            }
        }
コード例 #2
0
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            CreateUserProfileResponse response = new CreateUserProfileResponse();

            context.Read();

            UnmarshallResult(context, response);
            return(response);
        }
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            CreateUserProfileResponse response = new CreateUserProfileResponse();

            context.Read();

            response.CreateUserProfileResult = CreateUserProfileResultUnmarshaller.GetInstance().Unmarshall(context);

            return(response);
        }
コード例 #4
0
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            CreateUserProfileResponse response = new CreateUserProfileResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("createdTimestamp", targetDepth))
                {
                    var unmarshaller = DateTimeUnmarshaller.Instance;
                    response.CreatedTimestamp = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("displayName", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.DisplayName = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("emailAddress", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.EmailAddress = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("lastModifiedTimestamp", targetDepth))
                {
                    var unmarshaller = DateTimeUnmarshaller.Instance;
                    response.LastModifiedTimestamp = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("sshPublicKey", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.SshPublicKey = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("userArn", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.UserArn = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
コード例 #5
0
ファイル: OpsWorks.cs プロジェクト: wittryd/aws-sdk-net
        public void CRUDUserProfile()
        {
            var createUserRequest = new Amazon.IdentityManagement.Model.CreateUserRequest {
                UserName = "******" + DateTime.Now.Ticks
            };
            var createUserResponse = iamClient.CreateUser(createUserRequest);

            try
            {
                CreateUserProfileResponse createUserProfileResponse = Client.CreateUserProfile(new CreateUserProfileRequest
                {
                    IamUserArn = createUserResponse.User.Arn
                });

                Assert.IsNotNull(createUserProfileResponse.IamUserArn);

                DescribeUserProfilesResponse describeResponse = Client.DescribeUserProfiles(new DescribeUserProfilesRequest
                {
                    IamUserArns = new List <string> {
                        createUserProfileResponse.IamUserArn
                    }
                });

                Assert.AreEqual(1, describeResponse.UserProfiles.Count);
                Assert.AreEqual(createUserProfileResponse.IamUserArn, describeResponse.UserProfiles[0].IamUserArn);

                Client.DeleteUserProfile(new DeleteUserProfileRequest {
                    IamUserArn = createUserProfileResponse.IamUserArn
                });

                AssertExtensions.ExpectException((() =>
                {
                    Client.DescribeUserProfiles(new DescribeUserProfilesRequest
                    {
                        IamUserArns = new List <string> {
                            createUserProfileResponse.IamUserArn
                        }
                    });
                }), typeof(ResourceNotFoundException));
            }
            finally
            {
                iamClient.DeleteUser(new Amazon.IdentityManagement.Model.DeleteUserRequest {
                    UserName = createUserRequest.UserName
                });
            }
        }
コード例 #6
0
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            CreateUserProfileResponse response = new CreateUserProfileResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("IamUserArn", targetDepth))
                {
                    response.IamUserArn = StringUnmarshaller.GetInstance().Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
コード例 #7
0
        private static void UnmarshallResult(JsonUnmarshallerContext context, CreateUserProfileResponse response)
        {
            int originalDepth = context.CurrentDepth;
            int targetDepth   = originalDepth + 1;

            while (context.Read())
            {
                if (context.TestExpression("IamUserArn", targetDepth))
                {
                    context.Read();
                    response.IamUserArn = StringUnmarshaller.GetInstance().Unmarshall(context);
                    continue;
                }

                if (context.CurrentDepth <= originalDepth)
                {
                    return;
                }
            }

            return;
        }
コード例 #8
0
        public CreateUserProfileResponse SaveUserProfile(CreateUserProfileRequest userprofileRequest)
        {
            var createUserProfileResponse = new CreateUserProfileResponse();

            var userprofile = _messageMapper.MapToUserProfile(userprofileRequest.UserProfile);

            try
            {
                _userprofileRepository.SaveUserProfile(userprofile);
                var userprofileDto = _messageMapper.MapToUserProfileDto(userprofile);
                createUserProfileResponse.UserProfile = userprofileDto;
                createUserProfileResponse.Messages.Add("Successfully saved the userprofile");
                createUserProfileResponse.StatusCode = HttpStatusCode.Created;
            }
            catch (Exception e)
            {
                var error = e.ToString();
                createUserProfileResponse.Messages.Add(error);
                createUserProfileResponse.StatusCode = HttpStatusCode.InternalServerError;
            }

            return(createUserProfileResponse);
        }
コード例 #9
0
ファイル: CreateUserTests.cs プロジェクト: anuviswan/nt
        public async Task CreateUser_ResponseStatus_200(CreateUserProfileRequest request, CreateUserProfileResponse expectedResult)
        {
            // Arrange
            var userProfileEntity = Mapper.Map <UserProfileEntity>(request);

            var mockUserProfileService = new Mock <IUserProfileService>();

            mockUserProfileService.Setup(x => x.CreateUserAsync(It.IsAny <UserProfileEntity>())).Returns(Task.FromResult(userProfileEntity));

            var userController = new UserController(Mapper, mockUserProfileService.Object, null, null);

            MockModelState(request, userController);

            // Act
            var response = await userController.CreateUser(request);

            // Assert
            var okObjectResult = Assert.IsType <OkObjectResult>(response.Result);
            var result         = Assert.IsType <CreateUserProfileResponse>(okObjectResult.Value);

            Assert.Equal(expectedResult.UserName, result.UserName);
        }