Skip to content

Commit

Permalink
Merge branch 'release/0.5.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalberger committed Aug 21, 2020
2 parents 438f7d7 + 4396c63 commit eb5a2c1
Show file tree
Hide file tree
Showing 54 changed files with 1,166 additions and 263 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace Cake.AzureDevOps
{
using System;
using Cake.AzureDevOps.Authentication;

public class BaseAzureDevOpsCollectionSettingsImpl : BaseAzureDevOpsCollectionSettings
{
public BaseAzureDevOpsCollectionSettingsImpl(Uri collectionUrl, IAzureDevOpsCredentials credentials)
: base(collectionUrl, credentials)
{
}

public BaseAzureDevOpsCollectionSettingsImpl(BaseAzureDevOpsCollectionSettings settings)
: base(settings)
{
}

public BaseAzureDevOpsCollectionSettingsImpl(IAzureDevOpsCredentials credentials)
: base(credentials)
{
}
}
}
216 changes: 216 additions & 0 deletions src/Cake.AzureDevOps.Tests/BaseAzureDevOpsCollectionSettingsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
namespace Cake.AzureDevOps.Tests
{
using System;
using Cake.AzureDevOps.Authentication;
using Shouldly;
using Xunit;

public sealed class BaseAzureDevOpsCollectionSettingsTests
{
public sealed class TheCtor
{
public sealed class WithCollectionUrlAndCredentialsParameter
{
[Fact]
public void Should_Throw_If_CollectionUrl_Is_Null()
{
// Given
Uri collectionUrl = null;
var credentials = AuthenticationProvider.AuthenticationNtlm();

// When
var result = Record.Exception(() => new BaseAzureDevOpsCollectionSettingsImpl(collectionUrl, credentials));

// Then
result.IsArgumentNullException("collectionUrl");
}

[Fact]
public void Should_Throw_If_Credentials_Are_Null()
{
// Given
var collectionUrl = new Uri("http://example.com/collection");
IAzureDevOpsCredentials credentials = null;

// When
var result = Record.Exception(() => new BaseAzureDevOpsCollectionSettingsImpl(collectionUrl, credentials));

// Then
result.IsArgumentNullException("credentials");
}

[Fact]
public void Should_Set_Credentials()
{
// Given
var collectionUrl = new Uri("http://example.com/collection");
var credentials = AuthenticationProvider.AuthenticationNtlm();

// When
var result = new BaseAzureDevOpsCollectionSettingsImpl(collectionUrl, credentials);

// Then
result.Credentials.ShouldBe(credentials);
}

[Fact]
public void Should_Set_Collection_Url()
{
// Given
var collectionUrl = new Uri("http://example.com/collection");
var credentials = AuthenticationProvider.AuthenticationNtlm();

// When
var result = new BaseAzureDevOpsCollectionSettingsImpl(collectionUrl, credentials);

// Then
result.CollectionUrl.ShouldBe(collectionUrl);
}
}

public sealed class WithSettingsParameter
{
[Fact]
public void Should_Throw_If_Settings_Are_Null()
{
// Given
BaseAzureDevOpsCollectionSettingsImpl settings = null;

// When
var result = Record.Exception(() => new BaseAzureDevOpsCollectionSettingsImpl(settings));

// Then
result.IsArgumentNullException("settings");
}

[Fact]
public void Should_Set_Credentials()
{
// Given
var collectionUrl = new Uri("http://example.com/collection");
var credentials = AuthenticationProvider.AuthenticationNtlm();
var settings = new BaseAzureDevOpsCollectionSettingsImpl(collectionUrl, credentials);

// When
var result = new BaseAzureDevOpsCollectionSettingsImpl(settings);

// Then
result.Credentials.ShouldBe(credentials);
}

[Fact]
public void Should_Set_CollectionUrl()
{
// Given
var collectionUrl = new Uri("http://example.com/collection");
var credentials = AuthenticationProvider.AuthenticationNtlm();
var settings = new BaseAzureDevOpsCollectionSettingsImpl(collectionUrl, credentials);

// When
var result = new BaseAzureDevOpsCollectionSettingsImpl(settings);

// Then
result.CollectionUrl.ShouldBe(collectionUrl);
}
}

public sealed class WithCredentialsParameter : IDisposable
{
private readonly string originalCollectionUrl;

public WithCredentialsParameter()
{
this.originalCollectionUrl = Environment.GetEnvironmentVariable("SYSTEM_TEAMFOUNDATIONCOLLECTIONURI");
}

[Fact]
public void Should_Throw_If_Credentials_Are_Null()
{
// Given
IAzureDevOpsCredentials credentials = null;

// When
var result = Record.Exception(() => new BaseAzureDevOpsCollectionSettingsImpl(credentials));

// Then
result.IsArgumentNullException("credentials");
}

[Fact]
public void Should_Throw_If_Collection_Url_Env_Var_Is_Not_Set()
{
// Given
var credentials = new AzureDevOpsNtlmCredentials();
Environment.SetEnvironmentVariable("SYSTEM_TEAMFOUNDATIONCOLLECTIONURI", null);

// When
var result = Record.Exception(() => new BaseAzureDevOpsCollectionSettingsImpl(credentials));

// Then
result.IsInvalidOperationException();
}

[Fact]
public void Should_Throw_If_Collection_Url_Env_Var_Is_Empty()
{
// Given
var credentials = new AzureDevOpsNtlmCredentials();
Environment.SetEnvironmentVariable("SYSTEM_TEAMFOUNDATIONCOLLECTIONURI", string.Empty);

// When
var result = Record.Exception(() => new BaseAzureDevOpsCollectionSettingsImpl(credentials));

// Then
result.IsInvalidOperationException();
}

[Fact]
public void Should_Throw_If_Collection_Url_Env_Var_Is_WhiteSpace()
{
// Given
var credentials = new AzureDevOpsNtlmCredentials();
Environment.SetEnvironmentVariable("SYSTEM_TEAMFOUNDATIONCOLLECTIONURI", " ");

// When
var result = Record.Exception(() => new BaseAzureDevOpsCollectionSettingsImpl(credentials));

// Then
result.IsInvalidOperationException();
}

[Fact]
public void Should_Set_Credentials()
{
// Given
var credentials = new AzureDevOpsNtlmCredentials();
Environment.SetEnvironmentVariable("SYSTEM_TEAMFOUNDATIONCOLLECTIONURI", "https://example.com/collection");

// When
var settings = new BaseAzureDevOpsCollectionSettingsImpl(credentials);

// Then
settings.Credentials.ShouldBe(credentials);
}

[Fact]
public void Should_Set_Collection_Url()
{
// Given
var credentials = new AzureDevOpsNtlmCredentials();
Environment.SetEnvironmentVariable("SYSTEM_TEAMFOUNDATIONCOLLECTIONURI", "https://example.com/collection");

// When
var settings = new BaseAzureDevOpsCollectionSettingsImpl(credentials);

// Then
settings.CollectionUrl.ToString().ShouldBe(new Uri("https://example.com/collection").ToString());
}

public void Dispose()
{
Environment.SetEnvironmentVariable("SYSTEM_TEAMFOUNDATIONCOLLECTIONURI", this.originalCollectionUrl);
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Cake.AzureDevOps.Tests
{
using Cake.AzureDevOps.Authentication;

public class BaseAzureDevOpsCredentialsSettingsImpl : BaseAzureDevOpsCredentialsSettings
{
public BaseAzureDevOpsCredentialsSettingsImpl(IAzureDevOpsCredentials credentials)
: base(credentials)
{
}

public BaseAzureDevOpsCredentialsSettingsImpl(BaseAzureDevOpsCredentialsSettingsImpl settings)
: base(settings)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
namespace Cake.AzureDevOps.Tests
{
using Cake.AzureDevOps.Authentication;
using Shouldly;
using Xunit;

public sealed class BaseAzureDevOpsCredentialsSettingsTests
{
public sealed class TheCtor
{
public sealed class WithCredentialsParameter
{
[Fact]
public void Should_Throw_If_Credentials_Are_Null()
{
// Given
IAzureDevOpsCredentials credentials = null;

// When
var result = Record.Exception(() => new BaseAzureDevOpsCredentialsSettingsImpl(credentials));

// Then
result.IsArgumentNullException("credentials");
}

[Fact]
public void Should_Set_Credentials()
{
// Given
var credentials = AuthenticationProvider.AuthenticationNtlm();

// When
var result = new BaseAzureDevOpsCredentialsSettingsImpl(credentials);

// Then
result.Credentials.ShouldBe(credentials);
}
}

public sealed class WithSettingsParameter
{
[Fact]
public void Should_Throw_If_Settings_Are_Null()
{
// Given
BaseAzureDevOpsCredentialsSettingsImpl settings = null;

// When
var result = Record.Exception(() => new BaseAzureDevOpsCredentialsSettingsImpl(settings));

// Then
result.IsArgumentNullException("settings");
}

[Fact]
public void Should_Set_Credentials()
{
// Given
var credentials = AuthenticationProvider.AuthenticationNtlm();
var settings = new BaseAzureDevOpsCredentialsSettingsImpl(credentials);

// When
var result = new BaseAzureDevOpsCredentialsSettingsImpl(settings);

// Then
result.Credentials.ShouldBe(credentials);
}
}
}
}
}
28 changes: 28 additions & 0 deletions src/Cake.AzureDevOps.Tests/BaseAzureDevOpsProjectSettingsImpl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace Cake.AzureDevOps
{
using System;
using Cake.AzureDevOps.Authentication;

public class BaseAzureDevOpsProjectSettingsImpl : BaseAzureDevOpsProjectSettings
{
public BaseAzureDevOpsProjectSettingsImpl(Uri collectionUrl, Guid projectGuid, IAzureDevOpsCredentials credentials)
: base(collectionUrl, projectGuid, credentials)
{
}

public BaseAzureDevOpsProjectSettingsImpl(Uri collectionUrl, string projectName, IAzureDevOpsCredentials credentials)
: base(collectionUrl, projectName, credentials)
{
}

public BaseAzureDevOpsProjectSettingsImpl(BaseAzureDevOpsProjectSettings settings)
: base(settings)
{
}

public BaseAzureDevOpsProjectSettingsImpl(IAzureDevOpsCredentials credentials)
: base(credentials)
{
}
}
}
Loading

0 comments on commit eb5a2c1

Please sign in to comment.