Add Net 6.0 to our test matrix (#2391)

* net6

* fix

* remove net6.0 specific settings

* remove net6

* merge conflicts

* code review comments

* merge conflicts

* update

* remove references to obsolete class: WebRequest

* add net6 to linux builds

* fix for net6

* test fix for linux build

* include pre-release
This commit is contained in:
Timothy Mothra 2021-09-21 14:53:27 -07:00 коммит произвёл GitHub
Родитель 72d817aaea
Коммит 1c9ef10d91
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
9 изменённых файлов: 36 добавлений и 225 удалений

Просмотреть файл

@ -20,7 +20,7 @@
- net5.0 (EoL Feb 2022)
- net6.0 (GA Nov 2021)
-->
<TargetFrameworks>net462;net472;net480;netcoreapp3.1;net5.0</TargetFrameworks>
<TargetFrameworks>net462;net472;net480;netcoreapp3.1;net5.0;net6.0</TargetFrameworks>
<TargetFrameworks Condition="$(OS) != 'Windows_NT'">netcoreapp3.1;net5.0</TargetFrameworks>
</PropertyGroup>

Просмотреть файл

@ -21,6 +21,12 @@ steps:
inputs:
version: '5.0.x'
- task: UseDotNet@2
displayName: install dotnet 6
inputs:
version: 6.0.x
includePreviewVersions: true
- task: DotNetCoreCLI@2
displayName: DotNetCoreCLI - Restore Solution
inputs:

Просмотреть файл

@ -6,7 +6,7 @@
[TestClass]
public class WebEventSourceTest
{
#if !NET5_0 // TODO: WHY DOES THIS NOT WORK?
#if !NET5_0_OR_GREATER // TODO: WHY DOES THIS NOT WORK?
[TestMethod]
public void MethodsAreImplementedConsistentlyWithTheirAttributes()
{

Просмотреть файл

@ -1,95 +0,0 @@
namespace Microsoft.ApplicationInsights.TestFramework
{
using System;
using System.IO;
using System.Net;
using System.Threading.Tasks;
internal class StubWebRequest : WebRequest
{
public Func<string> OnGetContentType;
public Action<string> OnSetContentType;
public Func<WebHeaderCollection> OnGetHeaders;
public Action<WebHeaderCollection> OnSetHeaders;
public Func<string> OnGetMethod;
public Action<string> OnSetMethod;
public Func<Uri> OnGetRequestUri;
public Action OnAbort;
public Func<AsyncCallback, object, IAsyncResult> OnBeginGetRequestStream;
public Func<IAsyncResult, Stream> OnEndGetRequestStream;
public Func<AsyncCallback, object, IAsyncResult> OnBeginGetResponse;
public Func<IAsyncResult, WebResponse> OnEndGetResponse;
private string contentType;
private WebHeaderCollection headers;
private string method;
private StubStream requestStream;
private WebResponse response;
public StubWebRequest()
{
this.OnGetContentType = () => this.contentType;
this.OnSetContentType = value => this.contentType = value;
this.OnGetHeaders = () => this.headers = new WebHeaderCollection();
this.OnSetHeaders = value => this.headers = value;
this.OnGetMethod = () => this.method;
this.OnSetMethod = value => this.method = value;
this.OnGetRequestUri = () => default(Uri);
this.OnAbort = () => { };
this.OnBeginGetRequestStream = (callback, state) => Task.FromResult<object>(null).AsAsyncResult(callback, this);
this.OnEndGetRequestStream = asyncResult => this.requestStream = new StubStream();
this.OnBeginGetResponse = (callback, state) => Task.FromResult<object>(null).AsAsyncResult(callback, this);
this.OnEndGetResponse = asyncResult => this.response = new StubWebResponse();
}
public override string ContentType
{
get { return this.OnGetContentType(); }
set { this.OnSetContentType(value); }
}
public override WebHeaderCollection Headers
{
get { return this.OnGetHeaders(); }
set { this.OnSetHeaders(value); }
}
public override string Method
{
get { return this.OnGetMethod(); }
set { this.OnSetMethod(value); }
}
public override Uri RequestUri
{
get { return this.OnGetRequestUri(); }
}
public override void Abort()
{
this.OnAbort();
}
public override IAsyncResult BeginGetRequestStream(AsyncCallback callback, object state)
{
return this.OnBeginGetRequestStream(callback, state);
}
public override Stream EndGetRequestStream(IAsyncResult asyncResult)
{
return this.OnEndGetRequestStream(asyncResult);
}
public override IAsyncResult BeginGetResponse(AsyncCallback callback, object state)
{
return this.OnBeginGetResponse(callback, state);
}
public override WebResponse EndGetResponse(IAsyncResult asyncResult)
{
return this.OnEndGetResponse(asyncResult);
}
}
}

Просмотреть файл

@ -26,7 +26,6 @@
<Compile Include="$(MSBuildThisFileDirectory)StubDebugOutput.cs" />
<Compile Include="$(MSBuildThisFileDirectory)StubTelemetryProcessor.cs" />
<Compile Include="$(MSBuildThisFileDirectory)StubTelemetryInitializer.cs" />
<Compile Include="$(MSBuildThisFileDirectory)StubWebRequest.cs" />
<Compile Include="$(MSBuildThisFileDirectory)StubWebResponse.cs" />
<Compile Include="$(MSBuildThisFileDirectory)StubPlatform.cs" />
<Compile Include="$(MSBuildThisFileDirectory)StubStream.cs" />

Просмотреть файл

@ -79,11 +79,11 @@
<PropertyGroup>
<!-- https://docs.microsoft.com/dotnet/csharp/language-reference/configure-language-version -->
<LangVersion>latest</LangVersion>
<LangVersion>preview</LangVersion>
<IsNetFramework Condition="'$(TargetFramework)' == 'net452' Or '$(TargetFramework)' == 'net46' Or '$(TargetFramework)' == 'net461' Or '$(TargetFramework)' == 'net462' Or '$(TargetFramework)' == 'net472' Or '$(TargetFramework)' == 'net480' ">True</IsNetFramework>
<IsNetCore Condition="'$(TargetFramework)' == 'netcoreapp3.1' Or '$(TargetFramework)' == 'net5.0'">True</IsNetCore>
<IsNetStandard20 Condition="'$(TargetFramework)' == 'net461' Or '$(TargetFramework)' == 'net462' Or '$(TargetFramework)' == 'net472' Or '$(TargetFramework)' == 'net480' Or '$(TargetFramework)' == 'netcoreapp3.1' Or '$(TargetFramework)' == 'net5.0'">True</IsNetStandard20>
<IsNetCore Condition="'$(TargetFramework)' == 'netcoreapp3.1' Or '$(TargetFramework)' == 'net5.0' Or '$(TargetFramework)' == 'net6.0'">True</IsNetCore>
<IsNetStandard20 Condition="'$(TargetFramework)' == 'net461' Or '$(TargetFramework)' == 'net462' Or '$(TargetFramework)' == 'net472' Or '$(TargetFramework)' == 'net480' Or '$(TargetFramework)' == 'netcoreapp3.1' Or '$(TargetFramework)' == 'net5.0' Or '$(TargetFramework)' == 'net6.0'">True</IsNetStandard20>
</PropertyGroup>

Просмотреть файл

@ -28,6 +28,12 @@ steps:
inputs:
version: 5.0.x
- task: UseDotNet@2
displayName: install dotnet 6
inputs:
version: 6.0.x
includePreviewVersions: true
- task: DotNetCoreCLI@2
displayName: DotNetCoreCLI - Restore Solution
inputs:

Просмотреть файл

@ -1,104 +0,0 @@
namespace Microsoft.ApplicationInsights.Tests
{
using System;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading;
internal class HttpWebRequestUtils : IDisposable
{
private ManualResetEvent allDone = new ManualResetEvent(false);
public void Dispose()
{
if (this.allDone != null)
{
this.allDone.Dispose();
}
}
internal void ExecuteAsyncHttpRequest(string url, HttpMethod httpMethod)
{
// Create a new HttpWebRequest object.
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.ContentType = "application/x-www-form-urlencoded";
request.Method = httpMethod.Method;
if (httpMethod == HttpMethod.Post)
{
// start the asynchronous operation
request.BeginGetRequestStream(new AsyncCallback(this.GetRequestStreamCallback), request);
}
else
{
// Start the asynchronous operation to get the response
request.BeginGetResponse(this.GetResponseCallback, request);
}
// Keep the main thread from continuing while the asynchronous
// operation completes. A real world application
// could do something useful such as updating its user interface.
this.allDone.WaitOne();
}
private void GetRequestStreamCallback(IAsyncResult asynchronousResult)
{
try
{
HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;
// End the operation
using (Stream postStream = request.EndGetRequestStream(asynchronousResult))
{
string postData = "Please enter the input data to be posted:";
// Convert the string into a byte array.
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
// Write to the request stream.
postStream.Write(byteArray, 0, postData.Length);
}
// Start the asynchronous operation to get the response
request.BeginGetResponse(this.GetResponseCallback, request);
}
catch (Exception)
{
// swallowing to not break up the debugging thread
// set the state to signaled as we don't process further
this.allDone.Set();
}
}
private void GetResponseCallback(IAsyncResult asynchronousResult)
{
try
{
HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;
// End the operation
using (HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asynchronousResult))
{
Stream streamResponse = response.GetResponseStream();
using (StreamReader streamRead = new StreamReader(streamResponse))
{
string responseString = streamRead.ReadToEnd();
}
}
}
catch (Exception)
{
// swallowing to not break up the debugging thread
}
finally
{
this.allDone.Set();
}
}
}
}

Просмотреть файл

@ -14,14 +14,13 @@
{
private Tuple<DependencyTelemetry, bool> telemetryTuple;
private ObjectInstanceBasedOperationHolder<DependencyTelemetry> objectInstanceBasedOperationHolder;
private WebRequest webRequest;
private Object obj = new object();
[TestInitialize]
public void TestInitialize()
{
this.telemetryTuple = new Tuple<DependencyTelemetry, bool>(new DependencyTelemetry(), true);
this.objectInstanceBasedOperationHolder = new ObjectInstanceBasedOperationHolder<DependencyTelemetry>();
this.webRequest = WebRequest.Create(new Uri("http://bing.com"));
}
/// <summary>
@ -40,9 +39,9 @@
[TestMethod]
public void StoreAddsTelemetryTupleToTheObjectInstance()
{
Assert.IsNull(this.objectInstanceBasedOperationHolder.Get(this.webRequest));
this.objectInstanceBasedOperationHolder.Store(this.webRequest, this.telemetryTuple);
Assert.AreEqual(this.telemetryTuple, this.objectInstanceBasedOperationHolder.Get(this.webRequest));
Assert.IsNull(this.objectInstanceBasedOperationHolder.Get(this.obj));
this.objectInstanceBasedOperationHolder.Store(this.obj, this.telemetryTuple);
Assert.AreEqual(this.telemetryTuple, this.objectInstanceBasedOperationHolder.Get(this.obj));
}
/// <summary>
@ -52,10 +51,10 @@
[ExpectedException(typeof(ArgumentException))]
public void StoreThrowsExceptionWhenAddingAlreadyExistingKey()
{
Assert.IsNull(this.objectInstanceBasedOperationHolder.Get(this.webRequest));
Assert.IsNull(this.objectInstanceBasedOperationHolder.Get(this.obj));
var tuple = new Tuple<DependencyTelemetry, bool>(new DependencyTelemetry(), true);
this.objectInstanceBasedOperationHolder.Store(this.webRequest, tuple);
this.objectInstanceBasedOperationHolder.Store(this.webRequest, this.telemetryTuple);
this.objectInstanceBasedOperationHolder.Store(this.obj, tuple);
this.objectInstanceBasedOperationHolder.Store(this.obj, this.telemetryTuple);
}
/// <summary>
@ -65,7 +64,7 @@
[ExpectedException(typeof(ArgumentNullException))]
public void StoreThrowsExceptionForNullTelemetryTupleInObjectInstance()
{
this.objectInstanceBasedOperationHolder.Store(this.webRequest, null);
this.objectInstanceBasedOperationHolder.Store(this.obj, null);
}
/// <summary>
@ -84,10 +83,10 @@
[TestMethod]
public void RemoveDeletesTelemetryTupleFromTheObjectInstance()
{
this.objectInstanceBasedOperationHolder.Store(this.webRequest, this.telemetryTuple);
Assert.AreEqual(this.telemetryTuple, this.objectInstanceBasedOperationHolder.Get(this.webRequest));
this.objectInstanceBasedOperationHolder.Remove(this.webRequest);
Assert.IsNull(this.objectInstanceBasedOperationHolder.Get(this.webRequest));
this.objectInstanceBasedOperationHolder.Store(this.obj, this.telemetryTuple);
Assert.AreEqual(this.telemetryTuple, this.objectInstanceBasedOperationHolder.Get(this.obj));
this.objectInstanceBasedOperationHolder.Remove(this.obj);
Assert.IsNull(this.objectInstanceBasedOperationHolder.Get(this.obj));
}
/// <summary>
@ -96,10 +95,10 @@
[TestMethod]
public void RemoveDoesNotThrowExceptionForNonExistingItemFromTheObjectInstance()
{
this.objectInstanceBasedOperationHolder.Store(this.webRequest, this.telemetryTuple);
Assert.IsTrue(this.objectInstanceBasedOperationHolder.Remove(this.webRequest));
Assert.IsFalse(this.objectInstanceBasedOperationHolder.Remove(this.webRequest));
Assert.IsFalse(this.objectInstanceBasedOperationHolder.Remove(this.webRequest));
this.objectInstanceBasedOperationHolder.Store(this.obj, this.telemetryTuple);
Assert.IsTrue(this.objectInstanceBasedOperationHolder.Remove(this.obj));
Assert.IsFalse(this.objectInstanceBasedOperationHolder.Remove(this.obj));
Assert.IsFalse(this.objectInstanceBasedOperationHolder.Remove(this.obj));
}
/// <summary>
@ -108,8 +107,8 @@
[TestMethod]
public void GetReturnsItemIfItExistsInTheObjectInstanceTable()
{
this.objectInstanceBasedOperationHolder.Store(this.webRequest, this.telemetryTuple);
Assert.AreEqual(this.telemetryTuple, this.objectInstanceBasedOperationHolder.Get(this.webRequest));
this.objectInstanceBasedOperationHolder.Store(this.obj, this.telemetryTuple);
Assert.AreEqual(this.telemetryTuple, this.objectInstanceBasedOperationHolder.Get(this.obj));
}
/// <summary>
@ -118,7 +117,7 @@
[TestMethod]
public void GetReturnsNullIfIdDoesNotExistInObjectInstance()
{
Assert.IsNull(this.objectInstanceBasedOperationHolder.Get(this.webRequest));
Assert.IsNull(this.objectInstanceBasedOperationHolder.Get(this.obj));
}
/// <summary>