Пример #1
0
        public void SearchAdsFromUrl_CategoryIsSelected_ReturnParentCategoryLabelUrlPartAsImagePath()
        {
            // Given
            Category cat = new Category {
                Id = 12, LabelUrlPart = "cat-url-label", Label = "Label", ImageName = "image"
            };

            var adRepoMock = new Moq.Mock <ISearchRepository>();

            adRepoMock.Setup(r => r.SearchAds(null, null, It.Is <int[]>(x => x[0] == cat.Id))).Returns(new List <SearchAdCache>());

            var repoMock = new Moq.Mock <IRepository>();

            repoMock.Setup(r => r.Get <Category>(cat.Id)).Returns(cat);

            var catRepoMock = new Moq.Mock <ICategoryRepository>();

            catRepoMock.Setup(r => r.GetCategoryFromUrlPart("cat-url-label")).Returns(cat);

            SearchServices service = new SearchServices(repoMock.Object, catRepoMock.Object, adRepoMock.Object, null, null, null);

            // When
            AdSearchResultModel result = service.SearchAdsFromUrl(null, "cat-url-label");

            // Then
            Assert.IsNull(result.SearchString);
            Assert.IsNull(result.CitySelectedId);
            Assert.AreEqual(12, result.CategorySelectedId);
            Assert.AreEqual("image", result.CategoryImagePath);
            Assert.AreEqual("Label", result.CategorySelectedLabel);

            adRepoMock.VerifyAll();
        }
Пример #2
0
        public void SearchAdsFromUrl_CategoryIsSelected_RunSearchWithCategory()
        {
            // Given
            Category cat = new Category {
                Id = 12, LabelUrlPart = "cat-url-label", Label = "Label"
            };

            IList <SearchAdCache> searchResult = new List <SearchAdCache>();

            searchResult.Add(new SearchAdCache
            {
                Title = "ship",
                City  = new City()
                {
                    Label = "the city"
                },
                Category = cat
            });

            var adRepoMock = new Moq.Mock <ISearchRepository>();

            adRepoMock.Setup(r => r.SearchAds(null, null, It.Is <int[]>(x => x[0] == cat.Id))).Returns(searchResult);

            var repoMock = new Moq.Mock <IRepository>();

            repoMock.Setup(r => r.Get <Category>(cat.Id)).Returns(cat);

            var catRepoMock = new Moq.Mock <ICategoryRepository>();

            catRepoMock.Setup(r => r.GetCategoryFromUrlPart("cat-url-label")).Returns(cat);

            SearchServices service = new SearchServices(repoMock.Object, catRepoMock.Object, adRepoMock.Object, null, null, null);

            // When
            AdSearchResultModel result = service.SearchAdsFromUrl(null, "cat-url-label");

            // Then
            Assert.IsNull(result.SearchString);
            Assert.IsNull(result.CitySelectedId);
            Assert.AreEqual(12, result.CategorySelectedId);
            Assert.AreEqual("Label", result.CategorySelectedLabel);
            Assert.AreEqual(1, result.SearchResult.Count);
            Assert.AreEqual(1, result.SearchResultTotalCount);
            Assert.AreEqual("ship", result.SearchResult[0].Title);

            adRepoMock.VerifyAll();
        }
Пример #3
0
        public void SearchAdsFromUrl_CityIsSelected_RunSearchWithCity()
        {
            // Given
            City city = new City {
                Id = 12, LabelUrlPart = "city-url-label", Label = "Label"
            };

            IList <SearchAdCache> searchResult = new List <SearchAdCache>();

            searchResult.Add(new SearchAdCache
            {
                Title    = "ship",
                City     = city,
                Category = new Category {
                    Label = "pouet"
                }
            });

            var adRepoMock = new Moq.Mock <ISearchRepository>();

            adRepoMock.Setup(r => r.SearchAds(null, city.Id, null)).Returns(searchResult);

            var catLocationServiceMock = new Moq.Mock <ILocationServices>();

            catLocationServiceMock.Setup(r => r.GetCityFromLabelUrlPart("city-url-label")).Returns(city);

            SearchServices service = new SearchServices(null, null, adRepoMock.Object, null, null, catLocationServiceMock.Object);

            // When
            AdSearchResultModel result = service.SearchAdsFromUrl("city-url-label", null);

            // Then
            Assert.IsNull(result.SearchString);
            Assert.AreEqual(12, result.CitySelectedId);
            Assert.AreEqual(1, result.SearchResult.Count);
            Assert.AreEqual(1, result.SearchResultTotalCount);
            Assert.AreEqual("ship", result.SearchResult[0].Title);

            adRepoMock.VerifyAll();
        }