Skip to content

Commit ba0308e

Browse files
Merge branch 'dev' into v1.0/pipelinebuild/977754
2 parents 2fa071a + 9d77596 commit ba0308e

21 files changed

+201
-215
lines changed

appveyor.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ branches:
44
- dev
55
- master
66
image: Visual Studio 2017
7+
78
before_build:
89
- cmd: >-
910
nuget restore
10-
11-
dotnet restore
1211
build:
1312
verbosity: minimal
1413

src/Microsoft.Graph.Core/Extensions/RequestExtensions.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
namespace Microsoft.Graph
66
{
77
using System.Net.Http;
8+
using System.Threading.Tasks;
9+
810
/// <summary>
911
/// Contains extension methods for <see cref="HttpRequestMessage"/>
1012
/// </summary>
@@ -26,5 +28,36 @@ internal static bool IsBuffered(this HttpRequestMessage httpRequestMessage)
2628
}
2729
return true;
2830
}
31+
32+
/// <summary>
33+
/// Create a new HTTP request by copying previous HTTP request's headers and properties from response's request message.
34+
/// </summary>
35+
/// <param name="originalRequest">The previous <see cref="HttpRequestMessage"/> needs to be copy.</param>
36+
/// <returns>The <see cref="HttpRequestMessage"/>.</returns>
37+
/// <remarks>
38+
/// Re-issue a new HTTP request with the previous request's headers and properities
39+
/// </remarks>
40+
internal static async Task<HttpRequestMessage> CloneAsync(this HttpRequestMessage originalRequest)
41+
{
42+
var newRequest = new HttpRequestMessage(originalRequest.Method, originalRequest.RequestUri);
43+
44+
foreach (var header in originalRequest.Headers)
45+
{
46+
newRequest.Headers.TryAddWithoutValidation(header.Key, header.Value);
47+
}
48+
49+
foreach (var property in originalRequest.Properties)
50+
{
51+
newRequest.Properties.Add(property);
52+
}
53+
54+
// Set Content if previous request contains
55+
if (originalRequest.Content != null && originalRequest.Content.Headers.ContentLength != 0)
56+
{
57+
newRequest.Content = new StreamContent(await originalRequest.Content.ReadAsStreamAsync());
58+
}
59+
60+
return newRequest;
61+
}
2962
}
3063
}

src/Microsoft.Graph.Core/Requests/AuthenticationHandler.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,16 @@ private async Task<HttpResponseMessage> SendRetryAsync(HttpResponseMessage httpR
6464
int retryAttempt = 0;
6565
while (retryAttempt < MaxRetry)
6666
{
67-
var originalRequest = httpResponseMessage.RequestMessage;
67+
// general clone request with internal CloneAsync (see CloneAsync for details) extension method
68+
var newRequest = await httpResponseMessage.RequestMessage.CloneAsync();
6869

6970
// Authenticate request using AuthenticationProvider
70-
await AuthenticationProvider.AuthenticateRequestAsync(originalRequest);
71-
httpResponseMessage = await base.SendAsync(originalRequest, cancellationToken);
71+
await AuthenticationProvider.AuthenticateRequestAsync(newRequest);
72+
httpResponseMessage = await base.SendAsync(newRequest, cancellationToken);
7273

7374
retryAttempt++;
7475

75-
if (!IsUnauthorized(httpResponseMessage) || !originalRequest.IsBuffered())
76+
if (!IsUnauthorized(httpResponseMessage) || !newRequest.IsBuffered())
7677
{
7778
// Re-issue the request to get a new access token
7879
return httpResponseMessage;

src/Microsoft.Graph.Core/Requests/RedirectHandler.cs

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
6565

6666
while (redirectCount < maxRedirects)
6767
{
68-
// general copy request with internal CopyRequest(see copyRequest for details) method
69-
var newRequest = await CopyRequest(response.RequestMessage);
68+
// general clone request with internal CloneAsync (see CloneAsync for details) extension method
69+
var newRequest = await response.RequestMessage.CloneAsync();
7070

7171
// status code == 303: change request method from post to get and content to be null
7272
if (response.StatusCode == HttpStatusCode.SeeOther)
@@ -107,37 +107,6 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
107107

108108
}
109109

110-
/// <summary>
111-
/// Create a new HTTP request by copying previous HTTP request's headers and properties from response's request message.
112-
/// </summary>
113-
/// <param name="originalRequest">The previous <see cref="HttpRequestMessage"/> needs to be copy.</param>
114-
/// <returns>The <see cref="HttpRequestMessage"/>.</returns>
115-
/// <remarks>
116-
/// Re-issue a new HTTP request with the previous request's headers and properities
117-
/// </remarks>
118-
internal async Task<HttpRequestMessage> CopyRequest(HttpRequestMessage originalRequest)
119-
{
120-
var newRequest = new HttpRequestMessage(originalRequest.Method, originalRequest.RequestUri);
121-
122-
foreach (var header in originalRequest.Headers)
123-
{
124-
newRequest.Headers.TryAddWithoutValidation(header.Key, header.Value);
125-
}
126-
127-
foreach (var property in originalRequest.Properties)
128-
{
129-
newRequest.Properties.Add(property);
130-
}
131-
132-
// Set Content if previous request contains
133-
if (originalRequest.Content != null && originalRequest.Content.Headers.ContentLength != 0)
134-
{
135-
newRequest.Content = new StreamContent(await originalRequest.Content.ReadAsStreamAsync());
136-
}
137-
138-
return newRequest;
139-
}
140-
141110

142111
/// <summary>
143112
/// Checks whether <see cref="HttpStatusCode"/> is redirected

src/Microsoft.Graph.Core/Requests/RetryHandler.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,15 @@ protected async override Task<HttpResponseMessage> SendAsync(HttpRequestMessage
7171
/// <returns></returns>
7272
public async Task<HttpResponseMessage> SendRetryAsync(HttpResponseMessage response, CancellationToken cancellationToken)
7373
{
74-
75-
7674
int retryCount = 0;
7775

78-
7976
while (retryCount < MaxRetry)
8077
{
81-
8278
// Call Delay method to get delay time from response's Retry-After header or by exponential backoff
8379
Task delay = Delay(response, retryCount, cancellationToken);
8480

85-
// Get the original request
86-
var request = response.RequestMessage;
81+
// general clone request with internal CloneAsync (see CloneAsync for details) extension method
82+
var request = await response.RequestMessage.CloneAsync();
8783

8884
// Increase retryCount and then update Retry-Attempt in request header
8985
retryCount++;
@@ -110,8 +106,6 @@ public async Task<HttpResponseMessage> SendRetryAsync(HttpResponseMessage respon
110106

111107
}
112108

113-
114-
115109
/// <summary>
116110
/// Check the HTTP response's status to determine whether it should be retried or not.
117111
/// </summary>
@@ -127,7 +121,6 @@ public bool IsRetry(HttpResponseMessage response)
127121
return false;
128122
}
129123

130-
131124
/// <summary>
132125
/// Update Retry-Attempt header in the HTTP request
133126
/// </summary>

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.Core.Test/Microsoft.Graph.Core.Test.csproj

Lines changed: 17 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3-
<Import Project="..\..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props')" />
4-
<Import Project="..\..\packages\Microsoft.NET.Test.Sdk.15.9.0-preview-20180816-01\build\net45\Microsoft.Net.Test.Sdk.props" Condition="Exists('..\..\packages\Microsoft.NET.Test.Sdk.15.9.0-preview-20180816-01\build\net45\Microsoft.Net.Test.Sdk.props')" />
5-
<Import Project="..\..\packages\Microsoft.CodeCoverage.15.9.0-preview-20180816-01\build\netstandard1.0\Microsoft.CodeCoverage.props" Condition="Exists('..\..\packages\Microsoft.CodeCoverage.15.9.0-preview-20180816-01\build\netstandard1.0\Microsoft.CodeCoverage.props')" />
63
<PropertyGroup>
74
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
85
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@@ -19,6 +16,8 @@
1916
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
2017
<IsCodedUITest>False</IsCodedUITest>
2118
<TestProjectType>UnitTest</TestProjectType>
19+
<NuGetPackageImportStamp>
20+
</NuGetPackageImportStamp>
2221
</PropertyGroup>
2322
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
2423
<DebugSymbols>true</DebugSymbols>
@@ -38,34 +37,10 @@
3837
<WarningLevel>4</WarningLevel>
3938
</PropertyGroup>
4039
<ItemGroup>
41-
<Reference Include="Castle.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
42-
<HintPath>..\..\packages\Castle.Core.4.2.1\lib\net45\Castle.Core.dll</HintPath>
43-
</Reference>
44-
<Reference Include="Microsoft.VisualStudio.CodeCoverage.Shim, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
45-
<HintPath>..\..\packages\Microsoft.CodeCoverage.15.9.0-preview-20180816-01\lib\net45\Microsoft.VisualStudio.CodeCoverage.Shim.dll</HintPath>
46-
</Reference>
47-
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
48-
<HintPath>..\..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
49-
</Reference>
50-
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
51-
<HintPath>..\..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
52-
</Reference>
53-
<Reference Include="Moq, Version=4.8.0.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
54-
<HintPath>..\..\packages\Moq.4.8.1\lib\net45\Moq.dll</HintPath>
55-
</Reference>
56-
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
57-
<HintPath>..\..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
58-
</Reference>
5940
<Reference Include="System" />
6041
<Reference Include="System.Configuration" />
6142
<Reference Include="System.Net.Http" />
6243
<Reference Include="System.Runtime.Serialization" />
63-
<Reference Include="System.Threading.Tasks.Extensions, Version=4.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
64-
<HintPath>..\..\packages\System.Threading.Tasks.Extensions.4.3.0\lib\portable-net45+win8+wp8+wpa81\System.Threading.Tasks.Extensions.dll</HintPath>
65-
</Reference>
66-
<Reference Include="System.ValueTuple, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
67-
<HintPath>..\..\packages\System.ValueTuple.4.3.0\lib\netstandard1.0\System.ValueTuple.dll</HintPath>
68-
</Reference>
6944
</ItemGroup>
7045
<Choose>
7146
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
@@ -127,9 +102,21 @@
127102
</ProjectReference>
128103
</ItemGroup>
129104
<ItemGroup>
130-
<None Include="packages.config">
131-
<SubType>Designer</SubType>
132-
</None>
105+
<PackageReference Include="Microsoft.CodeCoverage">
106+
<Version>15.9.0</Version>
107+
</PackageReference>
108+
<PackageReference Include="Microsoft.NET.Test.Sdk">
109+
<Version>15.9.0</Version>
110+
</PackageReference>
111+
<PackageReference Include="Moq">
112+
<Version>4.10.1</Version>
113+
</PackageReference>
114+
<PackageReference Include="MSTest.TestAdapter">
115+
<Version>1.4.0</Version>
116+
</PackageReference>
117+
<PackageReference Include="MSTest.TestFramework">
118+
<Version>1.4.0</Version>
119+
</PackageReference>
133120
</ItemGroup>
134121
<Choose>
135122
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
@@ -151,20 +138,6 @@
151138
</Choose>
152139
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
153140
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
154-
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
155-
<PropertyGroup>
156-
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
157-
</PropertyGroup>
158-
<Error Condition="!Exists('..\..\packages\Microsoft.CodeCoverage.15.9.0-preview-20180816-01\build\netstandard1.0\Microsoft.CodeCoverage.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Microsoft.CodeCoverage.15.9.0-preview-20180816-01\build\netstandard1.0\Microsoft.CodeCoverage.props'))" />
159-
<Error Condition="!Exists('..\..\packages\Microsoft.CodeCoverage.15.9.0-preview-20180816-01\build\netstandard1.0\Microsoft.CodeCoverage.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Microsoft.CodeCoverage.15.9.0-preview-20180816-01\build\netstandard1.0\Microsoft.CodeCoverage.targets'))" />
160-
<Error Condition="!Exists('..\..\packages\Microsoft.NET.Test.Sdk.15.9.0-preview-20180816-01\build\net45\Microsoft.Net.Test.Sdk.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Microsoft.NET.Test.Sdk.15.9.0-preview-20180816-01\build\net45\Microsoft.Net.Test.Sdk.props'))" />
161-
<Error Condition="!Exists('..\..\packages\Microsoft.NET.Test.Sdk.15.9.0-preview-20180816-01\build\net45\Microsoft.Net.Test.Sdk.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Microsoft.NET.Test.Sdk.15.9.0-preview-20180816-01\build\net45\Microsoft.Net.Test.Sdk.targets'))" />
162-
<Error Condition="!Exists('..\..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props'))" />
163-
<Error Condition="!Exists('..\..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets'))" />
164-
</Target>
165-
<Import Project="..\..\packages\Microsoft.CodeCoverage.15.9.0-preview-20180816-01\build\netstandard1.0\Microsoft.CodeCoverage.targets" Condition="Exists('..\..\packages\Microsoft.CodeCoverage.15.9.0-preview-20180816-01\build\netstandard1.0\Microsoft.CodeCoverage.targets')" />
166-
<Import Project="..\..\packages\Microsoft.NET.Test.Sdk.15.9.0-preview-20180816-01\build\net45\Microsoft.Net.Test.Sdk.targets" Condition="Exists('..\..\packages\Microsoft.NET.Test.Sdk.15.9.0-preview-20180816-01\build\net45\Microsoft.Net.Test.Sdk.targets')" />
167-
<Import Project="..\..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets" Condition="Exists('..\..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets')" />
168141
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
169142
Other similar extension points exist, see Microsoft.Common.targets.
170143
<Target Name="BeforeBuild">

0 commit comments

Comments
 (0)