Exemplo n.º 1
0
        public async Task Deny_Zero_Arguments()
        {
            var command  = new PlainCommand("MGET");
            var response = await connection.ExecuteAsync(command).ConfigureAwait(false);

            response.Should().Be(new Error("ERR wrong number of arguments for 'mget' command"));
        }
        public static PlainCommand GetPlainCommand(this ObservableObject payLoad, CommandContainer commandContainer, string commandName)
        {
            string functionName = $"Can{commandName}";

            functionName = functionName.Replace("Async", "");
            MethodInfo?method = payLoad.GetPrivateMethod(commandName);

            if (method == null)
            {
                Type type = payLoad.GetType();
                throw new BasicBlankException($"Method with the name of {commandName} was not found  Type was {type.Name}");
            }
            MethodInfo?  fun = payLoad.GetPrivateMethod(functionName);
            PlainCommand output;

            if (fun != null)
            {
                output = new PlainCommand(payLoad, method, canExecuteM: fun, commandContainer);
            }
            else
            {
                PropertyInfo?pp = payLoad.GetPrivateProperty(functionName);
                output = new PlainCommand(payLoad, method, canExecute: pp, commandContainer);
            }
            return(output);
        }
Exemplo n.º 3
0
        public SolitairePilesCP(CommandContainer command)
        {
            MethodInfo method = this.GetPrivateMethod(nameof(PrivateColumnAsync));

            ColumnCommand = new PlainCommand(this, method, canExecute: null, command);
            method        = this.GetPrivateMethod(nameof(PrivateDoubleAsync));
            DoubleCommand = new PlainCommand(this, method, canExecute: null, command);
        }
        public GameBoardObservable(CommandContainer container)
        {
            CommandContainer = container;

            //decided to use plain command here.
            MethodInfo method = this.GetPrivateMethod(nameof(ClickProcessAsync)); //hopefully protected is fine (?)
            MethodInfo fun    = this.GetPrivateMethod(nameof(CanExecute));

            ObjectCommand = new PlainCommand(this, method, fun, CommandContainer);
            CommandContainer.AddControl(this); //i think it should be here instead.
        }
        public TriangleObservable(ITriangleVM thisMod, CommandContainer command, IGamePackageResolver resolver, int maxColumnsRows)
        {
            _thisMod        = thisMod;
            _maxRowsColumns = maxColumnsRows;
            _thisP          = resolver.Resolve <IProportionImage>(ts.TagUsed);
            MethodInfo method = this.GetPrivateMethod(nameof(PrivateCardClickAsync));
            MethodInfo fun    = this.GetPrivateMethod(nameof(CanClickCard));

            CardCommand = new PlainCommand(this, method, fun, command);
            LoadBoard();
        }
Exemplo n.º 6
0
        public async Task Exploratory_1()
        {
            var key          = fixture.NewKey();
            var group        = new GroupName("group-1");
            var xadd         = new XADD(key, ("name", "value"));
            var xgroupCreate = new XGROUP.CREATE(key, group, Offset.FromId(Id.Minimum), NotCreateStream);
            await fixture.ExecuteAsync(xadd).ConfigureAwait(false);

            await fixture.ExecuteAsync(xgroupCreate).ConfigureAwait(false);

            var @new = new PlainCommand("XREADGROUP", "GROUP", "group-1", "consumer", "STREAMS", key.ToBytes(), ">")
                       .WithResponseStructure(CompositeVisitors.StreamEntriesList);
            var entries = await fixture.ExecuteAsync(@new).ConfigureAwait(false);

            Equals(entries, new Stream(key, new Entry(("name", "value"))));
        }
Exemplo n.º 7
0
        public async Task Useless_Dollar()
        {
            var          key          = fixture.NewKey();
            const string group        = "group";
            var          xgroupCreate = new XGROUP.CREATE(key, group, Offset.FromId(Id.Minimum), CreateStreamIfNotExists);
            await fixture.ExecuteAsync(xgroupCreate).ConfigureAwait(false);

            var sut      = new PlainCommand("XREADGROUP", "GROUP", group, "consumer", "STREAMS", key.ToBytes(), "$");
            var response = await fixture.ExecuteAsync(sut).ConfigureAwait(false);

            response.Should().Be(
                new Error(
                    "ERR The $ ID is meaningless in the context of XREADGROUP: "
                    + "you want to read the history of this consumer by specifying "
                    + "a proper ID, or use the > ID to get new messages. The $ ID "
                    + "would just return an empty result set."
                    )
                );
        }
Exemplo n.º 8
0
        public async Task Not_Block_If_One_Of_Ids_Is_Not_Greater_Than()
        {
            var          key1  = fixture.NewKey("key1");
            var          key2  = fixture.NewKey("key2");
            const string group = "group";

            foreach (var key in new[] { key1, key2 })
            {
                var xgroupCreate = new XGROUP.CREATE(key, group, Offset.FromId(Id.Minimum), CreateStreamIfNotExists);
                await fixture.ExecuteAsync(xgroupCreate).ConfigureAwait(false);
            }

            var sut = new PlainCommand(
                "XREADGROUP",
                "GROUP",
                "group",
                "consumer",
                "BLOCK",
                "0",
                "STREAMS",
                key1.ToBytes(),
                key2.ToBytes(),
                ">",
                "100"
                );
            var response = await fixture.ExecuteAsync(sut).ConfigureAwait(false);

            response.Should().Be(
                new PlainArray(
                    new PlainArray(
                        key2.ToBulkString(BulkStringFactory.Plain),
                        Array.Empty
                        ) as DataType
                    )
                );
        }
Exemplo n.º 9
0
        private static ICommand GetCommand(object viewModel, MethodInfo method, MethodInfo?validateM, PropertyInfo?foundProperty)
        {
            var item = method.GetCustomAttribute <CommandAttribute>();

            if (item == null)
            {
                throw new BasicBlankException("Was not even a custom command.  Rethink");
            }
            ICommand?output;

            if (!(viewModel is IBlankGameVM blank))
            {
                throw new BasicBlankException("This is not a blank game view model.  Rethink");
            }
            if (blank.CommandContainer == null)
            {
                throw new BasicBlankException("The command container for command not there.  Rethink");
            }
            switch (item.Category)
            {
            case EnumCommandCategory.Plain:
                if (foundProperty == null && validateM != null)
                {
                    output = new PlainCommand(viewModel, method, validateM, blank.CommandContainer);
                }
                else
                {
                    output = new PlainCommand(viewModel, method, foundProperty !, blank.CommandContainer);
                }
                break;

            case EnumCommandCategory.Game:
                if (!(viewModel is IBasicEnableProcess basics))
                {
                    throw new BasicBlankException("You need to implement the IEnableAlways in order to use out of turn command.  Rethink");
                }
                if (foundProperty == null && validateM != null)
                {
                    output = new BasicGameCommand(basics, method, validateM, blank.CommandContainer);
                }
                else
                {
                    output = new BasicGameCommand(basics, method, foundProperty !, blank.CommandContainer);
                }
                break;

            case EnumCommandCategory.Limited:
                if (!(viewModel is IBasicEnableProcess basics2))
                {
                    throw new BasicBlankException("You need to implement the IEnableAlways in order to use out of turn command.  Rethink");
                }
                if (foundProperty == null && validateM != null)
                {
                    output = new LimitedGameCommand(basics2, method, validateM, blank.CommandContainer);
                }
                else
                {
                    output = new LimitedGameCommand(basics2, method, foundProperty !, blank.CommandContainer);
                }
                break;

            case EnumCommandCategory.OutOfTurn:

                if (!(viewModel is IEnableAlways enables))
                {
                    throw new BasicBlankException("You need to implement the IEnableAlways in order to use out of turn command.  Rethink");
                }

                output = new OutOfTurnCommand(enables, method, blank.CommandContainer);
                break;

            case EnumCommandCategory.Open:
                if (foundProperty == null && validateM != null)
                {
                    output = new OpenCommand(viewModel, method, validateM, blank.CommandContainer);
                }
                else
                {
                    output = new OpenCommand(viewModel, method, foundProperty !, blank.CommandContainer);
                }
                break;

            case EnumCommandCategory.Control:
                if (!(viewModel is IControlObservable control))
                {
                    throw new BasicBlankException("You need to implement the IControlVM in order to use control command.  Rethink");
                }
                output = new ControlCommand(control, method, blank.CommandContainer);
                break;

            case EnumCommandCategory.Old:
                if (foundProperty == null && validateM != null)
                {
                    output = new ReflectiveCommand(viewModel, method, validateM);
                }
                else
                {
                    output = new ReflectiveCommand(viewModel, method, foundProperty !);
                }
                break;

            default:
                throw new BasicBlankException("Not supported");
            }
            if (output == null)
            {
                throw new BasicBlankException("No command.   Rethink");
            }
            return(output);
        }
Exemplo n.º 10
0
        public IEnumerable <BulkString> Parse(string query)
        {
            var command = PlainCommand.Parse(query);

            return(command.Request(BulkStringFactory.Plain));
        }