public async Task CreateAsyncShouldNotCallCreateOnListingViewModelFactoryIfCancellationRequested()
        {
            // arrange
            var itemListingsQueryResult = new ItemListingsQueryResult
            {
                Result = new List <ListingResult>
                {
                    new ListingResult(),
                    new ListingResult()
                },
            };
            var item = new CurrencyItem();

            var cancellationTokenSource = new CancellationTokenSource();
            var cancellationToken       = cancellationTokenSource.Token;

            this.listingViewModelFactoryMock.Setup(x => x.CreateAsync(itemListingsQueryResult.Result[0], It.IsAny <Item>(), It.IsAny <CancellationToken>()))
            .Callback(() => cancellationTokenSource.Cancel());

            // act
            ItemListingsViewModel result = await this.itemListingsViewModelFactory.CreateAsync(item, itemListingsQueryResult, cancellationToken);

            // assert
            this.listingViewModelFactoryMock.Verify(x => x.CreateAsync(It.IsAny <ListingResult>(), It.IsAny <Item>(), It.IsAny <CancellationToken>()), Times.Once);
        }
        public async Task CreateAsyncShouldSetItemRarity()
        {
            var itemListingsQueryResult = new ItemListingsQueryResult();
            var item = new EquippableItem(ItemRarity.Rare);

            ItemListingsViewModel result = await this.itemListingsViewModelFactory.CreateAsync(item, itemListingsQueryResult);

            Assert.That(result.ItemRarity, Is.EqualTo(item.Rarity));
        }
        public async Task CreateAsyncShouldSetUri()
        {
            var itemListingsQueryResult = new ItemListingsQueryResult
            {
                Uri = new Uri("http://www.google.de")
            };

            ItemListingsViewModel result = await this.itemListingsViewModelFactory.CreateAsync(new CurrencyItem(), itemListingsQueryResult);

            Assert.That(result.ListingsUri, Is.EqualTo(itemListingsQueryResult.Uri));
        }
        public async Task CreateAsyncShouldSetItemDescription()
        {
            var itemListingsQueryResult = new ItemListingsQueryResult();
            var item = new EquippableItem(ItemRarity.Rare)
            {
                Name = "Brood Blast",
                Type = "Thicket Bow"
            };

            ItemListingsViewModel result = await this.itemListingsViewModelFactory.CreateAsync(item, itemListingsQueryResult);

            Assert.That(result.ItemDescription, Is.EqualTo(item.DisplayName));
        }
        public async Task ExecuteAdvancedQueryAsyncShouldSetItemListingsViewModel()
        {
            ItemListingsViewModel expected = new ItemListingsViewModel();

            this.poeTradeApiClientMock.Setup(x => x.GetListingsAsync(It.IsAny <IQueryRequest>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(new ItemListingsQueryResult());

            this.itemListingsViewModelFactoryMock.Setup(x => x.CreateAsync(It.IsAny <Item>(), It.IsAny <ItemListingsQueryResult>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(expected);

            await this.itemSearchOverlayViewModel.ExecuteAdvancedQueryAsync();

            Assert.That(this.itemSearchOverlayViewModel.ItemListings, Is.EqualTo(expected));
        }
        public async Task CreateAsyncShouldCallCreateOnListingViewModelFactory()
        {
            // arrange
            var itemListingsQueryResult = new ItemListingsQueryResult
            {
                Result = new List <ListingResult>
                {
                    new ListingResult(),
                    new ListingResult()
                },
            };
            var item = new CurrencyItem();

            var cancellationTokenSource = new CancellationTokenSource();
            var cancellationToken       = cancellationTokenSource.Token;

            // act
            ItemListingsViewModel result = await this.itemListingsViewModelFactory.CreateAsync(item, itemListingsQueryResult, cancellationToken);

            // assert
            this.listingViewModelFactoryMock.Verify(x => x.CreateAsync(itemListingsQueryResult.Result[0], item, cancellationToken));
            this.listingViewModelFactoryMock.Verify(x => x.CreateAsync(itemListingsQueryResult.Result[1], item, cancellationToken));
        }
Пример #7
0
        public async Task <ItemListingsViewModel> CreateAsync(Item item, ItemListingsQueryResult itemListingsQueryResult, CancellationToken cancellationToken = default)
        {
            var result = new ItemListingsViewModel
            {
                ListingsUri     = itemListingsQueryResult.Uri,
                ItemDescription = item.DisplayName,
                ItemRarity      = item.Rarity
            };

            foreach (var listingResult in itemListingsQueryResult.Result)
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    break;
                }

                SimpleListingViewModel itemListingViewModel = await this.listingViewModelFactory.CreateAsync(listingResult, item, cancellationToken);

                result.Listings.Add(itemListingViewModel);
            }

            return(result);
        }