public CreateTodoHandlerTests() { _invalidComand = new CreateTodoCommand("", "", DateTime.Now); _validComand = new CreateTodoCommand("criando tarefa", "douglas", DateTime.Now); _handler = new TodoHandler(new FakeTodoRepository()); _result = new GenericCommandResult(); }
public async Task <IActionResult> GetPedidos() { try { var login = User.Identity.Name; var usuario = await _usuarioRepository.Get(login); if (usuario == null) { return(BadRequest(GenericCommandResult.Failure(new List <string> { ErrorMessages.UserNotExists }))); } var result = await _mediator.Send(new GetUsuarioPedidosCommand(usuario.Id)); if (result.Ok) { return(Ok(result.Data)); } return(BadRequest(result.Errors)); } catch (Exception ex) { //logar erro em algum lugar return(StatusCode(500, ex.Message)); } }
public GenericCommandResult Signup(string endpoint, User user) { HttpResponseMessage response = _http.PostAsync($"{Settings.API_URL}/{endpoint}", new StringContent( JsonConvert.SerializeObject(new { email = user.Email, password = user.Password, FistName = user.Password, lastName = user.LastName, document = user.Document.Replace(".", "").Replace("-", ""), gender = user.Gender, birthDate = user.BirthDate, phone = user.Phone.Replace("(", "").Replace(")", "").Replace(" ", "").Replace("-", ""), street = user.Street, number = user.Number, neighborhood = user.Neighborhood, city = user.City, state = user.Street, country = user.Country, zipCode = user.ZipCode.Replace(".", "").Replace("-", ""), }), Encoding.UTF8, "application/json")).Result; string content = response.Content.ReadAsStringAsync().Result; GenericCommandResult result = JsonConvert.DeserializeObject <GenericCommandResult>(content); return(result); }
public void Dado_um_Comando_Invalido_deve_interromper_a_execucao() { var command = new CreateTodoCommand("", "", DateTime.Now); _result = (GenericCommandResult)_handler.Handle(_invalidCommand); Assert.AreEqual(_result.Sucess, false); }
public void Dado_um_Comando_valido_deve_executar() { var command = new CreateTodoCommand("Titulo da Tarefa", "MatheusMunhoz", DateTime.Now); _result = (GenericCommandResult)_handler.Handle(_validCommand); Assert.AreEqual(_result.Sucess, true); }
public void Invalid_UpdateCommand_Should_Return_False() { var invalidUpdateCommand = new UpdateClientCommand(new Client()); _result = (GenericCommandResult)_handler.Handle(invalidUpdateCommand); Assert.AreEqual(false, _result.Success); }
public void Valid_UpdateCommand_Should_Return_False() { var validUpdateCommand = new UpdateClientCommand(_validClient); _result = (GenericCommandResult)_handler.Handle(validUpdateCommand); Assert.AreEqual(true, _result.Success); }
public CreateContactHandlerTests() { _validCommand = new CreateContactCommand("Leonardo", "Masculino", new DateTime(1984, 2, 16));; _invalidCommand = new CreateContactCommand("", "", new DateTime()); _handler = new ContactHandler(new FakeContactRepository()); _result = new GenericCommandResult(); }
public void Dado_um_comando_invalido_deve_interromper_a_execucao() { //MOCK //MOQ FRAMEWORD //FAKE REPOSITORIES _result = (GenericCommandResult)_handler.Handle(_invalidCommand); Assert.AreEqual(_result.Sucess, false); }
public void Dado_um_comando_valido_deve_criar_a_tarefa() { var handler = new TodoHandler(new FakeTodoRepository()); _result = (GenericCommandResult)_handler.Handle(_validCommand); Assert.AreEqual(_result.Success, true); }
public void Dado_um_comando_invalido_deve_interromper_a_execucao() { var handler = new TodoHandler(new FakeTodoRepository()); _result = (GenericCommandResult)_handler.Handle(_invalidCommand); Assert.AreEqual(_result.Success, false); }
public GenericCommandResult Delete(string route) { HttpResponseMessage response = _http.DeleteAsync($"{Settings.API_URL}/{route}").Result; string content = response.Content.ReadAsStringAsync().Result; GenericCommandResult result = JsonConvert.DeserializeObject <GenericCommandResult>(content); return(result); }
public async Task CommandResult(GenericCommandResult result) { result.DeviceID = Device.ID; var commandContext = DataService.GetCommandContext(result.CommandContextID); commandContext.CommandResults.Add(result); DataService.AddOrUpdateCommandContext(commandContext); await BrowserHub.Clients.Client(commandContext.SenderConnectionID).SendAsync("CommandResult", result); }
public GenericCommandResult Put(string route, UpdateEndpointCommand command) { HttpResponseMessage response = _http.PutAsync( $"{Settings.API_URL}/{route}", new StringContent(JsonConvert.SerializeObject(command), Encoding.UTF8, "application/json")).Result; string content = response.Content.ReadAsStringAsync().Result; GenericCommandResult result = JsonConvert.DeserializeObject <GenericCommandResult>(content); return(result); }
/// <summary> /// Lists this instance. /// </summary> /// <returns></returns> public List <string> List( ) { Mode = BartMode.List; CopyBart( ); string command = string.Format(CultureInfo.InvariantCulture, "sh {0} {1}", BARTDE, CreateArgs( )); GenericCommandResult result = CommandRunner.Instance.ShellRun(command) as GenericCommandResult; string data = result.Output.ToString( ); string[] folders = data.Split(new string[] { " ", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries); this.LogDebug("Bart List: {0}", string.Join(",", folders)); //Cleanup ( ); return(new List <string> (folders)); }
public ICommandResult Execute(Book entity, IProductRepository repository) { GenericCommandResult result = new GenericCommandResult(); foreach (var s in _strategyList) { result = (GenericCommandResult)s.Execute(entity, repository); if (!result.Success) { break; } } return(result); }
public async Task <GenericCommandResult> DeleteTruck( [FromQuery] string id, [FromServices] IHandler <TruckDeleteCommand> handler) { if (string.IsNullOrEmpty(id)) { GenericCommandResult commandResult = new GenericCommandResult(false, HttpStatusCode.NoContent, null); return(commandResult); } TruckDeleteCommand command = new TruckDeleteCommand(); command.Id = id; return((GenericCommandResult)await handler.Handle(command)); }
private GenericCommandResult GeneratePartialResult() { var partialResult = new GenericCommandResult() { CommandResultID = LastInputID, DeviceID = ConfigService.GetConnectionInfo().DeviceID, CommandType = "WinPS", StandardOutput = StandardOut, ErrorOutput = "WARNING: The command execution timed out and was forced to return before finishing. " + "The results may be partial, and the console process has been reset. " + "Please note that interactive commands aren't supported." + Environment.NewLine + ErrorOut }; ProcessIdleTimeout_Elapsed(this, null); return(partialResult); }
public IActionResult Response(GenericCommandResult commandResult) { var obj = new { commandResult.Success, commandResult.Message, commandResult.Data }; if (commandResult.Success) { return(Ok(obj)); } return(BadRequest(obj)); }
public GenericCommandResult Login(string endpoint, Account account) { HttpResponseMessage response = _http.PostAsync($"{Settings.API_URL}/{endpoint}", new StringContent( JsonConvert.SerializeObject(new { username = account.UserName, password = account.Password }), Encoding.UTF8, "application/json")).Result; string content = response.Content.ReadAsStringAsync().Result; GenericCommandResult result = JsonConvert.DeserializeObject <GenericCommandResult>(content); //if (result.Success) // Settings.Token = ((AccountToken)result.Data).Token; return(result); }
private GenericCommandResult GeneratePartialResult() { OutputDone = true; var partialResult = new GenericCommandResult() { CommandContextID = LastInputID, MachineID = Utilities.GetConnectionInfo().MachineID, CommandType = "Bash", StandardOutput = StandardOut, ErrorOutput = "WARNING: The command execution froze and was forced to return before finishing. " + "The results may be partial, and the console process has been reset." + "Please note that interactive commands aren't supported." + Environment.NewLine + ErrorOut }; ProcessIdleTimeout_Elapsed(this, null); return(partialResult); }
static void Create() { Console.WriteLine("Digite o Número Serial"); var serialNumber = Console.ReadLine(); Console.WriteLine(); Console.WriteLine("Digite o ID do Modelo do Medidor"); var meterModelId = Console.ReadLine(); Console.WriteLine(); Console.WriteLine("Número do Modelo do Meididor"); var meterNumber = Console.ReadLine(); Console.WriteLine(); Console.WriteLine("Digite a Versão do Firmware"); var meterFirmwareVersion = Console.ReadLine(); Console.WriteLine(); Console.WriteLine("Digite o Estado"); Console.WriteLine(); Console.WriteLine("0 - Desconectado"); Console.WriteLine("1 - Conectado"); Console.WriteLine("2 - Armado"); var switchState = Console.ReadLine(); Console.WriteLine(); RegisterEndpointCommand command = new RegisterEndpointCommand( serialNumber, int.Parse(meterModelId), int.Parse(meterNumber), meterFirmwareVersion, (EEndpointState)Enum.GetValues(typeof(EEndpointState)).GetValue(int.Parse(switchState.ToString()))); GenericCommandResult result = _service.Post("v1/endpoints", command); Console.WriteLine(result.Message); }
public ICommandResult Handle(CreateOrderCommand command) { var result = new GenericCommandResult(); command.Validate(); if (command.Invalid) { result.Fail(command.Notifications); return(result); } var customer = _customerRepository.Get(command.CustomerId); var deliveryFee = _deliveryFeeRepository.Get(command.ZipCode); var discount = _discountRepository.Get(command.PromoCode); var products = _productRepository.Get(command.ExtractProductsIdsFromItems()); var order = new Order(customer, deliveryFee, discount); foreach (var item in command.Items) { var product = products.FirstOrDefault(x => x.Id == item.ProductId); order.AddItem(product, item.Quantity); } AddNotifications(order.Notifications); if (Invalid) { result.Fail(this.Notifications); } else { _orderRepository.Save(order); } return(result); }
static void Update() { Console.WriteLine("Digite o Número Serial"); var serialNumber = Console.ReadLine(); Console.WriteLine(); Console.WriteLine("Digite o Estado"); Console.WriteLine(); Console.WriteLine("0 - Desconectado"); Console.WriteLine("1 - Conectado"); Console.WriteLine("2 - Armado"); var switchState = Console.ReadLine(); Console.WriteLine(); UpdateEndpointCommand command = new UpdateEndpointCommand( serialNumber, (EEndpointState)Enum.GetValues(typeof(EEndpointState)).GetValue(int.Parse(switchState.ToString()))); GenericCommandResult result = _service.Put("v1/endpoints", command); Console.WriteLine(result.Message); }
public async Task <ICommandResult> Authenticate(AuthenticateRequest request) { _response = new GenericCommandResult(); User user = null; if (request.GrantType.Equals("password")) { user = await UserAuthentication(request); } else if (request.GrantType.Equals("refresh_token")) { user = await RefreshToken(request); } if (!_response.Success) { return(_response); } await GenerateJwt(user); return(_response); }
static void Delete() { Console.WriteLine("Digite o Número Serial"); var serialNumber = Console.ReadKey(); Console.WriteLine(); Console.WriteLine("Deseja realmente excluir esse registro?"); Console.WriteLine(); Console.WriteLine("1 - SIM"); Console.WriteLine("2 - NÃO"); Console.WriteLine(); var confirmation = Console.ReadKey(); Console.WriteLine(); if (confirmation.KeyChar != '1') { return; } GenericCommandResult result = _service.Delete($"v1/endpoints/{serialNumber.KeyChar}"); Console.WriteLine(result.Message); }
public void WhenInputCommandInvalidMustStopExecution() { _result = (GenericCommandResult)_handler.Handle(_invalidCommand); Assert.AreEqual(_result.Success, false); }
public void Dado_um_comando_valido_deve_criar_a_tarefa() { _result = (GenericCommandResult)_handler.Handle(_validCommand); Assert.AreEqual(_result.Success, true); }
public void WhenInputCommandValidMustExecution() { _result = (GenericCommandResult)_handler.Handle(_validCommand); Assert.AreEqual(_result.Success, true); }
public void mark_as_undone() { _result = (GenericCommandResult)_handler.Handle(_undonecommand); Assert.AreEqual(_result.Success, true); }