Exemple #1
0
        public async Task <RegisterUserResult> RegisterUserAsync(UserRegistration userRegistration)
        {
            var command = new RegisterUserCommand(userRegistration);
            var handler = _commands.Build(command);

            return(await handler.ExecuteAsync());
        }
        public void build()
        {
            var factory = new CommandFactory();

            factory.RegisterCommands(GetType().Assembly);

            factory.Build("my").ShouldBeOfType <MyCommand>();
            factory.Build("my2").ShouldBeOfType <My2Command>();
            factory.Build("this").ShouldBeOfType <DecoratedCommand>();
        }
Exemple #3
0
        static void Main(string[] args)
        {
            var config  = GetConfiguration();
            var command = CommandFactory.Build <FeeCalculationCommand>(config);

            command.Execute();
        }
Exemple #4
0
        public void ForGivenInput_ProgramShouldReturnExpectedOutput()
        {
            // Arrange
            var config         = TestData.GetConfiguration();
            var input          = TestData.GetInput();
            var expectedOutput = TestData.GetOutput();

            _fileReader
            .Setup(fr => fr.ReadLines(config.Input.TransactionsFilePath))
            .Returns(input);

            var transactionRepository = new TransactionRepository(
                config.Input.TransactionsFilePath,
                _fileReader.Object,
                new TransactionParser(
                    config.Input.Separator,
                    config.Input.DateFormat));

            var command = CommandFactory.Build <FeeCalculationCommand>(
                config,
                transactionRepository);

            var stringWriter = new StringWriter();

            Console.SetOut(stringWriter);

            // Act
            command.Execute();
            var actualOutput = stringWriter.ToString();

            stringWriter.Dispose();

            // Assert
            Assert.Equal(expectedOutput, actualOutput);
        }
Exemple #5
0
 public void DropNew(GameObject source)
 {
     this.token = Instantiate(source);
     this.token.GetComponent <CommandComponent>().command = factory.Build(source.GetComponent <CommandComponent>().command.name);
     this.token.transform.SetParent(transform);
     this.token.GetComponent <RectTransform>().anchoredPosition = new Vector2(0, 0);
     this.token.GetComponent <RectTransform>().localScale       = new Vector3(1, 1, 1);
     this.token.GetComponent <CanvasGroup>().blocksRaycasts     = true;
     this.token.GetComponent <CanvasGroup>().alpha = 1f;
 }
        public void TestExecuteObject()
        {
            var factory = new CommandFactory(typeof(TestCommandObjectInput));

            Assert.True(factory.IsValid);

            var cmd = factory.Build(new TestCommandObjectInput());

            var res1 = cmd.Invoke($"test-object --option1 {TestCommandStatic.ARG_1_EXPECTED}");

            Assert.Equal(TestCommandObjectInput.OBJECT_RESULT, res1);
        }
Exemple #7
0
        private void ReceiveCallback(IAsyncResult results)
        {
            Socket current = results.AsyncState as Socket;
            int    received;

            try
            {
                received = current.EndReceive(results);
            }
            catch (SocketException)
            {
                Console.WriteLine("Client forcefully disconnected");

                // Don't shutdown because the socket may be disposed and
                // its disconnected anyway:
                current.Close();
                this.ConnectedSockets.Remove(current);
                return;
            }

            // Get request as string:
            byte[] recBuf = new byte[received];
            Array.Copy(Buffer, recBuf, received);
            string text = CommunicationProperties.CommunicationEncoding
                          .GetString(recBuf);

            Console.WriteLine("Request: <{0}>", text);

            // Get request as serialized object:
            BaseRequest request = this.GetRequest(text);

            if (request == null)
            {
                // TODO: Retornar mensagem de erro.
            }
            else
            {
                // Perform some asynchronous action based on the request received:
                BaseResponse response = CommandFactory.Build(request);

                // Create the corresponding response, based on the action
                // performed previously:
                current.Send(this.GetResponseData(response));

                current.BeginReceive(Buffer, 0, CommunicationProperties.PackageSize,
                                     SocketFlags.None, ReceiveCallback, current);
            }
        }
        public void TestExecuteStaticHandler()
        {
            var factory = new CommandFactory(typeof(TestCommandStatic));

            Assert.True(factory.IsValid);

            var cmd = factory.Build(new TestCommandStatic());

            var res1 = cmd.Invoke($"test-static --option1 {TestCommandStatic.ARG_1_EXPECTED}");
            var res2 = cmd.Invoke($"a1 {TestCommandStatic.OP_1_ALIAS} {TestCommandStatic.ARG_1_EXPECTED}");
            var res3 = cmd.Invoke($"a2 {TestCommandStatic.OP_1_ALIAS} {TestCommandStatic.ARG_1_EXPECTED}");

            Assert.Equal(TestCommandStatic.RESULT, res1);
            Assert.Equal(TestCommandStatic.RESULT, res2);
            Assert.Equal(TestCommandStatic.RESULT, res3);
        }
        public void build_command_with_a_replacement_commandcreator()
        {
            var creator = MockRepository.GenerateMock <ICommandCreator>();

            creator.Stub(c => c.Create(typeof(MyCommand)))
            .Repeat.Once()
            .Return(new MyCommand());

            var factory = new CommandFactory(creator);

            factory.RegisterCommands(GetType().Assembly);

            var cmd = factory.Build("my");

            creator.VerifyAllExpectations();
            cmd.ShouldBeOfType <MyCommand>();
        }
Exemple #10
0
        public void run()
        {
            string line;

            while (!(line = Console.ReadLine()).Equals(EndCommand))
            {
                string[] tokens = Regex.Split(line, InputSeperator);

                if (line.Equals(StatisticsCommand))
                {
                    Console.WriteLine(Restourant.Statistics());
                    continue;
                }

                Command command = CommandFactory.Build(tokens);
                command.execute(Restourant);
            }

            Console.WriteLine(Restourant.Statistics());
        }
Exemple #11
0
        public bool Init(string path)
        {
            try {
                int            idx       = 0;
                string         json      = File.ReadAllText(path);
                LevelData      levelData = JsonUtility.FromJson <LevelData>(json);
                CommandFactory factory   = new CommandFactory();

                this.level  = levelData.level;
                this.title  = levelData.title;
                this.input  = levelData.input;
                this.output = levelData.output;

                this.commands = new ICommand[levelData.commands.Length];
                foreach (string name in levelData.commands)
                {
                    ICommand command = factory.Build(name);
                    this.commands[idx] = command;
                    idx++;
                }
                idx = 0;

                this.slots = new Value[levelData.slots.Length];
                foreach (Slot slot in levelData.slots)
                {
                    this.slots[idx] = new Value(slot.index, slot.value);
                    idx++;
                }

                this.instructions = levelData.instructions;

                return(true);
            } catch (Exception e) {
                Debug.LogError("An error occured while parsing JSON level file");
                Debug.LogException(e);

                return(false);
            }
        }
Exemple #12
0
 protected override IDbCommand GetCommand()
 {
     return(CommandFactory.Build <SqlCommand>());
 }