Example #1
0
        public async Task ShouldRunWithinASpaceWhenSpaceNameSpecified()
        {
            var client = Substitute.For <IOctopusAsyncClient>();

            ClientFactory.CreateAsyncClient(null).ReturnsForAnyArgs(client);

            Repository.Spaces.FindByName(Arg.Any <string>()).Returns(new SpaceResource {
                Id = "Spaces-2", Name = "test"
            });
            client.ForSystem().Returns(Repository);

            apiCommand = new DummyApiCommand(RepositoryFactory, FileSystem, ClientFactory, CommandOutputProvider);
            var  argsWithSpaceName     = CommandLineArgs.Concat(new[] { "--space=test" });
            bool isInRightSpaceContext = false;

            RepositoryFactory.CreateRepository(client, Arg.Do <RepositoryScope>(x =>
            {
                x.Apply(space =>
                {
                    space.Id.Should().Be("Spaces-2");
                    isInRightSpaceContext = true;
                }, () => { }, () => { });
            }));

            await apiCommand.Execute(argsWithSpaceName.ToArray()).ConfigureAwait(false);

            Assert.IsTrue(isInRightSpaceContext);
        }
Example #2
0
        public Task ShouldExecuteCommandWhenCorrectCommandLineParametersArePassedWithSpaceName()
        {
            var client = Substitute.For <IOctopusAsyncClient>();

            ClientFactory.CreateAsyncClient(null).ReturnsForAnyArgs(client);

            Repository.Spaces.FindByName(Arg.Any <string>()).Returns(new SpaceResource {
                Id = "Spaces-2"
            });
            client.ForSystem().Returns(Repository);

            apiCommand = new DummyApiCommand(RepositoryFactory, FileSystem, ClientFactory, CommandOutputProvider);
            var argsWithSpaceName = CommandLineArgs.Concat(new [] { "--space=abc" });

            return(apiCommand.Execute(argsWithSpaceName.ToArray()));
        }
Example #3
0
        public void ShouldThrowWhenThereIsNoSpaceMatchTheProvidedName()
        {
            var client = Substitute.For <IOctopusAsyncClient>();

            ClientFactory.CreateAsyncClient(null).ReturnsForAnyArgs(client);

            Repository.Spaces.FindByName("test").Returns(new SpaceResource {
                Id = "Spaces-2", Name = "test"
            });
            client.ForSystem().Returns(Repository);

            apiCommand = new DummyApiCommand(RepositoryFactory, FileSystem, ClientFactory, CommandOutputProvider);
            var argsWithSpaceName = CommandLineArgs.Concat(new[] { "--space=nonExistent" });

            Func <Task> action = async() => await apiCommand.Execute(argsWithSpaceName.ToArray()).ConfigureAwait(false);

            action.ShouldThrow <CommandException>().WithMessage("Cannot find the space with name or id 'nonExistent'. Please check the spelling and that you have permissions to view it. Please use Configuration > Test Permissions to confirm.");
        }