diff --git a/nuspec/nuget/Cake.Tfs.nuspec b/nuspec/nuget/Cake.Tfs.nuspec index 32476fa9..8f1266e4 100644 --- a/nuspec/nuget/Cake.Tfs.nuspec +++ b/nuspec/nuget/Cake.Tfs.nuspec @@ -17,7 +17,7 @@ Copyright © Pascal Berger Cake Script Team-Foundation-Server TFS Azure-DevOps - https://github.com/cake-contrib/Cake.Tfs/releases/tag/0.2.6 + https://github.com/cake-contrib/Cake.Tfs/releases/tag/0.2.7 diff --git a/src/Cake.Tfs.Tests/Cake.Tfs.Tests.csproj b/src/Cake.Tfs.Tests/Cake.Tfs.Tests.csproj index f4da739e..75c78ef3 100644 --- a/src/Cake.Tfs.Tests/Cake.Tfs.Tests.csproj +++ b/src/Cake.Tfs.Tests/Cake.Tfs.Tests.csproj @@ -14,7 +14,7 @@ - + diff --git a/src/Cake.Tfs.Tests/PullRequest/CommentThread/TfsPullRequestCommentThreadTests.cs b/src/Cake.Tfs.Tests/PullRequest/CommentThread/TfsPullRequestCommentThreadTests.cs index f9e07fdd..85496346 100644 --- a/src/Cake.Tfs.Tests/PullRequest/CommentThread/TfsPullRequestCommentThreadTests.cs +++ b/src/Cake.Tfs.Tests/PullRequest/CommentThread/TfsPullRequestCommentThreadTests.cs @@ -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("key")); + var result = tfsThread.GetValue("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("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("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("key"); + + // Then + result.ShouldBe(default(int)); } [Fact] diff --git a/src/Cake.Tfs/Cake.Tfs.csproj b/src/Cake.Tfs/Cake.Tfs.csproj index 51311a7d..eefec70a 100644 --- a/src/Cake.Tfs/Cake.Tfs.csproj +++ b/src/Cake.Tfs/Cake.Tfs.csproj @@ -23,8 +23,8 @@ - - + + diff --git a/src/Cake.Tfs/PullRequest/CommentThread/TfsPullRequestCommentThread.cs b/src/Cake.Tfs/PullRequest/CommentThread/TfsPullRequestCommentThread.cs index 09fd3a0f..aa4f8547 100644 --- a/src/Cake.Tfs/PullRequest/CommentThread/TfsPullRequestCommentThread.cs +++ b/src/Cake.Tfs/PullRequest/CommentThread/TfsPullRequestCommentThread.cs @@ -119,14 +119,14 @@ public IDictionary Properties /// /// Type of the value. /// Name of the property. - /// Value of the property. + /// Value of the property or default value for if property does not exist. public T GetValue(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)); @@ -138,6 +138,7 @@ public T GetValue(string propertyName) /// Type of the value. /// Name of the property. /// Value to set. + /// If properties collection is not created. public void SetValue(string propertyName, T value) { propertyName.NotNullOrWhiteSpace(nameof(propertyName)); diff --git a/src/Cake.Tfs/TfsAliases.Authentication.cs b/src/Cake.Tfs/TfsAliases.Authentication.cs index 75c232d2..4692a07d 100644 --- a/src/Cake.Tfs/TfsAliases.Authentication.cs +++ b/src/Cake.Tfs/TfsAliases.Authentication.cs @@ -7,7 +7,6 @@ /// /// Contains functionality related to authenticating to Team Foundation Server or Azure DevOps. /// - [CakeNamespaceImport("Cake.Tfs.Authentication")] public static partial class TfsAliases { /// @@ -18,6 +17,7 @@ public static partial class TfsAliases /// Credentials for integrated / NTLM authentication [CakeMethodAlias] [CakeAliasCategory("Authentication")] + [CakeNamespaceImport("Cake.Tfs.Authentication")] public static ITfsCredentials TfsAuthenticationNtlm( this ICakeContext context) { @@ -37,6 +37,7 @@ public static ITfsCredentials TfsAuthenticationNtlm( /// Credentials for basic authentication. [CakeMethodAlias] [CakeAliasCategory("Authentication")] + [CakeNamespaceImport("Cake.Tfs.Authentication")] public static ITfsCredentials TfsAuthenticationBasic( this ICakeContext context, string userName, @@ -58,6 +59,7 @@ public static ITfsCredentials TfsAuthenticationBasic( /// Credentials for authentication with a personal access token. [CakeMethodAlias] [CakeAliasCategory("Authentication")] + [CakeNamespaceImport("Cake.Tfs.Authentication")] public static ITfsCredentials TfsAuthenticationPersonalAccessToken( this ICakeContext context, string personalAccessToken) @@ -77,6 +79,7 @@ public static ITfsCredentials TfsAuthenticationPersonalAccessToken( /// Credentials for OAuth authentication. [CakeMethodAlias] [CakeAliasCategory("Authentication")] + [CakeNamespaceImport("Cake.Tfs.Authentication")] public static ITfsCredentials TfsAuthenticationOAuth( this ICakeContext context, string accessToken) @@ -97,6 +100,7 @@ public static ITfsCredentials TfsAuthenticationOAuth( /// Credentials for authentication with an Azure Active Directory. [CakeMethodAlias] [CakeAliasCategory("Authentication")] + [CakeNamespaceImport("Cake.Tfs.Authentication")] public static ITfsCredentials TfsAuthenticationAzureActiveDirectory( this ICakeContext context, string userName, diff --git a/src/Cake.Tfs/TfsAliases.PullRequest.cs b/src/Cake.Tfs/TfsAliases.PullRequest.cs index 3acc7575..4c91e1cc 100644 --- a/src/Cake.Tfs/TfsAliases.PullRequest.cs +++ b/src/Cake.Tfs/TfsAliases.PullRequest.cs @@ -8,7 +8,6 @@ /// /// Contains functionality related to Team Foundation Server or Azure DevOps pull requests. /// - [CakeNamespaceImport("Cake.Tfs.PullRequest")] public static partial class TfsAliases { /// @@ -39,6 +38,8 @@ public static partial class TfsAliases /// is set to true. [CakeMethodAlias] [CakeAliasCategory("Pull Request")] + [CakeNamespaceImport("Cake.Tfs.PullRequest")] + [CakeNamespaceImport("Cake.Tfs.PullRequest.CommentThread")] public static TfsPullRequest TfsPullRequest( this ICakeContext context, TfsPullRequestSettings settings) @@ -80,6 +81,8 @@ public static TfsPullRequest TfsPullRequest( /// 'Allow Scripts to access OAuth token' option is not enabled on the build definition. [CakeMethodAlias] [CakeAliasCategory("Pull Request")] + [CakeNamespaceImport("Cake.Tfs.PullRequest")] + [CakeNamespaceImport("Cake.Tfs.PullRequest.CommentThread")] public static TfsPullRequest TfsPullRequestUsingTfsBuildOAuthToken( this ICakeContext context) { @@ -117,6 +120,8 @@ public static TfsPullRequest TfsPullRequestUsingTfsBuildOAuthToken( /// is set to true. [CakeMethodAlias] [CakeAliasCategory("Pull Request")] + [CakeNamespaceImport("Cake.Tfs.PullRequest")] + [CakeNamespaceImport("Cake.Tfs.PullRequest.CommentThread")] public static void TfsVotePullRequest( this ICakeContext context, TfsPullRequestSettings settings, @@ -163,6 +168,8 @@ public static void TfsVotePullRequest( /// is set to true. [CakeMethodAlias] [CakeAliasCategory("Pull Request")] + [CakeNamespaceImport("Cake.Tfs.PullRequest")] + [CakeNamespaceImport("Cake.Tfs.PullRequest.CommentThread")] public static void TfsSetPullRequestStatus( this ICakeContext context, TfsPullRequestSettings settings, @@ -203,6 +210,8 @@ public static void TfsSetPullRequestStatus( /// If the target branch could not be found. [CakeMethodAlias] [CakeAliasCategory("Pull Request")] + [CakeNamespaceImport("Cake.Tfs.PullRequest")] + [CakeNamespaceImport("Cake.Tfs.PullRequest.CommentThread")] public static TfsPullRequest TfsCreatePullRequest( this ICakeContext context, TfsCreatePullRequestSettings settings)