示例#1
0
        /// <summary>
        /// Create a new Legal Hold Policy. Optional date filter may be passed.
        /// If Policy has a date filter, any Custodian assignments will apply only to file versions created or uploaded inside of the date range.
        /// (Other assignment types, such as folders and files, will ignore the date filter).
        /// </summary>
        /// <param name="createRequest">BoxLegalHoldPolicyRequest object.</param>
        /// <returns>For a successful request, returns information about the Legal Hold Policy created.
        /// If the Policy Name is in use for your enterprise, will return null.
        /// </returns>
        public async Task <BoxLegalHoldPolicy> CreateLegalHoldPolicyAsync(BoxLegalHoldPolicyRequest createRequest)
        {
            createRequest.ThrowIfNull("createRequest")
            .PolicyName.ThrowIfNullOrWhiteSpace("createRequest.PolicyName");

            BoxRequest request = new BoxRequest(_config.LegalHoldPoliciesEndpointUri)
                                 .Method(RequestMethod.Post)
                                 .Payload(_converter.Serialize(createRequest));

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

            return(response.ResponseObject);
        }
示例#2
0
        /// <summary>
        /// Update existing Legal Hold Policy. Only name and description can be modified.
        /// </summary>
        /// <param name="legalHoldPolicyId">Id of the legal hold policy.</param>
        /// <param name="updateRequest">BoxLegalHoldPolicyRequest object.</param>
        /// <returns>Returns information about the Legal Hold Policy updated.</returns>
        public async Task <BoxLegalHoldPolicy> UpdateLegalHoldPolicyAsync(string legalHoldPolicyId, BoxLegalHoldPolicyRequest updateRequest)
        {
            legalHoldPolicyId.ThrowIfNull("legalHoldPolicyId");
            updateRequest.ThrowIfNull("updateRequest");

            BoxRequest request = new BoxRequest(_config.LegalHoldPoliciesEndpointUri, legalHoldPolicyId)
                                 .Method(RequestMethod.Put)
                                 .Payload(_converter.Serialize(updateRequest));

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

            return(response.ResponseObject);
        }
示例#3
0
        public async Task UpdateLegalHoldPolicy_ValidResponse()
        {
            /*** Arrange ***/
            var         responseString        = @"{
                                          ""type"": ""legal_hold_policy"",
                                          ""id"": ""166921"",
                                          ""policy_name"": ""New Policy 3"",
                                          ""description"": ""Policy 3 New Description"",
                                          ""created_by"": {
                                            ""type"": ""user"",
                                            ""id"": ""2030388321"",
                                            ""name"": ""Ryan Churchill"",
                                            ""login"": ""*****@*****.**""
                                          },
                                          ""created_at"": ""2016-05-18T16:18:49-07:00"",
                                          ""modified_at"": ""2016-05-18T16:20:47-07:00"",
                                          ""deleted_at"": null,
                                          ""filter_started_at"": ""2016-05-11T01:00:00-07:00"",
                                          ""filter_ended_at"": ""2016-05-13T01:00:00-07:00""
                                        }";
            IBoxRequest boxRequest            = null;
            var         legalHoldsPoliciesUri = new Uri(Constants.LegalHoldPoliciesEndpointString);

            Config.SetupGet(x => x.LegalHoldPoliciesEndpointUri).Returns(legalHoldsPoliciesUri);
            Handler.Setup(h => h.ExecuteAsync <BoxLegalHoldPolicy>(It.IsAny <IBoxRequest>()))
            .Returns(Task.FromResult <IBoxResponse <BoxLegalHoldPolicy> >(new BoxResponse <BoxLegalHoldPolicy>()
            {
                Status        = ResponseStatus.Success,
                ContentString = responseString
            }))
            .Callback <IBoxRequest>(r => boxRequest = r);

            /*** Act ***/
            var updateRequest = new BoxLegalHoldPolicyRequest()
            {
                PolicyName  = "New Policy 3",
                Description = "Policy 3 New Description"
            };
            BoxLegalHoldPolicy result = await _legalHoldPoliciesManager.UpdateLegalHoldPolicyAsync("166921", updateRequest);

            /*** Assert ***/
            //Request check
            Assert.IsNotNull(boxRequest);
            Assert.AreEqual(RequestMethod.Put, boxRequest.Method);
            Assert.AreEqual(legalHoldsPoliciesUri + "166921", boxRequest.AbsoluteUri.AbsoluteUri);
            BoxLegalHoldPolicyRequest payLoad = JsonConvert.DeserializeObject <BoxLegalHoldPolicyRequest>(boxRequest.Payload);

            Assert.AreEqual("New Policy 3", payLoad.PolicyName);
            Assert.AreEqual("Policy 3 New Description", payLoad.Description);

            //Response check
            Assert.AreEqual("legal_hold_policy", result.Type);
            Assert.AreEqual("166921", result.Id);
            Assert.AreEqual("New Policy 3", result.PolicyName);
            Assert.AreEqual("Policy 3 New Description", result.Description);
            Assert.IsNull(result.Status);
            Assert.AreEqual("2030388321", result.CreatedBy.Id);
            Assert.AreEqual("Ryan Churchill", result.CreatedBy.Name);
            Assert.AreEqual(DateTimeOffset.Parse("2016-05-18T16:18:49-07:00"), result.CreatedAt);
            Assert.AreEqual(DateTimeOffset.Parse("2016-05-18T16:20:47-07:00"), result.ModifiedAt);
            Assert.AreEqual(DateTimeOffset.Parse("2016-05-11T01:00:00-07:00"), result.FilterStartedAt);
            Assert.AreEqual(DateTimeOffset.Parse("2016-05-13T01:00:00-07:00"), result.FilterEndedAt);
        }