/// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            GetCallerIdentityResponse response = new GetCallerIdentityResponse();

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

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.IsStartElement)
                {
                    if (context.TestExpression("GetCallerIdentityResult", 2))
                    {
                        UnmarshallResult(context, response);
                        continue;
                    }

                    if (context.TestExpression("ResponseMetadata", 2))
                    {
                        response.ResponseMetadata = ResponseMetadataUnmarshaller.Instance.Unmarshall(context);
                    }
                }
            }

            return(response);
        }
Example #2
0
        private static void UnmarshallResult(XmlUnmarshallerContext context, GetCallerIdentityResponse response)
        {
            int currentDepth = context.get_CurrentDepth();
            int num          = currentDepth + 1;

            if (context.get_IsStartOfDocument())
            {
                num += 2;
            }
            while (context.ReadAtDepth(currentDepth))
            {
                if (context.get_IsStartElement() || context.get_IsAttribute())
                {
                    if (context.TestExpression("Account", num))
                    {
                        StringUnmarshaller instance = StringUnmarshaller.get_Instance();
                        response.Account = instance.Unmarshall(context);
                    }
                    else if (context.TestExpression("Arn", num))
                    {
                        StringUnmarshaller instance2 = StringUnmarshaller.get_Instance();
                        response.Arn = instance2.Unmarshall(context);
                    }
                    else if (context.TestExpression("UserId", num))
                    {
                        StringUnmarshaller instance3 = StringUnmarshaller.get_Instance();
                        response.UserId = instance3.Unmarshall(context);
                    }
                }
            }
        }
Example #3
0
        public AmazonSecurityTokenServiceStub WithGetCallerIdentityResponse(
            GetCallerIdentityResponse getCallerIdentityResponse)
        {
            AmazonSecurityTokenServiceStub.GetCallerIdentityResponse = getCallerIdentityResponse;

            return(AmazonSecurityTokenServiceStub);
        }
        public async Task Will_Return_A_Role_If_CreateRoleAsync_Response_Is_Ok()
        {
            // Arrange
            var role = new Role();
            var createRoleResponse = new CreateRoleResponse();

            createRoleResponse.HttpStatusCode = HttpStatusCode.OK;
            createRoleResponse.Role           = role;
            var amazonIdentityManagementServiceStubBuilder = new AmazonIdentityManagementServiceStubBuilder();


            var getCallerIdentityResponse = new GetCallerIdentityResponse();

            getCallerIdentityResponse.Account = "AccountDoesNotMatter";
            var amazonSecurityTokenServiceStubBuilder = new AmazonSecurityTokenServiceStubBuilder();
            var roleName = "doesNotMatter";

            var identityManagementClient = new IdentityManagementServiceClientStub();

            var sut = new AwsIdentityCommandClient(
                amazonIdentityManagementServiceStubBuilder.WithCreateRoleResponse(createRoleResponse),
                amazonSecurityTokenServiceStubBuilder.WithGetCallerIdentityResponse(getCallerIdentityResponse),
                new PolicyTemplateRepositoryStub(),
                identityManagementClient
                );


            // Act
            var resultRole = await sut.PutRoleAsync(new RoleName(roleName));


            // Assert
            Assert.Same(role, resultRole);
        }
        public async Task Will_Throw_A_Exception_If_CreateRoleAsync_Response_Is_Not_Ok()
        {
            // Arrange
            var createRoleResponse = new CreateRoleResponse();

            createRoleResponse.HttpStatusCode   = HttpStatusCode.ServiceUnavailable;
            createRoleResponse.ResponseMetadata = new ResponseMetadata();
            createRoleResponse.ResponseMetadata.Metadata["foo"] = "bar";

            var amazonIdentityManagementServiceStubBuilder = new AmazonIdentityManagementServiceStubBuilder();

            var getCallerIdentityResponse = new GetCallerIdentityResponse();

            getCallerIdentityResponse.Account = "AccountDoesNotMatter";
            var amazonSecurityTokenServiceStubBuilder = new AmazonSecurityTokenServiceStubBuilder();
            var roleName = "doesNotMatter";

            var identityManagementClient = new IdentityManagementServiceClientStub();


            var sut = new AwsIdentityCommandClient(
                amazonIdentityManagementServiceStubBuilder.WithCreateRoleResponse(createRoleResponse),
                amazonSecurityTokenServiceStubBuilder.WithGetCallerIdentityResponse(getCallerIdentityResponse),
                new PolicyTemplateRepositoryStub(),
                identityManagementClient
                );

            // Act / Assert
            await Assert.ThrowsAsync <Exception>(() => sut.PutRoleAsync(new RoleName(roleName)));
        }
        public static GetCallerIdentityResponse Unmarshall(UnmarshallerContext context)
        {
            GetCallerIdentityResponse getCallerIdentityResponse = new GetCallerIdentityResponse();

            getCallerIdentityResponse.HttpResponse = context.HttpResponse;
            getCallerIdentityResponse.AccountId    = context.StringValue("GetCallerIdentity.AccountId");
            getCallerIdentityResponse.UserId       = context.StringValue("GetCallerIdentity.UserId");
            getCallerIdentityResponse.Arn          = context.StringValue("GetCallerIdentity.Arn");
            getCallerIdentityResponse.RequestId    = context.StringValue("GetCallerIdentity.RequestId");

            return(getCallerIdentityResponse);
        }
Example #7
0
        public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            GetCallerIdentityResponse getCallerIdentityResponse = new GetCallerIdentityResponse();

            context.Read();
            int currentDepth = context.get_CurrentDepth();

            while (context.ReadAtDepth(currentDepth))
            {
                if (context.get_IsStartElement())
                {
                    if (context.TestExpression("GetCallerIdentityResult", 2))
                    {
                        UnmarshallResult(context, getCallerIdentityResponse);
                    }
                    else if (context.TestExpression("ResponseMetadata", 2))
                    {
                        getCallerIdentityResponse.set_ResponseMetadata(ResponseMetadataUnmarshaller.get_Instance().Unmarshall(context));
                    }
                }
            }
            return(getCallerIdentityResponse);
        }
        private static void UnmarshallResult(XmlUnmarshallerContext context, GetCallerIdentityResponse response)
        {
            int originalDepth = context.CurrentDepth;
            int targetDepth   = originalDepth + 1;

            if (context.IsStartOfDocument)
            {
                targetDepth += 2;
            }

            while (context.ReadAtDepth(originalDepth))
            {
                if (context.IsStartElement || context.IsAttribute)
                {
                    if (context.TestExpression("Account", targetDepth))
                    {
                        var unmarshaller = StringUnmarshaller.Instance;
                        response.Account = unmarshaller.Unmarshall(context);
                        continue;
                    }
                    if (context.TestExpression("Arn", targetDepth))
                    {
                        var unmarshaller = StringUnmarshaller.Instance;
                        response.Arn = unmarshaller.Unmarshall(context);
                        continue;
                    }
                    if (context.TestExpression("UserId", targetDepth))
                    {
                        var unmarshaller = StringUnmarshaller.Instance;
                        response.UserId = unmarshaller.Unmarshall(context);
                        continue;
                    }
                }
            }

            return;
        }