public CustomerReviewSearchServiceTests()
 {
     _randomizer            = new Fixture();
     _repository            = new Mock <ICustomerReviewRepository>();
     _customerReviewService = new Mock <ICustomerReviewService>();
     _searchService         = new CustomerReviewSearchService(() => _repository.Object, _customerReviewService.Object);
 }
 public CustomerReviewSearchServiceTests()
 {
     randomizer            = new Fixture();
     repository            = new Mock <ICustomerReviewRepository>();
     customerReviewService = new Mock <ICustomerReviewService>();
     service = new CustomerReviewSearchService(() => repository.Object, customerReviewService.Object);
 }
        public void CanDoCRUDandSearch()
        {
            // Read non-existing item
            var getByIdsResult = CustomerReviewService.GetByIds(new[] { CustomerReviewId });

            Assert.NotNull(getByIdsResult);
            Assert.Empty(getByIdsResult);

            // Create
            var item = new CustomerReview
            {
                Id             = CustomerReviewId,
                ProductId      = ProductId,
                CreatedDate    = DateTime.Now,
                CreatedBy      = "initial data seed",
                AuthorNickname = "John Doe",
                Content        = "Liked that",
                Virtues        = "Liked that!",
                Disadvantages  = "Not",
                Rate           = 3
            };

            CustomerReviewService.SaveCustomerReviews(new[] { item });

            getByIdsResult = CustomerReviewService.GetByIds(new[] { CustomerReviewId });
            Assert.Single(getByIdsResult);

            item = getByIdsResult[0];
            Assert.Equal(CustomerReviewId, item.Id);

            // Update
            var updatedContent = "Updated content";

            Assert.NotEqual(updatedContent, item.Content);

            item.Content = updatedContent;
            CustomerReviewService.SaveCustomerReviews(new[] { item });
            getByIdsResult = CustomerReviewService.GetByIds(new[] { CustomerReviewId });
            Assert.Single(getByIdsResult);

            item = getByIdsResult[0];
            Assert.Equal(updatedContent, item.Content);

            // Search
            Assert.Throws <ArgumentNullException>(() => CustomerReviewSearchService.SearchCustomerReviews(null));

            var criteria = new CustomerReviewSearchCriteria {
                ProductIds = new[] { ProductId }
            };
            var searchResult = CustomerReviewSearchService.SearchCustomerReviews(criteria);

            Assert.NotNull(searchResult);
            Assert.Equal(1, searchResult.TotalCount);
            Assert.Single(searchResult.Results);

            // Delete
            CanDeleteCustomerReviews();
        }
        public void SearchCustomerReviews_ExistingItem_ReturnsItem()
        {
            string testProductId = "testProductId";
            var    criteria      = new CustomerReviewSearchCriteria {
                ProductIds = new[] { testProductId }
            };
            var searchResult = CustomerReviewSearchService.SearchCustomerReviews(criteria);

            Assert.NotNull(searchResult);
            Assert.NotEqual(0, searchResult.TotalCount);
        }
示例#5
0
        public async Task CanDoCRUDandSearch()
        {
            // Read non-existing item
            var getByIdsResult = await CustomerReviewService.GetByIdsAsync(new[] { CustomerReviewId });

            Assert.NotNull(getByIdsResult);
            Assert.Empty(getByIdsResult);

            // Create
            var item = new CustomerReview
            {
                Id            = CustomerReviewId,
                ProductId     = ProductId,
                CreatedDate   = DateTime.Now,
                CreatedBy     = "initial data seed",
                CustomerName  = "John Doe",
                ReviewContent = "Liked that"
            };

            await CustomerReviewService.SaveCustomerReviewsAsync(new[] { item });

            _mockCustomerReviewRepository.Setup(ss => ss.GetByIdsAsync(new[] { CustomerReviewId }))
            .ReturnsAsync(new[] { new CustomerReviewEntity().FromModel(item, new PrimaryKeyResolvingMap()) });

            getByIdsResult = await CustomerReviewService.GetByIdsAsync(new[] { CustomerReviewId });

            Assert.Single(getByIdsResult);

            item = getByIdsResult[0];
            Assert.Equal(CustomerReviewId, item.Id);

            // Update
            var updatedContent = "Updated content";

            Assert.NotEqual(updatedContent, item.ReviewContent);

            item.ReviewContent = updatedContent;
            await CustomerReviewService.SaveCustomerReviewsAsync(new[] { item });

            getByIdsResult = await CustomerReviewService.GetByIdsAsync(new[] { CustomerReviewId });

            Assert.Single(getByIdsResult);

            item = getByIdsResult[0];
            Assert.Equal(updatedContent, item.ReviewContent);

            // Search
            var mockReviews = new[] { new CustomerReviewEntity().FromModel(item, new PrimaryKeyResolvingMap()) }.AsQueryable().BuildMock();

            _mockCustomerReviewRepository.SetupGet(x => x.CustomerReviews).Returns(mockReviews.Object);

            var criteria = new CustomerReviewSearchCriteria {
                ProductIds = new[] { ProductId }
            };
            var cacheKey = CacheKey.With(CustomerReviewSearchService.GetType(), nameof(CustomerReviewSearchService.SearchCustomerReviewsAsync), criteria.GetCacheKey());

            _platformMemoryCacheMock.Setup(pmc => pmc.CreateEntry(cacheKey)).Returns(_cacheEntryMock.Object);

            var searchResult = await CustomerReviewSearchService.SearchCustomerReviewsAsync(criteria);

            Assert.NotNull(searchResult);
            Assert.Equal(1, searchResult.TotalCount);
            Assert.Single(searchResult.Results);

            // Delete
            _mockCustomerReviewRepository.Setup(ss => ss.GetByIdsAsync(new[] { CustomerReviewId }))
            .ReturnsAsync(new CustomerReviewEntity[0]);

            await CanDeleteCustomerReviews();
        }
        public void SearchCustomerReviews_Null_ThrowsArgumentNullException()
        {
            Action actual = () => CustomerReviewSearchService.SearchCustomerReviews(null);

            Assert.Throws <ArgumentNullException>(actual);
        }