Skip to content

Commit

Permalink
feat: add support for system.text.json
Browse files Browse the repository at this point in the history
update to .NET 6.0
  • Loading branch information
mozts2005 committed Nov 10, 2021
1 parent 487f154 commit aa82f0b
Show file tree
Hide file tree
Showing 49 changed files with 966 additions and 222 deletions.
12 changes: 11 additions & 1 deletion GitVersion.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,14 @@ commits-since-version-source-padding: 3
commit-message-incrementing: Enabled
branches:
master:
tag: alpha
tag: alpha
pull-request:
mode: ContinuousDelivery
tag: PullRequest
increment: None
prevent-increment-of-merged-branch-version: false
tag-number-pattern: '[/-](?<number>\d+)[-/]'
track-merge-target: false
regex: (pull|pull\-requests|pr|[0-9]+)[/-]
tracks-release-branches: false
is-release-branch: false
1 change: 1 addition & 0 deletions src/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,4 @@ dotnet_naming_rule.public_constant_fields_rule.severity = warning
dotnet_naming_rule.public_static_readonly_fields_rule.symbols = public_static_readonly_fields
dotnet_naming_rule.public_static_readonly_fields_rule.style = pascal_case
dotnet_naming_rule.public_static_readonly_fields_rule.severity = warning
dotnet_diagnostic.CA2000.severity=silent
25 changes: 13 additions & 12 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,25 @@
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
<Deterministic>true</Deterministic>
</PropertyGroup>

<ItemGroup Condition="$(IsTestProject) != 'true'">
<AdditionalFiles Include="$(MSBuildThisFileDirectory)stylecop.json">
<Link>stylecop.json</Link>
</AdditionalFiles>
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="16.6.13" PrivateAssets="all"/>
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.0.0" PrivateAssets="all"/>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.0-beta-20204-02" PrivateAssets="all"/>
<!--<PackageReference Include="Microsoft.CodeAnalysis." Version="3.3.1" PrivateAssets="all"/>-->
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.0.64" PrivateAssets="all"/>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.0" PrivateAssets="all"/>
<PackageReference Include="DotNetAnalyzers.DocumentationAnalyzers" Version="1.0.0-beta.59" PrivateAssets="all" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.164" PrivateAssets="all" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.354" PrivateAssets="all" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0" />
</ItemGroup>

<ItemGroup Condition="$(IsTestProject) == 'true'">
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.4" />
<PackageReference Include="nunit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0-beta.1" PrivateAssets="all"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="NUnit.Analyzers" Version="0.2.0" PrivateAssets="all"/>
<ItemGroup Condition="'$(IsTestProject)' == 'true'">
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="NUnit.Analyzers" Version="3.2.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.0.0" />
</ItemGroup>

<PropertyGroup>
Expand All @@ -47,7 +48,7 @@
CS1591: Missing XML comment for publicly visible type or member 'Type_or_Member'
VSTHRD200:Use "Async" suffix in names of methods that return an awaitable type. -->
<TestNoWarn>1701,1702,CS1591</TestNoWarn>
<NoWarn>NU5105</NoWarn>
<NoWarn>NU5105,CS0400,CS1591</NoWarn>
</PropertyGroup>

</Project>
6 changes: 3 additions & 3 deletions src/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!-- Workaround. Remove once we're on 3.1.300+
https://github.com/dotnet/sourcelink/issues/572 -->
<Project>
<PropertyGroup Condition="$(IsTestProject) != 'true'">
<!--<PropertyGroup Condition="$(IsTestProject) != 'true'">
<TargetFrameworkMonikerAssemblyAttributesPath>$([System.IO.Path]::Combine('$(IntermediateOutputPath)','$(TargetFrameworkMoniker).AssemblyAttributes$(DefaultLanguageSourceExtension)'))</TargetFrameworkMonikerAssemblyAttributesPath>
<GitVersionInformationPath>$([System.IO.Path]::Combine('$(IntermediateOutputPath)','GitVersionInformation.g$(DefaultLanguageSourceExtension)'))</GitVersionInformationPath>
</PropertyGroup>
Expand All @@ -11,7 +11,7 @@ https://github.com/dotnet/sourcelink/issues/572 -->
<EmbeddedFiles Include="$(GitVersionInformationPath)"/>
</ItemGroup>
<!-- Workaround for https://github.com/dotnet/sdk/issues/11105 -->
--><!-- Workaround for https://github.com/dotnet/sdk/issues/11105 --><!--
<ItemGroup>
<SourceRoot Include="$(NuGetPackageRoot)" />
</ItemGroup>
Expand All @@ -23,6 +23,6 @@ https://github.com/dotnet/sourcelink/issues/572 -->
<ItemGroup>
<_LocalTopLevelSourceRoot Include="@(SourceRoot)" Condition="'%(SourceRoot.NestedRoot)' == ''"/>
</ItemGroup>
</Target>
</Target>-->

</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/Speedygeek.ZendeskAPI.UnitTests/Base/ResponseSaver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage

if (!File.Exists(filePath) | FileName == DEFAULTFILENAME)
{
var content = await resp.Content.ReadAsStringAsync().ConfigureAwait(false);
var content = await resp.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
content = Regex.Replace(content, @"\s+", " ");
await File.WriteAllTextAsync(filePath, content);
await File.WriteAllTextAsync(filePath, content, cancellationToken);
}
return resp;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,21 @@ public void ApiTokenAuthApiTokenNull()
[Test]
public void ApiTokenAuthNullClient()
{
Assert.That(() => { new APITokenCredentials(Settings.AdminUserName, Settings.ApiToken).ConfigureHttpClientAsync(null).ConfigureAwait(false); },
Assert.That(() => { new APITokenCredentials(Settings.AdminUserName, Settings.ApiToken).ConfigureHttpClient(null); },
Throws.ArgumentNullException);
}

[Test]
public void OAuthTokenAuthNullClient()
{
Assert.That(() => { new OAuthAccessTokenCredentials(Settings.AdminOAuthToken).ConfigureHttpClientAsync(null).ConfigureAwait(false); },
Assert.That(() => { new OAuthAccessTokenCredentials(Settings.AdminOAuthToken).ConfigureHttpClient(null); },
Throws.ArgumentNullException);
}

[Test]
public void BasicAuthNullClient()
{
Assert.That(() => { new BasicCredentials(Settings.AdminUserName, Settings.AdminPassword).ConfigureHttpClientAsync(null).ConfigureAwait(false); },
Assert.That(() => { new BasicCredentials(Settings.AdminUserName, Settings.AdminPassword).ConfigureHttpClient(null); },
Throws.ArgumentNullException);
}

Expand All @@ -80,12 +80,12 @@ public void OAuthTokenAuthNullEndUserId()
}

[Test]
public async Task ApiTokenAuthBuildHeader()
public void ApiTokenAuthBuildHeader()
{
using var client = new HttpClient();
var cred = new APITokenCredentials(Settings.AdminUserName, Settings.ApiToken);

await cred.ConfigureHttpClientAsync(client).ConfigureAwait(false);
cred.ConfigureHttpClient(client);

var headerScheme = client.DefaultRequestHeaders.Authorization.Scheme;
var headerParameter = client.DefaultRequestHeaders.Authorization.Parameter;
Expand All @@ -95,12 +95,12 @@ public async Task ApiTokenAuthBuildHeader()
}

[Test]
public async Task BasicAuthBuildHeader()
public void BasicAuthBuildHeader()
{
using var client = new HttpClient();
var cred = new BasicCredentials(Settings.AdminUserName, Settings.AdminPassword);

await cred.ConfigureHttpClientAsync(client).ConfigureAwait(false);
cred.ConfigureHttpClient(client);

var headerScheme = client.DefaultRequestHeaders.Authorization.Scheme;
var headerParameter = client.DefaultRequestHeaders.Authorization.Parameter;
Expand All @@ -110,13 +110,13 @@ public async Task BasicAuthBuildHeader()
}

[Test]
public async Task OAuthOnBehalfOfAuthBuildHeader()
public void OAuthOnBehalfOfAuthBuildHeader()
{
using var client = new HttpClient();
var endUserId = "[email protected]";
var cred = new OAuthAccessTokenCredentials(Settings.AdminOAuthToken, endUserId);

await cred.ConfigureHttpClientAsync(client).ConfigureAwait(false);
cred.ConfigureHttpClient(client);

var headerValue = client.DefaultRequestHeaders.GetValues("X-On-Behalf-Of").FirstOrDefault();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ namespace Speedygeek.ZendeskAPI.UnitTests.Configuration
[TestFixture]
public class ServiceCollectionExtensionsTest
{

[Test]
public void BasicAuthSubDomainNull()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using Speedygeek.ZendeskAPI.Serialization;


namespace Speedygeek.ZendeskAPI.UnitTests
namespace Speedygeek.ZendeskAPI.UnitTests.Serialization
{
[TestFixture]
public class CollaboratorConverterTest
Expand All @@ -25,20 +25,20 @@ public void SetUp()
[Test]
public void ConvertMixedTypes()
{
var json = @"{ ""Ticket"": { ""id"": 1002, ""collaborators"": [ 562562562, ""[email protected]"", { ""name"": ""Someone Else"", ""email"": ""[email protected]"" } ]}}";
var json = @"{ ""id"": 1002, ""collaborators"": [ 562562562, ""[email protected]"", { ""name"": ""Someone Else"", ""email"": ""[email protected]"" } ]}";

TicketResponse resp = null;
using (var stream = new MemoryStream(Encoding.ASCII.GetBytes(json)))
Ticket resp = null;
using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(json)))
{
resp = _serializer.Deserialize<TicketResponse>(stream);
resp = _serializer.Deserialize<Ticket>(stream);
}

Assert.That(resp.Ticket, Is.Not.Null);
Assert.That(resp.Ticket.Collaborators[0].Id, Is.Not.Zero);
Assert.That(resp.Ticket.Collaborators[1].Email, Is.EqualTo("[email protected]"));
Assert.That(resp, Is.Not.Null);
Assert.That(resp.Collaborators[0].Id, Is.Not.Zero);
Assert.That(resp.Collaborators[1].Email, Is.EqualTo("[email protected]"));

Assert.That(resp.Ticket.Collaborators[2].Email, Is.EqualTo("[email protected]"));
Assert.That(resp.Ticket.Collaborators[2].Name, Is.EqualTo("Someone Else"));
Assert.That(resp.Collaborators[2].Email, Is.EqualTo("[email protected]"));
Assert.That(resp.Collaborators[2].Name, Is.EqualTo("Someone Else"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,37 @@ public void SetUp()
}


//[Test]
//public void PageNumber()
//{
// var json = @"{ ""next_page"":""https://csharpapi.zendesk.com/api/v2/tickets.json?page=3"",""previous_page"":""https://csharpapi.zendesk.com/api/v2/tickets.json?page=1"",""count"":1365}";

// TicketListResponse resp = null;
// using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(json)))
// {
// resp = _serializer.Deserialize<TicketListResponse>(stream);
// }

// Assert.That(resp.Page, Is.EqualTo(2));
//}


[Test]
public void PageNumber()
public void Meta()
{
var json = @"{ ""next_page"":""https://csharpapi.zendesk.com/api/v2/tickets.json?page=3"",""previous_page"":""https://csharpapi.zendesk.com/api/v2/tickets.json?page=1"",""count"":1365}";

var json = @"{ ""meta"": {""has_more"": true, ""after_cursor"": ""100"", ""before_cursor"": ""200"" },
""links"": {
""next"": ""https://example.zendesk.com/api/v2/tickets.json?page[size]=100&page[after]=101"",
""prev"": ""https://example.zendesk.com/api/v2/tickets.json?page[size]=100&page[before]=200""
}
}";
TicketListResponse resp = null;
using (var stream = new MemoryStream(Encoding.ASCII.GetBytes(json)))
using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(json)))
{
resp = _serializer.Deserialize<TicketListResponse>(stream);
}

Assert.That(resp.Page, Is.EqualTo(2));
Assert.That(resp.Meta.HasMore, Is.True);
}


}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp6.0</TargetFramework>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
Expand All @@ -15,10 +15,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="1.3.0" PrivateAssets="all" />
<PackageReference Include="Codecov" Version="1.10.0" PrivateAssets="all" />
<PackageReference Include="coverlet.msbuild" Version="2.9.0-preview-0001-gfa138c0e00" PrivateAssets="all"/>
<PackageReference Include="Moq" Version="4.14.1" />
<PackageReference Include="coverlet.collector" Version="3.1.0" PrivateAssets="all" />
<PackageReference Include="Codecov" Version="1.13.0" PrivateAssets="all" />
<PackageReference Include="coverlet.msbuild" Version="3.1.0" PrivateAssets="all" />
<PackageReference Include="Moq" Version="4.16.1" />
</ItemGroup>

<ItemGroup>
Expand Down
40 changes: 20 additions & 20 deletions src/Speedygeek.ZendeskAPI.UnitTests/Support/TicketTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,18 @@ public async Task TicketCreateMany()
Assert.That(resp.JobStatus.Status, Is.EqualTo(JobStatuses.Queued));
}

[Test]
public async Task TicketsByOrg()
{
BuildResponse("organizations/22560572/tickets.json?page=1&per_page=50", "organization_22560572_tickets.json");
//[Test]
//public async Task TicketsByOrg()
//{
// BuildResponse("organizations/22560572/tickets.json?page=1&per_page=50", "organization_22560572_tickets.json");

var resp = await Client.Support.Tickets.GetByOrganizationAsync(22560572, new TicketPageParams { PerPage = 50 }, TicketSideloads.None).ConfigureAwait(false);
// var resp = await Client.Support.Tickets.GetByOrganizationAsync(22560572, new TicketPageParams { PerPage = 50 }, TicketSideloads.None).ConfigureAwait(false);

Assert.That(resp.Tickets.Count, Is.EqualTo(50));
Assert.That(resp.NextPage, Is.Not.Null);
Assert.That(resp.PerPage, Is.EqualTo(50));
Assert.That(resp.TotalPages, Is.EqualTo(27));
}
// Assert.That(resp.Tickets.Count, Is.EqualTo(50));
// Assert.That(resp.NextPage, Is.Not.Null);
// Assert.That(resp.PerPage, Is.EqualTo(50));
// Assert.That(resp.TotalPages, Is.EqualTo(27));
//}

[Test]
public async Task TicketsGetAll()
Expand Down Expand Up @@ -333,22 +333,22 @@ public void TicketGetManyOver100()
Throws.ArgumentException.With.Message.EqualTo($"API will not accept a list over 100 items long{ Environment.NewLine}Parameter name: ids"));
}

[Test]
public async Task TicketNextPage()
{
BuildResponse("tickets.json", "ticketsGetAllV2.json");
var respAll = await Client.Support.Tickets.GetAllAsync().ConfigureAwait(false);
//[Test]
//public async Task TicketNextPage()
//{
// BuildResponse("tickets.json", "ticketsGetAllV2.json");
// var respAll = await Client.Support.Tickets.GetAllAsync().ConfigureAwait(false);

BuildResponse($"tickets.json?page=2", "TicketsNextPage.json", HttpMethod.Get);
var resp = await Client.Support.Tickets.GetNextPageAsync(respAll.NextPage).ConfigureAwait(false);
// BuildResponse($"tickets.json?page=2", "TicketsNextPage.json", HttpMethod.Get);
// var resp = await Client.Support.Tickets.GetPageAsync(respAll.NextPage).ConfigureAwait(false);

Assert.That(resp.Page, Is.EqualTo(2));
}
// Assert.That(resp.Page, Is.EqualTo(2));
//}

[Test]
public void TicketNextPageNull()
{
Assert.That(async () => { var resp = await Client.Support.Tickets.GetNextPageAsync(null).ConfigureAwait(false); },
Assert.That(async () => { var resp = await Client.Support.Tickets.GetPageAsync(null).ConfigureAwait(false); },
Throws.ArgumentNullException);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ public APITokenCredentials(string userName, string apiToken)
/// Configure the <see cref="HttpClient"/> authentication header
/// </summary>
/// <param name="client">to update</param>
/// <returns><see cref="Task"/> when completed</returns>
public Task ConfigureHttpClientAsync(HttpClient client)
public void ConfigureHttpClient(HttpClient client)
{
if (client is null)
{
Expand All @@ -53,7 +52,6 @@ public Task ConfigureHttpClientAsync(HttpClient client)

var auth = Convert.ToBase64String(Encoding.UTF8.GetBytes($"{_userName}/token:{_apiToken}"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", auth);
return Task.CompletedTask;
}
}
}
4 changes: 1 addition & 3 deletions src/Speedygeek.ZendeskAPI/Configuration/BasicCredentials.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ public BasicCredentials(string userName, string password)
/// Configure the <see cref="HttpClient"/> authentication header
/// </summary>
/// <param name="client">to update</param>
/// <returns><see cref="Task"/> when completed</returns>
public Task ConfigureHttpClientAsync(HttpClient client)
public void ConfigureHttpClient(HttpClient client)
{
if (client is null)
{
Expand All @@ -53,7 +52,6 @@ public Task ConfigureHttpClientAsync(HttpClient client)

var auth = Convert.ToBase64String(Encoding.UTF8.GetBytes($"{_userName}:{_password}"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", auth);
return Task.CompletedTask;
}
}
}
Loading

0 comments on commit aa82f0b

Please sign in to comment.