Exemplo n.º 1
0
        /// <summary>
        /// Invites an existing user to join an Enterprise. The existing user cannot be part of another Enterprise and must already have a Box account.
        /// Once invited, the user will receive an email and prompt to accept the invitation within the Box web application. 
        /// This method requires the "Manage An Enterprise" scope for the enterprise, which can be enabled within your developer console.
        /// </summary>
        /// <param name="userInviteRequest">BoxUserInviteRequest object.</param>
        /// <param name="fields">Attribute(s) to include in the response.</param>
        /// <returns>A new invite object will be returned if successful.</returns>
        public async Task<BoxUserInvite> InviteUserToEnterpriseAsync(BoxUserInviteRequest userInviteRequest, List<string> fields = null)
        {
            userInviteRequest.ThrowIfNull("userInviteRequest")
                .Enterprise.ThrowIfNull("Enterprise").Id.ThrowIfNullOrWhiteSpace("userInviteRequest.Enterprise.Id");
            userInviteRequest.ActionableBy.ThrowIfNull("userInviteRequest.ActionableBy")
               .Login.ThrowIfNullOrWhiteSpace("userInviteRequest.ActionableBy.Login");

            BoxRequest request = new BoxRequest(_config.InviteEndpointUri)
            .Param(ParamFields, fields)
            .Payload(_converter.Serialize(userInviteRequest))
            .Method(RequestMethod.Post);

            IBoxResponse<BoxUserInvite> response = await ToResponseAsync<BoxUserInvite>(request).ConfigureAwait(false);

            return response.ResponseObject;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Invites an existing user to join an Enterprise. The existing user cannot be part of another Enterprise and must already have a Box account.
        /// </summary>
        /// <returns></returns>
        /// 
        public async Task<BoxUserInvite> InviteUserToEnterpriseAsync(BoxUserInviteRequest userInviteRequest, List<string> fields = null)
        {
            BoxRequest request = new BoxRequest(_config.InviteEndpointUri)
            .Param(ParamFields, fields)
            .Payload(_converter.Serialize(userInviteRequest))
            .Method(RequestMethod.Post);

            IBoxResponse<BoxUserInvite> response = await ToResponseAsync<BoxUserInvite>(request).ConfigureAwait(false);

            return response.ResponseObject;
        }
Exemplo n.º 3
0
        public async Task InviteUser_ValidResponse_ValidUser()
        {
            /*** Arrange ***/
            string responseString = "{ \"type\":\"invite\",\"id\":\"238632\",\"invited_to\":{ \"type\":\"enterprise\",\"id\":\"42500\",\"name\":\"Blosser Account\"},\"actionable_by\":{ \"type\":\"user\",\"id\":\"229667663\",\"name\":\"Lleyton Hewitt\",\"login\":\"[email protected]\"},\"invited_by\":{ \"type\":\"user\",\"id\":\"10523870\",\"name\":\"Ted Blosser\",\"login\":\"[email protected]\"},\"status\":\"pending\",\"created_at\":\"2014-12-23T12:55:53-08:00\",\"modified_at\":\"2014-12-23T12:55:53-08:00\"}";
            IBoxRequest boxRequest = null;
            _handler.Setup(h => h.ExecuteAsync<BoxUserInvite>(It.IsAny<IBoxRequest>()))
                .Returns(Task.FromResult<IBoxResponse<BoxUserInvite>>(new BoxResponse<BoxUserInvite>()
                {
                    Status = ResponseStatus.Success,
                    ContentString = responseString
                }))
                .Callback<IBoxRequest>(r => boxRequest = r);

            /*** Act ***/
            BoxUserInviteRequest userInviteRequest = new BoxUserInviteRequest()
            {
                Enterprise = new BoxRequestEntity()
                {
                    Id = "42500"
                },
                ActionableBy = new BoxActionableByRequest()
                {
                    Login = "******"
                }
            };
            BoxUserInvite userInvite = await _usersManager.InviteUserToEnterpriseAsync(userInviteRequest);

            /*** Assert ***/

            // Request check
            Assert.IsNotNull(boxRequest);
            Assert.AreEqual(RequestMethod.Post, boxRequest.Method);
            Assert.AreEqual(_InviteUri, boxRequest.AbsoluteUri.AbsoluteUri);
            BoxUserInviteRequest payload = JsonConvert.DeserializeObject<BoxUserInviteRequest>(boxRequest.Payload);
            Assert.AreEqual(userInviteRequest.Enterprise.Id, payload.Enterprise.Id);
            Assert.AreEqual(userInviteRequest.ActionableBy.Login, payload.ActionableBy.Login);

            //Response check
            Assert.AreEqual("238632", userInvite.Id);
            Assert.AreEqual("*****@*****.**", userInvite.ActionableBy.Login);
        }
        public async Task InviteUser_ValidResponse_ValidUser()
        {
            /*** Arrange ***/
            string responseString = "{ \"type\":\"invite\",\"id\":\"238632\",\"invited_to\":{ \"type\":\"enterprise\",\"id\":\"42500\",\"name\":\"Blosser Account\"},\"actionable_by\":{ \"type\":\"user\",\"id\":\"229667663\",\"name\":\"Lleyton Hewitt\",\"login\":\"[email protected]\"},\"invited_by\":{ \"type\":\"user\",\"id\":\"10523870\",\"name\":\"Ted Blosser\",\"login\":\"[email protected]\"},\"status\":\"pending\",\"created_at\":\"2014-12-23T12:55:53-08:00\",\"modified_at\":\"2014-12-23T12:55:53-08:00\"}";
            _handler.Setup(h => h.ExecuteAsync<BoxUserInvite>(It.IsAny<IBoxRequest>()))
                .Returns(Task.FromResult<IBoxResponse<BoxUserInvite>>(new BoxResponse<BoxUserInvite>()
                {
                    Status = ResponseStatus.Success,
                    ContentString = responseString
                }));

            /*** Act ***/
            BoxUserInviteRequest userInviteRequest = new BoxUserInviteRequest()
            {
                Enterprise = new BoxRequestEntity()
                {
                    Id = "42500"
                },
                ActionableBy = new BoxActionableByRequest()
                {
                    Login = "******"
                }
            };
            BoxUserInvite userInvite = await _usersManager.InviteUserToEnterpriseAsync(userInviteRequest);

            /*** Assert ***/
            Assert.AreEqual("*****@*****.**", userInvite.ActionableBy.Login);
        }