Skip to content

Commit

Permalink
Merge branch 'release/0.16.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalberger committed Oct 27, 2018
2 parents af6b029 + 8c1a63b commit d23715b
Show file tree
Hide file tree
Showing 16 changed files with 1,490 additions and 2 deletions.
4 changes: 2 additions & 2 deletions nuspec/nuget/Cake.Npm.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
<description>A set of aliases for Cake to help with running Npm (Node Package Manager) commands</description>
<licenseUrl>https://github.com/cake-contrib/cake-npm/blob/master/LICENSE</licenseUrl>
<projectUrl>https://github.com/cake-contrib/cake-npm</projectUrl>
<iconUrl>https://cdn.rawgit.com/cake-contrib/graphics/a5cf0f881c390650144b2243ae551d5b9f836196/png/cake-contrib-medium.png</iconUrl>
<iconUrl>https://cdn.jsdelivr.net/gh/cake-contrib/graphics@a5cf0f881c390650144b2243ae551d5b9f836196/png/cake-contrib-medium.png</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<tags>cake npm cake-build cake-contrib</tags>
<releaseNotes>https://github.com/cake-contrib/Cake.Npm/releases/tag/0.14.0</releaseNotes>
<releaseNotes>https://github.com/cake-contrib/Cake.Npm/releases/tag/0.16.0</releaseNotes>
</metadata>
<files>
<file src="netstandard2.0\Cake.Npm.dll" target="lib\netstandard2.0" />
Expand Down
17 changes: 17 additions & 0 deletions src/Cake.Npm.Tests/AddUser/NpmAddUserFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Cake.Npm.AddUser;

namespace Cake.Npm.Tests.AddUser
{
internal class NpmAddUserFixture : NpmFixture<NpmAddUserSettings>
{
public NpmAddUserFixture()
{
}

protected override void RunTool()
{
var tool = new NpmAddUser(FileSystem, Environment, ProcessRunner, Tools, Log);
tool.AddUser(Settings);
}
}
}
194 changes: 194 additions & 0 deletions src/Cake.Npm.Tests/AddUser/NpmAddUserSettingsExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
namespace Cake.Npm.Tests.AddUser
{
using System;
using Cake.Npm.AddUser;
using Shouldly;
using Xunit;

public sealed class NpmAddUserSettingsExtensionsTests
{
public sealed class TheFromRegistryMethod
{
[Fact]
public void Should_Throw_If_Settings_Are_Null()
{
// Given
NpmAddUserSettings settings = null;
Uri registry = new Uri("https://myregistry.com");

// When
var result = Record.Exception(() => settings.ForRegistry(registry));

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

[Fact]
public void Should_Throw_If_Registry_Is_Null()
{
// Given
var settings = new NpmAddUserSettings();
Uri registry = null;

// When
var result = Record.Exception(() => settings.ForRegistry(registry));

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

[Fact]
public void Should_Set_Registry()
{
// Given
var settings = new NpmAddUserSettings();
Uri registry = new Uri("https://myregistry.com");

// When
var result = settings.ForRegistry(registry);

// Then
result.Registry.ShouldBe(registry);
}
}

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

// When
var result = Record.Exception(() => settings.ForScope("@bar"));

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

[Fact]
public void Should_Throw_If_Scope_Is_Null()
{
// Given
var settings = new NpmAddUserSettings();

// When
var result = Record.Exception(() => settings.ForScope(null));

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

[Fact]
public void Should_Throw_If_Scope_Is_Empty()
{
// Given
var settings = new NpmAddUserSettings();

// When
var result = Record.Exception(() => settings.ForScope(string.Empty));

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

[Fact]
public void Should_Throw_If_Scope_Is_WhiteSpace()
{
// Given
var settings = new NpmAddUserSettings();

// When
var result = Record.Exception(() => settings.ForScope(" "));

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

[Fact]
public void Should_Throw_If_Scope_Does_Not_Start_With_At()
{
// Given
var settings = new NpmAddUserSettings();

// When
var result = Record.Exception(() => settings.ForScope("bar"));

// Then
result.IsArgumentException("scope");
}

[Fact]
public void Should_Set_Scope()
{
// Given
var settings = new NpmAddUserSettings();

// When
settings.ForScope("@bar");

// Then
Assert.Equal("@bar", settings.Scope);
}
}

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

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

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

[Fact]
public void Should_Set_AlwaysAuth_To_True()
{
// Given
var settings = new NpmAddUserSettings();

// When
settings.AlwaysAuthenticate();

// Then
Assert.True(settings.AlwaysAuth);
}
}

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

// When
var result = Record.Exception(() => settings.UsingAuthentication(AuthType.Legacy));

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

[Fact]
public void Should_Set_AuthType_To_Legacy_Settings()
{
// Given
var settings = new NpmAddUserSettings();

// When
settings.UsingAuthentication(AuthType.Legacy);

// Then
Assert.Equal(AuthType.Legacy, settings.AuthType);
}
}
}
}
162 changes: 162 additions & 0 deletions src/Cake.Npm.Tests/AddUser/NpmAddUserTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
using System;
using Xunit;
using Cake.Npm.AddUser;

namespace Cake.Npm.Tests.AddUser
{
public class NpmAddUserTests
{
public sealed class TheAddUserMethod
{
[Fact]
public void Should_Redirect_Standard_Error()
{
var fixture = new NpmAddUserFixture();
fixture.Settings.RedirectStandardError = true;

var result = fixture.Run();

Assert.True(result.Process.RedirectStandardError);
}

[Fact]
public void Should_Throw_If_Settings_Are_Null()
{
// Given
var fixture = new NpmAddUserFixture();
fixture.Settings = null;

// When
var result = Record.Exception(() => fixture.Run());

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

[Fact]
public void Should_Add_Registry_Url_To_Arguments()
{
// Given
var fixture = new NpmAddUserFixture();
fixture.Settings.ForRegistry(new Uri("https://registry.com"));

// When
var result = fixture.Run();

// Then
Assert.Equal("adduser --registry https://registry.com/", result.Args);
}

[Fact]
public void Should_Add_Scope_To_Arguments()
{
// Given
var fixture = new NpmAddUserFixture();
fixture.Settings.ForScope("@foo");

// When
var result = fixture.Run();

// Then
Assert.Equal("adduser --scope @foo", result.Args);
}

[Fact]
public void Should_Throw_If_Scope_Does_Not_Start_With_At()
{
// Given
var fixture = new NpmAddUserFixture();

// When
var result = Record.Exception(() => fixture.Settings.ForScope("bar"));

// Then
Assert.IsType<ArgumentException>(result);
}

[Fact]
public void Should_Add_AlwaysAuth_To_Arguments_If_True()
{
// Given
var fixture = new NpmAddUserFixture();
fixture.Settings.AlwaysAuth = true;

// When
var result = fixture.Run();

// Then
Assert.Equal("adduser --always-auth", result.Args);
}

[Fact]
public void Should_Not_Add_Registry_To_Arguments_If_Not_Set()
{
// Given
var fixture = new NpmAddUserFixture();
fixture.Settings.Registry = null;

// When
var result = fixture.Run();

// Then
Assert.Equal("adduser", result.Args);
}

[Fact]
public void Should_Add_AuthType_Of_Legacy()
{
// Given
var fixture = new NpmAddUserFixture();
fixture.Settings.AuthType = AuthType.Legacy;

// When
var result = fixture.Run();

// Then
Assert.Equal("adduser --auth-type legacy", result.Args);
}

[Fact]
public void Should_Add_AuthType_Of_OAuth()
{
// Given
var fixture = new NpmAddUserFixture();
fixture.Settings.AuthType = AuthType.OAuth;

// When
var result = fixture.Run();

// Then
Assert.Equal("adduser --auth-type oauth", result.Args);
}

[Fact]
public void Should_Add_AuthType_Of_SSO()
{
// Given
var fixture = new NpmAddUserFixture();
fixture.Settings.AuthType = AuthType.SSO;

// When
var result = fixture.Run();

// Then
Assert.Equal("adduser --auth-type sso", result.Args);
}

[Fact]
public void Should_Add_AuthType_Of_Saml()
{
// Given
var fixture = new NpmAddUserFixture();
fixture.Settings.AuthType = AuthType.Saml;

// When
var result = fixture.Run();

// Then
Assert.Equal("adduser --auth-type saml", result.Args);
}
}
}
}
Loading

0 comments on commit d23715b

Please sign in to comment.