public async Task <PagedListViewModel <AdvertiserListViewModel> > Get([FromUri] AdvertiserQueryViewModel model)
        {
            var advertiserQueryOptions = _mapping.Map <AdvertiserQueryOptions>(model);
            var advertisers            = await _advertiserService.GetAdvertisers(advertiserQueryOptions).ToPagedListAsync(model).ConfigureAwait(false);

            return(_mapping.Map <PagedListViewModel <AdvertiserListViewModel> >(advertisers));
        }
示例#2
0
        public async Task Get_ShouldReturnListOfAdvertisers()
        {
            // Arrange
            var userId = Guid.NewGuid();
            var model  = new AdvertiserQueryViewModel {
                UserId = userId
            };
            var buyerAccount1 = new BuyerAccount {
                BuyerAccountId = 1
            };
            var buyerAccount2 = new BuyerAccount {
                BuyerAccountId = 2
            };
            var advertisers = new List <Advertiser>
            {
                new Advertiser {
                    BuyerAccountId = buyerAccount1.BuyerAccountId, BuyerAccount = buyerAccount1
                },
                new Advertiser {
                    BuyerAccountId = buyerAccount1.BuyerAccountId, BuyerAccount = buyerAccount1
                },
                new Advertiser {
                    BuyerAccountId = buyerAccount2.BuyerAccountId, BuyerAccount = buyerAccount2
                }
            };

            Mock.Mock <IAdvertiserService>().Setup(x => x.GetAdvertisers(It.IsAny <AdvertiserQueryOptions>()))
            .Returns(advertisers.ToAsyncEnumerable());

            // Act
            var retVal = await Controller.Get(model);

            // Assert
            Assert.That(retVal, Is.Not.Null);
            Assert.That(retVal.TotalItemCount, Is.EqualTo(3));
        }