Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Various unit test fixes. #1997

Merged
merged 14 commits into from
Oct 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .ncrunch/GitHub.App.UnitTests.v3.ncrunchproject
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<ProjectConfiguration>
<Settings>
<CopyReferencedAssembliesToWorkspace>True</CopyReferencedAssembliesToWorkspace>
</Settings>
</ProjectConfiguration>
5 changes: 5 additions & 0 deletions .ncrunch/GitHub.Exports.UnitTests.v3.ncrunchproject
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<ProjectConfiguration>
<Settings>
<CopyReferencedAssembliesToWorkspace>True</CopyReferencedAssembliesToWorkspace>
</Settings>
</ProjectConfiguration>
2 changes: 1 addition & 1 deletion GitHubVS.v3.ncrunchsolution
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<AdditionalFilesToIncludeForSolution>
<Value>lib\**.*</Value>
</AdditionalFilesToIncludeForSolution>
<AllowParallelTestExecution>False</AllowParallelTestExecution>
<AllowParallelTestExecution>True</AllowParallelTestExecution>
<ProjectConfigStoragePathRelativeToSolutionDir>.ncrunch</ProjectConfigStoragePathRelativeToSolutionDir>
<SolutionConfigured>True</SolutionConfigured>
</Settings>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public PullRequestDetailViewModelDesigner()

Files = new PullRequestFilesViewModelDesigner();

Checks = new PullRequestCheckViewModelDesigner[0];
Checks = Array.Empty<PullRequestCheckViewModelDesigner>();
}

public PullRequestDetailModel Model { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public PullRequestUserReviewsViewModelDesigner()
{
IsExpanded = true,
HasDetails = true,
FileComments = new IPullRequestReviewFileCommentViewModel[0],
FileComments = Array.Empty<IPullRequestReviewFileCommentViewModel>(),
StateDisplay = "approved",
Model = new PullRequestReviewModel
{
Expand Down
4 changes: 2 additions & 2 deletions src/GitHub.App/Services/ModelService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ IObservable<IReadOnlyList<IRemoteRepositoryModel>> GetUserRepositories(Repositor
log.Error(e,
"Retrieving {RepositoryType} user repositories failed because user is not stored in the cache",
repositoryType);
return Observable.Return(new IRemoteRepositoryModel[] {});
return Observable.Return(Array.Empty<IRemoteRepositoryModel>());
});
}

Expand Down Expand Up @@ -355,7 +355,7 @@ IObservable<IReadOnlyList<IRemoteRepositoryModel>> GetOrganizationRepositories(s
{
log.Error(e, "Retrieveing {Organization} org repositories failed because user is not stored in the cache",
organization);
return Observable.Return(new IRemoteRepositoryModel[] {});
return Observable.Return(Array.Empty<IRemoteRepositoryModel>());
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/GitHub.App/Services/StandardUserErrors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public static IObservable<RecoveryOptionResult> ShowUserErrorThatRequiresNavigat

return exception.DisplayErrorMessage(
errorType,
new object[] { },
Array.Empty<object>(),
new[] { OpenBrowser("View Plans", account.Billing()), Cancel });
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public async Task InitializeAsync(IConnection connection)

accounts = modelService.GetAccounts()
.ObserveOn(RxApp.MainThreadScheduler)
.ToProperty(this, vm => vm.Accounts, initialValue: new ReadOnlyCollection<IAccount>(new IAccount[] { }));
.ToProperty(this, vm => vm.Accounts, initialValue: new ReadOnlyCollection<IAccount>(Array.Empty<IAccount>()));

this.WhenAny(x => x.Accounts, x => x.Value)
.Select(accts => accts?.FirstOrDefault())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static IEnumerable<IPullRequestCheckViewModel> Build(IViewViewModelFactor
pullRequestCheckViewModel.DetailsUrl = !string.IsNullOrEmpty(model.TargetUrl) ? new Uri(model.TargetUrl) : null;

return pullRequestCheckViewModel;
}) ?? new PullRequestCheckViewModel[0];
}) ?? Array.Empty<PullRequestCheckViewModel>();

var checks = pullRequest.CheckSuites?.SelectMany(model => model.CheckRuns)
.Select(model =>
Expand Down Expand Up @@ -97,7 +97,7 @@ public static IEnumerable<IPullRequestCheckViewModel> Build(IViewViewModelFactor
pullRequestCheckViewModel.DetailsUrl = new Uri(model.DetailsUrl);

return pullRequestCheckViewModel;
}) ?? new PullRequestCheckViewModel[0];
}) ?? Array.Empty<PullRequestCheckViewModel>();

return statuses.Concat(checks).OrderBy(model => model.Title);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public RepositoryPublishViewModel(
.SelectMany(async c => (await modelServiceFactory.CreateAsync(c)).GetAccounts())
.Switch()
.ObserveOn(RxApp.MainThreadScheduler)
.ToProperty(this, x => x.Accounts, initialValue: new ReadOnlyCollection<IAccount>(new IAccount[] {}));
.ToProperty(this, x => x.Accounts, initialValue: new ReadOnlyCollection<IAccount>(Array.Empty<IAccount>()));

this.WhenAny(x => x.Accounts, x => x.Value)
.WhereNotNull()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static ObservableCollection<T> CreateListenerCollection<T>(this ITracking
{
if (stickieItemsOnTop == null)
{
stickieItemsOnTop = new T[0];
stickieItemsOnTop = Array.Empty<T>();
}

var col = new ObservableCollection<T>(stickieItemsOnTop.Concat(tcol));
Expand Down
3 changes: 3 additions & 0 deletions test/GitHub.Api.UnitTests/GitHub.Api.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
<PropertyGroup>
<TargetFramework>net461</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\Helpers\GlobalSuppressions.cs" Link="GlobalSuppressions.cs" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\GitHub.Exports.Reactive\GitHub.Exports.Reactive.csproj" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Reactive;
using System.Reactive.Linq;
Expand Down Expand Up @@ -105,7 +106,7 @@ protected override string CreateViewModel(string model)

protected override async Task<Page<string>> LoadPage(string after)
{
var page = after != null ? int.Parse(after) : 0;
var page = after != null ? int.Parse(after, CultureInfo.InvariantCulture) : 0;

if (loadTrigger != null)
{
Expand All @@ -121,7 +122,7 @@ protected override async Task<Page<string>> LoadPage(string after)

return new Page<string>
{
EndCursor = (page + 1).ToString(),
EndCursor = (page + 1).ToString(CultureInfo.InvariantCulture),
HasNextPage = page < PageCount,
Items = Enumerable.Range(page * PageSize, PageSize).Select(x => "Item " + x).ToList(),
TotalCount = PageSize * PageCount,
Expand Down
1 change: 1 addition & 0 deletions test/GitHub.App.UnitTests/GitHub.App.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
</ItemGroup>

<ItemGroup>
<Compile Include="..\Helpers\GlobalSuppressions.cs" Link="GlobalSuppressions.cs" />
<Compile Include="..\Helpers\SplatModeDetectorSetUp.cs" />
<Compile Include="..\Helpers\LazySubstitute.cs" />
<Compile Include="..\Helpers\ReactiveTestHelper.cs" />
Expand Down
2 changes: 1 addition & 1 deletion test/GitHub.App.UnitTests/Models/AccountModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public static bool BitmapSourcesAreEqual(BitmapSource image1, BitmapSource image

public static byte[] BitmapSourceToBytes(BitmapSource image)
{
byte[] data = new byte[] { };
byte[] data = Array.Empty<byte>();
if (image != null)
{
try
Expand Down
11 changes: 6 additions & 5 deletions test/GitHub.App.UnitTests/Services/AvatarProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using NSubstitute;
using UnitTests.Helpers;
using NUnit.Framework;
using System.Globalization;

public class AvatarProviderTests
{
Expand All @@ -25,14 +26,14 @@ public async Task CanBeAccessedFromMultipleThreadsAsync()
sharedCache.LocalMachine.Returns(blobCache);
var imageCache = new TestImageCache();
var avatarProvider = new AvatarProvider(sharedCache, imageCache);
var expected = avatarProvider.DefaultOrgBitmapImage.ToString();
var expected = avatarProvider.DefaultOrgBitmapImage.ToString(CultureInfo.InvariantCulture);
int mainThreadId = Thread.CurrentThread.ManagedThreadId;
int otherThreadId = mainThreadId;

var actual = await Task.Run(() =>
{
otherThreadId = Thread.CurrentThread.ManagedThreadId;
return avatarProvider.DefaultOrgBitmapImage.ToString();
return avatarProvider.DefaultOrgBitmapImage.ToString(CultureInfo.InvariantCulture);
});

Assert.That(expected, Is.EqualTo(actual));
Expand All @@ -50,14 +51,14 @@ public async Task CanBeAccessedFromMultipleThreadsAsync()
sharedCache.LocalMachine.Returns(blobCache);
var imageCache = new TestImageCache();
var avatarProvider = new AvatarProvider(sharedCache, imageCache);
var expected = avatarProvider.DefaultUserBitmapImage.ToString();
var expected = avatarProvider.DefaultUserBitmapImage.ToString(CultureInfo.InvariantCulture);
int mainThreadId = Thread.CurrentThread.ManagedThreadId;
int otherThreadId = mainThreadId;

var actual = await Task.Run(() =>
{
otherThreadId = Thread.CurrentThread.ManagedThreadId;
return avatarProvider.DefaultUserBitmapImage.ToString();
return avatarProvider.DefaultUserBitmapImage.ToString(CultureInfo.InvariantCulture);
});

Assert.That(expected, Is.EqualTo(actual));
Expand Down Expand Up @@ -130,7 +131,7 @@ public class TheInvalidateAvatarMethod : TestBaseClass
public void DoesNotThrowOnNullUserOrAvatarUrl()
{
var blobStore = Substitute.For<IBlobCache>();
blobStore.Invalidate(null).Returns(_ => { throw new ArgumentNullException(); });
blobStore.Invalidate(null).Returns(_ => { throw new ArgumentNullException("key"); });
var sharedCache = Substitute.For<ISharedCache>();
sharedCache.LocalMachine.Returns(blobStore);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ static IVSGitExt CreateGitExt()

static void SetActiveRepository(IVSGitExt gitExt, ILocalRepositoryModel repo)
{
var repos = repo != null ? new[] { repo } : new ILocalRepositoryModel[0];
var repos = repo != null ? new[] { repo } : Array.Empty<ILocalRepositoryModel>();
gitExt.ActiveRepositories.Returns(repos);
gitExt.ActiveRepositoriesChanged += Raise.Event<Action>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,15 @@ public async Task Switching_To_EnterprisePage_Loads_It()
}

[Test]
public async Task Path_Is_Initialized()
public void Path_Is_Initialized()
{
var target = CreateTarget();

Assert.That(target.Path, Is.EqualTo(defaultPath));
}

[Test]
public async Task Owner_And_Repository_Name_Is_Appended_To_Base_Path()
public void Owner_And_Repository_Name_Is_Appended_To_Base_Path()
{
var owner = "owner";
var repo = "repo";
Expand All @@ -169,7 +169,7 @@ public async Task Owner_And_Repository_Name_Is_Appended_To_Base_Path()
}

[Test]
public async Task PathWarning_Is_Not_Set_When_No_Repository_Selected()
public void PathWarning_Is_Not_Set_When_No_Repository_Selected()
{
var target = CreateTarget();

Expand All @@ -179,7 +179,7 @@ public async Task PathWarning_Is_Not_Set_When_No_Repository_Selected()
}

[Test]
public async Task PathWarning_Is_Set_For_Existing_File_At_Destination()
public void PathWarning_Is_Set_For_Existing_File_At_Destination()
{
var target = CreateTarget();
SetRepository(target.GitHubTab, CreateRepositoryModel("owner", "repo"));
Expand All @@ -189,7 +189,7 @@ public async Task PathWarning_Is_Set_For_Existing_File_At_Destination()
}

[Test]
public async Task PathWarning_Is_Set_For_Existing_Clone_At_Destination()
public void PathWarning_Is_Set_For_Existing_Clone_At_Destination()
{
var owner = "owner";
var repo = "repo";
Expand All @@ -203,7 +203,7 @@ public async Task PathWarning_Is_Set_For_Existing_Clone_At_Destination()
}

[Test]
public async Task PathWarning_Is_Set_For_Repository_With_No_Origin()
public void PathWarning_Is_Set_For_Repository_With_No_Origin()
{
var owner = "owner";
var repo = "repo";
Expand All @@ -216,7 +216,7 @@ public async Task PathWarning_Is_Set_For_Repository_With_No_Origin()
}

[Test]
public async Task PathWarning_Is_Set_For_Directory_With_No_Repository()
public void PathWarning_Is_Set_For_Directory_With_No_Repository()
{
var owner = "owner";
var repo = "repo";
Expand All @@ -229,7 +229,7 @@ public async Task PathWarning_Is_Set_For_Directory_With_No_Repository()
}

[Test]
public async Task PathWarning_Is_Set_For_Existing_Repository_At_Destination_With_Different_Remote()
public void PathWarning_Is_Set_For_Existing_Repository_At_Destination_With_Different_Remote()
{
var originalOwner = "original_Owner";
var forkedOwner = "forked_owner";
Expand All @@ -246,7 +246,7 @@ public async Task PathWarning_Is_Set_For_Existing_Repository_At_Destination_With
}

[Test]
public async Task Repository_Name_Replaces_Last_Part_Of_Non_Base_Path()
public void Repository_Name_Replaces_Last_Part_Of_Non_Base_Path()
{
var target = CreateTarget();

Expand Down Expand Up @@ -281,7 +281,7 @@ public async Task Repository_Name_Replaces_Last_Part_Of_Non_Base_Path()
Description = "Owner deleted")]
[TestCase("c:\\base", "same/same", "c:\\base\\same\\same", "owner2/repo2", "c:\\base\\owner2\\repo2",
Description = "Owner and repo have same name")]
public async Task User_Edits_Path(string defaultClonePath, string repo1, string userPath, string repo2, string expectPath)
public void User_Edits_Path(string defaultClonePath, string repo1, string userPath, string repo2, string expectPath)
{
var target = CreateTarget(defaultClonePath: defaultClonePath);
SetRepository(target.GitHubTab, CreateRepositoryModel(repo1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void SignalsCloseWhenContentRaisesClosed()
public class TheStartWithConnectionMethod
{
[Test]
public async Task ShowsLoginDialogWhenNoConnectionsAvailableAsync()
public void ShowsLoginDialogWhenNoConnectionsAvailableAsync()
{
var target = CreateTarget();
var content = Substitute.For<ITestViewModel>();
Expand Down
Loading