public async Task Given_A_CardsByArchetype_Article_Should_Execute_ArchetypeByName()
        {
            // Arrange
            var article = new UnexpandedArticle {
                Title = "Clear Wing", Url = "/wiki/List_of_\"Clear_Wing\"_cards"
            };

            _config.WikiaDomainUrl.Returns("http://yugioh.wikia.com");
            _archetypeService.ArchetypeByName(Arg.Any <string>()).Returns((Archetype)null);
            _archetypeService.Add(Arg.Any <AddArchetypeCommand>()).Returns((Archetype)null);

            // Act
            await _sut.ProcessItem(article);

            // Assert
            await _archetypeService.Received(1).ArchetypeByName(Arg.Any <string>());
        }
        public async Task <ArchetypeDataTaskResult <ArchetypeMessage> > Process(ArchetypeMessage archetypeData)
        {
            var articleDataTaskResult = new ArchetypeDataTaskResult <ArchetypeMessage>
            {
                ArchetypeData = archetypeData
            };

            var existingArchetype = await _archetypeService.ArchetypeById(archetypeData.Id);

            if (existingArchetype == null)
            {
                var newArchetype = new Archetype
                {
                    Id      = archetypeData.Id,
                    Name    = archetypeData.Name,
                    Url     = archetypeData.ProfileUrl,
                    Created = DateTime.UtcNow,
                    Updated = archetypeData.Revision
                };

                await _archetypeService.Add(newArchetype);
            }
            else
            {
                existingArchetype.Name    = archetypeData.Name;
                existingArchetype.Url     = archetypeData.ProfileUrl;
                existingArchetype.Updated = archetypeData.Revision;

                await _archetypeService.Update(existingArchetype);
            }

            if (!string.IsNullOrWhiteSpace(archetypeData.ImageUrl))
            {
                var downloadImage = new DownloadImage
                {
                    RemoteImageUrl = new Uri(archetypeData.ImageUrl),
                    ImageFileName  = archetypeData.Id.ToString(),
                };

                await _archetypeImageQueueService.Publish(downloadImage);
            }

            return(articleDataTaskResult);
        }
Exemple #3
0
        public async Task <ArticleTaskResult> ProcessItem(UnexpandedArticle item)
        {
            var response = new ArticleTaskResult {
                Article = item
            };

            if (!item.Title.Equals("Archetype", StringComparison.OrdinalIgnoreCase))
            {
                var archetypeUrl = new Uri(new Uri(_config.WikiaDomainUrl), item.Url);

                var thumbNailUrl = await _archetypeWebPage.ArchetypeThumbnail(item.Id, item.Url);

                var existingArchetype = await _archetypeService.ArchetypeById(item.Id);

                var archetype = existingArchetype == null
                    ? await _archetypeService.Add(new AddArchetypeCommand
                {
                    ArchetypeNumber = item.Id,
                    Name            = item.Title,
                    ImageUrl        = ImageHelper.ExtractImageUrl(thumbNailUrl),
                    ProfileUrl      = archetypeUrl.AbsoluteUri
                })
                    : await _archetypeService.Update(new UpdateArchetypeCommand
                {
                    Id         = existingArchetype.Id,
                    Name       = item.Title,
                    ImageUrl   = ImageHelper.ExtractImageUrl(thumbNailUrl),
                    ProfileUrl = archetypeUrl.AbsoluteUri
                });


                if (archetype != null)
                {
                    response.IsSuccessfullyProcessed = true;
                }
            }

            return(response);
        }
Exemple #4
0
        public async Task Given_An_Archetype_Article_Should_Execute_ArchetypeByName()
        {
            // Arrange
            var article = new UnexpandedArticle {
                Title = "Blue-Eyes", Url = "/wiki/Blue-Eyes"
            };

            _config.WikiaDomainUrl.Returns("http://yugioh.wikia.com");
            _archetypeWebPage.Cards(Arg.Any <Uri>()).Returns(new List <string> {
                "Blue-Eyes White Dragon"
            });
            _archetypeService.Add(Arg.Any <AddArchetypeCommand>()).Returns(new Archetype());

            // Act
            await _sut.ProcessItem(article);

            // Assert
            await _archetypeService.Received(1).ArchetypeById(Arg.Any <int>());
        }