Exemplo n.º 1
0
        public void Greet(string name)
        {
            var message = _nameValidator.IsValid(name)
                ? $"Hello World, {name}!"
                : "I don't know you, stranger.";

            _inOut.WriteToOutput(message);
        }
Exemplo n.º 2
0
        public async Task Execute(AcceptTheRulesInput input)
        {
            if (input is null)
            {
                throw new Exception($"The parameter {nameof(input)} cannot be null.");
            }

            if (!_validator.IsValid(input.Username))
            {
                Output.Error("Invalid Username");
                return;
            }

            await _roles.AssignMemberRole(input.UserId);

            Output.Default(new AcceptTheRulesOutput(input.Username, input.Bio));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Register a command.
        /// </summary>
        /// <param name="type">The <see cref="Type" /> implementing the command.</param>
        public void Register(Type type)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            var implementsInterface = DoesImplementICommand(type);

            if (!implementsInterface)
            {
                throw new ArgumentException(string.Format(Texts.ParameterDoesNotImplementICommand, type.FullName), nameof(type));
            }

            var descriptor = _commandDescriptorGenerator.DescribeCommand(type);

            if (descriptor == null)
            {
                throw new InvalidOperationException(string.Format(Texts.DescriptorCouldNotBeGenerated, type.FullName));
            }

            var validCommandName = _nameValidator.IsValid(descriptor.CommandName);

            if (!validCommandName)
            {
                throw new InvalidCommandNameException(descriptor.CommandName);
            }

            if (_registeredTypes.ContainsKey(descriptor.CommandName))
            {
                var existing = _registeredTypes[descriptor.CommandName];
                if (existing.ImplementingType != type)
                {
                    throw new CommandNameAlreadyUsedException(descriptor.CommandName, type, _registeredTypes[descriptor.CommandName].ImplementingType);
                }
            }
            else
            {
                _registeredTypes.Add(descriptor.CommandName, descriptor);
            }
        }