Skip to content

Commit b4913f9

Browse files
committed
Merge branch 'release/1.1.0'
2 parents 3322414 + a28cd93 commit b4913f9

File tree

7 files changed

+183
-45
lines changed

7 files changed

+183
-45
lines changed

.github/dependabot.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: nuget
4+
directory: "/src"
5+
schedule:
6+
interval: daily
7+
time: "04:00"
8+
open-pull-requests-limit: 10
9+
ignore:
10+
- dependency-name: Cake.Core
11+
versions:
12+
- "> 1.0.0, < 2"
13+
- dependency-name: Cake.Common
14+
versions:
15+
- "> 1.0.0, < 2"
16+
- dependency-name: Cake.Testing
17+
versions:
18+
- "> 1.0.0, < 2"

src/Cake.AzureDevOps.Tests/Cake.AzureDevOps.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
</PropertyGroup>
1515

1616
<ItemGroup>
17-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1" />
17+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
1818
<PackageReference Include="Cake.Core" Version="1.0.0" />
1919
<PackageReference Include="Cake.Testing" Version="1.0.0" />
2020
<PackageReference Include="Microsoft.TeamFoundationServer.Client" Version="16.143.2" />

src/Cake.AzureDevOps.Tests/ExceptionAssertExtensions.cs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,21 @@
1010
public static class ExceptionAssertExtensions
1111
{
1212
/// <summary>
13-
/// Checks if an execption is of type <see cref="ArgumentNullException"/>.
13+
/// Checks if an exception is of type <typeparamref name="T"/>.
14+
/// </summary>
15+
/// <typeparam name="T">The <see cref="ArgumentException"/> or one of its descendants.</typeparam>
16+
/// <param name="exception">Exception to check.</param>
17+
/// <param name="expectedExceptionType">The expected type of the exception.</param>
18+
/// <param name="parameterName">Expected name of the parameter which has caused the exception.</param>
19+
public static void IsArgumentException<T>(this T exception, Type expectedExceptionType, string parameterName)
20+
where T : ArgumentException
21+
{
22+
Assert.IsType(expectedExceptionType, exception);
23+
Assert.Equal(parameterName, exception.ParamName);
24+
}
25+
26+
/// <summary>
27+
/// Checks if an exception is of type <see cref="ArgumentNullException"/>.
1428
/// </summary>
1529
/// <param name="exception">Exception to check.</param>
1630
/// <param name="parameterName">Expected name of the parameter which has caused the exception.</param>
@@ -21,7 +35,7 @@ public static void IsArgumentNullException(this Exception exception, string para
2135
}
2236

2337
/// <summary>
24-
/// Checks if an execption is of type <see cref="ArgumentOutOfRangeException"/>.
38+
/// Checks if an exception is of type <see cref="ArgumentOutOfRangeException"/>.
2539
/// </summary>
2640
/// <param name="exception">Exception to check.</param>
2741
/// <param name="parameterName">Expected name of the parameter which has caused the exception.</param>
@@ -32,7 +46,7 @@ public static void IsArgumentOutOfRangeException(this Exception exception, strin
3246
}
3347

3448
/// <summary>
35-
/// Checks if an execption is of type <see cref="ArgumentException"/>.
49+
/// Checks if an exception is of type <see cref="ArgumentException"/>.
3650
/// </summary>
3751
/// <param name="exception">Exception to check.</param>
3852
/// <param name="parameterName">Expected name of the parameter which has caused the exception.</param>
@@ -43,7 +57,7 @@ public static void IsArgumentException(this Exception exception, string paramete
4357
}
4458

4559
/// <summary>
46-
/// Checks if an execption is of type <see cref="InvalidOperationException"/>.
60+
/// Checks if an exception is of type <see cref="InvalidOperationException"/>.
4761
/// </summary>
4862
/// <param name="exception">Exception to check.</param>
4963
public static void IsInvalidOperationException(this Exception exception)
@@ -70,7 +84,7 @@ public static void IsAzureDevOpsPullRequestNotFoundException(this Exception exce
7084
}
7185

7286
/// <summary>
73-
/// Checks if an exception is of type <see cref="AzureDevOpsException"/>
87+
/// Checks if an exception is of type <see cref="AzureDevOpsException"/>.
7488
/// </summary>
7589
/// <param name="exception">Exception to check.</param>
7690
public static void IsAzureDevOpsException(this Exception exception)
@@ -79,7 +93,7 @@ public static void IsAzureDevOpsException(this Exception exception)
7993
}
8094

8195
/// <summary>
82-
/// Checks if an exception is of type <see cref="AzureDevOpsBranchNotFoundException"/>
96+
/// Checks if an exception is of type <see cref="AzureDevOpsBranchNotFoundException"/>.
8397
/// </summary>
8498
/// <param name="exception">Exception to check.</param>
8599
/// <param name="message">Exception message which should be checked.</param>

src/Cake.AzureDevOps.Tests/Repos/PullRequest/AzureDevOpsPullRequestTests.cs

Lines changed: 52 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace Cake.AzureDevOps.Tests.Repos.PullRequest
22
{
3+
using System;
34
using System.Collections.Generic;
45
using System.Linq;
56
using Cake.AzureDevOps.Repos.PullRequest;
@@ -767,97 +768,115 @@ public void Should_Return_Valid_Comment_Threads()
767768

768769
public sealed class TheCreateCommentMethod
769770
{
770-
[Fact]
771-
public void Should_Throw_If_Comment_Is_Null()
771+
[Theory]
772+
[InlineData((string)null, typeof(ArgumentNullException))]
773+
[InlineData("", typeof(ArgumentOutOfRangeException))]
774+
[InlineData(" ", typeof(ArgumentOutOfRangeException))]
775+
public void Should_Throw_If_Comment_Is_Null_Or_Empty_Or_Whitespace(string comment, Type expectedExceptionType)
772776
{
773777
// Given
774778
var fixture = new PullRequestFixture(BasePullRequestFixture.ValidAzureDevOpsServerUrl, 100);
775779
var pullRequest = new AzureDevOpsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory);
776780

777781
// When
778-
var result = Record.Exception(() => pullRequest.CreateComment(null));
782+
var result = Record.Exception(() => pullRequest.CreateComment(comment)) as ArgumentException;
779783

780784
// Then
781-
result.IsArgumentNullException("comment");
785+
result.ShouldNotBeNull();
786+
result.IsArgumentException(expectedExceptionType, "comment");
782787
}
783788

784789
[Fact]
785-
public void Should_Throw_If_Comment_Is_Empty()
790+
public void Should_Return_Null_If_Null_Is_Returned_From_Git_Client()
786791
{
787792
// Given
788-
var fixture = new PullRequestFixture(BasePullRequestFixture.ValidAzureDevOpsServerUrl, 100);
793+
var fixture = new PullRequestFixture(BasePullRequestFixture.ValidAzureDevOpsServerUrl, 100)
794+
{
795+
GitClientFactory = new FakeNullForMethodsGitClientFactory(),
796+
};
789797
var pullRequest = new AzureDevOpsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory);
790798

791799
// When
792-
var result = Record.Exception(() => pullRequest.CreateComment(string.Empty));
800+
var thread = pullRequest.CreateComment("Foo");
793801

794802
// Then
795-
result.IsArgumentOutOfRangeException("comment");
803+
thread.ShouldBeNull();
796804
}
797805

798806
[Fact]
799-
public void Should_Throw_If_Comment_Is_Whitespace()
807+
public void Should_Create_Valid_Thread_With_One_Comment()
800808
{
801809
// Given
802810
var fixture = new PullRequestFixture(BasePullRequestFixture.ValidAzureDevOpsServerUrl, 100);
803811
var pullRequest = new AzureDevOpsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory);
804812

805813
// When
806-
var result = Record.Exception(() => pullRequest.CreateComment(" "));
814+
var thread = pullRequest.CreateComment("Valid");
807815

808816
// Then
809-
result.IsArgumentOutOfRangeException("comment");
817+
thread.ShouldNotBeNull();
818+
thread.Status.ShouldBe(AzureDevOpsCommentThreadStatus.Active);
819+
thread.Comments.ShouldNotBeNull();
820+
thread.Comments.Count().ShouldBe(1);
821+
822+
var comment = thread.Comments.First();
823+
comment.CommentType.ShouldBe(AzureDevOpsCommentType.System);
824+
comment.IsDeleted.ShouldBeFalse();
825+
comment.Content.ShouldBe("Valid");
810826
}
827+
}
811828

829+
public sealed class TheCreateCommentThreadMethod
830+
{
812831
[Fact]
813-
public void Should_Not_Throw_If_Null_Is_Returned()
832+
public void Should_Throw_If_Input_Thread_Is_Null()
814833
{
815834
// Given
816-
var fixture = new PullRequestFixture(BasePullRequestFixture.ValidAzureDevOpsServerUrl, 100)
817-
{
818-
GitClientFactory = new FakeNullForMethodsGitClientFactory(),
819-
};
835+
var fixture = new PullRequestFixture(BasePullRequestFixture.ValidAzureDevOpsServerUrl, 100);
820836
var pullRequest = new AzureDevOpsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory);
821837

822838
// When
823-
pullRequest.CreateComment("Foo");
839+
var result = Record.Exception(() => pullRequest.CreateCommentThread(null));
824840

825841
// Then
826-
// ?? Nothing to validate here since the method returns void
842+
result.IsArgumentNullException("thread");
827843
}
828-
}
829844

830-
public sealed class TheCreateCommentThreadMethod
831-
{
832845
[Fact]
833-
public void Should_Throw_If_Input_Thread_Is_Null()
846+
public void Should_Return_Null_If_Pull_Request_Is_Invalid()
834847
{
835848
// Given
836-
var fixture = new PullRequestFixture(BasePullRequestFixture.ValidAzureDevOpsServerUrl, 100);
849+
var fixture = new PullRequestFixture(BasePullRequestFixture.ValidAzureDevOpsServerUrl, 100)
850+
{
851+
GitClientFactory = new FakeNullGitClientFactory(),
852+
};
853+
fixture.Settings.ThrowExceptionIfPullRequestCouldNotBeFound = false;
854+
837855
var pullRequest = new AzureDevOpsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory);
838856

839857
// When
840-
var result = Record.Exception(() => pullRequest.CreateCommentThread(null));
858+
var outThread = pullRequest.CreateCommentThread(new AzureDevOpsPullRequestCommentThread());
841859

842860
// Then
843-
result.IsArgumentNullException("thread");
861+
outThread.ShouldBeNull();
844862
}
845863

846864
[Fact]
847-
public void Should_Not_Throw_If_Null_Is_Returned()
865+
public void Should_Return_Null_If_Null_Is_Returned_From_Git_Client()
848866
{
849867
// Given
850868
var fixture = new PullRequestFixture(BasePullRequestFixture.ValidAzureDevOpsServerUrl, 100)
851869
{
852870
GitClientFactory = new FakeNullForMethodsGitClientFactory(),
853871
};
872+
854873
var pullRequest = new AzureDevOpsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory);
855874

856875
// When
857-
pullRequest.CreateCommentThread(new AzureDevOpsPullRequestCommentThread());
876+
var outThread = pullRequest.CreateCommentThread(new AzureDevOpsPullRequestCommentThread());
858877

859878
// Then
860-
// ?? Nothing to validate here since the method returns void
879+
outThread.ShouldBeNull();
861880
}
862881

863882
[Fact]
@@ -866,12 +885,15 @@ public void Should_Create_Valid_Comment_Thread()
866885
// Given
867886
var fixture = new PullRequestFixture(BasePullRequestFixture.ValidAzureDevOpsUrl, 200);
868887
var pullRequest = new AzureDevOpsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory);
888+
var inThread = new AzureDevOpsPullRequestCommentThread { Id = 300, Status = AzureDevOpsCommentThreadStatus.Pending, FilePath = "/index.html" };
869889

870890
// When
871-
pullRequest.CreateCommentThread(new AzureDevOpsPullRequestCommentThread { Id = 300, Status = AzureDevOpsCommentThreadStatus.Pending, FilePath = "/index.html" });
891+
var outThread = pullRequest.CreateCommentThread(inThread);
872892

873893
// Then
874-
// ?? Nothing to validate here since the method returns void
894+
outThread.Id.ShouldBe(inThread.Id);
895+
outThread.Status.ShouldBe(inThread.Status);
896+
outThread.FilePath.ShouldBeEquivalentTo(inThread.FilePath);
875897
}
876898
}
877899

src/Cake.AzureDevOps/AzureDevOpsAliases.Pipelines.cs

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,42 @@ public static AzureDevOpsBuild AzureDevOpsBuildUsingAzurePipelinesOAuthToken(
8989
return AzureDevOpsBuild(context, settings);
9090
}
9191

92+
/// <summary>
93+
/// Gets the description of the Azure Pipelines build which is running.
94+
/// Make sure the build has the 'Allow Scripts to access OAuth token' option enabled.
95+
/// </summary>
96+
/// <param name="context">The context.</param>
97+
/// <param name="throwExceptionIfBuildCouldNotBeFound">Value indicating whether an exception
98+
/// should be thrown if build could not be found.</param>
99+
/// <example>
100+
/// <para>Get current Azure Pipelines build. Don't throw exception in case the build is not found:</para>
101+
/// <code>
102+
/// <![CDATA[
103+
/// var build =
104+
/// AzureDevOpsBuildUsingAzurePipelinesOAuthToken(false);
105+
/// ]]>
106+
/// </code>
107+
/// </example>
108+
/// <returns>Description of the build.
109+
/// Returns <c>null</c> if build could not be found and
110+
/// <paramref name="throwExceptionIfBuildCouldNotBeFound"/> is set to <c>false</c>.</returns>
111+
/// <exception cref="AzureDevOpsBuildNotFoundException">If build could not be found and
112+
/// <paramref name="throwExceptionIfBuildCouldNotBeFound"/> is set to <c>true</c>.</exception>
113+
[CakeMethodAlias]
114+
[CakeAliasCategory("Azure Pipelines")]
115+
[CakeNamespaceImport("Cake.AzureDevOps.Pipelines")]
116+
public static AzureDevOpsBuild AzureDevOpsBuildUsingAzurePipelinesOAuthToken(
117+
this ICakeContext context,
118+
bool throwExceptionIfBuildCouldNotBeFound)
119+
{
120+
context.NotNull(nameof(context));
121+
122+
var settings = AzureDevOpsBuildSettings.UsingAzurePipelinesOAuthToken();
123+
settings.ThrowExceptionIfBuildCouldNotBeFound = throwExceptionIfBuildCouldNotBeFound;
124+
125+
return AzureDevOpsBuild(context, settings);
126+
}
127+
92128
/// <summary>
93129
/// Gets the description of a specific build which is running the access token provided by Azure Pipelines.
94130
/// Make sure the build has the 'Allow Scripts to access OAuth token' option enabled.
@@ -100,7 +136,7 @@ public static AzureDevOpsBuild AzureDevOpsBuildUsingAzurePipelinesOAuthToken(
100136
/// <code>
101137
/// <![CDATA[
102138
/// var build =
103-
/// AzureDevOpsBuildUsingAzurePipelinesOAuthToken();
139+
/// AzureDevOpsBuildUsingAzurePipelinesOAuthToken(42);
104140
/// ]]>
105141
/// </code>
106142
/// </example>
@@ -124,6 +160,45 @@ public static AzureDevOpsBuild AzureDevOpsBuildUsingAzurePipelinesOAuthToken(
124160
return AzureDevOpsBuild(context, settings);
125161
}
126162

163+
/// <summary>
164+
/// Gets the description of a specific build which is running the access token provided by Azure Pipelines.
165+
/// Make sure the build has the 'Allow Scripts to access OAuth token' option enabled.
166+
/// </summary>
167+
/// <param name="context">The context.</param>
168+
/// <param name="buildId">ID of the build.</param>
169+
/// <param name="throwExceptionIfBuildCouldNotBeFound">Value indicating whether an exception
170+
/// should be thrown if build could not be found.</param>
171+
/// <example>
172+
/// <para>Get an Azure Pipelines build. Don't throw exception in case the build is not found:</para>
173+
/// <code>
174+
/// <![CDATA[
175+
/// var build =
176+
/// AzureDevOpsBuildUsingAzurePipelinesOAuthToken(42, false);
177+
/// ]]>
178+
/// </code>
179+
/// </example>
180+
/// <returns>Description of the build.
181+
/// Returns <c>null</c> if build could not be found and
182+
/// <paramref name="throwExceptionIfBuildCouldNotBeFound"/> is set to <c>false</c>.</returns>
183+
/// <exception cref="AzureDevOpsBuildNotFoundException">If build could not be found and
184+
/// <paramref name="throwExceptionIfBuildCouldNotBeFound"/> is set to <c>true</c>.</exception>
185+
[CakeMethodAlias]
186+
[CakeAliasCategory("Azure Pipelines")]
187+
[CakeNamespaceImport("Cake.AzureDevOps.Pipelines")]
188+
public static AzureDevOpsBuild AzureDevOpsBuildUsingAzurePipelinesOAuthToken(
189+
this ICakeContext context,
190+
int buildId,
191+
bool throwExceptionIfBuildCouldNotBeFound)
192+
{
193+
context.NotNull(nameof(context));
194+
buildId.NotNegativeOrZero(nameof(buildId));
195+
196+
var settings = AzureDevOpsBuildSettings.UsingAzurePipelinesOAuthToken(buildId);
197+
settings.ThrowExceptionIfBuildCouldNotBeFound = throwExceptionIfBuildCouldNotBeFound;
198+
199+
return AzureDevOpsBuild(context, settings);
200+
}
201+
127202
/// <summary>
128203
/// Gets Azure Pipelines builds using the specified settings.
129204
/// </summary>

src/Cake.AzureDevOps/Cake.AzureDevOps.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<PackageLicenseExpression>MIT</PackageLicenseExpression>
2323
<RepositoryType>git</RepositoryType>
2424
<RepositoryUrl>https://github.com/cake-contrib/Cake.AzureDevOps.git</RepositoryUrl>
25-
<PackageReleaseNotes>https://github.com/cake-contrib/Cake.AzureDevOps/releases/tag/1.0.0</PackageReleaseNotes>
25+
<PackageReleaseNotes>https://github.com/cake-contrib/Cake.AzureDevOps/releases/tag/1.1.0</PackageReleaseNotes>
2626
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
2727
<IncludeBuildOutput>false</IncludeBuildOutput>
2828
<TargetsForTfmSpecificContentInPackage>$(TargetsForTfmSpecificContentInPackage);PackBuildOutputs</TargetsForTfmSpecificContentInPackage>

0 commit comments

Comments
 (0)