Пример #1
0
        private CommandDescriptor CreateSampleCommand2Descriptor()
        {
            var descriptions = new LocalisedTexts();

            descriptions.AddText("description", "en");

            var builder = new CommandDescriptor.Builder("sample2", typeof(SampleCommand2), descriptions);

            return(builder.Build());
        }
Пример #2
0
        public void Build_WhenCalled_ReturnsCommandDescriptor()
        {
            // arrange
            var sut = new CommandDescriptor.Builder("command", GetType(), Substitute.For <ITextResolver>());

            // act
            var commandDescriptor = sut.Build();

            // assert
            Assert.Equal("command", commandDescriptor.CommandName);
            Assert.Equal(commandDescriptor.ImplementingType, GetType());
            Assert.Empty(commandDescriptor.NumberedParameters);
            Assert.Empty(commandDescriptor.NamedParameters);
        }
Пример #3
0
        public void GetDescription_CultureIsNull_ThrowsException()
        {
            // arrange
            var texts = Substitute.For <ITextResolver>();

            texts.GetText("en").Returns("text");

            var    builder   = new CommandDescriptor.Builder("command", GetType(), texts);
            var    sut       = builder.Build();
            Action sutAction = () => sut.GetDescription(null);

            // act, assert
            var ex = Assert.Throws <ArgumentNullException>(sutAction);

            Assert.Equal("cultureName", ex.ParamName);
        }
Пример #4
0
        public void GetDescription_DescriptionHasBeenSet_ReturnsDescription()
        {
            // arrange
            var texts = Substitute.For <ITextResolver>();

            texts.GetText("en").Returns("text");

            var builder = new CommandDescriptor.Builder("command", GetType(), texts);
            var sut     = builder.Build();

            // act
            var result = sut.GetDescription("en");

            // assert
            Assert.Equal("text", result);
        }
Пример #5
0
        public void Build_AfterFlagParameterAdded_ReturnsCommandDescriptorWithFlagParameter()
        {
            // arrange
            var sut        = new CommandDescriptor.Builder("command", GetType(), Substitute.For <ITextResolver>());
            var property   = CreateProperty();
            var descriptor = new FlagParameterDescriptor("name", property, Substitute.For <ITextResolver>(), false);

            sut.AddFlagParameter(descriptor);

            // act
            var commandDescriptor = sut.Build();

            // assert
            Assert.Equal(1, commandDescriptor.FlagParameters.Count);
            Assert.Equal(descriptor, commandDescriptor.FlagParameters[0]);
        }
Пример #6
0
        public CommandDescriptor DescribeCommand(Type commandType)
        {
            if (commandType == null)
            {
                throw new ArgumentNullException(nameof(commandType));
            }

            var commandAttribute = ExtractCommandAttribute(commandType);

            if (commandAttribute == null)
            {
                throw new TypeNotACommandException(commandType);
            }

            var descriptions = ExtractDescriptions(commandType);

            var builder = new CommandDescriptor.Builder(commandAttribute.CommandName, commandType, descriptions);

            AddParameters(commandType, builder);

            return(builder.Build());
        }