Skip to content

Commit

Permalink
(build) Fix unit tests
Browse files Browse the repository at this point in the history
As a result of changes to "how" a release is found from GitHub, it is
no longer the case that an exception is thrown, but rather, if a
specific release can't be found, it simply returns a null value. The
unit tests were updated to reflect this change in functionality.
  • Loading branch information
gep13 committed May 31, 2021
1 parent a4b9ef4 commit d8608b0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
20 changes: 8 additions & 12 deletions src/GitReleaseManager.Core.Tests/Provider/GitHubProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -631,30 +631,26 @@ public async Task Should_Get_Release()
var result = await _gitHubProvider.GetReleaseAsync(OWNER, REPOSITORY, TAG_NAME).ConfigureAwait(false);
result.ShouldBeSameAs(release);

await _gitHubClient.Repository.Release.Received(1).Get(OWNER, REPOSITORY, TAG_NAME).ConfigureAwait(false);
await _gitHubClient.Repository.Release.Received(1).GetAll(OWNER, REPOSITORY).ConfigureAwait(false);
_mapper.Received(1).Map<Release>(Arg.Any<object>());
}

[Test]
public async Task Should_Throw_An_Exception_On_Getting_Release_For_Non_Existent_Tag()
public async Task Should_Return_Null_On_Getting_Release_For_Non_Existent_Tag()
{
_gitHubClient.Repository.Release.Get(OWNER, REPOSITORY, TAG_NAME)
.Returns(Task.FromException<Octokit.Release>(_notFoundException));

var ex = await Should.ThrowAsync<NotFoundException>(() => _gitHubProvider.GetReleaseAsync(OWNER, REPOSITORY, TAG_NAME)).ConfigureAwait(false);
ex.Message.ShouldBe(_notFoundException.Message);
ex.InnerException.ShouldBe(_notFoundException);
var release = await _gitHubProvider.GetReleaseAsync(OWNER, REPOSITORY, TAG_NAME).ConfigureAwait(false);

release.ShouldBeNull();
}

[Test]
public async Task Should_Throw_An_Exception_On_Getting_Release()
public async Task Should_Return_Null_Getting_Release()
{
_gitHubClient.Repository.Release.Get(OWNER, REPOSITORY, TAG_NAME)
.Returns(Task.FromException<Octokit.Release>(_exception));

var ex = await Should.ThrowAsync<ApiException>(() => _gitHubProvider.GetReleaseAsync(OWNER, REPOSITORY, TAG_NAME)).ConfigureAwait(false);
ex.Message.ShouldBe(_exception.Message);
ex.InnerException.ShouldBe(_exception);
var release = await _gitHubProvider.GetReleaseAsync(OWNER, REPOSITORY, TAG_NAME).ConfigureAwait(false);
release.ShouldBeNull();
}

[Test]
Expand Down
6 changes: 3 additions & 3 deletions src/GitReleaseManager.Core.Tests/VcsServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ public async Task Should_Create_Release_From_Milestone()
.Returns(Task.FromResult(RELEASE_NOTES));

_vcsProvider.GetReleaseAsync(OWNER, REPOSITORY, MILESTONE_TITLE)
.Returns(Task.FromException<Release>(_notFoundException));
.Returns(Task.FromResult<Release>(null));

_vcsProvider.CreateReleaseAsync(OWNER, REPOSITORY, Arg.Any<Release>())
.Returns(Task.FromResult(release));
Expand Down Expand Up @@ -330,7 +330,7 @@ public async Task Should_Create_Release_From_Milestone_Using_Template_File()
.Returns(Task.FromResult(RELEASE_NOTES));

_vcsProvider.GetReleaseAsync(OWNER, REPOSITORY, MILESTONE_TITLE)
.Returns(Task.FromException<Release>(_notFoundException));
.Returns(Task.FromResult<Release>(null));

_vcsProvider.CreateReleaseAsync(OWNER, REPOSITORY, Arg.Any<Release>())
.Returns(Task.FromResult(release));
Expand Down Expand Up @@ -434,7 +434,7 @@ public async Task Should_Create_Release_From_InputFile()
var release = new Release();

_vcsProvider.GetReleaseAsync(OWNER, REPOSITORY, MILESTONE_TITLE)
.Returns(Task.FromException<Release>(_notFoundException));
.Returns(Task.FromResult<Release>(null));

_vcsProvider.CreateReleaseAsync(OWNER, REPOSITORY, Arg.Any<Release>())
.Returns(Task.FromResult(release));
Expand Down

0 comments on commit d8608b0

Please sign in to comment.