コード例 #1
0
        public async Task Given_A_Valid_Message_Banlist_Property_Should_Not_Be_Null()
        {
            // Arrange
            var banlistDataConsumer = new BanlistDataConsumer
            {
                Message = "{\"ArticleId\":642752,\"Title\":\"April 2000 Lists\",\"BanlistType\":\"Ocg\",\"StartDate\":\"2000-04-01T00:00:00\",\"Sections\":[{\"Title\":\"April 2000 Lists\",\"Content\":[]},{\"Title\":\"Full Lists\",\"Content\":[]},{\"Title\":\"Limited\",\"Content\":[\"Change of Heart\",\"Dark Hole\",\"Exodia the Forbidden One\",\"Last Will\",\"Left Arm of the Forbidden One\",\"Left Leg of the Forbidden One\",\"Mirror Force\",\"Pot of Greed\",\"Raigeki\",\"Right Arm of the Forbidden One\",\"Right Leg of the Forbidden One\"]},{\"Title\":\"Semi-Limited\",\"Content\":[\"Graceful Charity\",\"Harpie's Feather Duster\",\"Monster Reborn\"]}]}"
            };

            _banlistService.Add(Arg.Any <YugiohBanlist>()).Returns(new Banlist());

            // Act
            var result = await _sut.Handle(banlistDataConsumer, CancellationToken.None);

            // Assert
            result.YugiohBanlist.Should().NotBeNull();
        }
コード例 #2
0
        public async Task <BanlistDataConsumerResult> Handle(BanlistDataConsumer request, CancellationToken cancellationToken)
        {
            var banlistDataConsumerResult = new BanlistDataConsumerResult();

            try
            {
                var yugiohBanlist = JsonConvert.DeserializeObject <YugiohBanlist>(request.Message);

                if (yugiohBanlist != null && yugiohBanlist.Sections.Any())
                {
                    banlistDataConsumerResult.YugiohBanlist = yugiohBanlist;

                    _logger.LogInformation(
                        $"{yugiohBanlist.BanlistType.ToString()}, {yugiohBanlist.Title}, {yugiohBanlist.StartDate}");

                    var banlistExists = await _banlistService.BanlistExist(yugiohBanlist.ArticleId);

                    var result = banlistExists
                        ? await _banlistService.Update(yugiohBanlist)
                        : await _banlistService.Add(yugiohBanlist);

                    banlistDataConsumerResult.BanlistId = result.Id;
                }
                else
                {
                    _logger.LogInformation("Banlist not processed, {@Title}, {@StartDate}", yugiohBanlist.Title, yugiohBanlist.StartDate);
                }
            }
            catch (ArgumentNullException ex)
            {
                _logger.LogError("Argument {@Param} was null. Message: {@Message}: ", ex.ParamName, request.Message);
            }
            catch (NullReferenceException ex)
            {
                _logger.LogError("Null reference exception {@Message}. Exception: {@Exception}: ", request.Message, ex);
            }
            catch (Exception ex)
            {
                _logger.LogError("Unexpected error occured {@Exception}: ", ex);
            }

            return(banlistDataConsumerResult);
        }
コード例 #3
0
        public async Task <Banlist> AddOrUpdate(YugiohBanlist yugiohBanlist)
        {
            var format = await _formatService.FormatByAcronym(yugiohBanlist.BanlistType.ToString());

            if (format == null)
            {
                throw new ArgumentException($"Format with acronym '{yugiohBanlist.BanlistType.ToString()}' not found.");
            }

            var banlist = await _banlistService.BanlistById(yugiohBanlist.ArticleId);

            if (banlist == null)
            {
                var addCommand = new AddBanlistCommand
                {
                    Id          = yugiohBanlist.ArticleId,
                    FormatId    = format.Id,
                    Name        = yugiohBanlist.Title,
                    ReleaseDate = yugiohBanlist.StartDate
                };

                banlist = await _banlistService.Add(addCommand);
            }
            else
            {
                var updateCommand = new UpdateBanlistCommand
                {
                    Id          = yugiohBanlist.ArticleId,
                    FormatId    = format.Id,
                    Name        = yugiohBanlist.Title,
                    ReleaseDate = yugiohBanlist.StartDate
                };

                banlist = await _banlistService.Update(updateCommand);
            }

            var banlistCards = await _banlistCardsService.MapToBanlistCards(banlist.Id, yugiohBanlist.Sections);

            banlist.Cards = await _banlistService.Update(banlist.Id, new UpdateBanlistCardsCommand { BanlistCards = banlistCards });

            return(banlist);
        }