Skip to content

Commit

Permalink
Add EnsureSiteAssets to Web request
Browse files Browse the repository at this point in the history
  • Loading branch information
pschaeflein committed Jul 14, 2023
1 parent 7d0ff61 commit 3a3ed21
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/Requests/Web/IWebRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public interface IWebRequest : IBaseRequest
Task<Web> GetAssociatedGroupsAsync(bool includeUsers);
Task<Web> GetAssociatedGroupsAsync(bool includeUsers, CancellationToken cancellationToken);

Task<List> EnsureSiteAssetsAsync();
Task<List> EnsureSiteAssetsAsync(CancellationToken cancellationToken);

/// <summary>
/// Adds the specified expand value to the request.
/// </summary>
Expand Down
14 changes: 14 additions & 0 deletions src/Requests/Web/WebRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,20 @@ public async Task<List> GetSitePagesListAsync(CancellationToken cancellationToke
return null;
}

public Task<List> EnsureSiteAssetsAsync()
{
return this.EnsureSiteAssetsAsync(CancellationToken.None);
}

public async Task<List> EnsureSiteAssetsAsync(CancellationToken cancellationToken)
{
this.AppendSegmentToRequestUrl("Lists/EnsureSiteAssetsLibrary");
this.Method = HttpMethods.POST;

var entity = await this.SendAsync<Graph.Community.List>(null, cancellationToken).ConfigureAwait(false);
return entity;
}

public IWebRequest Expand(string value)
{
this.QueryOptions.Add(new QueryOption("$expand", value));
Expand Down
6 changes: 2 additions & 4 deletions test/Graph.Community.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<None Remove="Mocks\GetSitePageVersionsResponse.json" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Mocks\ApplySiteDesignResponse.json" />
<EmbeddedResource Include="Mocks\CreateSiteDesignResponse.json" />
Expand Down Expand Up @@ -45,6 +41,7 @@
<EmbeddedResource Include="Mocks\SearchQueryResponse.json" />
<EmbeddedResource Include="Mocks\UpdateSiteDesignResponse.json" />
<EmbeddedResource Include="Mocks\UpdateSiteScriptResponse.json" />
<EmbeddedResource Include="Mocks\EnsureSiteAssetsResponse.json" />
</ItemGroup>

<ItemGroup>
Expand All @@ -61,4 +58,5 @@
<ProjectReference Include="..\src\Graph.Community.csproj" />
</ItemGroup>


</Project>
60 changes: 60 additions & 0 deletions test/Mocks/EnsureSiteAssetsResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"odata.metadata": "https://mock.sharepoint.com/sites/mockSite/_api/$metadata#SP.ApiData.Lists/@Element",
"odata.type": "SP.List",
"odata.id": "https://mock.sharepoint.com/sites/mockSite/_api/Web/Lists(guid'481f59e9-e3a8-4216-8188-642076ab4c74')",
"odata.etag": "\"26\"",
"odata.editLink": "Web/Lists(guid'481f59e9-e3a8-4216-8188-642076ab4c74')",
"AllowContentTypes": true,
"BaseTemplate": 101,
"BaseType": 1,
"ContentTypesEnabled": false,
"CrawlNonDefaultViews": false,
"Created": "2023-04-24T14:15:26Z",
"CurrentChangeToken": { "StringValue": "1;3;481f59e9-e3a8-4216-8188-642076ab4c74;638249480363130000;930274798" },
"DefaultContentApprovalWorkflowId": "00000000-0000-0000-0000-000000000000",
"DefaultItemOpenUseListSetting": false,
"Description": "Use this library to store files which are included on pages within this site, such as images on Wiki pages.",
"Direction": "none",
"DisableCommenting": false,
"DisableGridEditing": false,
"DocumentTemplateUrl": "/sites/mockSite/SiteAssets/Forms/template.doc",
"DraftVersionVisibility": 0,
"EnableAttachments": false,
"EnableFolderCreation": true,
"EnableMinorVersions": false,
"EnableModeration": false,
"EnableRequestSignOff": true,
"EnableVersioning": true,
"EntityTypeName": "SiteAssets",
"ExemptFromBlockDownloadOfNonViewableFiles": false,
"FileSavePostProcessingEnabled": false,
"ForceCheckout": false,
"HasExternalDataSource": false,
"Hidden": false,
"Id": "481f59e9-e3a8-4216-8188-642076ab4c74",
"ImagePath": { "DecodedUrl": "/_layouts/15/images/itdl.png?rev=44" },
"ImageUrl": "/_layouts/15/images/itdl.png?rev=44",
"DefaultSensitivityLabelForLibrary": "",
"IrmEnabled": false,
"IrmExpire": false,
"IrmReject": false,
"IsApplicationList": true,
"IsCatalog": false,
"IsPrivate": false,
"ItemCount": 27,
"LastItemDeletedDate": "2023-04-24T14:15:26Z",
"LastItemModifiedDate": "2023-07-13T18:33:25Z",
"LastItemUserModifiedDate": "2023-04-24T14:16:08Z",
"ListExperienceOptions": 0,
"ListItemEntityTypeFullName": "SP.Data.SiteAssetsItem",
"MajorVersionLimit": 500,
"MajorWithMinorVersionsLimit": 0,
"MultipleDataList": false,
"NoCrawl": false,
"ParentWebPath": { "DecodedUrl": "/sites/mockSite" },
"ParentWebUrl": "/sites/mockSite",
"ParserDisabled": false,
"ServerTemplateCanCreateFolders": true,
"TemplateFeatureId": "00bfea71-e717-4e80-aa17-d0c71b360101",
"Title": "Site Assets"
}
61 changes: 61 additions & 0 deletions test/WebRequestTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -385,5 +385,66 @@ public async Task GetAssociatedGroupsWithUsers_ReturnsCorrectResponse()
}
}


[Fact]
public async Task EnsureSiteAssets_GeneratesCorrectRequest()
{
// ARRANGE
var expectedUri = new Uri($"{mockWebUrl}/_api/web/Lists/EnsureSiteAssetsLibrary");

using HttpResponseMessage response = new HttpResponseMessage();
using GraphServiceTestClient gsc = GraphServiceTestClient.Create(response);

// ACT
await gsc.GraphServiceClient
.SharePointAPI(mockWebUrl)
.Web
.Request()
.EnsureSiteAssetsAsync();

// ASSERT
gsc.HttpProvider.Verify(
provider => provider.SendAsync(
It.Is<HttpRequestMessage>(req =>
req.Method == HttpMethod.Post &&
req.RequestUri == expectedUri &&
req.Headers.Authorization != null
),
It.IsAny<HttpCompletionOption>(),
It.IsAny<CancellationToken>()
),
Times.Exactly(1)
);
}

[Fact]
public async Task EnsureSiteAssets_ReturnsCorrectResponse()
{
// ARRANGE
var responseContent = ResourceManager.GetHttpResponseContent("EnsureSiteAssetsResponse.json");
HttpResponseMessage responseMessage = new HttpResponseMessage()
{
StatusCode = HttpStatusCode.OK,
Content = new StringContent(responseContent),
};


using (responseMessage)
using (var gsc = GraphServiceTestClient.Create(responseMessage))
{
// ACT
var response = await gsc.GraphServiceClient
.SharePointAPI(mockWebUrl)
.Web
.Request()
.EnsureSiteAssetsAsync();
var actual = response;

// ASSERT
Assert.NotNull(actual);
Assert.Equal("481f59e9-e3a8-4216-8188-642076ab4c74", actual.Id);
}
}

}
}

0 comments on commit 3a3ed21

Please sign in to comment.