Skip to content

Commit 3f8082c

Browse files
authored
Update dependencies and refactor for asynchronous code (#46)
* Update dependencies and refactor for asynchronous code This commit updates the target .NET frameworks of the build and tests to .NET 8.0, and also updates various packages to newer versions. In addition, the existing synchronous code has been refactored to asynchronous, utilizing 'async' and 'await' key words to improve code performance and readability. 'TreatWarningsAsErrors' has been enabled for better code quality control. * Refactor assertion statements in test files This commit refactors the assertion statements in multiple test classes to improve clarity and readability. The adjustments involve replacing certain "Assert.True" statements with more straightforward assertions, like "Assert.NotNull" and "Assert.False", as well as revising the checking method of object counts for more precise verification. * Refactor test assertion in NotesServiceTests Changed the assertion method used in the test of NotesServiceTests. Rather than comparing the Notes count to zero, the refactored code now uses Assert.Empty to check if the Notes collection is empty, improving readability and conciseness of the code. * Update dotnet-sonarscanner version The dotnet-sonarscanner version has been updated from 5.13.1 to 6.1.0 in the _build.csproj file. This update aims to leverage new features and improvements added in the newer version of the scanner. * Update SonarQube login method Updated the login strategy from .SetLogin to .SetToken in Build.cs. This change reflects the recent requirement in SonarQube API that advises usage of tokens over login password for security reasons.
1 parent b6c7088 commit 3f8082c

18 files changed

+197
-177
lines changed

Todoist.Net.sln.DotSettings

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2+
<s:Boolean x:Key="/Default/UserDictionary/Words/=Todoist/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

build/Build.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class Build : NukeBuild
8484
s = s
8585
.SetServer("https://sonarcloud.io")
8686
.SetFramework("net5.0")
87-
.SetLogin(SonarQubeApiKey)
87+
.SetToken(SonarQubeApiKey)
8888
.SetProjectKey("todoist-net")
8989
.SetName("Todoist.Net")
9090
.SetOrganization("olsh")

build/_build.csproj

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net6.0</TargetFramework>
5+
<TargetFramework>net8.0</TargetFramework>
66
<RootNamespace></RootNamespace>
77
<NoWarn>CS0649;CS0169;CA1050;CA1822;CA2211;IDE1006</NoWarn>
88
<NukeRootDirectory>..</NukeRootDirectory>
@@ -12,8 +12,8 @@
1212
</PropertyGroup>
1313

1414
<ItemGroup>
15-
<PackageReference Include="Nuke.Common" Version="7.0.4" />
16-
<PackageDownload Include="dotnet-sonarscanner" Version="[5.13.1]" />
15+
<PackageReference Include="Nuke.Common" Version="8.0.0" />
16+
<PackageDownload Include="dotnet-sonarscanner" Version="[6.1.0]" />
1717
</ItemGroup>
1818

1919
</Project>

src/Todoist.Net.Tests/Services/ActivityServiceTests.cs

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System.Threading.Tasks;
2+
13
using Todoist.Net.Models;
24
using Todoist.Net.Tests.Extensions;
35

@@ -18,26 +20,28 @@ public ActivityServiceTests(ITestOutputHelper outputHelper)
1820
}
1921

2022
[Fact]
21-
public void GetActivity_HasEntries()
23+
public async Task TestActivityLogIsNotEmpty()
2224
{
2325
var client = TodoistClientFactory.Create(_outputHelper);
2426

25-
var logEntries = client.Activity.GetAsync(new LogFilter { Limit = 50 }).Result.Events;
27+
const int LogEntriesLimit = 50;
28+
var logFilter = new LogFilter { Limit = LogEntriesLimit };
29+
var logEntries = await client.Activity.GetAsync(logFilter);
2630

27-
Assert.NotEmpty(logEntries);
31+
Assert.NotEmpty(logEntries.Events);
2832
}
2933

3034
[Fact]
31-
public void GetActivityWithEventObjectFilter_HasEntries()
35+
public async Task GetActivityWithEventObjectFilter_HasEntries()
3236
{
3337
var client = TodoistClientFactory.Create(_outputHelper);
3438

3539
var logFilter = new LogFilter();
36-
logFilter.ObjectEventTypes.Add(new ObjectEventTypes() { ObjectType = "project" });
40+
logFilter.ObjectEventTypes.Add(new ObjectEventTypes { ObjectType = "project" });
3741

38-
var logEntries = client.Activity.GetAsync(logFilter).Result.Events;
42+
var logEntries = await client.Activity.GetAsync(logFilter);
3943

40-
Assert.NotEmpty(logEntries);
44+
Assert.NotEmpty(logEntries.Events);
4145
}
4246
}
4347
}

src/Todoist.Net.Tests/Services/BackupServiceTests.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using System.Linq;
2+
using System.Threading.Tasks;
3+
24
using Todoist.Net.Tests.Extensions;
35

46
using Xunit;
@@ -18,11 +20,11 @@ public BackupServiceTests(ITestOutputHelper outputHelper)
1820
}
1921

2022
[Fact]
21-
public void GetBackups_Success()
23+
public async Task GetBackups_Success()
2224
{
2325
var client = TodoistClientFactory.Create(_outputHelper);
2426

25-
var backups = client.Backups.GetAsync().Result;
27+
var backups = await client.Backups.GetAsync();
2628

2729
Assert.True(backups.Any());
2830
}

src/Todoist.Net.Tests/Services/EmailServiceTests.cs

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Threading.Tasks;
23

34
using Todoist.Net.Models;
45
using Todoist.Net.Tests.Extensions;
@@ -20,18 +21,20 @@ public EmailServiceTests(ITestOutputHelper outputHelper)
2021

2122
[Fact]
2223
[Trait(Constants.TraitName, Constants.IntegrationPremiumTraitValue)]
23-
public void GetOrCreateAsyncDisable_NewProject_Success()
24+
public async Task GetOrCreateAsyncDisable_NewProject_Success()
2425
{
2526
var client = TodoistClientFactory.Create(_outputHelper);
2627

27-
var projectId = client.Projects.AddAsync(new Project(Guid.NewGuid().ToString())).Result;
28-
var emailInfo = client.Emails.GetOrCreateAsync(ObjectType.Project, projectId).Result;
28+
var project = new Project(Guid.NewGuid().ToString());
29+
var projectId = await client.Projects.AddAsync(project);
30+
31+
var emailInfo = await client.Emails.GetOrCreateAsync(ObjectType.Project, projectId);
2932

3033
Assert.NotNull(emailInfo);
3134
Assert.NotNull(emailInfo.Email);
3235

33-
client.Emails.DisableAsync(ObjectType.Project, projectId).Wait();
34-
client.Projects.DeleteAsync(projectId).Wait();
36+
await client.Emails.DisableAsync(ObjectType.Project, projectId);
37+
await client.Projects.DeleteAsync(projectId);
3538
}
3639
}
3740
}

src/Todoist.Net.Tests/Services/FiltersServiceTests.cs

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Linq;
3+
using System.Threading.Tasks;
34

45
using Todoist.Net.Models;
56
using Todoist.Net.Tests.Extensions;
@@ -21,42 +22,41 @@ public FiltersServiceTests(ITestOutputHelper outputHelper)
2122
}
2223

2324
[Fact]
24-
public void GetFilterInfo_Success()
25+
public async Task GetFilterInfo_Success()
2526
{
2627
var client = TodoistClientFactory.Create(_outputHelper);
2728

28-
var filters = client.Filters.GetAsync().Result.ToList();
29+
var filters = (await client.Filters.GetAsync()).ToList();
2930

30-
Assert.True(filters.Any());
31+
Assert.True(filters.Count > 0);
3132

32-
var result = client.Filters.GetAsync(filters.First().Id).Result;
33+
var result = await client.Filters.GetAsync(filters.First().Id);
3334

34-
Assert.True(result != null);
35+
Assert.NotNull(result);
3536
}
3637

3738
[Fact]
38-
public void CreateUpdateDelete_Success()
39+
public async Task CreateUpdateDelete_Success()
3940
{
4041
var client = TodoistClientFactory.Create(_outputHelper);
4142

4243
var filter = new Filter(Guid.NewGuid().ToString(), "today");
43-
client.Filters.AddAsync(filter).Wait();
44+
await client.Filters.AddAsync(filter);
4445

45-
var filters = client.Filters.GetAsync().Result;
46+
var filters = await client.Filters.GetAsync();
4647

4748
Assert.Contains(filters, f => f.Name == filter.Name);
4849

4950
filter.Query = "test";
50-
client.Filters.UpdateAsync(filter)
51-
.Wait();
51+
await client.Filters.UpdateAsync(filter);
5252
var filterOrder = 2;
53-
client.Filters.UpdateOrderAsync(new OrderEntry(filter.Id, filterOrder)).Wait();
53+
await client.Filters.UpdateOrderAsync(new OrderEntry(filter.Id, filterOrder));
5454

55-
var filterInfo = client.Filters.GetAsync(filter.Id).Result;
55+
var filterInfo = await client.Filters.GetAsync(filter.Id);
5656
Assert.Equal(filter.Query, filterInfo.Filter.Query);
5757
Assert.Equal(filterOrder, filterInfo.Filter.ItemOrder);
5858

59-
client.Filters.DeleteAsync(filter.Id).Wait();
59+
await client.Filters.DeleteAsync(filter.Id);
6060
}
6161
}
6262
}

0 commit comments

Comments
 (0)