-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
1,490 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
194
src/Cake.Npm.Tests/AddUser/NpmAddUserSettingsExtensionsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.