public void GestStockTest() { Response output = new Response(); try { output = Apis.GestStock(); } catch (Exception e) { StringAssert.Contains(e.Message, "Error al ejecutar el método"); return; } Assert.AreEqual(true, output.Status); }
private void SendStock(string message, bool dayrange) { Response stockResponse = Apis.GestStock(); if (stockResponse.Status) { StockModel model = ConvertCsvToStockModel(stockResponse.Message); string output = $"APPL quote is ${model.Close} per share"; if (dayrange) { output = $"APPL ({model.Symbol}) Days Low quote is ${model.Low} and Days High quote is ${model.High}"; } using (var db = new ApplicationDbContext()) { UserViewModel sender = _Connections.Where(u => u.Username == IdentityName).First(); ApplicationUser user = db.Users.Where(u => u.UserName == IdentityName).FirstOrDefault(); string adminId = "Administrador"; UserViewModel adminViewModel = _Connections.Where(x => x.Username == adminId).FirstOrDefault(); ApplicationUser admin = db.Users.Where(u => u.UserName == adminId).FirstOrDefault(); if (adminViewModel == null) { adminViewModel = Mapper.Map <ApplicationUser, UserViewModel>(admin); adminViewModel.Device = "Web"; adminViewModel.CurrentRoom = ""; _Connections.Add(adminViewModel); Clients.Caller.addUser(adminViewModel); _ConnectionsMap.Add(adminId, Context.ConnectionId); } // Create and save message in database Message msgIn = new Message() { Content = Regex.Replace(message, @"(?i)<(?!img|a|/a|/img).*?>", string.Empty), Timestamp = DateTime.Now.Ticks.ToString(), FromUser = user, IsPrivate = true }; db.Messages.Add(msgIn); db.SaveChanges(); MessageViewModel messageInViewModel = Mapper.Map <Message, MessageViewModel>(msgIn); Message msgOut = new Message() { Content = output, Timestamp = DateTime.Now.Ticks.ToString(), FromUser = admin, IsPrivate = true }; db.Messages.Add(msgOut); db.SaveChanges(); MessageViewModel messageOutViewModel = Mapper.Map <Message, MessageViewModel>(msgOut); // Broadcast the message Clients.Client(adminId).newMessage(messageInViewModel); Clients.Caller.newMessage(messageInViewModel); Clients.Caller.newMessage(messageOutViewModel); } } }