コード例 #1
0
        public async Task Validar_comando_correto()
        {
            var command = new CreateServerCommand("teste", "127.0.0.1", 80);

            var result = await _validator.ValidateAsync(command);

            result.IsValid.Should().BeTrue();
        }
コード例 #2
0
        public async Task Retornar_erros_e_nao_criar_servidor_quando_comando_invalido()
        {
            var command = new CreateServerCommand("", "teste", 0);

            var result = await _handler.Handle(command, CancellationToken.None);

            result.IsFail.Should().BeTrue();
            _serverRepositoryMock.Verify(x => x.SaveChangesAsync(), Times.Never());
        }
コード例 #3
0
        public async Task Retornar_erro_quando_comando_tiver_porta_zerada()
        {
            var command = new CreateServerCommand("teste", "127.0.0.1", 0);

            var result = await _validator.ValidateAsync(command);

            result.IsValid.Should().BeFalse();
            result.Errors.Should().Contain(x => x.ErrorMessage == "Porta informada deve ser maior que 0");
        }
コード例 #4
0
        public async Task Retornar_erro_quando_comando_tiver_ip_invalido()
        {
            var command = new CreateServerCommand("teste", "google.com.br", 80);

            var result = await _validator.ValidateAsync(command);

            result.IsValid.Should().BeFalse();
            result.Errors.Should().Contain(x => x.ErrorMessage == "IP inválido");
        }
コード例 #5
0
        public async Task Retornar_erro_quando_comando_nao_tiver_ip()
        {
            var command = new CreateServerCommand("teste", null, 80);

            var result = await _validator.ValidateAsync(command);

            result.IsValid.Should().BeFalse();
            result.Errors.Should().Contain(x => x.ErrorMessage == "IP é obrigatório");
        }
コード例 #6
0
        public async Task Criar_servidor_quando_comando_valido()
        {
            _serverRepositoryMock.Setup(x => x.AddAsync(It.IsAny <Server>())).ReturnsAsync(new Server("teste", "127.0.0.1", 1234));
            var command = new CreateServerCommand("teste", "127.0.0.1", 1234);

            var result = await _handler.Handle(command, CancellationToken.None);

            result.SuccessData.Should().NotBeNull();
            _serverRepositoryMock.Verify(x => x.SaveChangesAsync(), Times.Once());
        }
コード例 #7
0
ファイル: ServersController.cs プロジェクト: MateusC/Seventh
        public async Task <IActionResult> Create([FromBody] CreateServerCommand command)
        {
            var result = await _mediator.Send(command);

            if (result.IsSuccess)
            {
                return(Created($"/servers/{result.SuccessData.Id}", result.SuccessData));
            }

            return(BadRequest(result.FailData));
        }
コード例 #8
0
        public async Task <IActionResult> Post([FromBody] CreateUpdateServerDto server, CancellationToken cancellationToken)
        {
            var command = new CreateServerCommand {
                Server = server
            };
            var id = await Mediator.Send(command, cancellationToken);

            return(new JsonResult(new { id })
            {
                StatusCode = 201
            });
        }
コード例 #9
0
        public void OnCreateServerCommand(CreateServerCommand command)
        {
            string serverId = command.ServerId;
            string url      = HttpURLs.FromHostAndPort(command.Host, command.Port);

            // Check if server already exists
            if (!nameServiceDB.TryAddServer(serverId, url))
            {
                Console.Error.WriteLine("Server with id {0} already exists", serverId);
                return;
            }

            PCSConnection connection = new PCSConnection(command.Host);

            connection.CreateServerAsync(
                serverId,
                command.Port,
                command.MinDelay,
                command.MaxDelay,
                config.Version)
            .ContinueWith(antecedent => {
                if (antecedent.Result)
                {
                    Console.WriteLine(
                        "[{0}] Server started at {1}:{2}",
                        DateTime.Now.ToString("HH:mm:ss"),
                        command.Host,
                        command.Port);
                }
                else
                {
                    // Remove inserted id if operation failed
                    nameServiceDB.RemoveServer(serverId);
                }
            });
        }
コード例 #10
0
        public IActionResult Create([FromServices] ServerHandler handler, [FromBody] CreateServerCommand command)
        {
            var response = (DefaultCommandResult)handler.Handle(command);

            return(this.DefaultCommandResultToActionResult(response));
        }