Esempio n. 1
0
        public void SearchAssociatedProducts_ReturnsProducts()
        {
            // Arrange
            var verifySet = new[] { "prod-1", "prod-2", "prod-3", "prod-4" }.Select(x => new domainModel.CatalogProduct {
                Id = x
            }).ToArray();
            var criteria = new ProductAssociationSearchCriteria
            {
                ObjectIds     = new[] { "prod-1" },
                ResponseGroup = domainModel.ItemResponseGroup.ItemInfo.ToString(),
                Sort          = "Id"
            };
            var catalogRepository = new Mock <ICatalogRepository>();

            catalogRepository.Setup(x => x.Associations).Returns(TestAssociationEntities.AsQueryable());
            catalogRepository.Setup(x => x.Items).Returns(TestItemEntities.AsQueryable());
            catalogRepository.Setup(x => x.GetAllChildrenCategoriesIds(It.Is <string[]>(ids => ids.SequenceEqual(new [] { "cat-1" })))).Returns(TestChildCategories);

            var itemService = new Mock <IItemService>();

            itemService.Setup(x => x.GetByIds(It.Is <string[]>(ids => ids.SequenceEqual(verifySet.Select(p => p.Id))), It.IsIn(domainModel.ItemResponseGroup.ItemInfo), It.IsAny <string>()))
            .Returns(verifySet);
            var sut = new ProductAssociationSearchService(() => catalogRepository.Object, itemService.Object);
            // Act
            var result = sut.SearchProductAssociations(criteria);

            // Assert
            Assert.True(result.TotalCount == 4);
            Assert.Equal(result.Results, verifySet);
        }
Esempio n. 2
0
        public void GetCriteria_InvalidArguments_ThrowsArgumentNullException()
        {
            var criteria = new ProductAssociationSearchCriteria()
            {
                ObjectIds = new string[] { }.ToList()
            };
            var catalogRepository = new Mock <ICatalogRepository>();
            var itemService       = new Mock <IItemService>();
            var sut = new ProductAssociationSearchService(() => catalogRepository.Object, itemService.Object);

            Assert.Throws <ArgumentNullException>(() => sut.SearchProductAssociations(criteria));
        }