public async Task WebLinks_CRUD_LiveSession() { const string subFolderId = "1927308583"; var url = new Uri("http://www.box.com"); const string description = "A weblink to Box.com"; const string name = "Box.com website"; //create weblink var wlr = new BoxWebLinkRequest() { Url = url, Name = name, Description = description, Parent = new BoxRequestEntity() { Id = "0" } }; var weblink = await _client.WebLinksManager.CreateWebLinkAsync(wlr); Assert.AreEqual(name, weblink.Name, "Failed to create weblink."); Assert.AreEqual(url, weblink.Url); //get weblink var fetchedWeblink = await _client.WebLinksManager.GetWebLinkAsync(weblink.Id); Assert.AreEqual(weblink.Id, fetchedWeblink.Id, "Failed to fetch existing weblink."); Assert.AreEqual(weblink.Name, fetchedWeblink.Name, "Failed to fetch existing weblink."); //update weblink var newUrl = new Uri("http://www.google.com"); var newName = "Google website"; var newDescription = "A weblink to Google.com"; wlr = new BoxWebLinkRequest() { Url = newUrl, Description = newDescription, Name = newName }; var updatedWeblink = await _client.WebLinksManager.UpdateWebLinkAsync(fetchedWeblink.Id, wlr); Assert.AreEqual(fetchedWeblink.Id, updatedWeblink.Id, "Failed to update existing weblink."); Assert.AreEqual(newUrl, updatedWeblink.Url, "Failed to update existing weblink."); Assert.AreEqual(newDescription, updatedWeblink.Description, "Failed to update existing weblink."); Assert.AreEqual(newName, updatedWeblink.Name, "Failed to update existing weblink."); //delete weblink var result = await _client.WebLinksManager.DeleteWebLinkAsync(updatedWeblink.Id); Assert.IsTrue(result, "Failed to delete weblink."); }
/// <summary> /// Updates information for a web link. /// </summary> /// <param name="webLinkId">Id of the weblink.</param> /// <param name="updateWebLinkRequest">BoxWebLinkRequest object</param> /// <returns>An updated web link object if the update was successful.</returns> public async Task<BoxWebLink> UpdateWebLinkAsync(string webLinkId, BoxWebLinkRequest updateWebLinkRequest) { webLinkId.ThrowIfNullOrWhiteSpace("webLinkId"); updateWebLinkRequest.ThrowIfNull("updateWebLinkRequest"); BoxRequest request = new BoxRequest(_config.WebLinksEndpointUri, webLinkId) .Method(RequestMethod.Put) .Payload(_converter.Serialize(updateWebLinkRequest)); IBoxResponse<BoxWebLink> response = await ToResponseAsync<BoxWebLink>(request).ConfigureAwait(false); return response.ResponseObject; }
/// <summary> /// Creates a web link object within a given folder. /// </summary> /// <param name="createWebLinkRequest">BoxWebLinkRequest object</param> /// <returns>The web link object is returned.</returns> public async Task<BoxWebLink> CreateWebLinkAsync(BoxWebLinkRequest createWebLinkRequest) { createWebLinkRequest.ThrowIfNull("createWebLinkRequest") .Parent.ThrowIfNull("createWebLinkRequest.Parent") .Id.ThrowIfNullOrWhiteSpace("createWebLinkRequest.Parent.Id"); BoxRequest request = new BoxRequest(_config.WebLinksEndpointUri) .Method(RequestMethod.Post) .Payload(_converter.Serialize(createWebLinkRequest)); IBoxResponse<BoxWebLink> response = await ToResponseAsync<BoxWebLink>(request).ConfigureAwait(false); return response.ResponseObject; }
public async Task UpdateWeblink_ValidResponse() { /*** Arrange ***/ string responseString = @"{ ""type"": ""web_link"", ""id"": ""6742981"", ""sequence_id"": ""2"", ""etag"": ""2"", ""name"": ""Box Marketing Web Page"", ""url"": ""https://www.box.com"", ""created_by"": { ""type"": ""user"", ""id"": ""10523870"", ""name"": ""Ted Blosser"", ""login"": ""*****@*****.**"" }, ""created_at"": ""2015-05-07T14:31:16-07:00"", ""modified_at"": ""2015-05-07T15:45:04-07:00"", ""parent"": { ""type"": ""folder"", ""id"": ""848123342"", ""sequence_id"": ""1"", ""etag"": ""1"", ""name"": ""Documentation"" }, ""description"": ""Cloud Content Management"", ""item_status"": ""active"", ""trashed_at"": null, ""purged_at"": null, ""shared_link"": null, ""path_collection"": { ""total_count"": 2, ""entries"": [ { ""type"": ""folder"", ""id"": ""0"", ""sequence_id"": null, ""etag"": null, ""name"": ""All Files"" }, { ""type"": ""folder"", ""id"": ""848123342"", ""sequence_id"": ""1"", ""etag"": ""1"", ""name"": ""Documentation"" } ] }, ""modified_by"": { ""type"": ""user"", ""id"": ""10523870"", ""name"": ""Ted Blosser"", ""login"": ""*****@*****.**"" }, ""owned_by"": { ""type"": ""user"", ""id"": ""10523870"", ""name"": ""Ted Blosser"", ""login"": ""*****@*****.**"" } }"; IBoxRequest boxRequest = null; Uri webLinksUri = new Uri(Constants.WebLinksEndpointString); _config.SetupGet(x => x.WebLinksEndpointUri).Returns(webLinksUri); _handler.Setup(h => h.ExecuteAsync<BoxWebLink>(It.IsAny<IBoxRequest>())) .Returns(Task.FromResult<IBoxResponse<BoxWebLink>>(new BoxResponse<BoxWebLink>() { Status = ResponseStatus.Success, ContentString = responseString })) .Callback<IBoxRequest>(r => boxRequest = r); /*** Act ***/ BoxWebLinkRequest updateWebLinkRequest = new BoxWebLinkRequest() { Name = "Box Marketing Web Page" }; BoxWebLink result = await _webLinkManager.UpdateWebLinkAsync("6742981", updateWebLinkRequest); /*** Assert ***/ //Request check Assert.IsNotNull(boxRequest); Assert.AreEqual(RequestMethod.Put, boxRequest.Method); Assert.AreEqual(webLinksUri + "6742981", boxRequest.AbsoluteUri.AbsoluteUri); BoxWebLinkRequest payload = JsonConvert.DeserializeObject<BoxWebLinkRequest>(boxRequest.Payload); Assert.AreEqual("Box Marketing Web Page", payload.Name); //Response check Assert.AreEqual("web_link", result.Type); Assert.AreEqual("6742981", result.Id); Assert.AreEqual(new Uri("https://www.box.com"), result.Url); Assert.AreEqual("Box Marketing Web Page", result.Name); Assert.AreEqual("Cloud Content Management", result.Description); Assert.AreEqual("0", result.PathCollection.Entries[0].Id); Assert.AreEqual("All Files", result.PathCollection.Entries[0].Name); Assert.AreEqual("848123342", result.PathCollection.Entries[1].Id); Assert.AreEqual("Documentation", result.PathCollection.Entries[1].Name); Assert.AreEqual("10523870", result.ModifiedBy.Id); Assert.AreEqual("10523870", result.OwnedBy.Id); }