public void Run([ServiceBusTrigger("hweb_poc_passage_published_topic", "hweb_sbus_subscription_passage_processor", Connection = "SASListener")] Message sbusMsg, ILogger log) { try { ParaMessage message = null; if (sbusMsg != null && sbusMsg.Body != null) { var messageBody = Encoding.UTF8.GetString(sbusMsg.Body); message = JsonConvert.DeserializeObject <ParaMessage>(messageBody, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); log.LogInformation($"C# ServiceBus topic trigger function processed message: {message.Title}"); } if (message != null) { var result = _analyser.Analyse(message.Sample); if (result != null) { log.LogInformation($"Longest Sentence is: {result.LongestSentence} having {result.MaxWordCount} words!"); } } } catch (Exception ex) { log.LogCritical(ex, $"FAILED to process message! : {ex.Message} - {ex.StackTrace}"); } }
public void TestParagraphModel() { var message = new ParaMessage { Title = "Treasure Island", Published = new DateTime(1722, 3, 23), Author = "Robert Lewis Stephenson", Type = BookType.Fiction, Sample = "Long John Silver is a terrible man and prirate. He wore a long black coat, parot and sword. He is very scary." }; Assert.AreEqual(message.Year, 1722); }
public void TestParagraphModelGuardTest() { var message = new ParaMessage("Treasure Island", "Robert L Stephenson"); message.Published = new DateTime(1722, 3, 23); message.Type = BookType.Fiction; message.Sample = "Some Sample"; var json = JsonConvert.SerializeObject(message, Formatting.Indented); var deserialisedMessage = JsonConvert.DeserializeObject<ParaMessage>(json); Assert.AreEqual(message.Author, deserialisedMessage.Author); Assert.AreEqual(message.Year, 1722); Assert.AreEqual(message.Created, deserialisedMessage.Created); }
public void TestParagraphModelJson() { var message = new ParaMessage { Title = "Treasure Island", Published = new DateTime(1722, 3, 23), Author = "Robert Lewis Stephenson", Type = BookType.Fiction, Sample = "Long John Silver is a terrible man and prirate. He wore a long black coat, parot and sword. He is very scary." }; var json = JsonConvert.SerializeObject(message, Formatting.Indented); var deserialisedMessage = JsonConvert.DeserializeObject<ParaMessage>(json); Assert.AreEqual(message.Author, deserialisedMessage.Author); Assert.AreEqual(message.Year, 1722); Assert.AreEqual(message.Created, deserialisedMessage.Created); }
public async Task <IActionResult> getAllMessages(int myId, [FromQuery] ParaMessage para) { if (myId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } var repoMember = await _repoMember.Get(myId); if (repoMember == null) { return(NotFound()); } para.UserId = myId; var pageMessages = await _repoMessage.GetMessagesForUser(para); Response.AddPagination(pageMessages.CurrentPage, pageMessages.PageSize, pageMessages.TotalCount, pageMessages.TotalPages); var dtoMessages = _mapper.Map <IEnumerable <DtoMessageList> >(pageMessages); return(Ok(dtoMessages)); }