public async Task Given_A_CardSectionMessage_Should_Invoke_Update_Method_Once() { // Arrange const int expected = 1; var cardSectionMessage = new CardSectionMessage { CardSections = new List <CardSection> { new CardSection { Name = "Call Of The Haunted", ContentList = new List <string> { "It's a trap!" } } } }; _cardService.CardByName(Arg.Any <string>()).Returns(new Card()); // Act await _sut.Process(cardSectionMessage); // Assert await _cardTipService.Received(expected).Update(Arg.Any <List <TipSection> >()); }
public async Task <CardSectionMessage> ProcessItem(Article article) { var cardSections = new List <CardSection>(); var contentResult = await _wikiArticle.Simple(article.Id); foreach (var section in contentResult.Sections) { if (section.Title.Equals("References", StringComparison.OrdinalIgnoreCase)) { continue; } var rulingSection = new CardSection { Name = section.Title, ContentList = SectionHelper.GetSectionContentList(section) }; cardSections.Add(rulingSection); } var cardSectionMessage = new CardSectionMessage { Name = article.Title, CardSections = cardSections }; return(cardSectionMessage); }
public async Task Given_A_CardSectionMessage_If_Card_Is_Not_Found_Should_Return_Errors() { // Arrange var cardSectionMessage = new CardSectionMessage(); // Act var result = await _sut.Process(cardSectionMessage); // Assert result.Errors.Should().NotBeNullOrEmpty(); }
public async Task Given_A_CardSectionMessage_If_Card_Is_Not_Found_IsSuccessful_Should_be_False() { // Arrange var cardSectionMessage = new CardSectionMessage(); // Act var result = await _sut.Process(cardSectionMessage); // Assert result.IsSuccessful.Should().BeFalse(); }
public async Task Given_A_CardSectionMessage_Should_Invoke_CardByName_Method_Once() { // Arrange const int expected = 1; var cardSectionMessage = new CardSectionMessage(); // Act await _sut.Process(cardSectionMessage); // Assert await _cardService.Received(expected).CardByName(Arg.Any <string>()); }
public async Task <CardSectionDataTaskResult <CardSectionMessage> > Process(CardSectionMessage cardSectionData) { var cardSectionDataTaskResult = new CardSectionDataTaskResult <CardSectionMessage> { CardSectionData = cardSectionData }; var card = await _cardService.CardByName(cardSectionData.Name); if (card != null) { await _cardTipService.DeleteByCardId(card.Id); var newTipSectionList = new List <TipSection>(); foreach (var cardSection in cardSectionData.CardSections) { var newTipSection = new TipSection { CardId = card.Id, Name = cardSection.Name, Created = DateTime.UtcNow, Updated = DateTime.UtcNow }; foreach (var tip in cardSection.ContentList) { newTipSection.Tip.Add(new Tip { TipSection = newTipSection, Text = tip, Created = DateTime.UtcNow, Updated = DateTime.UtcNow }); } newTipSectionList.Add(newTipSection); } if (newTipSectionList.Any()) { await _cardTipService.Update(newTipSectionList); } } else { cardSectionDataTaskResult.Errors.Add($"Card Tips: card '{cardSectionData.Name}' not found."); } return(cardSectionDataTaskResult); }
public async Task <CardSectionDataTaskResult <CardSectionMessage> > Process(CardSectionMessage cardSectionData) { var cardSectionDataTaskResult = new CardSectionDataTaskResult <CardSectionMessage> { CardSectionData = cardSectionData }; var card = await _cardService.CardByName(cardSectionData.Name); if (card != null) { await _cardRulingService.DeleteByCardId(card.Id); var rulingSections = new List <RulingSection>(); foreach (var cardSection in cardSectionData.CardSections) { var rulingSection = new RulingSection { CardId = card.Id, Name = cardSection.Name, Created = DateTime.UtcNow, Updated = DateTime.UtcNow }; foreach (var ruling in cardSection.ContentList) { rulingSection.Ruling.Add(new Ruling { RulingSection = rulingSection, Text = ruling, Created = DateTime.UtcNow, Updated = DateTime.UtcNow }); } rulingSections.Add(rulingSection); } if (rulingSections.Any()) { await _cardRulingService.Update(rulingSections); } } else { cardSectionDataTaskResult.Errors.Add($"Card Rulings: card '{cardSectionData.Name}' not found."); } return(cardSectionDataTaskResult); }
public async Task Given_A_CardSectionMessage_Should_Invoke_DeleteByCardId_Method_Once() { // Arrange const int expected = 1; var cardSectionMessage = new CardSectionMessage(); _cardService.CardByName(Arg.Any <string>()).Returns(new Card()); // Act await _sut.Process(cardSectionMessage); // Assert await _cardRulingService.Received(expected).DeleteByCardId(Arg.Any <long>()); }
public async Task Given_A_Category_And_CardSectionMessage_Should_Invoke_Process_Method_Once() { // Arrange const string category = "category"; var cardSectionMessage = new CardSectionMessage(); var handler = Substitute.For <ICardSectionProcessorStrategy>(); handler.Handles(Arg.Any <string>()).Returns(true); handler.Process(Arg.Any <CardSectionMessage>()).Returns(new CardSectionDataTaskResult <CardSectionMessage> ()); _cardSectionProcessorStrategies.GetEnumerator().Returns(new List <ICardSectionProcessorStrategy> { handler }.GetEnumerator()); // Act await _sut.Process(category, cardSectionMessage); // Assert await handler.Received(1).Process(Arg.Any <CardSectionMessage>()); }
public async Task Given_A_Category_And_CardSectionMessage_IsSuccessful_Should_Be_True() { // Arrange const string category = "category"; var cardSectionMessage = new CardSectionMessage(); var handler = Substitute.For <ICardSectionProcessorStrategy>(); handler.Handles(Arg.Any <string>()).Returns(true); handler.Process(Arg.Any <CardSectionMessage>()).Returns(new CardSectionDataTaskResult <CardSectionMessage> ()); _cardSectionProcessorStrategies.GetEnumerator().Returns(new List <ICardSectionProcessorStrategy> { handler }.GetEnumerator()); // Act var result = await _sut.Process(category, cardSectionMessage); // Assert result.IsSuccessful.Should().BeTrue(); }
public Task Publish(CardSectionMessage message) { try { var messageBodyBytes = System.Text.Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(message)); var factory = new ConnectionFactory() { HostName = _rabbitMqConfig.Value.Host }; using (var connection = factory.CreateConnection()) using (var channel = connection.CreateModel()) { var props = channel.CreateBasicProperties(); props.ContentType = _rabbitMqConfig.Value.ContentType; props.DeliveryMode = _rabbitMqConfig.Value.Exchanges[RabbitMqExchangeConstants.YugiohHeadersData].PersistentMode; props.Headers = _rabbitMqConfig.Value .Exchanges[RabbitMqExchangeConstants.YugiohHeadersData] .Queues[RabbitMqQueueConstants.CardRulingsData] .Headers.ToDictionary(k => k.Key, k => (object)k.Value); channel.BasicPublish ( RabbitMqExchangeConstants.YugiohHeadersData, "", props, messageBodyBytes ); } } catch (Exception ex) { Console.WriteLine(ex); throw; } return(Task.CompletedTask); }
public async Task <ArticleTaskResult> ProcessItem(Article article) { var response = new ArticleTaskResult { Article = article }; var tipSections = new List <CardSection>(); var articleCardTips = await _wikiArticle.Simple(article.Id); foreach (var cardTipSection in articleCardTips.Sections) { var tipSection = new CardSection { Name = cardTipSection.Title, ContentList = SectionHelper.GetSectionContentList(cardTipSection) }; if (cardTipSection.Title.Equals("List", StringComparison.OrdinalIgnoreCase) || cardTipSection.Title.Equals("Lists", StringComparison.OrdinalIgnoreCase)) { tipSection.Name = tipSection.ContentList.First(); tipSection.ContentList.Clear(); _tipRelatedWebPage.GetTipRelatedCards(tipSection, article); } tipSections.Add(tipSection); } var cardSectionMessage = new CardSectionMessage { Name = article.Title, CardSections = tipSections }; await _queues.Single(q => q.Handles(ArticleCategory.CardTips)).Publish(cardSectionMessage); return(response); }
public async Task <CardSectionDataTaskResult <CardSectionMessage> > Process(string category, CardSectionMessage cardSectionData) { var handler = _cardSectionProcessorStrategies.Single(h => h.Handles(category)); var cardSectionDataTaskResult = await handler.Process(cardSectionData); return(cardSectionDataTaskResult); }