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(); }
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()); }
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"); }
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"); }
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"); }
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()); }
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)); }
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 }); }
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); } }); }
public IActionResult Create([FromServices] ServerHandler handler, [FromBody] CreateServerCommand command) { var response = (DefaultCommandResult)handler.Handle(command); return(this.DefaultCommandResultToActionResult(response)); }