diff --git a/.ncrunch/GitHub.App.UnitTests.v3.ncrunchproject b/.ncrunch/GitHub.App.UnitTests.v3.ncrunchproject new file mode 100644 index 0000000000..7b5b2139ff --- /dev/null +++ b/.ncrunch/GitHub.App.UnitTests.v3.ncrunchproject @@ -0,0 +1,5 @@ + + + True + + \ No newline at end of file diff --git a/.ncrunch/GitHub.Exports.UnitTests.v3.ncrunchproject b/.ncrunch/GitHub.Exports.UnitTests.v3.ncrunchproject new file mode 100644 index 0000000000..7b5b2139ff --- /dev/null +++ b/.ncrunch/GitHub.Exports.UnitTests.v3.ncrunchproject @@ -0,0 +1,5 @@ + + + True + + \ No newline at end of file diff --git a/GitHubVS.v3.ncrunchsolution b/GitHubVS.v3.ncrunchsolution index 2cd8e79788..531ec12867 100644 --- a/GitHubVS.v3.ncrunchsolution +++ b/GitHubVS.v3.ncrunchsolution @@ -7,7 +7,7 @@ lib\**.* - False + True .ncrunch True diff --git a/src/GitHub.App/SampleData/PullRequestDetailViewModelDesigner.cs b/src/GitHub.App/SampleData/PullRequestDetailViewModelDesigner.cs index 3bdd89bd09..6d8310a773 100644 --- a/src/GitHub.App/SampleData/PullRequestDetailViewModelDesigner.cs +++ b/src/GitHub.App/SampleData/PullRequestDetailViewModelDesigner.cs @@ -96,7 +96,7 @@ public PullRequestDetailViewModelDesigner() Files = new PullRequestFilesViewModelDesigner(); - Checks = new PullRequestCheckViewModelDesigner[0]; + Checks = Array.Empty(); } public PullRequestDetailModel Model { get; } diff --git a/src/GitHub.App/SampleData/PullRequestUserReviewsViewModelDesigner.cs b/src/GitHub.App/SampleData/PullRequestUserReviewsViewModelDesigner.cs index 1ad17701c1..0575871e59 100644 --- a/src/GitHub.App/SampleData/PullRequestUserReviewsViewModelDesigner.cs +++ b/src/GitHub.App/SampleData/PullRequestUserReviewsViewModelDesigner.cs @@ -27,7 +27,7 @@ public PullRequestUserReviewsViewModelDesigner() { IsExpanded = true, HasDetails = true, - FileComments = new IPullRequestReviewFileCommentViewModel[0], + FileComments = Array.Empty(), StateDisplay = "approved", Model = new PullRequestReviewModel { diff --git a/src/GitHub.App/Services/ModelService.cs b/src/GitHub.App/Services/ModelService.cs index 3c165df248..e35169d29c 100644 --- a/src/GitHub.App/Services/ModelService.cs +++ b/src/GitHub.App/Services/ModelService.cs @@ -320,7 +320,7 @@ IObservable> 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()); }); } @@ -355,7 +355,7 @@ IObservable> 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()); }); } diff --git a/src/GitHub.App/Services/StandardUserErrors.cs b/src/GitHub.App/Services/StandardUserErrors.cs index 2b3a3a6e24..40bfff09e9 100644 --- a/src/GitHub.App/Services/StandardUserErrors.cs +++ b/src/GitHub.App/Services/StandardUserErrors.cs @@ -189,7 +189,7 @@ public static IObservable ShowUserErrorThatRequiresNavigat return exception.DisplayErrorMessage( errorType, - new object[] { }, + Array.Empty(), new[] { OpenBrowser("View Plans", account.Billing()), Cancel }); } diff --git a/src/GitHub.App/ViewModels/Dialog/RepositoryCreationViewModel.cs b/src/GitHub.App/ViewModels/Dialog/RepositoryCreationViewModel.cs index 63a477fb4c..88fc6a8bb0 100644 --- a/src/GitHub.App/ViewModels/Dialog/RepositoryCreationViewModel.cs +++ b/src/GitHub.App/ViewModels/Dialog/RepositoryCreationViewModel.cs @@ -182,7 +182,7 @@ public async Task InitializeAsync(IConnection connection) accounts = modelService.GetAccounts() .ObserveOn(RxApp.MainThreadScheduler) - .ToProperty(this, vm => vm.Accounts, initialValue: new ReadOnlyCollection(new IAccount[] { })); + .ToProperty(this, vm => vm.Accounts, initialValue: new ReadOnlyCollection(Array.Empty())); this.WhenAny(x => x.Accounts, x => x.Value) .Select(accts => accts?.FirstOrDefault()) diff --git a/src/GitHub.App/ViewModels/GitHubPane/PullRequestCheckViewModel.cs b/src/GitHub.App/ViewModels/GitHubPane/PullRequestCheckViewModel.cs index 2264dec1c5..f95bd95fd1 100644 --- a/src/GitHub.App/ViewModels/GitHubPane/PullRequestCheckViewModel.cs +++ b/src/GitHub.App/ViewModels/GitHubPane/PullRequestCheckViewModel.cs @@ -51,7 +51,7 @@ public static IEnumerable Build(IViewViewModelFactor pullRequestCheckViewModel.DetailsUrl = !string.IsNullOrEmpty(model.TargetUrl) ? new Uri(model.TargetUrl) : null; return pullRequestCheckViewModel; - }) ?? new PullRequestCheckViewModel[0]; + }) ?? Array.Empty(); var checks = pullRequest.CheckSuites?.SelectMany(model => model.CheckRuns) .Select(model => @@ -97,7 +97,7 @@ public static IEnumerable Build(IViewViewModelFactor pullRequestCheckViewModel.DetailsUrl = new Uri(model.DetailsUrl); return pullRequestCheckViewModel; - }) ?? new PullRequestCheckViewModel[0]; + }) ?? Array.Empty(); return statuses.Concat(checks).OrderBy(model => model.Title); } diff --git a/src/GitHub.App/ViewModels/TeamExplorer/RepositoryPublishViewModel.cs b/src/GitHub.App/ViewModels/TeamExplorer/RepositoryPublishViewModel.cs index be7d493871..276cbeec1f 100644 --- a/src/GitHub.App/ViewModels/TeamExplorer/RepositoryPublishViewModel.cs +++ b/src/GitHub.App/ViewModels/TeamExplorer/RepositoryPublishViewModel.cs @@ -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(new IAccount[] {})); + .ToProperty(this, x => x.Accounts, initialValue: new ReadOnlyCollection(Array.Empty())); this.WhenAny(x => x.Accounts, x => x.Value) .WhereNotNull() diff --git a/src/GitHub.Exports.Reactive/Collections/TrackingCollection.cs b/src/GitHub.Exports.Reactive/Collections/TrackingCollection.cs index fc557d1a44..0c724bf9f0 100644 --- a/src/GitHub.Exports.Reactive/Collections/TrackingCollection.cs +++ b/src/GitHub.Exports.Reactive/Collections/TrackingCollection.cs @@ -52,7 +52,7 @@ public static ObservableCollection CreateListenerCollection(this ITracking { if (stickieItemsOnTop == null) { - stickieItemsOnTop = new T[0]; + stickieItemsOnTop = Array.Empty(); } var col = new ObservableCollection(stickieItemsOnTop.Concat(tcol)); diff --git a/submodules/reactiveui b/submodules/reactiveui index 5f790b636d..d0ff2eb66e 160000 --- a/submodules/reactiveui +++ b/submodules/reactiveui @@ -1 +1 @@ -Subproject commit 5f790b636df62450242e650f7d7f7e41781f27d8 +Subproject commit d0ff2eb66e3eb248f536e2281d7dbf3ca5fd6d54 diff --git a/test/GitHub.Api.UnitTests/GitHub.Api.UnitTests.csproj b/test/GitHub.Api.UnitTests/GitHub.Api.UnitTests.csproj index dfc5f75e9e..ae61e41a73 100644 --- a/test/GitHub.Api.UnitTests/GitHub.Api.UnitTests.csproj +++ b/test/GitHub.Api.UnitTests/GitHub.Api.UnitTests.csproj @@ -2,6 +2,9 @@ net461 + + + diff --git a/test/GitHub.App.UnitTests/Collections/SequentialListSourceTests.cs b/test/GitHub.App.UnitTests/Collections/SequentialListSourceTests.cs index a219b76fdd..1a1f65ebeb 100644 --- a/test/GitHub.App.UnitTests/Collections/SequentialListSourceTests.cs +++ b/test/GitHub.App.UnitTests/Collections/SequentialListSourceTests.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Reactive; using System.Reactive.Linq; @@ -105,7 +106,7 @@ protected override string CreateViewModel(string model) protected override async Task> LoadPage(string after) { - var page = after != null ? int.Parse(after) : 0; + var page = after != null ? int.Parse(after, CultureInfo.InvariantCulture) : 0; if (loadTrigger != null) { @@ -121,7 +122,7 @@ protected override async Task> LoadPage(string after) return new Page { - 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, diff --git a/test/GitHub.App.UnitTests/GitHub.App.UnitTests.csproj b/test/GitHub.App.UnitTests/GitHub.App.UnitTests.csproj index 70f68614eb..bd3583743a 100644 --- a/test/GitHub.App.UnitTests/GitHub.App.UnitTests.csproj +++ b/test/GitHub.App.UnitTests/GitHub.App.UnitTests.csproj @@ -12,6 +12,7 @@ + diff --git a/test/GitHub.App.UnitTests/Models/AccountModelTests.cs b/test/GitHub.App.UnitTests/Models/AccountModelTests.cs index cbbffe7d6e..b3dcb0f5f3 100644 --- a/test/GitHub.App.UnitTests/Models/AccountModelTests.cs +++ b/test/GitHub.App.UnitTests/Models/AccountModelTests.cs @@ -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(); if (image != null) { try diff --git a/test/GitHub.App.UnitTests/Services/AvatarProviderTests.cs b/test/GitHub.App.UnitTests/Services/AvatarProviderTests.cs index ccae7a7092..d29c273589 100644 --- a/test/GitHub.App.UnitTests/Services/AvatarProviderTests.cs +++ b/test/GitHub.App.UnitTests/Services/AvatarProviderTests.cs @@ -12,6 +12,7 @@ using NSubstitute; using UnitTests.Helpers; using NUnit.Framework; +using System.Globalization; public class AvatarProviderTests { @@ -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)); @@ -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)); @@ -130,7 +131,7 @@ public class TheInvalidateAvatarMethod : TestBaseClass public void DoesNotThrowOnNullUserOrAvatarUrl() { var blobStore = Substitute.For(); - blobStore.Invalidate(null).Returns(_ => { throw new ArgumentNullException(); }); + blobStore.Invalidate(null).Returns(_ => { throw new ArgumentNullException("key"); }); var sharedCache = Substitute.For(); sharedCache.LocalMachine.Returns(blobStore); diff --git a/test/GitHub.App.UnitTests/Services/TeamExplorerContextTests.cs b/test/GitHub.App.UnitTests/Services/TeamExplorerContextTests.cs index 68b8aa63c2..f539b589e0 100644 --- a/test/GitHub.App.UnitTests/Services/TeamExplorerContextTests.cs +++ b/test/GitHub.App.UnitTests/Services/TeamExplorerContextTests.cs @@ -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(); gitExt.ActiveRepositories.Returns(repos); gitExt.ActiveRepositoriesChanged += Raise.Event(); } diff --git a/test/GitHub.App.UnitTests/ViewModels/Dialog/Clone/RepositoryCloneViewModelTests.cs b/test/GitHub.App.UnitTests/ViewModels/Dialog/Clone/RepositoryCloneViewModelTests.cs index 6fac5a6fd0..2fd7b6140c 100644 --- a/test/GitHub.App.UnitTests/ViewModels/Dialog/Clone/RepositoryCloneViewModelTests.cs +++ b/test/GitHub.App.UnitTests/ViewModels/Dialog/Clone/RepositoryCloneViewModelTests.cs @@ -148,7 +148,7 @@ public async Task Switching_To_EnterprisePage_Loads_It() } [Test] - public async Task Path_Is_Initialized() + public void Path_Is_Initialized() { var target = CreateTarget(); @@ -156,7 +156,7 @@ public async Task Path_Is_Initialized() } [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"; @@ -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(); @@ -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")); @@ -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"; @@ -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"; @@ -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"; @@ -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"; @@ -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(); @@ -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)); diff --git a/test/GitHub.App.UnitTests/ViewModels/Dialog/GitHubDialogWindowViewModelTests.cs b/test/GitHub.App.UnitTests/ViewModels/Dialog/GitHubDialogWindowViewModelTests.cs index 66763b0da2..77fc3d36a9 100644 --- a/test/GitHub.App.UnitTests/ViewModels/Dialog/GitHubDialogWindowViewModelTests.cs +++ b/test/GitHub.App.UnitTests/ViewModels/Dialog/GitHubDialogWindowViewModelTests.cs @@ -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(); diff --git a/test/GitHub.App.UnitTests/ViewModels/Dialog/LoginCredentialsViewModelTests.cs b/test/GitHub.App.UnitTests/ViewModels/Dialog/LoginCredentialsViewModelTests.cs index e51fc2aac1..2ffb951c1c 100644 --- a/test/GitHub.App.UnitTests/ViewModels/Dialog/LoginCredentialsViewModelTests.cs +++ b/test/GitHub.App.UnitTests/ViewModels/Dialog/LoginCredentialsViewModelTests.cs @@ -20,65 +20,56 @@ public class TheDoneSignal : TestBaseClass [Test] public async Task SucessfulGitHubLoginSignalsDoneAsync() { - using (TestUtils.WithScheduler(Scheduler.CurrentThread)) - { - var connectionManager = Substitute.For(); - var connection = Substitute.For(); + var connectionManager = Substitute.For(); + var connection = Substitute.For(); - var gitHubLogin = CreateLoginToHostViewModel(connection); - var enterpriseLogin = CreateLoginToHostViewModel(); - var loginViewModel = new LoginCredentialsViewModel(connectionManager, gitHubLogin, enterpriseLogin); - var signalled = false; + var gitHubLogin = CreateLoginToHostViewModel(connection); + var enterpriseLogin = CreateLoginToHostViewModel(); + var loginViewModel = new LoginCredentialsViewModel(connectionManager, gitHubLogin, enterpriseLogin); + var signalled = false; - loginViewModel.Done.Subscribe(_ => signalled = true); - await gitHubLogin.Login.Execute(); + loginViewModel.Done.Subscribe(_ => signalled = true); + await gitHubLogin.Login.Execute(); - Assert.True(signalled); - } + Assert.True(signalled); } [Test] public async Task FailedGitHubLoginDoesNotSignalDoneAsync() { - using (TestUtils.WithScheduler(Scheduler.CurrentThread)) - { - var connectionManager = Substitute.For(); + var connectionManager = Substitute.For(); - var gitHubLogin = CreateLoginToHostViewModel(); - var enterpriseLogin = CreateLoginToHostViewModel(); - var loginViewModel = new LoginCredentialsViewModel(connectionManager, gitHubLogin, enterpriseLogin); - var signalled = false; + var gitHubLogin = CreateLoginToHostViewModel(); + var enterpriseLogin = CreateLoginToHostViewModel(); + var loginViewModel = new LoginCredentialsViewModel(connectionManager, gitHubLogin, enterpriseLogin); + var signalled = false; - loginViewModel.Done.Subscribe(_ => signalled = true); - await gitHubLogin.Login.Execute(); + loginViewModel.Done.Subscribe(_ => signalled = true); + await gitHubLogin.Login.Execute(); - Assert.False(signalled); - } + Assert.False(signalled); } [Test] public async Task AllowsLoginFromEnterpriseAfterGitHubLoginHasFailedAsync() { - using (TestUtils.WithScheduler(Scheduler.CurrentThread)) - { - var connectionManager = Substitute.For(); - var connection = Substitute.For(); - - var gitHubLogin = CreateLoginToHostViewModel(); - var enterpriseLogin = CreateLoginToHostViewModel(connection); - var loginViewModel = new LoginCredentialsViewModel(connectionManager, gitHubLogin, enterpriseLogin); - var success = false; - - loginViewModel.Done - .OfType() - .Where(x => x != null) - .Subscribe(_ => success = true); - - await gitHubLogin.Login.Execute(); - await enterpriseLogin.Login.Execute(); - - Assert.True(success); - } + var connectionManager = Substitute.For(); + var connection = Substitute.For(); + + var gitHubLogin = CreateLoginToHostViewModel(); + var enterpriseLogin = CreateLoginToHostViewModel(connection); + var loginViewModel = new LoginCredentialsViewModel(connectionManager, gitHubLogin, enterpriseLogin); + var success = false; + + loginViewModel.Done + .OfType() + .Where(x => x != null) + .Subscribe(_ => success = true); + + await gitHubLogin.Login.Execute(); + await enterpriseLogin.Login.Execute(); + + Assert.True(success); } } diff --git a/test/GitHub.App.UnitTests/ViewModels/Dialog/LoginToGitHubForEnterpriseViewModelTests.cs b/test/GitHub.App.UnitTests/ViewModels/Dialog/LoginToGitHubForEnterpriseViewModelTests.cs index 82b135c358..ddbf6425cd 100644 --- a/test/GitHub.App.UnitTests/ViewModels/Dialog/LoginToGitHubForEnterpriseViewModelTests.cs +++ b/test/GitHub.App.UnitTests/ViewModels/Dialog/LoginToGitHubForEnterpriseViewModelTests.cs @@ -10,6 +10,7 @@ using NUnit.Framework; using System.Windows.Input; using ReactiveUI.Testing; +using ReactiveUI; public class LoginToGitHubForEnterpriseViewModelTests { @@ -29,80 +30,70 @@ public void InvalidUrlReturnsNone() [Test] public async Task ReturnsCheckingWhenProbeNotFinished() { - using (TestUtils.WithScheduler(Scheduler.CurrentThread)) + Console.WriteLine(RxApp.MainThreadScheduler.GetType().Name); + + var scheduler = new TestScheduler(); + var caps = Substitute.For(); + var task = new TaskCompletionSource(); + caps.Probe(null).ReturnsForAnyArgs(task.Task); + var target = CreateTarget(scheduler, caps); + + target.EnterpriseUrl = "https://foo.bar"; + scheduler.AdvanceBy(TimeSpan.FromMilliseconds(500).Ticks); + + Assert.That(EnterpriseProbeStatus.Checking, Is.EqualTo(target.ProbeStatus)); + + try { - var scheduler = new TestScheduler(); - var caps = Substitute.For(); - var task = new TaskCompletionSource(); - caps.Probe(null).ReturnsForAnyArgs(task.Task); - var target = CreateTarget(scheduler, caps); - - target.EnterpriseUrl = "https://foo.bar"; - scheduler.AdvanceBy(TimeSpan.FromMilliseconds(500).Ticks); - - Assert.That(EnterpriseProbeStatus.Checking, Is.EqualTo(target.ProbeStatus)); - - try - { - task.SetCanceled(); - await task.Task; - } - catch (TaskCanceledException) { } + task.SetCanceled(); + await task.Task; } + catch (TaskCanceledException) { } } [Test] public async Task ReturnsValidWhenProbeReturnsOk() { - using (TestUtils.WithScheduler(Scheduler.CurrentThread)) - { - var scheduler = new TestScheduler(); - var caps = CreateCapabilties(EnterpriseProbeResult.Ok); - var target = CreateTarget(scheduler, caps); + var scheduler = new TestScheduler(); + var caps = CreateCapabilties(EnterpriseProbeResult.Ok); + var target = CreateTarget(scheduler, caps); - target.EnterpriseUrl = "https://foo.bar"; - scheduler.AdvanceBy(TimeSpan.FromMilliseconds(500).Ticks); - scheduler.Stop(); - await target.UpdatingProbeStatus; + target.EnterpriseUrl = "https://foo.bar"; + scheduler.AdvanceBy(TimeSpan.FromMilliseconds(500).Ticks); + scheduler.Stop(); + await target.UpdatingProbeStatus; - Assert.That(EnterpriseProbeStatus.Valid, Is.EqualTo(target.ProbeStatus)); - } + Assert.That(EnterpriseProbeStatus.Valid, Is.EqualTo(target.ProbeStatus)); } [Test] public async Task ReturnsInvalidWhenProbeReturnsFailed() { - using (TestUtils.WithScheduler(Scheduler.CurrentThread)) - { - var scheduler = new TestScheduler(); - var caps = CreateCapabilties(EnterpriseProbeResult.Failed); - var target = CreateTarget(scheduler, caps); + var scheduler = new TestScheduler(); + var caps = CreateCapabilties(EnterpriseProbeResult.Failed); + var target = CreateTarget(scheduler, caps); - target.EnterpriseUrl = "https://foo.bar"; - scheduler.AdvanceBy(TimeSpan.FromMilliseconds(500).Ticks); - scheduler.Stop(); - await target.UpdatingProbeStatus; + target.EnterpriseUrl = "https://foo.bar"; + scheduler.AdvanceBy(TimeSpan.FromMilliseconds(500).Ticks); + scheduler.Stop(); + await target.UpdatingProbeStatus; - Assert.That(EnterpriseProbeStatus.Invalid, Is.EqualTo(target.ProbeStatus)); - } + Assert.That(EnterpriseProbeStatus.Invalid, Is.EqualTo(target.ProbeStatus)); } [Test] public async Task ReturnsInvalidWhenProbeReturnsNotFound() { - using (TestUtils.WithScheduler(Scheduler.CurrentThread)) - { - var scheduler = new TestScheduler(); - var caps = CreateCapabilties(EnterpriseProbeResult.NotFound); - var target = CreateTarget(scheduler, caps); + var scheduler = new TestScheduler(); + var caps = CreateCapabilties(EnterpriseProbeResult.NotFound); + var target = CreateTarget(scheduler, caps); - target.EnterpriseUrl = "https://foo.bar"; - scheduler.AdvanceBy(TimeSpan.FromMilliseconds(500).Ticks); - scheduler.Stop(); - await target.UpdatingProbeStatus; + target.EnterpriseUrl = "https://foo.bar"; + scheduler.AdvanceBy(TimeSpan.FromMilliseconds(500).Ticks); + scheduler.Stop(); + await target.UpdatingProbeStatus; - Assert.That(EnterpriseProbeStatus.Invalid, Is.EqualTo(target.ProbeStatus)); - } + Assert.That(EnterpriseProbeStatus.Invalid, Is.EqualTo(target.ProbeStatus)); } } @@ -122,53 +113,44 @@ public void InvalidUrlReturnsNull() [Test] public void ReturnsToken() { - using (TestUtils.WithScheduler(Scheduler.CurrentThread)) - { - var scheduler = new TestScheduler(); - var caps = CreateCapabilties(EnterpriseLoginMethods.Token); - var target = CreateTarget(scheduler, caps); + var scheduler = new TestScheduler(); + var caps = CreateCapabilties(EnterpriseLoginMethods.Token); + var target = CreateTarget(scheduler, caps); - target.EnterpriseUrl = "https://foo.bar"; - scheduler.AdvanceBy(TimeSpan.FromMilliseconds(500).Ticks); + target.EnterpriseUrl = "https://foo.bar"; + scheduler.AdvanceBy(TimeSpan.FromMilliseconds(500).Ticks); - Assert.That(EnterpriseLoginMethods.Token, Is.EqualTo(target.SupportedLoginMethods)); - } + Assert.That(EnterpriseLoginMethods.Token, Is.EqualTo(target.SupportedLoginMethods)); } [Test] public void ReturnsUsernameAndPassword() { - using (TestUtils.WithScheduler(Scheduler.CurrentThread)) - { - var scheduler = new TestScheduler(); - var caps = CreateCapabilties(EnterpriseLoginMethods.UsernameAndPassword); - var target = CreateTarget(scheduler, caps); + var scheduler = new TestScheduler(); + var caps = CreateCapabilties(EnterpriseLoginMethods.UsernameAndPassword); + var target = CreateTarget(scheduler, caps); - target.EnterpriseUrl = "https://foo.bar"; - scheduler.AdvanceBy(TimeSpan.FromMilliseconds(500).Ticks); + target.EnterpriseUrl = "https://foo.bar"; + scheduler.AdvanceBy(TimeSpan.FromMilliseconds(500).Ticks); - Assert.That(EnterpriseLoginMethods.UsernameAndPassword, Is.EqualTo(target.SupportedLoginMethods)); - } + Assert.That(EnterpriseLoginMethods.UsernameAndPassword, Is.EqualTo(target.SupportedLoginMethods)); } [Test] public void GivesPrecedenceToUsernameAndPasswordOverToken() { - using (TestUtils.WithScheduler(Scheduler.CurrentThread)) - { - var scheduler = new TestScheduler(); - var caps = CreateCapabilties(EnterpriseLoginMethods.Token | - EnterpriseLoginMethods.UsernameAndPassword | - EnterpriseLoginMethods.OAuth); - var target = CreateTarget(scheduler, caps); - - target.EnterpriseUrl = "https://foo.bar"; - scheduler.AdvanceBy(TimeSpan.FromMilliseconds(500).Ticks); - - Assert.That( - EnterpriseLoginMethods.UsernameAndPassword | EnterpriseLoginMethods.OAuth, - Is.EqualTo(target.SupportedLoginMethods)); - } + var scheduler = new TestScheduler(); + var caps = CreateCapabilties(EnterpriseLoginMethods.Token | + EnterpriseLoginMethods.UsernameAndPassword | + EnterpriseLoginMethods.OAuth); + var target = CreateTarget(scheduler, caps); + + target.EnterpriseUrl = "https://foo.bar"; + scheduler.AdvanceBy(TimeSpan.FromMilliseconds(500).Ticks); + + Assert.That( + EnterpriseLoginMethods.UsernameAndPassword | EnterpriseLoginMethods.OAuth, + Is.EqualTo(target.SupportedLoginMethods)); } } @@ -177,70 +159,58 @@ public class TheLoginCommand : TestBaseClass [Test] public void DisabledWhenUserNameEmpty() { - using (TestUtils.WithScheduler(Scheduler.CurrentThread)) - { - var scheduler = new TestScheduler(); - var caps = CreateCapabilties(EnterpriseLoginMethods.UsernameAndPassword); - var target = CreateTarget(scheduler, caps); + var scheduler = new TestScheduler(); + var caps = CreateCapabilties(EnterpriseLoginMethods.UsernameAndPassword); + var target = CreateTarget(scheduler, caps); - target.EnterpriseUrl = "https://foo.bar"; - scheduler.AdvanceBy(TimeSpan.FromMilliseconds(500).Ticks); - target.Password = "pass"; + target.EnterpriseUrl = "https://foo.bar"; + scheduler.AdvanceBy(TimeSpan.FromMilliseconds(500).Ticks); + target.Password = "pass"; - Assert.False(((ICommand)target.Login).CanExecute(null)); - } + Assert.False(((ICommand)target.Login).CanExecute(null)); } [Test] public void DisabledWhenPasswordEmpty() { - using (TestUtils.WithScheduler(Scheduler.CurrentThread)) - { - var scheduler = new TestScheduler(); - var caps = CreateCapabilties(EnterpriseLoginMethods.UsernameAndPassword); - var target = CreateTarget(scheduler, caps); + var scheduler = new TestScheduler(); + var caps = CreateCapabilties(EnterpriseLoginMethods.UsernameAndPassword); + var target = CreateTarget(scheduler, caps); - target.EnterpriseUrl = "https://foo.bar"; - scheduler.AdvanceBy(TimeSpan.FromMilliseconds(500).Ticks); - target.UsernameOrEmail = "user"; + target.EnterpriseUrl = "https://foo.bar"; + scheduler.AdvanceBy(TimeSpan.FromMilliseconds(500).Ticks); + target.UsernameOrEmail = "user"; - Assert.False(((ICommand)target.Login).CanExecute(null)); - } + Assert.False(((ICommand)target.Login).CanExecute(null)); } [Test] public void EnabledWhenUsernameAndPasswordSet() { - using (TestUtils.WithScheduler(Scheduler.CurrentThread)) - { - var scheduler = new TestScheduler(); - var caps = CreateCapabilties(EnterpriseLoginMethods.UsernameAndPassword); - var target = CreateTarget(scheduler, caps); + var scheduler = new TestScheduler(); + var caps = CreateCapabilties(EnterpriseLoginMethods.UsernameAndPassword); + var target = CreateTarget(scheduler, caps); - target.EnterpriseUrl = "https://foo.bar"; - scheduler.AdvanceBy(TimeSpan.FromMilliseconds(500).Ticks); - target.UsernameOrEmail = "user"; - target.Password = "pass"; + target.EnterpriseUrl = "https://foo.bar"; + scheduler.AdvanceBy(TimeSpan.FromMilliseconds(500).Ticks); + target.UsernameOrEmail = "user"; + target.Password = "pass"; - Assert.True(((ICommand)target.Login).CanExecute(null)); - } + Assert.True(((ICommand)target.Login).CanExecute(null)); } [Test] public void EnabledWhenOnlyPasswordSetWhenUsingTokenLogin() { - using (TestUtils.WithScheduler(Scheduler.CurrentThread)) - { - var scheduler = new TestScheduler(); - var caps = CreateCapabilties(EnterpriseLoginMethods.Token); - var target = CreateTarget(scheduler, caps); + var scheduler = new TestScheduler(); + var caps = CreateCapabilties(EnterpriseLoginMethods.Token); + var target = CreateTarget(scheduler, caps); - target.EnterpriseUrl = "https://foo.bar"; - scheduler.AdvanceBy(TimeSpan.FromMilliseconds(500).Ticks); - target.Password = "pass"; + target.EnterpriseUrl = "https://foo.bar"; + scheduler.AdvanceBy(TimeSpan.FromMilliseconds(500).Ticks); + target.Password = "pass"; - Assert.True(((ICommand)target.Login).CanExecute(null)); - } + Assert.True(((ICommand)target.Login).CanExecute(null)); } } diff --git a/test/GitHub.App.UnitTests/ViewModels/Dialog/PullRequestCreationViewModelTests.cs b/test/GitHub.App.UnitTests/ViewModels/Dialog/PullRequestCreationViewModelTests.cs index 24ef1a8b93..63408b976f 100644 --- a/test/GitHub.App.UnitTests/ViewModels/Dialog/PullRequestCreationViewModelTests.cs +++ b/test/GitHub.App.UnitTests/ViewModels/Dialog/PullRequestCreationViewModelTests.cs @@ -151,53 +151,50 @@ public async Task CreatingPRsAsync( string targetRepoOwner, string targetBranchName, string title, string body) { - using (TestUtils.WithScheduler(Scheduler.CurrentThread)) - { - var remote = "origin"; - var data = PrepareTestData(repoName, sourceRepoOwner, sourceBranchName, targetRepoOwner, targetBranchName, "origin", - repoIsFork, sourceBranchIsTracking); - - var targetRepo = data.TargetRepo; - var gitClient = data.GitClient; - var l2repo = data.L2Repo; - var activeRepo = data.ActiveRepo; - var sourceBranch = data.SourceBranch; - var targetBranch = data.TargetBranch; - var ms = data.ModelService; - - var prservice = new PullRequestService(data.GitClient, data.GitService, Substitute.For(), Substitute.For(), data.ServiceProvider.GetOperatingSystem(), Substitute.For()); - var vm = new PullRequestCreationViewModel(data.GetModelServiceFactory(), prservice, data.NotificationService); - await vm.InitializeAsync(data.ActiveRepo, data.Connection); - - // the TargetBranch property gets set to whatever the repo default is (we assume master here), - // so we only set it manually to emulate the user selecting a different target branch - if (targetBranchName != "master") - vm.TargetBranch = new BranchModel(targetBranchName, targetRepo); - - if (title != null) - vm.PRTitle = title; - - // this is optional - if (body != null) - vm.Description = body; - - ms.CreatePullRequest(activeRepo, targetRepo, sourceBranch, targetBranch, Arg.Any(), Arg.Any()) - .Returns(x => - { - var pr = Substitute.For(); - pr.Base.Returns(new GitReferenceModel("ref", "label", "sha", "https://clone.url")); - return Observable.Return(pr); - }); - - await vm.CreatePullRequest.Execute(); - - var unused2 = gitClient.Received().Push(l2repo, sourceBranchName, remote); - if (!sourceBranchIsTracking) - unused2 = gitClient.Received().SetTrackingBranch(l2repo, sourceBranchName, remote); - else - unused2 = gitClient.DidNotReceiveWithAnyArgs().SetTrackingBranch(Args.LibGit2Repo, Args.String, Args.String); - var unused = ms.Received().CreatePullRequest(activeRepo, targetRepo, sourceBranch, targetBranch, title ?? "Source branch", body ?? String.Empty); - } + var remote = "origin"; + var data = PrepareTestData(repoName, sourceRepoOwner, sourceBranchName, targetRepoOwner, targetBranchName, "origin", + repoIsFork, sourceBranchIsTracking); + + var targetRepo = data.TargetRepo; + var gitClient = data.GitClient; + var l2repo = data.L2Repo; + var activeRepo = data.ActiveRepo; + var sourceBranch = data.SourceBranch; + var targetBranch = data.TargetBranch; + var ms = data.ModelService; + + var prservice = new PullRequestService(data.GitClient, data.GitService, Substitute.For(), Substitute.For(), data.ServiceProvider.GetOperatingSystem(), Substitute.For()); + var vm = new PullRequestCreationViewModel(data.GetModelServiceFactory(), prservice, data.NotificationService); + await vm.InitializeAsync(data.ActiveRepo, data.Connection); + + // the TargetBranch property gets set to whatever the repo default is (we assume master here), + // so we only set it manually to emulate the user selecting a different target branch + if (targetBranchName != "master") + vm.TargetBranch = new BranchModel(targetBranchName, targetRepo); + + if (title != null) + vm.PRTitle = title; + + // this is optional + if (body != null) + vm.Description = body; + + ms.CreatePullRequest(activeRepo, targetRepo, sourceBranch, targetBranch, Arg.Any(), Arg.Any()) + .Returns(x => + { + var pr = Substitute.For(); + pr.Base.Returns(new GitReferenceModel("ref", "label", "sha", "https://clone.url")); + return Observable.Return(pr); + }); + + await vm.CreatePullRequest.Execute(); + + var unused2 = gitClient.Received().Push(l2repo, sourceBranchName, remote); + if (!sourceBranchIsTracking) + unused2 = gitClient.Received().SetTrackingBranch(l2repo, sourceBranchName, remote); + else + unused2 = gitClient.DidNotReceiveWithAnyArgs().SetTrackingBranch(Args.LibGit2Repo, Args.String, Args.String); + var unused = ms.Received().CreatePullRequest(activeRepo, targetRepo, sourceBranch, targetBranch, title ?? "Source branch", body ?? String.Empty); } [Test] diff --git a/test/GitHub.App.UnitTests/ViewModels/Dialog/RepositoryCreationViewModelTests.cs b/test/GitHub.App.UnitTests/ViewModels/Dialog/RepositoryCreationViewModelTests.cs index 45057acfcf..b113c3f377 100644 --- a/test/GitHub.App.UnitTests/ViewModels/Dialog/RepositoryCreationViewModelTests.cs +++ b/test/GitHub.App.UnitTests/ViewModels/Dialog/RepositoryCreationViewModelTests.cs @@ -21,8 +21,6 @@ public class RepositoryCreationViewModelTests { - static object DefaultInstance = new object(); - static IRepositoryCreationViewModel GetMeAViewModel( IServiceProvider provider = null, IRepositoryCreationService creationService = null, diff --git a/test/GitHub.App.UnitTests/ViewModels/GitHubPane/PullRequestDetailViewModelTests.cs b/test/GitHub.App.UnitTests/ViewModels/GitHubPane/PullRequestDetailViewModelTests.cs index 00f62eac71..ac24f57097 100644 --- a/test/GitHub.App.UnitTests/ViewModels/GitHubPane/PullRequestDetailViewModelTests.cs +++ b/test/GitHub.App.UnitTests/ViewModels/GitHubPane/PullRequestDetailViewModelTests.cs @@ -620,7 +620,7 @@ static PullRequestDetailModel CreatePullRequestModel( { var author = Substitute.For(); - reviews = reviews ?? new PullRequestReviewModel[0]; + reviews = reviews ?? Array.Empty(); return new PullRequestDetailModel { diff --git a/test/GitHub.App.UnitTests/ViewModels/GitHubPane/PullRequestFilesViewModelTests.cs b/test/GitHub.App.UnitTests/ViewModels/GitHubPane/PullRequestFilesViewModelTests.cs index e3a3eac1a0..c4fff09d4a 100644 --- a/test/GitHub.App.UnitTests/ViewModels/GitHubPane/PullRequestFilesViewModelTests.cs +++ b/test/GitHub.App.UnitTests/ViewModels/GitHubPane/PullRequestFilesViewModelTests.cs @@ -12,8 +12,6 @@ namespace UnitTests.GitHub.App.ViewModels.GitHubPane { public class PullRequestFilesViewModelTests { - static readonly Uri Uri = new Uri("http://foo"); - [Test] public async Task ShouldCreateChangesTreeAsync() { diff --git a/test/GitHub.App.UnitTests/ViewModels/GitHubPane/PullRequestListViewModelTests.cs b/test/GitHub.App.UnitTests/ViewModels/GitHubPane/PullRequestListViewModelTests.cs index 54e026053f..adb8654359 100644 --- a/test/GitHub.App.UnitTests/ViewModels/GitHubPane/PullRequestListViewModelTests.cs +++ b/test/GitHub.App.UnitTests/ViewModels/GitHubPane/PullRequestListViewModelTests.cs @@ -21,7 +21,7 @@ public async Task OpenItem_Navigates_To_Correct_Fork_Url() var uri = (Uri)null; target.NavigationRequested.Subscribe(x => uri = x); - target.OpenItem.Execute(target.Items[1]); + await target.OpenItem.Execute(target.Items[1]); Assert.That(uri, Is.EqualTo(new Uri("github://pane/owner/name/pull/2"))); } diff --git a/test/GitHub.App.UnitTests/ViewModels/GitHubPane/PullRequestReviewAuthoringViewModelTests.cs b/test/GitHub.App.UnitTests/ViewModels/GitHubPane/PullRequestReviewAuthoringViewModelTests.cs index ddaca66877..d09094f127 100644 --- a/test/GitHub.App.UnitTests/ViewModels/GitHubPane/PullRequestReviewAuthoringViewModelTests.cs +++ b/test/GitHub.App.UnitTests/ViewModels/GitHubPane/PullRequestReviewAuthoringViewModelTests.cs @@ -488,7 +488,7 @@ static PullRequestDetailModel CreatePullRequest( { Login = authorLogin, }, - Reviews = (reviews ?? new PullRequestReviewModel[0]).ToList() + Reviews = (reviews ?? Array.Empty()).ToList() }; } diff --git a/test/GitHub.App.UnitTests/ViewModels/GitHubPane/PullRequestReviewViewModelTests.cs b/test/GitHub.App.UnitTests/ViewModels/GitHubPane/PullRequestReviewViewModelTests.cs index 8acbafe6d8..6f70fe174c 100644 --- a/test/GitHub.App.UnitTests/ViewModels/GitHubPane/PullRequestReviewViewModelTests.cs +++ b/test/GitHub.App.UnitTests/ViewModels/GitHubPane/PullRequestReviewViewModelTests.cs @@ -60,7 +60,7 @@ public void HasDetails_False_When_Has_No_Body_Or_Comments() var review = pr.Reviews[0]; review.Body = string.Empty; - review.Comments = new PullRequestReviewCommentModel[0]; + review.Comments = Array.Empty(); var target = CreateTarget(pullRequest: pr); diff --git a/test/GitHub.App.UnitTests/ViewModels/GitHubPane/PullRequestUserReviewsViewModelTests.cs b/test/GitHub.App.UnitTests/ViewModels/GitHubPane/PullRequestUserReviewsViewModelTests.cs index 835da92d9c..061985d76d 100644 --- a/test/GitHub.App.UnitTests/ViewModels/GitHubPane/PullRequestUserReviewsViewModelTests.cs +++ b/test/GitHub.App.UnitTests/ViewModels/GitHubPane/PullRequestUserReviewsViewModelTests.cs @@ -182,7 +182,7 @@ IPullRequestSessionManager CreateSessionManager(PullRequestDetailModel pullReque { pullRequest = pullRequest ?? new PullRequestDetailModel { - Reviews = new PullRequestReviewModel[0], + Reviews = Array.Empty(), }; var session = Substitute.For(); diff --git a/test/GitHub.Exports.Reactive.UnitTests/GitHub.Exports.Reactive.UnitTests.csproj b/test/GitHub.Exports.Reactive.UnitTests/GitHub.Exports.Reactive.UnitTests.csproj index 1c87c74938..6098f4875d 100644 --- a/test/GitHub.Exports.Reactive.UnitTests/GitHub.Exports.Reactive.UnitTests.csproj +++ b/test/GitHub.Exports.Reactive.UnitTests/GitHub.Exports.Reactive.UnitTests.csproj @@ -4,6 +4,7 @@ + diff --git a/test/GitHub.Exports.UnitTests/GitHub.Exports.UnitTests.csproj b/test/GitHub.Exports.UnitTests/GitHub.Exports.UnitTests.csproj index 7afb34f2b4..4ae1485c51 100644 --- a/test/GitHub.Exports.UnitTests/GitHub.Exports.UnitTests.csproj +++ b/test/GitHub.Exports.UnitTests/GitHub.Exports.UnitTests.csproj @@ -4,6 +4,7 @@ + diff --git a/test/GitHub.Exports.UnitTests/GlobalSuppressions.cs b/test/GitHub.Exports.UnitTests/GlobalSuppressions.cs deleted file mode 100644 index 556b42972b..0000000000 --- a/test/GitHub.Exports.UnitTests/GlobalSuppressions.cs +++ /dev/null @@ -1,13 +0,0 @@ - -// This file is used by Code Analysis to maintain SuppressMessage -// attributes that are applied to this project. -// Project-level suppressions either have no target or are given -// a specific target and scoped to a namespace, type, member, etc. - -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage( - "Naming", "CA1707:Identifiers should not contain underscores", - Justification = "Unit test names can contain a _")] - -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage( - "Design", "CA1034:Nested types should not be visible", - Justification = "Nested unit test classes should be visible")] diff --git a/test/GitHub.Exports.UnitTests/UriStringTests.cs b/test/GitHub.Exports.UnitTests/UriStringTests.cs index 6258fab7bf..86609c3c2d 100644 --- a/test/GitHub.Exports.UnitTests/UriStringTests.cs +++ b/test/GitHub.Exports.UnitTests/UriStringTests.cs @@ -298,7 +298,7 @@ public class TheEqualsMethod : TestBaseClass [TestCase("https://github.com/foo/bar", null, false)] public void ReturnsTrueForCaseSensitiveEquality(string source, string compare, bool expected) { - Assert.That(expected, Is.EqualTo(source.Equals(compare))); + Assert.That(expected, Is.EqualTo(source.Equals(compare, StringComparison.Ordinal))); Assert.That(expected, Is.EqualTo(EqualityComparer.Default.Equals(source, compare))); } diff --git a/test/GitHub.Extensions.UnitTests/GitHub.Extensions.UnitTests.csproj b/test/GitHub.Extensions.UnitTests/GitHub.Extensions.UnitTests.csproj index 7049913790..30b09267a5 100644 --- a/test/GitHub.Extensions.UnitTests/GitHub.Extensions.UnitTests.csproj +++ b/test/GitHub.Extensions.UnitTests/GitHub.Extensions.UnitTests.csproj @@ -2,6 +2,9 @@ net461 + + + diff --git a/test/GitHub.InlineReviews.UnitTests/GitHub.InlineReviews.UnitTests.csproj b/test/GitHub.InlineReviews.UnitTests/GitHub.InlineReviews.UnitTests.csproj index ff0fbcfd6c..cdc570ccee 100644 --- a/test/GitHub.InlineReviews.UnitTests/GitHub.InlineReviews.UnitTests.csproj +++ b/test/GitHub.InlineReviews.UnitTests/GitHub.InlineReviews.UnitTests.csproj @@ -17,6 +17,7 @@ + diff --git a/test/GitHub.InlineReviews.UnitTests/Models/DiffUtilitiesTests.cs b/test/GitHub.InlineReviews.UnitTests/Models/DiffUtilitiesTests.cs index 32be48765b..cee0012780 100644 --- a/test/GitHub.InlineReviews.UnitTests/Models/DiffUtilitiesTests.cs +++ b/test/GitHub.InlineReviews.UnitTests/Models/DiffUtilitiesTests.cs @@ -295,8 +295,8 @@ public void MatchSameLine() [Test] public void NoLineMatchesFromNoLines() { - var chunks = new DiffChunk[0]; - var lines = new DiffLine[0]; + var chunks = Array.Empty(); + var lines = Array.Empty(); var line = DiffUtilities.Match(chunks, lines); diff --git a/test/GitHub.InlineReviews.UnitTests/Services/PullRequestSessionManagerTests.cs b/test/GitHub.InlineReviews.UnitTests/Services/PullRequestSessionManagerTests.cs index ee9ba7b7ef..5b6dc68a57 100644 --- a/test/GitHub.InlineReviews.UnitTests/Services/PullRequestSessionManagerTests.cs +++ b/test/GitHub.InlineReviews.UnitTests/Services/PullRequestSessionManagerTests.cs @@ -37,37 +37,31 @@ public class TheConstructor : PullRequestSessionManagerTests [Test] public void ReadsPullRequestFromCorrectFork() { - using (TestUtils.WithScheduler(Scheduler.CurrentThread)) - { - var service = CreatePullRequestService(); - var sessionService = CreateSessionService(); + var service = CreatePullRequestService(); + var sessionService = CreateSessionService(); - service.GetPullRequestForCurrentBranch(null).ReturnsForAnyArgs( - Observable.Return(Tuple.Create("fork", CurrentBranchPullRequestNumber))); + service.GetPullRequestForCurrentBranch(null).ReturnsForAnyArgs( + Observable.Return(Tuple.Create("fork", CurrentBranchPullRequestNumber))); - var connectionManager = CreateConnectionManager(); - var target = CreateTarget( - service: service, - sessionService: sessionService, - connectionManager: connectionManager); + var connectionManager = CreateConnectionManager(); + var target = CreateTarget( + service: service, + sessionService: sessionService, + connectionManager: connectionManager); - var address = HostAddress.Create(OwnerCloneUrl); - sessionService.Received(1).ReadPullRequestDetail(address, "fork", "repo", 15); - } + var address = HostAddress.Create(OwnerCloneUrl); + sessionService.Received(1).ReadPullRequestDetail(address, "fork", "repo", 15); } [Test] public void LocalRepositoryModelNull() { - using (TestUtils.WithScheduler(Scheduler.CurrentThread)) - { - var repositoryModel = null as LocalRepositoryModel; - var teamExplorerContext = CreateTeamExplorerContext(repositoryModel); + var repositoryModel = null as LocalRepositoryModel; + var teamExplorerContext = CreateTeamExplorerContext(repositoryModel); - var target = CreateTarget(teamExplorerContext: teamExplorerContext); + var target = CreateTarget(teamExplorerContext: teamExplorerContext); - Assert.Null(target.CurrentSession); - } + Assert.Null(target.CurrentSession); } } @@ -76,154 +70,124 @@ public class TheCurrentSessionProperty : PullRequestSessionManagerTests [Test] public void CreatesSessionForCurrentBranch() { - using (TestUtils.WithScheduler(Scheduler.CurrentThread)) - { - var target = CreateTarget(); + var target = CreateTarget(); - Assert.That(target.CurrentSession, Is.Not.Null); - Assert.That(target.CurrentSession.IsCheckedOut, Is.True); - } + Assert.That(target.CurrentSession, Is.Not.Null); + Assert.That(target.CurrentSession.IsCheckedOut, Is.True); } [Test] public void CurrentSessionIsNullIfNoPullRequestForCurrentBranch() { - using (TestUtils.WithScheduler(Scheduler.CurrentThread)) - { - var service = CreatePullRequestService(); - service.GetPullRequestForCurrentBranch(null).ReturnsForAnyArgs(Observable.Empty>()); + var service = CreatePullRequestService(); + service.GetPullRequestForCurrentBranch(null).ReturnsForAnyArgs(Observable.Empty>()); - var target = CreateTarget(service: service); + var target = CreateTarget(service: service); - Assert.That(target.CurrentSession, Is.Null); - } + Assert.That(target.CurrentSession, Is.Null); } [Test] public void CurrentSessionChangesWhenBranchChanges() { - using (TestUtils.WithScheduler(Scheduler.CurrentThread)) - { - var service = CreatePullRequestService(); - var teamExplorerContext = CreateTeamExplorerContext(CreateRepositoryModel()); - var target = CreateTarget( - service: service, - teamExplorerContext: teamExplorerContext); + var service = CreatePullRequestService(); + var teamExplorerContext = CreateTeamExplorerContext(CreateRepositoryModel()); + var target = CreateTarget( + service: service, + teamExplorerContext: teamExplorerContext); - var session = target.CurrentSession; + var session = target.CurrentSession; - service.GetPullRequestForCurrentBranch(null).ReturnsForAnyArgs(Observable.Return(Tuple.Create("foo", 22))); - teamExplorerContext.StatusChanged += Raise.Event(); + service.GetPullRequestForCurrentBranch(null).ReturnsForAnyArgs(Observable.Return(Tuple.Create("foo", 22))); + teamExplorerContext.StatusChanged += Raise.Event(); - Assert.That(session, Is.Not.SameAs(target.CurrentSession)); - } + Assert.That(session, Is.Not.SameAs(target.CurrentSession)); } [Test] public void LocalRepositoryModelNull() { - using (TestUtils.WithScheduler(Scheduler.CurrentThread)) - { - var repositoryModel = null as LocalRepositoryModel; - var target = CreateTarget( - teamExplorerContext: CreateTeamExplorerContext(null)); + var repositoryModel = null as LocalRepositoryModel; + var target = CreateTarget( + teamExplorerContext: CreateTeamExplorerContext(null)); - Assert.That(target.CurrentSession, Is.Null); - } + Assert.That(target.CurrentSession, Is.Null); } [Test] public void CurrentSessionChangesToNullIfNoPullRequestForCurrentBranch() { - using (TestUtils.WithScheduler(Scheduler.CurrentThread)) - { - var service = CreatePullRequestService(); - var teamExplorerContext = CreateTeamExplorerContext(CreateRepositoryModel()); - var target = CreateTarget( - service: service, - teamExplorerContext: teamExplorerContext); - Assert.That(target.CurrentSession, Is.Not.Null); + var service = CreatePullRequestService(); + var teamExplorerContext = CreateTeamExplorerContext(CreateRepositoryModel()); + var target = CreateTarget( + service: service, + teamExplorerContext: teamExplorerContext); + Assert.That(target.CurrentSession, Is.Not.Null); - Tuple newPullRequest = null; - service.GetPullRequestForCurrentBranch(null).ReturnsForAnyArgs(Observable.Return(newPullRequest)); - teamExplorerContext.StatusChanged += Raise.Event(); + Tuple newPullRequest = null; + service.GetPullRequestForCurrentBranch(null).ReturnsForAnyArgs(Observable.Return(newPullRequest)); + teamExplorerContext.StatusChanged += Raise.Event(); - var session = target.CurrentSession; + var session = target.CurrentSession; - Assert.That(session, Is.Null); - } + Assert.That(session, Is.Null); } [Test] public void CurrentSessionChangesToNullWhenRepoChangedToNull() { - using (TestUtils.WithScheduler(Scheduler.CurrentThread)) - { - var teamExplorerContext = CreateTeamExplorerContext(CreateRepositoryModel()); - var target = CreateTarget(teamExplorerContext: teamExplorerContext); + var teamExplorerContext = CreateTeamExplorerContext(CreateRepositoryModel()); + var target = CreateTarget(teamExplorerContext: teamExplorerContext); - Assert.That(target.CurrentSession, Is.Not.Null); + Assert.That(target.CurrentSession, Is.Not.Null); - SetActiveRepository(teamExplorerContext, null); - var session = target.CurrentSession; + SetActiveRepository(teamExplorerContext, null); + var session = target.CurrentSession; - Assert.That(session, Is.Null); - } + Assert.That(session, Is.Null); } [Test] public void CurrentSessionChangesWhenRepoChanged() { - using (TestUtils.WithScheduler(Scheduler.CurrentThread)) - { - var teamExplorerContext = CreateTeamExplorerContext(CreateRepositoryModel()); - var target = CreateTarget(teamExplorerContext: teamExplorerContext); - var session = target.CurrentSession; + var teamExplorerContext = CreateTeamExplorerContext(CreateRepositoryModel()); + var target = CreateTarget(teamExplorerContext: teamExplorerContext); + var session = target.CurrentSession; - SetActiveRepository(teamExplorerContext, CreateRepositoryModel("https://github.com/owner/other")); + SetActiveRepository(teamExplorerContext, CreateRepositoryModel("https://github.com/owner/other")); - Assert.That(session, Is.Not.SameAs(target.CurrentSession)); - } + Assert.That(session, Is.Not.SameAs(target.CurrentSession)); } [Test] public void RepoChangedDoesntCreateNewSessionIfNotNecessary() { - using (TestUtils.WithScheduler(Scheduler.CurrentThread)) - { - var teamExplorerContext = CreateTeamExplorerContext(CreateRepositoryModel()); - var target = CreateTarget(teamExplorerContext: teamExplorerContext); - var session = target.CurrentSession; + var teamExplorerContext = CreateTeamExplorerContext(CreateRepositoryModel()); + var target = CreateTarget(teamExplorerContext: teamExplorerContext); + var session = target.CurrentSession; - teamExplorerContext.StatusChanged += Raise.Event(); + teamExplorerContext.StatusChanged += Raise.Event(); - Assert.That(session, Is.SameAs(target.CurrentSession)); - } + Assert.That(session, Is.SameAs(target.CurrentSession)); } [Test] public void RepoChangedHandlesNullRepository() { - using (TestUtils.WithScheduler(Scheduler.CurrentThread)) - { - var teamExplorerContext = CreateTeamExplorerContext(CreateRepositoryModel()); - var target = CreateTarget(teamExplorerContext: teamExplorerContext); + var teamExplorerContext = CreateTeamExplorerContext(CreateRepositoryModel()); + var target = CreateTarget(teamExplorerContext: teamExplorerContext); - SetActiveRepository(teamExplorerContext, null); + SetActiveRepository(teamExplorerContext, null); - Assert.That(target.CurrentSession, Is.Null); - } + Assert.That(target.CurrentSession, Is.Null); } [Test] public void CreatesSessionWithCorrectRepositoryOwner() { - using (TestUtils.WithScheduler(Scheduler.CurrentThread)) - { - var target = CreateTarget(service: CreatePullRequestService("this-owner")); + var target = CreateTarget(service: CreatePullRequestService("this-owner")); - Assert.That("this-owner", Is.EqualTo(target.CurrentSession.RepositoryOwner)); - } + Assert.That("this-owner", Is.EqualTo(target.CurrentSession.RepositoryOwner)); } } @@ -234,27 +198,21 @@ public class TheGetLiveFileMethod : PullRequestSessionManagerTests [Test] public async Task BaseShaIsSet() { - using (TestUtils.WithScheduler(Scheduler.CurrentThread)) - { - var textView = CreateTextView(); - var target = CreateTarget(); - var file = await target.GetLiveFile(FilePath, textView, textView.TextBuffer); + var textView = CreateTextView(); + var target = CreateTarget(); + var file = await target.GetLiveFile(FilePath, textView, textView.TextBuffer); - Assert.That("BASESHA", Is.SameAs(file.BaseSha)); - } + Assert.That("BASESHA", Is.SameAs(file.BaseSha)); } [Test] public async Task CommitShaIsSet() { - using (TestUtils.WithScheduler(Scheduler.CurrentThread)) - { - var textView = CreateTextView(); - var target = CreateTarget(); - var file = await target.GetLiveFile(FilePath, textView, textView.TextBuffer); + var textView = CreateTextView(); + var target = CreateTarget(); + var file = await target.GetLiveFile(FilePath, textView, textView.TextBuffer); - Assert.That("TIPSHA", Is.SameAs(file.CommitSha)); - } + Assert.That("TIPSHA", Is.SameAs(file.CommitSha)); } [Test] @@ -271,187 +229,169 @@ public async Task CommitShaIsNullIfModified() [Test] public async Task DiffIsSet() { - using (TestUtils.WithScheduler(Scheduler.CurrentThread)) - { - var textView = CreateTextView(); - var contents = Encoding.UTF8.GetBytes("File contents"); - var diff = new List(); - var sessionService = CreateSessionService(); - - sessionService.GetContents(textView.TextBuffer).Returns(contents); - sessionService.GetPullRequestMergeBase(null, null).ReturnsForAnyArgs("MERGE_BASE"); - sessionService.Diff( - Arg.Any(), - "MERGE_BASE", - "HEADSHA", - FilePath, - contents).Returns(diff); + var textView = CreateTextView(); + var contents = Encoding.UTF8.GetBytes("File contents"); + var diff = new List(); + var sessionService = CreateSessionService(); - var target = CreateTarget(sessionService: sessionService); - var file = await target.GetLiveFile(FilePath, textView, textView.TextBuffer); + sessionService.GetContents(textView.TextBuffer).Returns(contents); + sessionService.GetPullRequestMergeBase(null, null).ReturnsForAnyArgs("MERGE_BASE"); + sessionService.Diff( + Arg.Any(), + "MERGE_BASE", + "HEADSHA", + FilePath, + contents).Returns(diff); - Assert.That(diff, Is.SameAs(file.Diff)); - } + var target = CreateTarget(sessionService: sessionService); + var file = await target.GetLiveFile(FilePath, textView, textView.TextBuffer); + + Assert.That(diff, Is.SameAs(file.Diff)); } [Test] public async Task InlineCommentThreadsIsSet() { - using (TestUtils.WithScheduler(Scheduler.CurrentThread)) - { - var textView = CreateTextView(); - var sessionService = CreateSessionService(); - var threads = new List(); - var target = CreateTarget(sessionService: sessionService); + var textView = CreateTextView(); + var sessionService = CreateSessionService(); + var threads = new List(); + var target = CreateTarget(sessionService: sessionService); - sessionService.BuildCommentThreads( - target.CurrentSession.PullRequest, - FilePath, - Arg.Any>(), - Arg.Any()) - .Returns(threads); + sessionService.BuildCommentThreads( + target.CurrentSession.PullRequest, + FilePath, + Arg.Any>(), + Arg.Any()) + .Returns(threads); - var file = await target.GetLiveFile(FilePath, textView, textView.TextBuffer); + var file = await target.GetLiveFile(FilePath, textView, textView.TextBuffer); - Assert.That(threads, Is.SameAs(file.InlineCommentThreads)); - } + Assert.That(threads, Is.SameAs(file.InlineCommentThreads)); } [Test] public async Task CreatesTrackingPointsForThreads() { - using (TestUtils.WithScheduler(Scheduler.CurrentThread)) - { - var textView = CreateTextView(); - var sessionService = CreateSessionService(); - var threads = new List - { - CreateInlineCommentThreadModel(1), - CreateInlineCommentThreadModel(2), - }; + var textView = CreateTextView(); + var sessionService = CreateSessionService(); + var threads = new List + { + CreateInlineCommentThreadModel(1), + CreateInlineCommentThreadModel(2), + }; - var target = CreateTarget(sessionService: sessionService); + var target = CreateTarget(sessionService: sessionService); - sessionService.BuildCommentThreads( - target.CurrentSession.PullRequest, - FilePath, - Arg.Any>(), - Arg.Any()) - .Returns(threads); + sessionService.BuildCommentThreads( + target.CurrentSession.PullRequest, + FilePath, + Arg.Any>(), + Arg.Any()) + .Returns(threads); - var file = (PullRequestSessionLiveFile)await target.GetLiveFile(FilePath, textView, textView.TextBuffer); + var file = (PullRequestSessionLiveFile)await target.GetLiveFile(FilePath, textView, textView.TextBuffer); - Assert.That(2, Is.EqualTo(file.TrackingPoints.Count)); - } + Assert.That(2, Is.EqualTo(file.TrackingPoints.Count)); } [Test] public async Task MovingToNoRepositoryShouldNullOutProperties() { - using (TestUtils.WithScheduler(Scheduler.CurrentThread)) - { - var textView = CreateTextView(); - var sessionService = CreateSessionService(); - var threads = new List(); - var teamExplorerContext = CreateTeamExplorerContext(CreateRepositoryModel()); - - var target = CreateTarget( - sessionService: sessionService, - teamExplorerContext: teamExplorerContext); - - sessionService.BuildCommentThreads( - target.CurrentSession.PullRequest, - FilePath, - Arg.Any>(), - Arg.Any()) - .Returns(threads); + var textView = CreateTextView(); + var sessionService = CreateSessionService(); + var threads = new List(); + var teamExplorerContext = CreateTeamExplorerContext(CreateRepositoryModel()); - var file = (PullRequestSessionLiveFile)await target.GetLiveFile(FilePath, textView, textView.TextBuffer); + var target = CreateTarget( + sessionService: sessionService, + teamExplorerContext: teamExplorerContext); - Assert.That(file.BaseSha, Is.Not.Null); - Assert.That(file.CommitSha, Is.Not.Null); - Assert.That(file.Diff, Is.Not.Null); - Assert.That(file.InlineCommentThreads, Is.Not.Null); - Assert.That(file.TrackingPoints, Is.Not.Null); + sessionService.BuildCommentThreads( + target.CurrentSession.PullRequest, + FilePath, + Arg.Any>(), + Arg.Any()) + .Returns(threads); - SetActiveRepository(teamExplorerContext, null); + var file = (PullRequestSessionLiveFile)await target.GetLiveFile(FilePath, textView, textView.TextBuffer); - Assert.That(file.BaseSha, Is.Null); - Assert.That(file.CommitSha, Is.Null); - Assert.That(file.Diff, Is.Null); - Assert.That(file.InlineCommentThreads, Is.Null); - Assert.That(file.TrackingPoints, Is.Null); - } + Assert.That(file.BaseSha, Is.Not.Null); + Assert.That(file.CommitSha, Is.Not.Null); + Assert.That(file.Diff, Is.Not.Null); + Assert.That(file.InlineCommentThreads, Is.Not.Null); + Assert.That(file.TrackingPoints, Is.Not.Null); + + SetActiveRepository(teamExplorerContext, null); + + Assert.That(file.BaseSha, Is.Null); + Assert.That(file.CommitSha, Is.Null); + Assert.That(file.Diff, Is.Null); + Assert.That(file.InlineCommentThreads, Is.Null); + Assert.That(file.TrackingPoints, Is.Null); } [Test] public async Task ModifyingBufferMarksThreadsAsStaleAndSignalsRebuild() { - using (TestUtils.WithScheduler(Scheduler.CurrentThread)) - { - var textView = CreateTextView(); - var sessionService = CreateSessionService(); - var rebuild = Substitute.For>(); - sessionService.CreateRebuildSignal().Returns(rebuild); + var textView = CreateTextView(); + var sessionService = CreateSessionService(); + var rebuild = Substitute.For>(); + sessionService.CreateRebuildSignal().Returns(rebuild); - var threads = new List - { - CreateInlineCommentThreadModel(1), - CreateInlineCommentThreadModel(2), - }; + var threads = new List + { + CreateInlineCommentThreadModel(1), + CreateInlineCommentThreadModel(2), + }; - var target = CreateTarget(sessionService: sessionService); + var target = CreateTarget(sessionService: sessionService); - sessionService.BuildCommentThreads( - target.CurrentSession.PullRequest, - FilePath, - Arg.Any>(), - Arg.Any()) - .Returns(threads); + sessionService.BuildCommentThreads( + target.CurrentSession.PullRequest, + FilePath, + Arg.Any>(), + Arg.Any()) + .Returns(threads); - var file = (PullRequestSessionLiveFile)await target.GetLiveFile(FilePath, textView, textView.TextBuffer); - var linesChangedReceived = false; - file.LinesChanged.Subscribe(x => linesChangedReceived = true); + var file = (PullRequestSessionLiveFile)await target.GetLiveFile(FilePath, textView, textView.TextBuffer); + var linesChangedReceived = false; + file.LinesChanged.Subscribe(x => linesChangedReceived = true); - // Make the first tracking points return a different value so that the thread is marked as stale. - var snapshot = textView.TextSnapshot; - file.TrackingPoints[file.InlineCommentThreads[0]].GetPosition(snapshot).ReturnsForAnyArgs(5); + // Make the first tracking points return a different value so that the thread is marked as stale. + var snapshot = textView.TextSnapshot; + file.TrackingPoints[file.InlineCommentThreads[0]].GetPosition(snapshot).ReturnsForAnyArgs(5); - SignalTextChanged(textView.TextBuffer); + SignalTextChanged(textView.TextBuffer); - threads[0].Received().IsStale = true; - threads[1].DidNotReceive().IsStale = true; + threads[0].Received().IsStale = true; + threads[1].DidNotReceive().IsStale = true; - Assert.That(linesChangedReceived, Is.True); - file.Rebuild.Received().OnNext(Arg.Any()); - } + Assert.That(linesChangedReceived, Is.True); + file.Rebuild.Received().OnNext(Arg.Any()); } [Test] public async Task RebuildSignalUpdatesCommitSha() { - using (TestUtils.WithScheduler(Scheduler.CurrentThread)) - { - var textView = CreateTextView(); - var sessionService = CreateSessionService(); - sessionService.CreateRebuildSignal().Returns(new Subject()); + var textView = CreateTextView(); + var sessionService = CreateSessionService(); + sessionService.CreateRebuildSignal().Returns(new Subject()); - var threads = new List - { - CreateInlineCommentThreadModel(1), - CreateInlineCommentThreadModel(2), - }; + var threads = new List + { + CreateInlineCommentThreadModel(1), + CreateInlineCommentThreadModel(2), + }; - var target = CreateTarget(sessionService: sessionService); - var file = (PullRequestSessionLiveFile)await target.GetLiveFile(FilePath, textView, textView.TextBuffer); + var target = CreateTarget(sessionService: sessionService); + var file = (PullRequestSessionLiveFile)await target.GetLiveFile(FilePath, textView, textView.TextBuffer); - Assert.That("TIPSHA", Is.SameAs(file.CommitSha)); + Assert.That("TIPSHA", Is.SameAs(file.CommitSha)); - sessionService.IsUnmodifiedAndPushed(null, null, null).ReturnsForAnyArgs(false); - file.Rebuild.OnNext(textView.TextBuffer.CurrentSnapshot); + sessionService.IsUnmodifiedAndPushed(null, null, null).ReturnsForAnyArgs(false); + file.Rebuild.OnNext(textView.TextBuffer.CurrentSnapshot); - Assert.That(file.CommitSha, Is.Null); - } + Assert.That(file.CommitSha, Is.Null); } [Test] @@ -473,155 +413,146 @@ public async Task ClosingTextViewDisposesFile() [Test] public async Task InlineCommentThreadsAreLoadedFromCurrentSession() { - using (TestUtils.WithScheduler(Scheduler.CurrentThread)) - { - var baseContents = @"Line 1 + var baseContents = @"Line 1 Line 2 Line 3 Line 4"; - var contents = @"Line 1 + var contents = @"Line 1 Line 2 Line 3 with comment Line 4"; - var thread = CreateCommentThread(@"@@ -1,4 +1,4 @@ + var thread = CreateCommentThread(@"@@ -1,4 +1,4 @@ Line 1 Line 2 -Line 3 +Line 3 with comment"); - using (var diffService = new FakeDiffService()) - { - var textView = CreateTextView(contents); - var pullRequest = CreatePullRequestModel( - CurrentBranchPullRequestNumber, - thread); + using (var diffService = new FakeDiffService()) + { + var textView = CreateTextView(contents); + var pullRequest = CreatePullRequestModel( + CurrentBranchPullRequestNumber, + thread); - diffService.AddFile(FilePath, baseContents, "MERGE_BASE"); + diffService.AddFile(FilePath, baseContents, "MERGE_BASE"); - var target = CreateTarget(sessionService: CreateRealSessionService(diffService, pullRequest)); - var file = (PullRequestSessionLiveFile)await target.GetLiveFile(FilePath, textView, textView.TextBuffer); + var target = CreateTarget(sessionService: CreateRealSessionService(diffService, pullRequest)); + var file = (PullRequestSessionLiveFile)await target.GetLiveFile(FilePath, textView, textView.TextBuffer); - Assert.That(file.InlineCommentThreads.Count, Is.EqualTo(1)); - Assert.That(file.InlineCommentThreads[0].LineNumber, Is.EqualTo(2)); - } + Assert.That(file.InlineCommentThreads.Count, Is.EqualTo(1)); + Assert.That(file.InlineCommentThreads[0].LineNumber, Is.EqualTo(2)); } } [Test, NUnit.Framework.Category("CodeCoverageFlake")] public async Task UpdatesInlineCommentThreadsFromEditorContent() { - using (TestUtils.WithScheduler(Scheduler.CurrentThread)) - { - var baseContents = @"Line 1 + var baseContents = @"Line 1 Line 2 Line 3 Line 4"; - var contents = @"Line 1 + var contents = @"Line 1 Line 2 Line 3 with comment Line 4"; - var editorContents = @"New Line 1 + var editorContents = @"New Line 1 New Line 2 Line 1 Line 2 Line 3 with comment Line 4"; - var comment = CreateCommentThread(@"@@ -1,4 +1,4 @@ + var comment = CreateCommentThread(@"@@ -1,4 +1,4 @@ Line 1 Line 2 -Line 3 +Line 3 with comment"); - using (var diffService = new FakeDiffService()) - { - var textView = CreateTextView(contents); - var pullRequest = CreatePullRequestModel( - CurrentBranchPullRequestNumber, - comment); - - diffService.AddFile(FilePath, baseContents, "MERGE_BASE"); - - var target = CreateTarget(sessionService: CreateRealSessionService(diffService, pullRequest)); - var file = (PullRequestSessionLiveFile)await target.GetLiveFile(FilePath, textView, textView.TextBuffer); - - Assert.That(1, Is.EqualTo(file.InlineCommentThreads.Count)); - Assert.That(2, Is.EqualTo(file.InlineCommentThreads[0].LineNumber)); - - textView.TextSnapshot.GetText().Returns(editorContents); - SignalTextChanged(textView.TextBuffer); - - var linesChanged = await file.LinesChanged.Take(1); - - Assert.That(1, Is.EqualTo(file.InlineCommentThreads.Count)); - Assert.That(4, Is.EqualTo(file.InlineCommentThreads[0].LineNumber)); - Assert.That( - new[] - { - Tuple.Create(2, DiffSide.Right), - Tuple.Create(4, DiffSide.Right), - }, - Is.EqualTo(linesChanged.ToArray())); - } + using (var diffService = new FakeDiffService()) + { + var textView = CreateTextView(contents); + var pullRequest = CreatePullRequestModel( + CurrentBranchPullRequestNumber, + comment); + + diffService.AddFile(FilePath, baseContents, "MERGE_BASE"); + + var target = CreateTarget(sessionService: CreateRealSessionService(diffService, pullRequest)); + var file = (PullRequestSessionLiveFile)await target.GetLiveFile(FilePath, textView, textView.TextBuffer); + + Assert.That(1, Is.EqualTo(file.InlineCommentThreads.Count)); + Assert.That(2, Is.EqualTo(file.InlineCommentThreads[0].LineNumber)); + + textView.TextSnapshot.GetText().Returns(editorContents); + SignalTextChanged(textView.TextBuffer); + + var linesChanged = await file.LinesChanged.Take(1); + + Assert.That(1, Is.EqualTo(file.InlineCommentThreads.Count)); + Assert.That(4, Is.EqualTo(file.InlineCommentThreads[0].LineNumber)); + Assert.That( + new[] + { + Tuple.Create(2, DiffSide.Right), + Tuple.Create(4, DiffSide.Right), + }, + Is.EqualTo(linesChanged.ToArray())); } } [Test, NUnit.Framework.Category("CodeCoverageFlake")] public async Task UpdatesReviewCommentWithNewBody() { - using (TestUtils.WithScheduler(Scheduler.CurrentThread)) - { - var baseContents = @"Line 1 + var baseContents = @"Line 1 Line 2 Line 3 Line 4"; - var contents = @"Line 1 + var contents = @"Line 1 Line 2 Line 3 with comment Line 4"; - var comment = CreateCommentThread(@"@@ -1,4 +1,4 @@ + var comment = CreateCommentThread(@"@@ -1,4 +1,4 @@ Line 1 Line 2 -Line 3 +Line 3 with comment", "Original Comment"); - var updatedComment = CreateCommentThread(@"@@ -1,4 +1,4 @@ + var updatedComment = CreateCommentThread(@"@@ -1,4 +1,4 @@ Line 1 Line 2 -Line 3 +Line 3 with comment", "Updated Comment"); - using (var diffService = new FakeDiffService()) - { - var textView = CreateTextView(contents); - var pullRequest = CreatePullRequestModel( - CurrentBranchPullRequestNumber, - comment); - var sessionService = CreateRealSessionService(diffService, pullRequest); + using (var diffService = new FakeDiffService()) + { + var textView = CreateTextView(contents); + var pullRequest = CreatePullRequestModel( + CurrentBranchPullRequestNumber, + comment); + var sessionService = CreateRealSessionService(diffService, pullRequest); - diffService.AddFile(FilePath, baseContents, "MERGE_BASE"); + diffService.AddFile(FilePath, baseContents, "MERGE_BASE"); - var target = CreateTarget(sessionService: sessionService); - var file = (PullRequestSessionLiveFile)await target.GetLiveFile(FilePath, textView, textView.TextBuffer); + var target = CreateTarget(sessionService: sessionService); + var file = (PullRequestSessionLiveFile)await target.GetLiveFile(FilePath, textView, textView.TextBuffer); - Assert.That(file.InlineCommentThreads[0].Comments[0].Comment.Body, Is.EqualTo("Original Comment")); + Assert.That(file.InlineCommentThreads[0].Comments[0].Comment.Body, Is.EqualTo("Original Comment")); - pullRequest = CreatePullRequestModel( - CurrentBranchPullRequestNumber, - updatedComment); - sessionService.ReadPullRequestDetail( - Arg.Any(), - Arg.Any(), - Arg.Any(), - Arg.Any()).Returns(pullRequest); - await target.CurrentSession.Refresh(); + pullRequest = CreatePullRequestModel( + CurrentBranchPullRequestNumber, + updatedComment); + sessionService.ReadPullRequestDetail( + Arg.Any(), + Arg.Any(), + Arg.Any(), + Arg.Any()).Returns(pullRequest); + await target.CurrentSession.Refresh(); - await file.LinesChanged.Take(1); + await file.LinesChanged.Take(1); - Assert.That("Updated Comment", Is.EqualTo(file.InlineCommentThreads[0].Comments[0].Comment.Body)); - } + Assert.That("Updated Comment", Is.EqualTo(file.InlineCommentThreads[0].Comments[0].Comment.Body)); } } - [Test, Ignore("Flaky test, see https://github.com/github/VisualStudio/issues/1795")] + [Test] public async Task AddsNewReviewCommentToThread() { var baseContents = @"Line 1 @@ -681,21 +612,18 @@ Line 2 [Test] public async Task CommitShaIsUpdatedOnTextChange() { - using (TestUtils.WithScheduler(Scheduler.CurrentThread)) - { - var textView = CreateTextView(); - var sessionService = CreateSessionService(); + var textView = CreateTextView(); + var sessionService = CreateSessionService(); - var target = CreateTarget(sessionService: sessionService); - var file = await target.GetLiveFile(FilePath, textView, textView.TextBuffer); + var target = CreateTarget(sessionService: sessionService); + var file = await target.GetLiveFile(FilePath, textView, textView.TextBuffer); - Assert.That("TIPSHA", Is.EqualTo(file.CommitSha)); + Assert.That("TIPSHA", Is.EqualTo(file.CommitSha)); - sessionService.IsUnmodifiedAndPushed(null, null, null).ReturnsForAnyArgs(false); - SignalTextChanged(textView.TextBuffer); + sessionService.IsUnmodifiedAndPushed(null, null, null).ReturnsForAnyArgs(false); + SignalTextChanged(textView.TextBuffer); - Assert.That(file.CommitSha, Is.Null); - } + Assert.That(file.CommitSha, Is.Null); } [Test] @@ -944,7 +872,7 @@ PullRequestDetailModel CreatePullRequestModel( } else { - result.Reviews = new PullRequestReviewModel[0]; + result.Reviews = Array.Empty(); } return result; diff --git a/test/GitHub.InlineReviews.UnitTests/Services/PullRequestSessionTests.cs b/test/GitHub.InlineReviews.UnitTests/Services/PullRequestSessionTests.cs index 81c5f463e1..7389fc99a3 100644 --- a/test/GitHub.InlineReviews.UnitTests/Services/PullRequestSessionTests.cs +++ b/test/GitHub.InlineReviews.UnitTests/Services/PullRequestSessionTests.cs @@ -18,8 +18,6 @@ namespace GitHub.InlineReviews.UnitTests.Services public class PullRequestSessionTests { const int PullRequestNumber = 5; - const string PullRequestNodeId = "pull_request_id"; - const string RepoUrl = "https://foo.bar/owner/repo"; const string FilePath = "test.cs"; public class TheHasPendingReviewProperty @@ -418,7 +416,7 @@ public async Task PostsToCorrectForkWithNoPendingReview() var target = CreateTarget(service, "fork", "owner", false); service.PostStandaloneReviewComment(null, null, null, null, null, 0).ReturnsForAnyArgs(CreatePullRequest()); - await target.PostReviewComment("New Comment", "COMMIT_ID", "file.cs", new DiffChunk[0], 1); + await target.PostReviewComment("New Comment", "COMMIT_ID", "file.cs", Array.Empty(), 1); await service.Received(1).PostStandaloneReviewComment( target.LocalRepository, @@ -452,7 +450,7 @@ public async Task PostsToCorrectForkWithPendingReview() var target = CreateTarget(service, "fork", "owner", true); service.PostPendingReviewComment(null, null, null, null, null, 0).ReturnsForAnyArgs(CreatePullRequest()); - await target.PostReviewComment("New Comment", "COMMIT_ID", "file.cs", new DiffChunk[0], 1); + await target.PostReviewComment("New Comment", "COMMIT_ID", "file.cs", Array.Empty(), 1); await service.Received(1).PostPendingReviewComment( target.LocalRepository, @@ -689,7 +687,7 @@ static PullRequestReviewThreadModel CreateThread(string diffHunk, string body = static PullRequestDetailModel CreatePullRequest() { - return CreatePullRequest(new PullRequestReviewModel[0]); + return CreatePullRequest(Array.Empty()); } static PullRequestDetailModel CreatePullRequest(params PullRequestReviewModel[] reviews) diff --git a/test/GitHub.InlineReviews.UnitTests/ViewModels/InlineCommentThreadViewModelTests.cs b/test/GitHub.InlineReviews.UnitTests/ViewModels/InlineCommentThreadViewModelTests.cs index d68eeeb935..724d6b824a 100644 --- a/test/GitHub.InlineReviews.UnitTests/ViewModels/InlineCommentThreadViewModelTests.cs +++ b/test/GitHub.InlineReviews.UnitTests/ViewModels/InlineCommentThreadViewModelTests.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Reactive.Linq; using GitHub.InlineReviews.Services; @@ -89,7 +90,7 @@ IEnumerable CreateComments(params string[] bodies) foreach (var body in bodies) { - yield return CreateComment((id++).ToString(), body); + yield return CreateComment((id++).ToString(CultureInfo.InvariantCulture), body); } } diff --git a/test/GitHub.TeamFoundation.UnitTests/GitHub.TeamFoundation.UnitTests.csproj b/test/GitHub.TeamFoundation.UnitTests/GitHub.TeamFoundation.UnitTests.csproj index 65d49470f6..18e6fe82df 100644 --- a/test/GitHub.TeamFoundation.UnitTests/GitHub.TeamFoundation.UnitTests.csproj +++ b/test/GitHub.TeamFoundation.UnitTests/GitHub.TeamFoundation.UnitTests.csproj @@ -13,6 +13,7 @@ +