Skip to content

Commit

Permalink
Merge branch 'release/0.2.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalberger committed Mar 31, 2019
2 parents a439220 + 08b38d2 commit 08ef159
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 11 deletions.
2 changes: 1 addition & 1 deletion nuspec/nuget/Cake.Tfs.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<repository type="git" url="https://github.com/cake-contrib/Cake.Tfs"/>
<copyright>Copyright © Pascal Berger</copyright>
<tags>Cake Script Team-Foundation-Server TFS Azure-DevOps</tags>
<releaseNotes>https://github.com/cake-contrib/Cake.Tfs/releases/tag/0.2.6</releaseNotes>
<releaseNotes>https://github.com/cake-contrib/Cake.Tfs/releases/tag/0.2.7</releaseNotes>
</metadata>
<files>
<file src="net461\Cake.Tfs.dll" target="lib\net461" />
Expand Down
2 changes: 1 addition & 1 deletion src/Cake.Tfs.Tests/Cake.Tfs.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" />
<PackageReference Include="Cake.Core" Version="0.28.0" />
<PackageReference Include="Cake.Testing" Version="0.28.0" />
<PackageReference Include="Moq" Version="4.10.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,16 +259,67 @@ public void Should_Throw_If_Property_Name_Is_Empty()
}

[Fact]
public void Should_Throw_If_Property_Collection_Is_Null()
public void Should_Return_Default_Value_If_Property_Collection_Is_Null_For_String_Value()
{
// Given
var tfsThread = new TfsPullRequestCommentThread();

// When
var result = Record.Exception(() => tfsThread.GetValue<int>("key"));
var result = tfsThread.GetValue<string>("key");

// Then
result.IsInvalidOperationException();
result.ShouldBe(default(string));
}

[Fact]
public void Should_Return_Default_Value_If_Property_Collection_Is_Null_For_Integer_Value()
{
// Given
var tfsThread = new TfsPullRequestCommentThread();

// When
var result = tfsThread.GetValue<int>("key");

// Then
result.ShouldBe(default(int));
}

[Fact]
public void Should_Return_Default_Value_If_Property_Does_Not_Exist_For_String_Value()
{
// Given
var tfsThread = new TfsPullRequestCommentThread(
new GitPullRequestCommentThread
{
Id = 42,
Status = CommentThreadStatus.Active,
Properties = new PropertiesCollection()
});

// When
var result = tfsThread.GetValue<string>("key");

// Then
result.ShouldBe(default(string));
}

[Fact]
public void Should_Return_Default_Value_If_Property_Does_Not_Exist_For_Int_Value()
{
// Given
var tfsThread = new TfsPullRequestCommentThread(
new GitPullRequestCommentThread
{
Id = 42,
Status = CommentThreadStatus.Active,
Properties = new PropertiesCollection()
});

// When
var result = tfsThread.GetValue<int>("key");

// Then
result.ShouldBe(default(int));
}

[Fact]
Expand Down
4 changes: 2 additions & 2 deletions src/Cake.Tfs/Cake.Tfs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

<ItemGroup>
<PackageReference Include="Cake.Core" Version="0.28.0" />
<PackageReference Include="Costura.Fody" Version="3.3.2" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.6.3" />
<PackageReference Include="Costura.Fody" Version="3.3.3" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.1" />
<PackageReference Include="Microsoft.TeamFoundationServer.Client" Version="15.131.1" />
<PackageReference Include="Microsoft.VisualStudio.Services.InteractiveClient" Version="15.131.1" />
<PackageReference Include="StyleCop.Analyzers" Version="1.0.2" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,14 @@ public IDictionary<string, object> Properties
/// </summary>
/// <typeparam name="T">Type of the value.</typeparam>
/// <param name="propertyName">Name of the property.</param>
/// <returns>Value of the property.</returns>
/// <returns>Value of the property or default value for <typeparamref name="T"/> if property does not exist.</returns>
public T GetValue<T>(string propertyName)
{
propertyName.NotNullOrWhiteSpace(nameof(propertyName));

if (this.thread.Properties == null)
{
throw new InvalidOperationException("Properties collection is not created.");
return default(T);
}

return this.thread.Properties.GetValue(propertyName, default(T));
Expand All @@ -138,6 +138,7 @@ public T GetValue<T>(string propertyName)
/// <typeparam name="T">Type of the value.</typeparam>
/// <param name="propertyName">Name of the property.</param>
/// <param name="value">Value to set.</param>
/// <exception cref="InvalidOperationException">If properties collection is not created.</exception>
public void SetValue<T>(string propertyName, T value)
{
propertyName.NotNullOrWhiteSpace(nameof(propertyName));
Expand Down
6 changes: 5 additions & 1 deletion src/Cake.Tfs/TfsAliases.Authentication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
/// <content>
/// Contains functionality related to authenticating to Team Foundation Server or Azure DevOps.
/// </content>
[CakeNamespaceImport("Cake.Tfs.Authentication")]
public static partial class TfsAliases
{
/// <summary>
Expand All @@ -18,6 +17,7 @@ public static partial class TfsAliases
/// <returns>Credentials for integrated / NTLM authentication</returns>
[CakeMethodAlias]
[CakeAliasCategory("Authentication")]
[CakeNamespaceImport("Cake.Tfs.Authentication")]
public static ITfsCredentials TfsAuthenticationNtlm(
this ICakeContext context)
{
Expand All @@ -37,6 +37,7 @@ public static ITfsCredentials TfsAuthenticationNtlm(
/// <returns>Credentials for basic authentication.</returns>
[CakeMethodAlias]
[CakeAliasCategory("Authentication")]
[CakeNamespaceImport("Cake.Tfs.Authentication")]
public static ITfsCredentials TfsAuthenticationBasic(
this ICakeContext context,
string userName,
Expand All @@ -58,6 +59,7 @@ public static ITfsCredentials TfsAuthenticationBasic(
/// <returns>Credentials for authentication with a personal access token.</returns>
[CakeMethodAlias]
[CakeAliasCategory("Authentication")]
[CakeNamespaceImport("Cake.Tfs.Authentication")]
public static ITfsCredentials TfsAuthenticationPersonalAccessToken(
this ICakeContext context,
string personalAccessToken)
Expand All @@ -77,6 +79,7 @@ public static ITfsCredentials TfsAuthenticationPersonalAccessToken(
/// <returns>Credentials for OAuth authentication.</returns>
[CakeMethodAlias]
[CakeAliasCategory("Authentication")]
[CakeNamespaceImport("Cake.Tfs.Authentication")]
public static ITfsCredentials TfsAuthenticationOAuth(
this ICakeContext context,
string accessToken)
Expand All @@ -97,6 +100,7 @@ public static ITfsCredentials TfsAuthenticationOAuth(
/// <returns>Credentials for authentication with an Azure Active Directory.</returns>
[CakeMethodAlias]
[CakeAliasCategory("Authentication")]
[CakeNamespaceImport("Cake.Tfs.Authentication")]
public static ITfsCredentials TfsAuthenticationAzureActiveDirectory(
this ICakeContext context,
string userName,
Expand Down
11 changes: 10 additions & 1 deletion src/Cake.Tfs/TfsAliases.PullRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
/// <content>
/// Contains functionality related to Team Foundation Server or Azure DevOps pull requests.
/// </content>
[CakeNamespaceImport("Cake.Tfs.PullRequest")]
public static partial class TfsAliases
{
/// <summary>
Expand Down Expand Up @@ -39,6 +38,8 @@ public static partial class TfsAliases
/// <see cref="TfsPullRequestSettings.ThrowExceptionIfPullRequestCouldNotBeFound"/> is set to <c>true</c>.</exception>
[CakeMethodAlias]
[CakeAliasCategory("Pull Request")]
[CakeNamespaceImport("Cake.Tfs.PullRequest")]
[CakeNamespaceImport("Cake.Tfs.PullRequest.CommentThread")]
public static TfsPullRequest TfsPullRequest(
this ICakeContext context,
TfsPullRequestSettings settings)
Expand Down Expand Up @@ -80,6 +81,8 @@ public static TfsPullRequest TfsPullRequest(
/// 'Allow Scripts to access OAuth token' option is not enabled on the build definition.</exception>
[CakeMethodAlias]
[CakeAliasCategory("Pull Request")]
[CakeNamespaceImport("Cake.Tfs.PullRequest")]
[CakeNamespaceImport("Cake.Tfs.PullRequest.CommentThread")]
public static TfsPullRequest TfsPullRequestUsingTfsBuildOAuthToken(
this ICakeContext context)
{
Expand Down Expand Up @@ -117,6 +120,8 @@ public static TfsPullRequest TfsPullRequestUsingTfsBuildOAuthToken(
/// <see cref="TfsPullRequestSettings.ThrowExceptionIfPullRequestCouldNotBeFound"/> is set to <c>true</c>.</exception>
[CakeMethodAlias]
[CakeAliasCategory("Pull Request")]
[CakeNamespaceImport("Cake.Tfs.PullRequest")]
[CakeNamespaceImport("Cake.Tfs.PullRequest.CommentThread")]
public static void TfsVotePullRequest(
this ICakeContext context,
TfsPullRequestSettings settings,
Expand Down Expand Up @@ -163,6 +168,8 @@ public static void TfsVotePullRequest(
/// <see cref="TfsPullRequestSettings.ThrowExceptionIfPullRequestCouldNotBeFound"/> is set to <c>true</c>.</exception>
[CakeMethodAlias]
[CakeAliasCategory("Pull Request")]
[CakeNamespaceImport("Cake.Tfs.PullRequest")]
[CakeNamespaceImport("Cake.Tfs.PullRequest.CommentThread")]
public static void TfsSetPullRequestStatus(
this ICakeContext context,
TfsPullRequestSettings settings,
Expand Down Expand Up @@ -203,6 +210,8 @@ public static void TfsSetPullRequestStatus(
/// <exception cref="TfsBranchNotFoundException">If the target branch could not be found.</exception>
[CakeMethodAlias]
[CakeAliasCategory("Pull Request")]
[CakeNamespaceImport("Cake.Tfs.PullRequest")]
[CakeNamespaceImport("Cake.Tfs.PullRequest.CommentThread")]
public static TfsPullRequest TfsCreatePullRequest(
this ICakeContext context,
TfsCreatePullRequestSettings settings)
Expand Down

0 comments on commit 08ef159

Please sign in to comment.