コード例 #1
0
        public void CopyCtor_withAdSearchModel()
        {
            // Given
            AdSearchModel searchModel = new AdSearchModel
            {
                SearchString = "toto",
                CitySelectedId = 12,
                CategorySelectedId = 7,
                CategorySelectedLabel = "Véhicules",
                CategoryImagePath = "thepath"
            };

            Category cat = new Category
            {
                Id = 16,
                Label = "Voitures",
                ImageName = "car.png"
            };

            // When
            searchModel.SetCategory(cat);

            // Then
            Assert.AreEqual(16, searchModel.CategorySelectedId);
            Assert.AreEqual("Voitures", searchModel.CategorySelectedLabel);
            Assert.AreEqual("car.png", searchModel.CategoryImagePath);
        }
コード例 #2
0
        public void AdvancedSearchAds_SearchThroughCarAds_CallSearchRepoOnCarAds()
        {
            // Given
            Category cat = new Category { Id = 1, LabelUrlPart = "cat-url-label", Label = "Label", Type = AdTypeEnum.CarAd };

            AdvancedAdSearchModel model = new AdvancedAdSearchModel();
            model.CategorySelectedId = 1;
            model.SearchString = "toto";
            model.CitySelectedId = 12;
            model.AgeBracketSelectedId = 1;
            model.KmBracketSelectedId = 1;
            model.BrandSelectedId = 19;
            model.FuelSelectedId = 89;
            model.IsAutomatic = true;

            IList<SearchAdCache> searchResult = new List<SearchAdCache>();
            searchResult.Add(new SearchAdCache
            {
                Title = "car",
                City = new City() { Label = "the city" },
                Category = cat
            });

            var repoMock = new Moq.Mock<IRepository>();
            repoMock.Setup(r => r.Get<Category>(cat.Id)).Returns(cat);

            var helperMock = new Moq.Mock<IHelperService>();
            helperMock.Setup(r => r.GetCurrentDateTime()).Returns(new DateTime(2013, 01, 01));

            IDictionary<int, BracketItemReference> ageRef = new Dictionary<int, BracketItemReference>();
            ageRef.Add(1, new BracketItemReference { LowValue = 0, HighValue = 3 });
            IDictionary<int, BracketItemReference> kmRef = new Dictionary<int, BracketItemReference>();
            kmRef.Add(1, new BracketItemReference { LowValue = 50, HighValue = 100 });

            var refMock = new Moq.Mock<IReferenceServices>();
            refMock.Setup(s => s.GetAllAgeBrackets()).Returns(ageRef);
            refMock.Setup(s => s.GetAllKmBrackets()).Returns(kmRef);

            var searchRepoMock = new Moq.Mock<ISearchRepository>();
            searchRepoMock.Setup(r => r.AdvancedSearchAds<CarAd>(
                It.Is<AdSearchParameters>(p =>
                    p.AndSearchStrings[0].Equals("toto")
                    && p.CityId == 12
                    && p.CategoryIds[0] == 1
                    && p.MinKm == 50
                    && p.MaxKm == 100
                    && p.MinYear == 2010
                    && p.MaxYear == 2013
                    && p.BrandId == 19
                    && p.FueldId == 89
                    && p.IsAuto.Value))).Returns(searchResult);

            SearchServices service = new SearchServices(repoMock.Object, null, searchRepoMock.Object, helperMock.Object, refMock.Object, null);

            // When
            AdSearchResultModel result = service.AdvancedSearchAds(model);

            // Then
            Assert.AreEqual(1, result.SearchResultTotalCount);
        }
コード例 #3
0
        public void AdvancedSearchAds_SearchThroughAds_CallSearchRepoOnAds()
        {
            // Given
            Category cat = new Category { Id = 1, LabelUrlPart = "cat-url-label", Label = "Label", Type = AdTypeEnum.Ad };

            AdSearchModel model = new AdSearchModel();
            model.CategorySelectedId = 1;
            model.SearchString = "toto";
            model.CitySelectedId = 12;

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

            var repoMock = new Moq.Mock<IRepository>();
            repoMock.Setup(r => r.Get<Category>(cat.Id)).Returns(cat);

            var searchRepoMock = new Moq.Mock<ISearchRepository>();
            searchRepoMock.Setup(r => r.SearchAds(It.Is<String[]>(x => x[0] == "toto"), 12, It.Is<int[]>(x => x[0] == 1))).Returns(searchResult);

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

            // When
            AdSearchResultModel result = service.LightSearchAds(model);

            // Then
            Assert.AreEqual(1, result.SearchResultTotalCount);
        }
コード例 #4
0
 public AdHomeSearchResultItemModel(Category category)
     : this()
 {
     CategoryId = category.Id;
     CategoryLabel = category.Label;
     CategoryUrlPart = category.LabelUrlPart;
     CategoryImageName = category.ImageName;
 }
コード例 #5
0
        public void CanDeleteAd_AdExistsAndAlreadyDeleted_ReturnFalse()
        {
            ISessionFactory sessionFactory = NhibernateHelper.SessionFactory;
            Repository repo = new Repository(sessionFactory);
            AdRepository adRepo = new AdRepository(sessionFactory);

            using (ITransaction transaction = sessionFactory.GetCurrentSession().BeginTransaction())
            {
                #region test data
                Province p1 = new Province
                {
                    Label = "p1"
                };

                User u = new User
                {
                    Email = "*****@*****.**",
                    Password = "******"
                };
                repo.Save<User>(u);

                City c = new City
                {
                    Label = "city",
                    LabelUrlPart = "city"
                };
                p1.AddCity(c);

                Category cat = new Category
                {
                    Label = "Informatique",
                    LabelUrlPart = "Informatique",
                    Type = AdTypeEnum.Ad
                };

                Ad a = new Ad
                {
                    Title = "video game",
                    Body = "the best!!",
                    CreatedBy = u,
                    CreationDate = new DateTime(2012, 01, 16, 23, 52, 18),
                    Category = cat,
                    IsDeleted = true
                };
                c.AddAd(a);
                cat.AddAd(a);
                repo.Save<Province>(p1);
                repo.Save<City>(c);
                repo.Save<Category>(cat);
                long id = repo.Save<Ad, long>(a);

                repo.Flush();

                #endregion

                Assert.IsFalse(adRepo.CanDeleteAd(id));
            }
        }
コード例 #6
0
ファイル: CarAdMapTest.cs プロジェクト: bea-project/bea-web
        public void CarAd_mapping_standalonetable()
        {
            ISessionFactory sessionFactory = NhibernateHelper.SessionFactory;
            IRepository repo = new Repository(sessionFactory);

            using (ITransaction transaction = sessionFactory.GetCurrentSession().BeginTransaction())
            {
                Province p = new Province { Label = "Province Sud" };
                City c = new City { Label = "Nouméa", Province = p, LabelUrlPart = "city" };
                p.AddCity(c);
                repo.Save(p);
                repo.Save(c);

                User u = new User
                {
                    Email = "email",
                    Password = "******"
                };
                repo.Save(u);

                Category cat = new Category
                {
                    Label = "label",
                    LabelUrlPart = "label"
                };
                repo.Save(cat);

                CarAd carAd = new CarAd()
                {
                    Title = "title",
                    Body = "bidy",
                    CreationDate = DateTime.Now,
                    IsOffer = true,
                    CreatedBy = u,
                    City = c,
                    Category = cat,
                    Kilometers = 2000,
                    Year = 2013
                };
                repo.Save(carAd);

                Ad ad = new Ad()
                {
                    Title = "title",
                    Body = "bidy",
                    CreationDate = DateTime.Now,
                    IsOffer = true,
                    CreatedBy = u,
                    City = c,
                    Category = cat
                };
                repo.Save(ad);
                repo.Flush();

            }
        }
コード例 #7
0
ファイル: BaseController.cs プロジェクト: bea-project/bea-web
        public void FillViewLists(Category category)
        {
            if (category == null)
                return;

            switch (category.Type)
            {
                case AdTypeEnum.CarAd:
                    ViewBag.KmBrackets = _referenceServices.GetAllKmBrackets().Select(x => new SelectListItem { Text = x.Value.Label, Value = x.Key.ToString() });
                    ViewBag.AgeBrackets = _referenceServices.GetAllAgeBrackets().Select(x => new SelectListItem { Text = x.Value.Label, Value = x.Key.ToString() });
                    ViewBag.Brands = _referenceServices.GetAllCarBrands().Select(x => new SelectListItem { Text = x.Label, Value = x.Id.ToString() }).ToList();
                    ViewBag.Fuels = _referenceServices.GetAllCarFuels().Select(x => new SelectListItem { Text = x.Label, Value = x.Id.ToString() }).ToList();
                    break;
                case AdTypeEnum.MotoAd:
                    ViewBag.Brands = _referenceServices.GetAllMotoBrands().Select(x => new SelectListItem { Text = x.Label, Value = x.Id.ToString() }).ToList();
                    ViewBag.KmBrackets = _referenceServices.GetAllKmBrackets().Select(x => new SelectListItem { Text = x.Value.Label, Value = x.Key.ToString() });
                    ViewBag.AgeBrackets = _referenceServices.GetAllAgeBrackets().Select(x => new SelectListItem { Text = x.Value.Label, Value = x.Key.ToString() });
                    ViewBag.EngineSizeBrackets = _referenceServices.GetAllEngineSizeBrackets().Select(x => new SelectListItem { Text = x.Value.Label, Value = x.Key.ToString() });
                    break;
                case AdTypeEnum.OtherVehiculeAd:
                    ViewBag.KmBrackets = _referenceServices.GetAllKmBrackets().Select(x => new SelectListItem { Text = x.Value.Label, Value = x.Key.ToString() });
                    ViewBag.AgeBrackets = _referenceServices.GetAllAgeBrackets().Select(x => new SelectListItem { Text = x.Value.Label, Value = x.Key.ToString() });
                    ViewBag.Fuels = _referenceServices.GetAllCarFuels().Select(x => new SelectListItem { Text = x.Label, Value = x.Id.ToString() }).ToList();
                    break;
                case AdTypeEnum.VehiculeAd:
                    ViewBag.AgeBrackets = _referenceServices.GetAllAgeBrackets().Select(x => new SelectListItem { Text = x.Value.Label, Value = x.Key.ToString() });
                    ViewBag.KmBrackets = _referenceServices.GetAllKmBrackets().Select(x => new SelectListItem { Text = x.Value.Label, Value = x.Key.ToString() });
                    break;
                case AdTypeEnum.RealEstateAd:
                    ViewBag.Rooms = _referenceServices.GetAllRealEstateNbRoomsBrackets().Select(x => new SelectListItem { Text = x.Value.Label, Value = x.Key.ToString() }).ToList();
                    ViewBag.SurfaceAreas = _referenceServices.GetAllSurfaceAreaBrackets().Select(x => new SelectListItem { Text = x.Value.Label, Value = x.Key.ToString() }).ToList();
                    ViewBag.Types = _referenceServices.GetAllRealEstateTypes().Select(x => new SelectListItem { Text = x.Label, Value = x.Id.ToString() }).ToList();
                    ViewBag.Districts = _locationServices.GetAllDistricts().Select(x => new SelectListItem { Text = x.Label, Value = x.Id.ToString() }).ToList();
                    ViewBag.FurnishedList = new List<SelectListItem>() { new SelectListItem { Text = "Meublé", Value = "true" }, new SelectListItem { Text = "Non meublé", Value = "false" } };
                    break;
                case AdTypeEnum.MotorBoatAd:
                    ViewBag.AgeBrackets = _referenceServices.GetAllAgeBrackets().Select(x => new SelectListItem { Text = x.Value.Label, Value = x.Key.ToString() });
                    ViewBag.Types = _referenceServices.GetAllMotorBoatTypes().Select(x => new SelectListItem { Text = x.Label, Value = x.Id.ToString() }).ToList();
                    ViewBag.MotorTypes = _referenceServices.GetAllMotorBoatEngineTypes().Select(x => new SelectListItem { Text = x.Label, Value = x.Id.ToString() }).ToList();
                    break;
                case AdTypeEnum.SailingBoatAd:
                    ViewBag.AgeBrackets = _referenceServices.GetAllAgeBrackets().Select(x => new SelectListItem { Text = x.Value.Label, Value = x.Key.ToString() });
                    ViewBag.Types = _referenceServices.GetAllSailingBoatTypes().Select(x => new SelectListItem { Text = x.Label, Value = x.Id.ToString() }).ToList();
                    ViewBag.HullTypes = _referenceServices.GetAllSailingBoatHullTypes().Select(x => new SelectListItem { Text = x.Label, Value = x.Id.ToString() }).ToList();
                    break;
                case AdTypeEnum.MotorBoatEngineAd:
                    ViewBag.AgeBrackets = _referenceServices.GetAllAgeBrackets().Select(x => new SelectListItem { Text = x.Value.Label, Value = x.Key.ToString() });
                    ViewBag.Types = _referenceServices.GetAllMotorBoatEngineTypes().Select(x => new SelectListItem { Text = x.Label, Value = x.Id.ToString() }).ToList();
                    break;
                case AdTypeEnum.WaterSportAd:
                    ViewBag.Types = _referenceServices.GetAllWaterSportTypes().Select(x => new SelectListItem { Text = x.Label, Value = x.Id.ToString() }).ToList();
                    break;
            }
        }
コード例 #8
0
        public void GetAllCategoriesAndGroups_ReturnCategoriesClassedByGroup()
        {
            // Given
            Category g1 = new Category { Id = 1, Label = "first" };
            Category g2 = new Category { Id = 3, Label = "second" };
            Category g3 = new Category { Id = 7, Label = "third" };

            Category c1 = new Category { Id = 2, Label = "first c1" };
            g1.AddCategory(c1);
            Category c2 = new Category { Id = 4, Label = "second c2" };
            g2.AddCategory(c2);
            Category c3 = new Category { Id = 6, Label = "second c3" };
            g2.AddCategory(c3);
            Category c4 = new Category { Id = 5, Label = "third c4" };
            g3.AddCategory(c4);

            var repoMock = new Moq.Mock<IRepository>();
            repoMock.Setup(x => x.GetAll<Category>()).Returns(new List<Category>() { g1, g2, g3 });

            CategoryServices service = new CategoryServices(repoMock.Object, null);

            // When
            IList<CategoryItemModel> result = service.GetAllCategoriesAndGroups();

            // Then
            Assert.AreEqual(1, result[0].Id);
            Assert.AreEqual("FIRST", result[0].Label);
            Assert.IsTrue(result[0].IsGroup);

            Assert.AreEqual(2, result[1].Id);
            Assert.AreEqual("first c1", result[1].Label);
            Assert.IsFalse(result[1].IsGroup);

            Assert.AreEqual(3, result[2].Id);
            Assert.AreEqual("SECOND", result[2].Label);
            Assert.IsTrue(result[2].IsGroup);

            Assert.AreEqual(4, result[3].Id);
            Assert.AreEqual("second c2", result[3].Label);
            Assert.IsFalse(result[3].IsGroup);

            Assert.AreEqual(6, result[4].Id);
            Assert.AreEqual("second c3", result[4].Label);
            Assert.IsFalse(result[4].IsGroup);

            Assert.AreEqual(7, result[5].Id);
            Assert.AreEqual("THIRD", result[5].Label);
            Assert.IsTrue(result[5].IsGroup);

            Assert.AreEqual(5, result[6].Id);
            Assert.AreEqual("third c4", result[6].Label);
            Assert.IsFalse(result[6].IsGroup);
        }
コード例 #9
0
        public void AdDetailsModel_ctor()
        {
            // Given
            City c = new City()
            {
                Label = "Nouméa"
            };

            User u = new User()
            {
                Firstname = "Nicolas"
            };

            Category cat = new Category()
            {
                Label = "Auto",
                LabelUrlPart = "Auto",
                ParentCategory = new Category { Label = "Véhicules", LabelUrlPart = "Vehicules" }
            };

            Ad ad = new Ad()
            {
                Id = 17,
                Title = "title",
                Price = 1270,
                City = c,
                CreatedBy = u,
                CreationDate = new DateTime(2012, 05, 12, 17, 26, 08),
                Body = "body",
            };
            cat.AddAd(ad);
            ad.Images.Add(new AdImage() { Id = Guid.Parse("e9da8b1e-aa77-401b-84e0-a1290130b7b7") });
            ad.Images.Add(new AdImage() { Id = Guid.Parse("e9da8b1e-aa77-401b-84e0-a1290130b7b9") });

            // When
            AdDetailsModel model = new AdDetailsModel(ad);

            // Then
            Assert.AreEqual("title", model.Title);
            Assert.AreEqual("Nouméa", model.Location);
            Assert.AreEqual("Nicolas", model.UserFirstName);
            Assert.AreEqual("samedi 12 mai 2012 17:26", model.CreationDateString);
            Assert.AreEqual("body", model.Body);
            Assert.AreEqual("1 270 Francs", model.Price);
            Assert.AreEqual(17, model.AdId);
            Assert.AreEqual(2, model.ImagesIds.Count);
            Assert.AreEqual("e9da8b1e-aa77-401b-84e0-a1290130b7b7", model.ImagesIds[0]);
            Assert.AreEqual("e9da8b1e-aa77-401b-84e0-a1290130b7b9", model.ImagesIds[1]);
            Assert.AreEqual("Auto", model.Category);
            Assert.AreEqual("Auto", model.CategoryUrlPart);
            Assert.AreEqual("Véhicules", model.CategoryGroup);
            Assert.AreEqual("Vehicules", model.CategoryGroupUrlPart);
        }
コード例 #10
0
        public void GetAllCategoriesOfAGroup_aCategoryItem_ReturnAllSubCategoriesAndParentCategory()
        {
            // Given
            Category group = new Category
            {
                Id = 7,
                Label = "huhu"
            };
            Category subC1 = new Category
            {
                Id = 8,
                ParentCategory = group,
                Label = "toto"
            };
            group.SubCategories.Add(subC1);
            Category subC2 = new Category
            {
                Id = 9,
                ParentCategory = group,
                Label = "titi"
            };
            group.SubCategories.Add(subC2);
            Category subC3 = new Category
            {
                Id = 13,
                ParentCategory = group,
                Label = "tutu"
            };
            group.SubCategories.Add(subC3);

            var repoMock = new Moq.Mock<IRepository>();
            repoMock.Setup(r => r.Get<Category>(9)).Returns(subC2);

            CategoryServices service = new CategoryServices(repoMock.Object, null);

            // When
            IList<CategoryItemModel> result = service.GetAllCategoriesOfAGroup(9);

            // Then
            Assert.AreEqual(4, result.Count);
            Assert.AreEqual(7, result[0].Id);
            Assert.AreEqual(8, result[1].Id);
            Assert.AreEqual(9, result[2].Id);
            Assert.AreEqual(13, result[3].Id);
            Assert.AreEqual("HUHU", result[0].Label);
            Assert.AreEqual("toto", result[1].Label);
            Assert.AreEqual("titi", result[2].Label);
            Assert.AreEqual("tutu", result[3].Label);
        }
コード例 #11
0
        public void TestGetCategoryFromLabel_1Match_ReturnItemAndChildren()
        {
            ISessionFactory sessionFactory = NhibernateHelper.SessionFactory;
            CategoryRepository catRepo = new CategoryRepository(sessionFactory);

            using (ITransaction transaction = sessionFactory.GetCurrentSession().BeginTransaction())
            {
                Category parent = new Category() { Label = "parentlabel", LabelUrlPart = "parentlabelurl" };
                sessionFactory.GetCurrentSession().Save(parent);
                Category child1 = new Category() { Label = "childlabel1", LabelUrlPart = "childlabel1url" };
                Category child2 = new Category() { Label = "childlabel2", LabelUrlPart = "childlabel2url" };
                parent.AddCategory(child1);
                parent.AddCategory(child2);
                sessionFactory.GetCurrentSession().SaveOrUpdate(parent);
                sessionFactory.GetCurrentSession().Save(child1);
                sessionFactory.GetCurrentSession().Save(child2);

                Category actual = catRepo.GetCategoryFromLabel("parentlabel");
                Assert.AreEqual(2, actual.SubCategories.Count);
                Assert.AreEqual("childlabel1url", actual.SubCategories[0].LabelUrlPart);
                Assert.AreEqual("childlabel2url", actual.SubCategories[1].LabelUrlPart);
            }
        }
コード例 #12
0
        public void CountByCategory_NoSearchString_Returnwholecount()
        {
            ISessionFactory sessionFactory = NhibernateHelper.SessionFactory;
            Repository repo = new Repository(sessionFactory);
            SearchRepository searchRepo = new SearchRepository(sessionFactory);

            using (ITransaction transaction = sessionFactory.GetCurrentSession().BeginTransaction())
            {
                // Given
                #region test data
                Province p1 = new Province
                {
                    Label = "p1"
                };

                User u = new User
                {
                    Email = "*****@*****.**",
                    Password = "******"
                };
                repo.Save<User>(u);

                City c = new City
                {
                    Label = "city",
                    LabelUrlPart = "city"
                };
                p1.AddCity(c);

                Category cat = new Category
                {
                    Label = "Voilier",
                    LabelUrlPart = "Bateau"
                };

                SearchAdCache a = new SearchAdCache
                {
                    AdId = 1,
                    Title = "bateau 1",
                    Body = "la desc du bateau",
                    City = c,
                    CreationDate = new DateTime(2012, 01, 16, 23, 52, 18),
                    Category = cat
                };

                Category cat2 = new Category
                {
                    Label = "Bateau à moteur",
                    LabelUrlPart = "Bateau"
                };

                SearchAdCache a2 = new SearchAdCache
                {
                    AdId = 2,
                    Title = "poupou",
                    Body = "la desc du bateau",
                    City = c,
                    CreationDate = new DateTime(2012, 06, 11, 23, 52, 18),
                    Category = cat2
                };

                repo.Save(p1);
                repo.Save(c);
                repo.Save(cat);
                repo.Save(u);
                repo.Save(a);
                repo.Save(cat2);
                repo.Save(a2);

                repo.Flush();

                #endregion

                // When
                IDictionary<Category, int> result = searchRepo.CountByCategory(new String[] { "bateau" }, null);

                // Then
                Assert.AreEqual(2, result.Count);
                Assert.AreEqual(cat2, result.First().Key);
                Assert.AreEqual(cat, result.Last().Key);
            }
        }
コード例 #13
0
        public void SearchAds_CategoryIsSelected_CallAdRepoWithOneCategoryId()
        {
            // Given
            Category cat = new Category { Id = 12 };

            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(new string[] { "ship" }, null, new int[] { 12 })).Returns(searchResult);

            var repoMock = new Moq.Mock<IRepository>();
            repoMock.Setup(r => r.Get<Category>(12)).Returns(cat);

            AdvancedAdSearchModel model = new AdvancedAdSearchModel()
            {
                SearchString = "ship",
                CategorySelectedId = 12
            };

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

            // When
            AdSearchResultModel result = service.LightSearchAds(model);

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

            adRepoMock.VerifyAll();
        }
コード例 #14
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();
        }
コード例 #15
0
        private IList<CategoryItemModel> GetAllCategoriesOfAGroup(Category c)
        {
            if (c == null)
                return new List<CategoryItemModel>();

            IList<CategoryItemModel> result = new List<CategoryItemModel>();

            if (c.SubCategories.Count == 0)
                c = c.ParentCategory;

            result.Add(new CategoryItemModel
            {
                Id = c.Id,
                Label = c.Label.ToUpper(),
                IsGroup = true
            });

            foreach (Category subC in c.SubCategories)
            {
                result.Add(new CategoryItemModel
                {
                    Id = subC.Id,
                    Label = subC.Label,
                    IsGroup = false
                });
            }

            return result;
        }
コード例 #16
0
        public void AdvancedSearchAds_RealEstateAds_RealEstateProperties_ReturnRealEstateAd()
        {
            ISessionFactory sessionFactory = NhibernateHelper.SessionFactory;
            Repository repo = new Repository(sessionFactory);
            SearchRepository adRepo = new SearchRepository(sessionFactory);

            using (ITransaction transaction = sessionFactory.GetCurrentSession().BeginTransaction())
            {
                // Given
                #region test data
                Province p1 = new Province
                {
                    Label = "p1"
                };

                User u = new User
                {
                    Email = "*****@*****.**",
                    Password = "******"
                };
                repo.Save<User>(u);

                City c = new City
                {
                    Label = "city",
                    LabelUrlPart = "city"
                };
                p1.AddCity(c);

                Category cat = new Category
                {
                    Label = "Location",
                    LabelUrlPart = "Location"
                };

                SearchAdCache a = new SearchAdCache
                {
                    AdId = 1,
                    Title = "appart",
                    Body = "boite a chaussure",
                    City = c,
                    CreationDate = new DateTime(2012, 01, 16, 23, 52, 18),
                    Category = cat
                };

                RealEstateType t1 = new RealEstateType
                {
                    Label = "Location"
                };

                District d = new District
                {
                    City = c,
                    Label = "Cheznous"
                };

                RealEstateAd loc = new RealEstateAd
                {
                    Id = 1,
                    Title = "appart",
                    Body = "boite a chaussure",
                    City = c,
                    CreationDate = new DateTime(2012, 01, 16, 23, 52, 18),
                    Category = cat,
                    CreatedBy = u,
                    Type = t1,
                    District = d,
                    RoomsNumber = 5,
                    IsFurnished = true,
                    SurfaceArea = 45
                };

                repo.Save(t1);
                repo.Save(d);
                repo.Save(p1);
                repo.Save(c);
                repo.Save(cat);
                repo.Save(u);
                repo.Save(loc);
                repo.Save(a);

                MotoBrand brand = new MotoBrand
                {
                    Label = "Suzuki"
                };

                SearchAdCache a2 = new SearchAdCache
                {
                    AdId = 2,
                    Title = "appart2",
                    Body = "boite a chaussure",
                    City = c,
                    CreationDate = new DateTime(2012, 01, 16, 23, 52, 18),
                    Category = cat
                };

                RealEstateAd loc2 = new RealEstateAd
                {
                    Id = 2,
                    Title = "appart2",
                    Body = "boite a chaussure",
                    City = c,
                    CreationDate = new DateTime(2012, 01, 16, 23, 52, 18),
                    Category = cat,
                    CreatedBy = u,
                    Type = t1,
                    District = d,
                    RoomsNumber = 4,
                    IsFurnished = true,
                    SurfaceArea = 65
                };
                repo.Save(loc2);
                repo.Save(a2);

                repo.Flush();

                #endregion

                AdSearchParameters param = new AdSearchParameters
                {
                    AndSearchStrings = new String[] { "appart" },
                    MinNbRooms = 2,
                    MaxNbRooms = 4,
                    DistrictId = 1,
                    RealEstateTypeId = 1,
                    IsFurnished = true,
                    MinSurfaceArea = 60,
                    MaxSurfaceArea = 65
                };

                // When
                IList<SearchAdCache> result = adRepo.AdvancedSearchAds<RealEstateAd>(param);

                // Then
                Assert.AreEqual(1, result.Count);
                Assert.AreEqual(a2, result[0]);
            }
        }
コード例 #17
0
        public void AdvancedSearchAds_MotoAds_MotoProperties_ReturnMotoAd()
        {
            ISessionFactory sessionFactory = NhibernateHelper.SessionFactory;
            Repository repo = new Repository(sessionFactory);
            SearchRepository adRepo = new SearchRepository(sessionFactory);

            using (ITransaction transaction = sessionFactory.GetCurrentSession().BeginTransaction())
            {
                // Given
                #region test data
                Province p1 = new Province
                {
                    Label = "p1"
                };

                User u = new User
                {
                    Email = "*****@*****.**",
                    Password = "******"
                };
                repo.Save<User>(u);

                City c = new City
                {
                    Label = "city",
                    LabelUrlPart = "city"
                };
                p1.AddCity(c);

                Category cat = new Category
                {
                    Label = "Auto",
                    LabelUrlPart = "Auto"
                };

                SearchAdCache a = new SearchAdCache
                {
                    AdId = 1,
                    Title = "aveo",
                    Body = "aveo sport 1.2 16s",
                    City = c,
                    CreationDate = new DateTime(2012, 01, 16, 23, 52, 18),
                    Category = cat
                };

                CarAd car = new CarAd
                {
                    Id = 1,
                    Title = "aveo",
                    Body = "aveo sport 1.2 16s",
                    City = c,
                    CreationDate = new DateTime(2012, 01, 16, 23, 52, 18),
                    Category = cat,
                    CreatedBy = u
                };

                repo.Save(p1);
                repo.Save(c);
                repo.Save(cat);
                repo.Save(u);
                repo.Save(car);
                repo.Save(a);

                Category cat2 = new Category
                {
                    Label = "Moto",
                    LabelUrlPart = "Moto"
                };

                MotoBrand brand = new MotoBrand
                {
                    Label = "Suzuki"
                };

                SearchAdCache a2 = new SearchAdCache
                {
                    AdId = 2,
                    Title = "aveo",
                    Body = "aveo sport 1.2 16s",
                    City = c,
                    CreationDate = new DateTime(2012, 01, 16, 23, 52, 18),
                    Category = cat2
                };

                MotoAd moto = new MotoAd
                {
                    Id = 2,
                    Title = "aveo",
                    Body = "aveo sport 1.2 16s",
                    City = c,
                    CreationDate = new DateTime(2012, 01, 16, 23, 52, 18),
                    Category = cat2,
                    Brand = brand,
                    EngineSize = 650,
                    CreatedBy = u
                };
                repo.Save(brand);
                repo.Save(cat2);
                repo.Save(moto);
                repo.Save(a2);

                repo.Flush();

                #endregion

                AdSearchParameters param = new AdSearchParameters
                {
                    AndSearchStrings = new String[] { "aveo" },
                    BrandId = brand.Id,
                    MinEngineSize = 250,
                    MaxEngineSize = 800
                };

                // When
                IList<SearchAdCache> result = adRepo.AdvancedSearchAds<MotoAd>(param);

                // Then
                Assert.AreEqual(1, result.Count);
                Assert.AreEqual(a2, result[0]);
            }
        }
コード例 #18
0
        public void AdvancedSearchAds_CarAds_CarProperties_ReturnCarAd()
        {
            ISessionFactory sessionFactory = NhibernateHelper.SessionFactory;
            Repository repo = new Repository(sessionFactory);
            SearchRepository adRepo = new SearchRepository(sessionFactory);

            using (ITransaction transaction = sessionFactory.GetCurrentSession().BeginTransaction())
            {
                // Given
                #region test data
                Province p1 = new Province
                {
                    Label = "p1"
                };

                User u = new User
                {
                    Email = "*****@*****.**",
                    Password = "******"
                };
                repo.Save<User>(u);

                City c = new City
                {
                    Label = "city",
                    LabelUrlPart = "city"
                };
                p1.AddCity(c);

                Category cat = new Category
                {
                    Label = "Auto",
                    LabelUrlPart = "Auto"
                };

                CarFuel fuel = new CarFuel
                {
                    Label = "Diesel"
                };

                VehicleBrand brand = new VehicleBrand
                {
                    Label = "Aveo"
                };

                SearchAdCache a = new SearchAdCache
                {
                    AdId = 1,
                    Title = "aveo",
                    Body = "aveo sport 1.2 16s",
                    City = c,
                    CreationDate = new DateTime(2012, 01, 16, 23, 52, 18),
                    Category = cat
                };

                CarAd car = new CarAd
                {
                    Id = 1,
                    Title = "aveo",
                    Body = "aveo sport 1.2 16s",
                    City = c,
                    CreationDate = new DateTime(2012, 01, 16, 23, 52, 18),
                    Category = cat,
                    Year = 2011,
                    Kilometers = 10000,
                    IsAutomatic = true,
                    Fuel = fuel,
                    Brand = brand,
                    CreatedBy = u
                };

                repo.Save(brand);
                repo.Save(fuel);
                repo.Save(p1);
                repo.Save(c);
                repo.Save(cat);
                repo.Save(u);
                repo.Save(car);
                repo.Save(a);

                SearchAdCache a2 = new SearchAdCache
                {
                    Title = "aveo",
                    Body = "aveo sport 1.2 16s",
                    City = c,
                    CreationDate = new DateTime(2012, 01, 16, 23, 52, 18),
                    Category = cat
                };

                CarAd car2 = new CarAd
                {
                    Id = 1,
                    Title = "aveo",
                    Body = "aveo sport 1.2 16s",
                    City = c,
                    CreationDate = new DateTime(2012, 01, 16, 23, 52, 18),
                    Category = cat,
                    Year = 2001,
                    Kilometers = 95000,
                    Brand = brand,
                    CreatedBy = u
                };
                repo.Save(car2);
                repo.Save(a2);

                repo.Flush();

                #endregion

                AdSearchParameters param = new AdSearchParameters
                {
                    AndSearchStrings = new String[] { "aveo" },
                    MinKm = 0,
                    MaxKm = 11000,
                    MinYear = 2000,
                    MaxYear = 2012,
                    BrandId = brand.Id,
                    FueldId = fuel.Id,
                    IsAuto = true
                };

                // When
                IList<SearchAdCache> result = adRepo.AdvancedSearchAds<CarAd>(param);

                // Then
                Assert.AreEqual(1, result.Count);
                Assert.AreEqual(a, result[0]);
            }
        }
コード例 #19
0
        public void SearchAds_SearchByTitleAndBodyAndString_CreateWhereAndQuery()
        {
            ISessionFactory sessionFactory = NhibernateHelper.SessionFactory;
            Repository repo = new Repository(sessionFactory);
            SearchRepository adRepo = new SearchRepository(sessionFactory);

            using (ITransaction transaction = sessionFactory.GetCurrentSession().BeginTransaction())
            {
                // Given
                #region test data
                Province p1 = new Province
                {
                    Label = "p1"
                };

                User u = new User
                {
                    Email = "*****@*****.**",
                    Password = "******"
                };
                repo.Save<User>(u);

                City c = new City
                {
                    Label = "city",
                    LabelUrlPart = "city"
                };
                p1.AddCity(c);

                Category cat = new Category
                {
                    Label = "Moto",
                    LabelUrlPart = "Moto"
                };

                SearchAdCache a = new SearchAdCache
                {
                    AdId = 1,
                    Title = "ship",
                    Body = "computer",
                    City = c,
                    CreationDate = new DateTime(2012, 01, 16, 23, 52, 18),
                    Category = cat
                };
                repo.Save<Province>(p1);
                repo.Save<City>(c);
                repo.Save<Category>(cat);
                repo.Save(a);

                Province p2 = new Province
                {
                    Label = "p2"
                };
                City c2 = new City
                {
                    Label = "CherzmOi2",
                    LabelUrlPart = "city2"
                };
                p2.AddCity(c2);
                SearchAdCache a2 = new SearchAdCache
                {
                    AdId = 2,
                    Title = "ship",
                    Body = "content",
                    City = c,
                    CreationDate = new DateTime(2012, 01, 16, 23, 52, 17),
                    Category = cat
                };
                repo.Save<Province>(p2);
                repo.Save<City>(c2);
                repo.Save(a2);

                repo.Flush();

                #endregion

                // When
                IList<SearchAdCache> result = adRepo.SearchAds(new String[] { "computer", "ship" }, null, null);

                // Then
                Assert.AreEqual(1, result.Count);
                Assert.AreEqual(a, result[0]);
            }
        }
コード例 #20
0
ファイル: Category.cs プロジェクト: bea-project/bea-web
 public virtual void AddCategory(Category categoryToBeAdded)
 {
     categoryToBeAdded.ParentCategory = this;
     this.SubCategories.Add(categoryToBeAdded);
 }
コード例 #21
0
        public void SearchAds_SearchByTitleAndCategories()
        {
            ISessionFactory sessionFactory = NhibernateHelper.SessionFactory;
            Repository repo = new Repository(sessionFactory);
            SearchRepository adRepo = new SearchRepository(sessionFactory);

            using (ITransaction transaction = sessionFactory.GetCurrentSession().BeginTransaction())
            {
                // Given
                #region test data

                User u = new User
                {
                    Email = "*****@*****.**",
                    Password = "******"
                };
                repo.Save<User>(u);

                City c = new City
                {
                    Label = "CherzmOi",
                    LabelUrlPart = "city"
                };

                Category cat = new Category
                {
                    Label = "Moto",
                    LabelUrlPart = "Moto"
                };

                SearchAdCache a = new SearchAdCache
                {
                    AdId = 1,
                    Title = "titre 1",
                    Body = "content",
                    City = c,
                    CreationDate = new DateTime(2012, 01, 16, 23, 52, 18),
                    Category = cat
                };
                repo.Save<City>(c);
                repo.Save<Category>(cat);
                repo.Save(a);

                City c2 = new City
                {
                    Label = "CherzmOi2",
                    LabelUrlPart = "city2"
                };

                Category cat2 = new Category
                {
                    Label = "Auto",
                    LabelUrlPart = "Auto"
                };

                SearchAdCache a2 = new SearchAdCache
                {
                    AdId = 2,
                    Title = "title 2",
                    Body = "content",
                    City = c2,
                    CreationDate = new DateTime(2012, 01, 16, 23, 52, 17),
                    Category = cat2
                };
                repo.Save<City>(c2);
                repo.Save<Category>(cat2);
                repo.Save(a2);

                repo.Flush();

                #endregion

                // When
                IList<SearchAdCache> result = adRepo.SearchAds(andSearchStrings: new String[] { "ti" }, categoryIds: new int[] { cat.Id, cat2.Id });

                // Then
                Assert.AreEqual(2, result.Count);
                Assert.AreEqual(a, result[0]);
                Assert.AreEqual(a2, result[1]);
            }
        }
コード例 #22
0
        public void AdvancedSearchAds_SearchThroughRealEstateAds_CallSearchRepoOnRealEstateAds()
        {
            // Given
            Category cat = new Category { Id = 1, LabelUrlPart = "cat-url-label", Label = "Label", Type = AdTypeEnum.RealEstateAd };

            AdvancedAdSearchModel model = new AdvancedAdSearchModel()
            {
                CategorySelectedId = 1,
                SearchString = "appart",
                NbRoomsBracketSelectedId = 2,
                SelectedDistrictId = 71,
                SelectedRealEstateTypeId = 2,
                MinPrice = 0,
                MaxPrice = 100000,
                SurfaceAreaBracketSelectedId = 3,
                IsFurnished = true
            };

            IList<SearchAdCache> searchResult = new List<SearchAdCache>();
            searchResult.Add(new SearchAdCache
            {
                Title = "appart",
                City = new City() { Label = "the city" },
                Category = cat
            });

            IDictionary<int, BracketItemReference> nbRoomsBr = new Dictionary<int, BracketItemReference>();
            nbRoomsBr.Add(2, new BracketItemReference { LowValue = 2, HighValue = 3 });

            IDictionary<int, BracketItemReference> surfBr = new Dictionary<int, BracketItemReference>();
            surfBr.Add(3, new BracketItemReference { LowValue = 45, HighValue = 70 });

            var refMock = new Moq.Mock<IReferenceServices>();
            refMock.Setup(s => s.GetAllRealEstateNbRoomsBrackets()).Returns(nbRoomsBr);
            refMock.Setup(s => s.GetAllSurfaceAreaBrackets()).Returns(surfBr);

            var repoMock = new Moq.Mock<IRepository>();
            repoMock.Setup(r => r.Get<Category>(cat.Id)).Returns(cat);

            var searchRepoMock = new Moq.Mock<ISearchRepository>();
            searchRepoMock.Setup(r => r.AdvancedSearchAds<RealEstateAd>(
                It.Is<AdSearchParameters>(p =>
                    p.AndSearchStrings[0].Equals("appart")
                    && p.MinNbRooms == 2
                    && p.MaxNbRooms == 3
                    && p.MinPrice == 0d
                    && p.MaxPrice == 100000d
                    && p.RealEstateTypeId == 2
                    && p.MinSurfaceArea == 45
                    && p.MaxSurfaceArea == 70
                    && p.IsFurnished.Value
                    && p.DistrictId == 71))).Returns(searchResult);

            SearchServices service = new SearchServices(repoMock.Object, null, searchRepoMock.Object, null, refMock.Object, null);

            // When
            AdSearchResultModel result = service.AdvancedSearchAds(model);

            // Then
            Assert.AreEqual(1, result.SearchResultTotalCount);
        }
コード例 #23
0
        public void AdvancedSearchAds_Ad_MinMaxPrice_ReturnMatchingAds()
        {
            ISessionFactory sessionFactory = NhibernateHelper.SessionFactory;
            Repository repo = new Repository(sessionFactory);
            SearchRepository adRepo = new SearchRepository(sessionFactory);

            using (ITransaction transaction = sessionFactory.GetCurrentSession().BeginTransaction())
            {
                // Given
                #region test data
                Province p1 = new Province
                {
                    Label = "p1"
                };

                User u = new User
                {
                    Email = "*****@*****.**",
                    Password = "******"
                };
                repo.Save<User>(u);

                City c = new City
                {
                    Label = "city",
                    LabelUrlPart = "city"
                };
                p1.AddCity(c);

                Category cat = new Category
                {
                    Label = "Location",
                    LabelUrlPart = "Location"
                };

                SearchAdCache a = new SearchAdCache
                {
                    AdId = 1,
                    Title = "chaussure",
                    Body = "boite a chaussure",
                    City = c,
                    CreationDate = new DateTime(2012, 01, 16, 23, 52, 18),
                    Category = cat
                };

                Ad loc = new Ad
                {
                    Id = 1,
                    Title = "chaussure",
                    Body = "boite a chaussure",
                    City = c,
                    CreationDate = new DateTime(2012, 01, 16, 23, 52, 18),
                    Category = cat,
                    CreatedBy = u,
                    Price = 1000
                };

                repo.Save(p1);
                repo.Save(c);
                repo.Save(cat);
                repo.Save(u);
                repo.Save(loc);
                repo.Save(a);

                SearchAdCache a2 = new SearchAdCache
                {
                    AdId = 2,
                    Title = "chaussure",
                    Body = "boite a chaussure",
                    City = c,
                    CreationDate = new DateTime(2012, 01, 16, 23, 52, 18),
                    Category = cat
                };

                Ad loc2 = new Ad
                {
                    Id = 2,
                    Title = "chaussure",
                    Body = "boite a chaussure",
                    City = c,
                    CreationDate = new DateTime(2012, 01, 16, 23, 52, 18),
                    Category = cat,
                    CreatedBy = u,
                    Price = 2000
                };
                repo.Save(loc2);
                repo.Save(a2);

                repo.Flush();

                #endregion

                AdSearchParameters param = new AdSearchParameters
                {
                    MinPrice = 0,
                    MaxPrice = 1000
                };

                // When
                IList<SearchAdCache> result = adRepo.AdvancedSearchAds<Ad>(param);

                // Then
                Assert.AreEqual(1, result.Count);
                Assert.AreEqual(a, result[0]);
            }
        }
コード例 #24
0
        public void AdvancedSearchAds_SearchThroughSailingBoatAds_CallSearchRepoOnSailingBoatAds()
        {
            // Given
            Category cat = new Category { Id = 1, LabelUrlPart = "cat-url-label", Label = "Label", Type = AdTypeEnum.SailingBoatAd };

            AdvancedAdSearchModel model = new AdvancedAdSearchModel()
            {
                CategorySelectedId = 1,
                SearchString = "voilier",
                AgeBracketSelectedId = 2,
                MinLength = 0,
                MaxLength = 13,
                SelectedSailingBoatTypeId = 6,
                SelectedHullTypeId = 2
            };

            IList<SearchAdCache> searchResult = new List<SearchAdCache>();
            searchResult.Add(new SearchAdCache
            {
                Title = "voilier",
                City = new City() { Label = "the city" },
                Category = cat
            });

            IDictionary<int, BracketItemReference> ageBr = new Dictionary<int, BracketItemReference>();
            ageBr.Add(2, new BracketItemReference { LowValue = 0, HighValue = 11 });

            var refMock = new Moq.Mock<IReferenceServices>();
            refMock.Setup(s => s.GetAllAgeBrackets()).Returns(ageBr);

            var repoMock = new Moq.Mock<IRepository>();
            repoMock.Setup(r => r.Get<Category>(cat.Id)).Returns(cat);

            var helperMock = new Moq.Mock<IHelperService>();
            helperMock.Setup(r => r.GetCurrentDateTime()).Returns(new DateTime(2013, 01, 01));

            var searchRepoMock = new Moq.Mock<ISearchRepository>();
            searchRepoMock.Setup(r => r.AdvancedSearchAds<SailingBoatAd>(
                It.Is<AdSearchParameters>(p =>
                    p.AndSearchStrings[0].Equals("voilier")
                    && p.MinLength == 0.0
                    && p.MaxLength == 13.0
                    && p.SailingBoatTypeId == 6
                    && p.HullTypeId == 2
                    && p.MinYear == 2002
                    && p.MaxYear == 2013))).Returns(searchResult);

            SearchServices service = new SearchServices(repoMock.Object, null, searchRepoMock.Object, helperMock.Object, refMock.Object, null);

            // When
            AdSearchResultModel result = service.AdvancedSearchAds(model);

            // Then
            Assert.AreEqual(1, result.SearchResultTotalCount);
        }
コード例 #25
0
        public void AdvancedSearchAds_MotorBoatEngineAd_MotorBoatEngineProperties_ReturnMotorBoatEngineAd()
        {
            ISessionFactory sessionFactory = NhibernateHelper.SessionFactory;
            Repository repo = new Repository(sessionFactory);
            SearchRepository adRepo = new SearchRepository(sessionFactory);

            using (ITransaction transaction = sessionFactory.GetCurrentSession().BeginTransaction())
            {
                // Given
                #region test data
                Province p1 = new Province
                {
                    Label = "p1"
                };

                User u = new User
                {
                    Email = "*****@*****.**",
                    Password = "******"
                };
                repo.Save<User>(u);

                City c = new City
                {
                    Label = "city",
                    LabelUrlPart = "city"
                };
                p1.AddCity(c);

                Category cat = new Category
                {
                    Label = "Bateau à moteur",
                    LabelUrlPart = "Bateau"
                };

                SearchAdCache a = new SearchAdCache
                {
                    AdId = 1,
                    Title = "bateau",
                    Body = "la desc du bateau",
                    City = c,
                    CreationDate = new DateTime(2012, 01, 16, 23, 52, 18),
                    Category = cat
                };

                MotorBoatEngineType mt = new MotorBoatEngineType()
                {
                    Id = 7,
                    Label = "4 temps"
                };

                MotorBoatEngineAd bat = new MotorBoatEngineAd
                {
                    Id = 1,
                    Title = "moteur",
                    Body = "la desc du bateau",
                    City = c,
                    CreationDate = new DateTime(2012, 01, 16, 23, 52, 18),
                    Category = cat,
                    CreatedBy = u,
                    Price = 1000,
                    Hp = 100,
                    Year = 2005,
                    MotorType = mt
                };

                repo.Save(mt);
                repo.Save(p1);
                repo.Save(c);
                repo.Save(cat);
                repo.Save(u);
                repo.Save(bat);
                repo.Save(a);

                repo.Flush();

                #endregion

                AdSearchParameters param = new AdSearchParameters
                {
                    MotorEngineTypeId = 1,
                    MinHp = 99,
                    MaxHp = 100,
                    MinYear = 2004,
                    MaxYear = 2006
                };

                // When
                IList<SearchAdCache> result = adRepo.AdvancedSearchAds<MotorBoatEngineAd>(param);

                // Then
                Assert.AreEqual(1, result.Count);
                Assert.AreEqual(a, result[0]);
            }
        }
コード例 #26
0
        public void AdvancedSearchAds_SearchThroughWaterSportAds_CallSearchRepoOnWaterSportAds()
        {
            // Given
            Category cat = new Category { Id = 1, LabelUrlPart = "cat-url-label", Label = "Label", Type = AdTypeEnum.WaterSportAd };

            AdvancedAdSearchModel model = new AdvancedAdSearchModel()
            {
                CategorySelectedId = 1,
                SearchString = "kite",
                SelectedWaterTypeId = 9
            };

            IList<SearchAdCache> searchResult = new List<SearchAdCache>();
            searchResult.Add(new SearchAdCache
            {
                Title = "kite surf",
                City = new City() { Label = "the city" },
                Category = cat
            });

            var repoMock = new Moq.Mock<IRepository>();
            repoMock.Setup(r => r.Get<Category>(cat.Id)).Returns(cat);

            var searchRepoMock = new Moq.Mock<ISearchRepository>();
            searchRepoMock.Setup(r => r.AdvancedSearchAds<WaterSportAd>(
                It.Is<AdSearchParameters>(p =>
                    p.AndSearchStrings[0].Equals("kite")
                    && p.WaterTypeId == 9))).Returns(searchResult);

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

            // When
            AdSearchResultModel result = service.AdvancedSearchAds(model);

            // Then
            Assert.AreEqual(1, result.SearchResultTotalCount);
        }
コード例 #27
0
        public void AdvancedSearchAds_WaterSportAd_WaterSportProperties_ReturnWaterSportAd()
        {
            ISessionFactory sessionFactory = NhibernateHelper.SessionFactory;
            Repository repo = new Repository(sessionFactory);
            SearchRepository adRepo = new SearchRepository(sessionFactory);

            using (ITransaction transaction = sessionFactory.GetCurrentSession().BeginTransaction())
            {
                // Given
                #region test data
                Province p1 = new Province
                {
                    Label = "p1"
                };

                User u = new User
                {
                    Email = "*****@*****.**",
                    Password = "******"
                };
                repo.Save<User>(u);

                City c = new City
                {
                    Label = "city",
                    LabelUrlPart = "city"
                };
                p1.AddCity(c);

                Category cat = new Category
                {
                    Label = "Bateau à moteur",
                    LabelUrlPart = "Bateau"
                };

                SearchAdCache a = new SearchAdCache
                {
                    AdId = 1,
                    Title = "bateau",
                    Body = "la desc du bateau",
                    City = c,
                    CreationDate = new DateTime(2012, 01, 16, 23, 52, 18),
                    Category = cat
                };

                WaterSportType st = new WaterSportType()
                {
                    Label = "pmt"
                };

                WaterSportAd bat = new WaterSportAd
                {
                    Id = 1,
                    Title = "bateau",
                    Body = "la desc du bateau",
                    City = c,
                    CreationDate = new DateTime(2012, 01, 16, 23, 52, 18),
                    Category = cat,
                    CreatedBy = u,
                    Type = st
                };

                repo.Save(st);
                repo.Save(p1);
                repo.Save(c);
                repo.Save(cat);
                repo.Save(u);
                repo.Save(bat);
                repo.Save(a);

                repo.Flush();

                #endregion

                AdSearchParameters param = new AdSearchParameters
                {
                    WaterTypeId = 1
                };

                // When
                IList<SearchAdCache> result = adRepo.AdvancedSearchAds<WaterSportAd>(param);

                // Then
                Assert.AreEqual(1, result.Count);
                Assert.AreEqual(a, result[0]);
            }
        }
コード例 #28
0
        public void QuickSearch_Test()
        {
            // Given
            AdSearchModel sM = new AdSearchModel();
            sM.SearchString = "verre";
            sM.CitySelectedId = 45;

            Category c1 = new Category
            {
                Label = "Vehicule",
            };
            Category c2 = new Category
            {
                Label = "Voiture",
            };
            c1.AddCategory(c2);
            Category c3 = new Category
            {
                Label = "Moto",
            };
            c1.AddCategory(c3);

            Category c4 = new Category
            {
                Label = "Maison",
            };
            Category c5 = new Category
            {
                Label = "Meuble",
            };
            c4.AddCategory(c5);
            Category c6 = new Category
            {
                Label = "Vaisselle",
            };
            c4.AddCategory(c6);

            IDictionary<Category, int> res = new Dictionary<Category, int>();
            res.Add(c2, 2);
            res.Add(c3, 1);
            res.Add(c6, 6);

            var searchRepoMock = new Moq.Mock<ISearchRepository>();
            searchRepoMock.Setup(x =>
                x.CountByCategory(It.Is<string[]>(b => b[0] == sM.SearchString), It.Is<int?>(i => i.Value == sM.CitySelectedId)))
                .Returns(res);

            SearchServices service = new SearchServices(null, null, searchRepoMock.Object, null, null, null);

            // When
            AdHomeSearchResultModel ress = service.QuickSearch(sM);

            // Then
            Assert.AreEqual(sM.CitySelectedId, ress.CitySelectedId);
            Assert.AreEqual(sM.SearchString, ress.SearchString);
            Assert.AreEqual(9, ress.SearchResultTotalCount);
            Assert.AreEqual(2, ress.Results.Count);
            Assert.AreEqual(3, ress.Results[0].ResultCount);
            Assert.AreEqual("Vehicule", ress.Results[0].CategoryLabel);
            Assert.AreEqual("Voiture", ress.Results[0].SubCategoriesResults[0].CategoryLabel);
            Assert.AreEqual(2, ress.Results[0].SubCategoriesResults[0].ResultCount);
            Assert.AreEqual(0, ress.Results[0].SubCategoriesResults[0].SubCategoriesResults.Count);
            Assert.AreEqual("Moto", ress.Results[0].SubCategoriesResults[1].CategoryLabel);
            Assert.AreEqual(1, ress.Results[0].SubCategoriesResults[1].ResultCount);
            Assert.AreEqual(0, ress.Results[0].SubCategoriesResults[1].SubCategoriesResults.Count);

            Assert.AreEqual(6, ress.Results[1].ResultCount);
            Assert.AreEqual("Maison", ress.Results[1].CategoryLabel);
            Assert.AreEqual("Vaisselle", ress.Results[1].SubCategoriesResults[0].CategoryLabel);
            Assert.AreEqual(6, ress.Results[1].SubCategoriesResults[0].ResultCount);
            Assert.AreEqual(0, ress.Results[1].SubCategoriesResults[0].SubCategoriesResults.Count);
        }
コード例 #29
0
ファイル: AdSearchModel.cs プロジェクト: bea-project/bea-web
 public void SetCategory(Category category)
 {
     this.CategorySelectedId = category.Id;
     this.CategorySelectedLabel = category.Label;
     this.CategoryImagePath = category.ImageName;
 }
コード例 #30
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();
        }