Esempio n. 1
0
        private static async Task <int> RunListAndReturnExitCode(ListOptions opts)
        {
            var repo   = GetCorrectRepository(opts);
            var cmd    = new ListCommand(opts, repo, new ConsoleTableWrapper());
            int result = await cmd.RunAsync();

            return(result);
        }
        public void It_should_run_and_list_long_FeatureBitDefinition()
        {
            // Arrange
            var sb = new StringBuilder();

            SystemContext.ConsoleWriteLine = s => sb.AppendLine(s);
            var bit1 = new CommandFeatureBitDefintion {
                Id = 1, Name = "foo1", OnOff = true, ExcludedEnvironments = "prod1", MinimumAllowedPermissionLevel = 10, ExactAllowedPermissionLevel = 30, AllowedUsers = "me1", IncludedEnvironments = "Dev1,Dev3"
            };
            var bit2 = new CommandFeatureBitDefintion {
                Id = 2, Name = "foo2", OnOff = false, ExcludedEnvironments = "prod2", MinimumAllowedPermissionLevel = 20, ExactAllowedPermissionLevel = 40, AllowedUsers = "me2", IncludedEnvironments = "Dev1,Dev3"
            };
            var opts = new ListOptions {
                Long = true
            };
            var repo         = Substitute.For <IFeatureBitsRepo>();
            var consoleTable = Substitute.For <IConsoleTable>();
            var fbits        = new List <IFeatureBitDefinition> {
                bit1, bit2
            };


            repo.GetAllAsync().Returns(Task.FromResult((IEnumerable <IFeatureBitDefinition>)fbits));

            var it = new ListCommand(opts, repo, consoleTable);

            // Act
            var result = it.RunAsync().Result;

            // Assert
            result.Should().Be(0);

            consoleTable.Received().Print(Arg.Is <DataTable>(dt =>
                                                             dt.Rows.Count == 2 &&
                                                             dt.Columns.Count == 8 &&
                                                             dt.Columns[0].Caption == "Id" &&
                                                             dt.Columns[1].Caption == "Name" &&
                                                             dt.Columns[2].Caption == "OnOff" &&
                                                             dt.Columns[3].Caption == "ExcludedEnvironments" &&
                                                             dt.Columns[4].Caption == "MinimumAllowedPermissionLevel" &&
                                                             dt.Columns[5].Caption == "ExactAllowedPermissionLevel" &&
                                                             dt.Columns[6].Caption == "AllowedUsers" &&
                                                             dt.Columns[7].Caption == "IncludedEnvironments"));
        }
        public void It_should_run_and_list_short_FeatureBitDefinition()
        {
            // Arrange
            var sb = new StringBuilder();

            SystemContext.ConsoleWriteLine = s => sb.AppendLine(s);
            var bit1 = new CommandFeatureBitDefintion {
                Id = 1, Name = "foo1"
            };
            var bit2 = new CommandFeatureBitDefintion {
                Id = 1, Name = "foo2"
            };
            var opts         = new ListOptions {
            };
            var repo         = Substitute.For <IFeatureBitsRepo>();
            var consoleTable = Substitute.For <IConsoleTable>();
            var fbits        = new List <IFeatureBitDefinition>();

            fbits.Add(bit1);
            fbits.Add(bit2);

            repo.GetAllAsync().Returns(Task.FromResult((IEnumerable <IFeatureBitDefinition>)fbits));

            var it = new ListCommand(opts, repo, consoleTable);

            // Act
            var result = it.RunAsync().Result;

            // Assert
            result.Should().Be(0);

            consoleTable.Received().Print(Arg.Is <DataTable>(dt =>
                                                             dt.Rows.Count == 2 &&
                                                             dt.Columns.Count == 2 &&
                                                             dt.Columns[0].Caption == "Id" &&
                                                             dt.Columns[1].Caption == "Name"));
        }
Esempio n. 4
0
 private async Task RunListOptions(ListOptions options)
 {
     await ListCommand.RunAsync(options);
 }