Skip to content

Commit eb141e8

Browse files
Merge pull request #376 from microsoftgraph/enableRootSiteAccess
Fixes #374: Adds route to a Site's root structural property.
2 parents 99b7a01 + 0a7662b commit eb141e8

File tree

4 files changed

+66
-12
lines changed

4 files changed

+66
-12
lines changed

src/Microsoft.Graph/Requests/Extensions/GraphServiceSitesCollectionRequestBuilderExtension.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,16 @@ public ISiteRequestBuilder GetByPath(string siteRelativePath, string hostname)
2727
string.Format("{0}/{1}:{2}", this.RequestUrl, hostname, siteRelativePath),
2828
this.Client);
2929
}
30+
31+
/// <summary>
32+
/// Gets a request builder for accessing a sites.
33+
/// </summary>
34+
public ISiteRequestBuilder Root
35+
{
36+
get
37+
{
38+
return new SiteRequestBuilder(this.AppendSegmentToRequestUrl("root"), this.Client);
39+
}
40+
}
3041
}
3142
}

src/Microsoft.Graph/Requests/Extensions/IGraphServiceSitesCollectionRequestBuilderExtension.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,10 @@ public partial interface IGraphServiceSitesCollectionRequestBuilder
1515
/// </summary>
1616
/// <returns>The <see cref="ISiteRequestBuilder"/>.</returns>
1717
ISiteRequestBuilder GetByPath(string siteRelativePath, string hostname);
18+
19+
/// <summary>
20+
/// Gets a request builder for accessing a site's root. This is how we can provide a request builder for structural properties.
21+
/// </summary>
22+
ISiteRequestBuilder Root { get; }
1823
}
1924
}

tests/Microsoft.Graph.Test/Requests/Functional/OneNoteTests.cs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ public class OneNoteTests : GraphTestBase
1717
private Notebook testNotebook;
1818
private static string firstSectionID;
1919

20-
[ClassInitialize]
21-
public static void GetTestSectionId(TestContext c)
22-
{
20+
public OneNoteTests() : base() {
2321
// Get a page of OneNote sections.
2422
IOnenoteSectionsCollectionPage sectionPage = graphClient.Me
2523
.Onenote
@@ -31,7 +29,7 @@ public static void GetTestSectionId(TestContext c)
3129
// Get a handle to the first section.
3230
firstSectionID = sectionPage[0].Id;
3331
}
34-
32+
3533
public async void TestPageCleanUp()
3634
{
3735
await graphClient.Me.Onenote.Pages[testPage.Id].Request().DeleteAsync();
@@ -731,5 +729,26 @@ public async Async.Task OneNoteAddPageWithMultipart()
731729
Assert.Fail("Error code: {0}", e.Message);
732730
}
733731
}
732+
733+
/// <summary>
734+
/// Test the custom 'Root' partial request builder and accessing Onenote notebook collection.
735+
/// </summary>
736+
/// <returns></returns>
737+
[TestMethod]
738+
public async Async.Task It_accesses_a_sites_OneNote_notebooks()
739+
{
740+
try
741+
{
742+
Site site = await graphClient.Sites.Root.Request().GetAsync();
743+
Assert.IsNotNull(site);
744+
745+
IOnenoteNotebooksCollectionPage notebooks = await graphClient.Sites[site.Id].Onenote.Notebooks.Request().GetAsync();
746+
Assert.IsNotNull(notebooks);
747+
}
748+
catch (Exception)
749+
{
750+
Assert.Fail("An unexpected exception was thrown. This test case failed.");
751+
}
752+
}
734753
}
735754
}

tests/Microsoft.Graph.Test/Requests/Functional/SharePointTests.cs

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ namespace Microsoft.Graph.Test.Requests.Functional
88
{
99
[Ignore]
1010
[TestClass]
11-
public class SharePointTests : GraphTestBase
11+
public class Given_a_valid_SharePoint_Site : GraphTestBase
1212
{
1313
// Test search a SharePoint site.
1414
[TestMethod]
15-
public async Async.Task SharePointSearchSites()
15+
public async Async.Task It_searches_the_SharePoint_Site_and_returns_results()
1616
{
1717
try
1818
{
@@ -34,9 +34,9 @@ public async Async.Task SharePointSearchSites()
3434
}
3535
}
3636

37-
// Test accessing the default document libraries for a SharePoint site.
37+
// Test accessing the document libraries for a SharePoint site.
3838
[TestMethod]
39-
public async Async.Task SharePointGetDocumentLibraries()
39+
public async Async.Task It_gets_the_sites_drives()
4040
{
4141
try
4242
{
@@ -64,7 +64,7 @@ public async Async.Task SharePointGetDocumentLibraries()
6464

6565
// Test accessing the non-default document library on a SharePoint site.
6666
[TestMethod]
67-
public async Async.Task SharePointGetNonDefaultDocumentLibraries()
67+
public async Async.Task It_gets_the_sites_drives_root_children()
6868
{
6969
try
7070
{
@@ -110,7 +110,7 @@ public async Async.Task SharePointGetNonDefaultDocumentLibraries()
110110
///
111111
[Ignore] // Need reset test data in demo tenant
112112
[TestMethod]
113-
public async Async.Task SharePointGetSiteWithPath()
113+
public async Async.Task It_gets_a_site_by_path()
114114
{
115115
try
116116
{
@@ -156,16 +156,35 @@ public async Async.Task SharePointGetSiteWithPath()
156156
Assert.Fail("Something happened, check out a trace. Error code: {0}", e.Error.Code);
157157
}
158158
}
159-
159+
160+
/// <summary>
161+
/// Test the custom 'Root' partial request builder.
162+
/// </summary>
163+
/// <returns></returns>
164+
[TestMethod]
165+
public async Async.Task It_gets_the_root_site()
166+
{
167+
try
168+
{
169+
Site site = await graphClient.Sites.Root.Request().GetAsync();
170+
Assert.IsNotNull(site);
171+
}
172+
catch (Exception)
173+
{
174+
Assert.Fail("An unexpected exception was thrown. This test case failed.");
175+
}
176+
}
177+
160178
/// <summary>
161179
/// Test to get information about a SharePoint site by its URL.
162180
/// </summary>
163181
[TestMethod]
164-
public async Async.Task SharePointAccessSiteByUrl()
182+
public async Async.Task It_gets_a_site_by_URL()
165183
{
166184
try
167185
{
168186
Site site = await graphClient.Shares[UrlToSharingToken("https://m365x462896.sharepoint.com/sites/portals2")].Site.Request().GetAsync();
187+
169188
Assert.IsNotNull(site);
170189
}
171190
catch (Microsoft.Graph.ServiceException e)

0 commit comments

Comments
 (0)