This repository has been archived by the owner on Jun 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #482 from github/fixes/477-crash-pr-empty-body
Fix crasher when creating a PR with nothing in the body
- Loading branch information
Showing
9 changed files
with
121 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/UnitTests/GitHub.App/Services/PullRequestServiceTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System.Reactive.Linq; | ||
using System.Threading.Tasks; | ||
using NSubstitute; | ||
using Xunit; | ||
using UnitTests; | ||
using GitHub.Models; | ||
using System; | ||
using GitHub.Services; | ||
|
||
public class PullRequestServiceTests : TestBaseClass | ||
{ | ||
[Fact] | ||
public async Task CreatePullRequestAllArgsMandatory() | ||
{ | ||
var serviceProvider = Substitutes.ServiceProvider; | ||
var service = new PullRequestService(); | ||
|
||
IRepositoryHost host = null; | ||
ISimpleRepositoryModel repository = null; | ||
string title = null; | ||
string body = null; | ||
IBranch source = null; | ||
IBranch target = null; | ||
|
||
Assert.Throws<ArgumentNullException>(() => service.CreatePullRequest(host, repository, title, body, source, target)); | ||
|
||
host = serviceProvider.GetRepositoryHosts().GitHubHost; | ||
Assert.Throws<ArgumentNullException>(() => service.CreatePullRequest(host, repository, title, body, source, target)); | ||
|
||
repository = new SimpleRepositoryModel("name", new GitHub.Primitives.UriString("http://github.com/github/stuff")); | ||
Assert.Throws<ArgumentNullException>(() => service.CreatePullRequest(host, repository, title, body, source, target)); | ||
|
||
title = "a title"; | ||
Assert.Throws<ArgumentNullException>(() => service.CreatePullRequest(host, repository, title, body, source, target)); | ||
|
||
body = "a body"; | ||
Assert.Throws<ArgumentNullException>(() => service.CreatePullRequest(host, repository, title, body, source, target)); | ||
|
||
source = new BranchModel() { Name = "source" }; | ||
Assert.Throws<ArgumentNullException>(() => service.CreatePullRequest(host, repository, title, body, source, target)); | ||
|
||
target = new BranchModel() { Name = "target" }; | ||
var pr = await service.CreatePullRequest(host, repository, title, body, source, target); | ||
|
||
Assert.NotNull(pr); | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
src/UnitTests/GitHub.App/ViewModels/PullRequestCreationViewModelTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Reactive.Linq; | ||
using System.Threading.Tasks; | ||
using NSubstitute; | ||
using Xunit; | ||
using UnitTests; | ||
using GitHub.Models; | ||
using System; | ||
using GitHub.Services; | ||
using GitHub.ViewModels; | ||
|
||
public class PullRequestCreationViewModelTests : TempFileBaseClass | ||
{ | ||
[Fact] | ||
public async Task NullDescriptionBecomesEmptyBody() | ||
{ | ||
var serviceProvider = Substitutes.ServiceProvider; | ||
var service = new PullRequestService(); | ||
var notifications = Substitute.For<INotificationService>(); | ||
|
||
var host = serviceProvider.GetRepositoryHosts().GitHubHost; | ||
var ms = Substitute.For<IModelService>(); | ||
host.ModelService.Returns(ms); | ||
|
||
var repository = new SimpleRepositoryModel("name", new GitHub.Primitives.UriString("http://github.com/github/stuff")); | ||
var title = "a title"; | ||
|
||
var vm = new PullRequestCreationViewModel(host, repository, service, notifications); | ||
vm.SourceBranch = new BranchModel() { Name = "source" }; | ||
vm.TargetBranch = new BranchModel() { Name = "target" }; | ||
vm.PRTitle = title; | ||
|
||
await vm.CreatePullRequest.ExecuteAsync(); | ||
var unused = ms.Received().CreatePullRequest(repository, vm.PRTitle, String.Empty, vm.SourceBranch, vm.TargetBranch); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters