public void WhenNameSpecified_ThrowsIfModuleNameIsInvalid() { // Arrange ExportModuleCommand cmd = new ExportModuleCommand().AutoConfigure(); TestCommandInvoker invoker = cmd.AttachInvoker(); cmd.Name = "Foo"; invoker.RegisterScript("Get-Module -ListAvailable 'Foo'", () => new[] { new SimpleModuleMetadata("Foo Bar", new Version(1, 0, 0, 0)) }); // Act/Assert InvalidOperationException ex = Assert.Throws<InvalidOperationException>(() => cmd.Execute()); Assert.Equal("Module name 'Foo Bar' is invalid, names must consist only of letters, numbers, '_' and '-'.", ex.Message); }
public void WhenNameSpecified_ThrowsIfModuleDoesNotExist() { // Arrange ExportModuleCommand cmd = new ExportModuleCommand().AutoConfigure(); TestCommandInvoker invoker = cmd.AttachInvoker(); cmd.Name = "Foo"; invoker.RegisterScript("Get-Module -ListAvailable 'Foo'", () => Enumerable.Empty<IModuleMetadata>()); // Act/Assert KeyNotFoundException ex = Assert.Throws<KeyNotFoundException>(() => cmd.Execute()); Assert.Equal("Module not found: 'Foo'", ex.Message); }