예제 #1
0
        public City(Province province, string name)
        {
            _province = province;
            _name     = name;

            _province.AddCity(this);
        }
예제 #2
0
        public void GetAdType_CarAdExists_ReturnType()
        {
            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        = "Auto",
                    LabelUrlPart = "Auto",
                    Type         = AdTypeEnum.CarAd
                };

                CarAd a = new CarAd
                {
                    Title        = "honda civic type R",
                    Body         = "the best!!",
                    CreatedBy    = u,
                    CreationDate = new DateTime(2012, 01, 16, 23, 52, 18),
                    Category     = cat,
                    Kilometers   = 25000,
                    Year         = 1998
                };
                c.AddAd(a);
                cat.AddAd(a);
                repo.Save <Province>(p1);
                repo.Save <City>(c);
                repo.Save <Category>(cat);
                long id = repo.Save <CarAd, long>(a);

                repo.Flush();

                #endregion

                Assert.AreEqual(AdTypeEnum.CarAd, adRepo.GetAdType(id));
            }
        }
예제 #3
0
        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();
            }
        }
예제 #4
0
        public void CanDeleteAd_AdExistsAndNotDeleted_ReturnTrue()
        {
            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    = false
                };
                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.IsTrue(adRepo.CanDeleteAd(id));
            }
        }
예제 #5
0
        public void GetAdById_GetAd_ReturnAdObject()
        {
            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        = "Moto",
                    LabelUrlPart = "Moto"
                };

                Ad a = new Ad
                {
                    Title        = "ship",
                    Body         = "computer",
                    CreatedBy    = u,
                    CreationDate = new DateTime(2012, 01, 16, 23, 52, 18),
                    Category     = cat
                };
                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.AreEqual(a, adRepo.GetAdById <Ad>(id));
            }
        }
예제 #6
0
        public void AdvancedSearchAds_MotorBoatAd_MotorBoatProperties_ReturnMotorBoatAd()
        {
            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
                };

                MotorBoatType mbt = new MotorBoatType()
                {
                    Id    = 5,
                    Label = "Bois"
                };

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

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

                repo.Save(mbt);
                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
                {
                    MotorBoatTypeId   = 1,
                    MotorEngineTypeId = 1,
                    MinHp             = 99,
                    MaxHp             = 100,
                    MinLength         = 6,
                    MaxLength         = 10,
                    MinYear           = 2004,
                    MaxYear           = 2006
                };

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

                // Then
                Assert.AreEqual(1, result.Count);
                Assert.AreEqual(a, result[0]);
            }
        }
예제 #7
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]);
            }
        }
예제 #8
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]);
            }
        }
예제 #9
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]);
            }
        }
예제 #10
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]);
            }
        }
예제 #11
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]);
            }
        }
예제 #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 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]);
            }
        }
예제 #14
0
        public void GetAdsByEmail_ReturnListOfAds_WithUserAndCategoryFetched()
        {
            ISessionFactory sessionFactory = NhibernateHelper.SessionFactory;
            AdRepository    adRepo         = new AdRepository(sessionFactory);
            Repository      repo           = new Repository(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);

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

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

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

                Category cat2 = new Category
                {
                    Label        = "Voiture",
                    LabelUrlPart = "Voiture",
                    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    = false,
                    IsActivated  = true
                };

                Ad a2 = new Ad
                {
                    Title        = "Ferrari F430",
                    Body         = "Valab'",
                    CreatedBy    = u,
                    CreationDate = new DateTime(2012, 01, 16, 23, 52, 18),
                    Category     = cat2,
                    IsDeleted    = false,
                    IsActivated  = true
                };

                Ad a3 = new Ad
                {
                    Title        = "Ferrari F430",
                    Body         = "Valab'",
                    CreatedBy    = u2,
                    CreationDate = new DateTime(2012, 01, 16, 23, 52, 18),
                    Category     = cat2,
                    IsDeleted    = false,
                    IsActivated  = true
                };
                c.AddAd(a);
                c.AddAd(a2);
                c.AddAd(a3);
                cat.AddAd(a);
                cat2.AddAd(a2);
                cat2.AddAd(a3);
                repo.Save <Province>(p1);
                repo.Save <City>(c);
                repo.Save <Category>(cat);
                repo.Save <Category>(cat2);
                repo.Save <Ad, long>(a);
                repo.Save <Ad, long>(a2);
                repo.Save <Ad, long>(a3);
                repo.Flush();
                #endregion

                List <BaseAd> adsUser1 = adRepo.GetAdsByEmail(u.Email).ToList();
                List <BaseAd> adsUser2 = adRepo.GetAdsByEmail(u2.Email).ToList();
                Assert.AreEqual(2, adsUser1.Count);
                Assert.AreEqual(u.Email, adsUser1[0].CreatedBy.Email);
                Assert.AreEqual(1, adsUser2.Count);
                Assert.AreEqual(u2.Email, adsUser2[0].CreatedBy.Email);
            }
        }
예제 #15
0
        public void InsertLocations()
        {
            //-------------------------------------------
            //         LOCATION REFERENCE TABLES
            //-------------------------------------------

            if (_repository.CountAll <City>() == 0)
            {
                //Create Provinces
                Province provinceNord = new Province();
                provinceNord.Label = "Province Nord";
                provinceNord.AddCity(new City {
                    LabelUrlPart = "Poya-Nord", Label = "Poya Nord"
                });
                provinceNord.AddCity(new City {
                    LabelUrlPart = "Pouembout", Label = "Pouembout"
                });
                provinceNord.AddCity(new City {
                    LabelUrlPart = "Kone", Label = "Koné"
                });
                provinceNord.AddCity(new City {
                    LabelUrlPart = "Voh", Label = "Voh"
                });
                provinceNord.AddCity(new City {
                    LabelUrlPart = "Kaala-Gomen", Label = "Kaala-Gomen"
                });
                provinceNord.AddCity(new City {
                    LabelUrlPart = "Koumac", Label = "Koumac"
                });
                provinceNord.AddCity(new City {
                    LabelUrlPart = "Poum", Label = "Poum"
                });
                provinceNord.AddCity(new City {
                    LabelUrlPart = "Iles-Belep", Label = "Iles Belep"
                });
                provinceNord.AddCity(new City {
                    LabelUrlPart = "Ouegoa", Label = "Ouégoa"
                });
                provinceNord.AddCity(new City {
                    LabelUrlPart = "Pouebo", Label = "Pouébo"
                });
                provinceNord.AddCity(new City {
                    LabelUrlPart = "Hienghene", Label = "Hienghène"
                });
                provinceNord.AddCity(new City {
                    LabelUrlPart = "Touho", Label = "Touho"
                });
                provinceNord.AddCity(new City {
                    LabelUrlPart = "Poindimie", Label = "Poindimié"
                });
                provinceNord.AddCity(new City {
                    LabelUrlPart = "Ponerihouen", Label = "Ponérihouen"
                });
                provinceNord.AddCity(new City {
                    LabelUrlPart = "Houailou", Label = "Houaïlou"
                });
                provinceNord.AddCity(new City {
                    LabelUrlPart = "Kouaoua", Label = "Kouaoua"
                });
                provinceNord.AddCity(new City {
                    LabelUrlPart = "Canala", Label = "Canala"
                });
                _repository.Save(provinceNord);

                Province provinceSud = new Province();
                provinceSud.Label = "Province Sud";

                City noumea = new City();
                noumea.Label        = "Nouméa";
                noumea.LabelUrlPart = "Noumea";

                noumea.AddDistrict(new District {
                    Label = "Centre-Ville"
                });
                noumea.AddDistrict(new District {
                    Label = "Nouville"
                });
                noumea.AddDistrict(new District {
                    Label = "Quartier Latin"
                });
                noumea.AddDistrict(new District {
                    Label = "Vallée du Génie"
                });
                noumea.AddDistrict(new District {
                    Label = "Artillerie"
                });
                noumea.AddDistrict(new District {
                    Label = "Orphelinat"
                });
                noumea.AddDistrict(new District {
                    Label = "Baie des Citrons"
                });
                noumea.AddDistrict(new District {
                    Label = "Anse Vata"
                });
                noumea.AddDistrict(new District {
                    Label = "Val Plaisance"
                });
                noumea.AddDistrict(new District {
                    Label = "N'Géa"
                });
                noumea.AddDistrict(new District {
                    Label = "Receiving"
                });
                noumea.AddDistrict(new District {
                    Label = "Motor Pool"
                });
                noumea.AddDistrict(new District {
                    Label = "Trianon"
                });
                noumea.AddDistrict(new District {
                    Label = "Riviere-Salée"
                });
                noumea.AddDistrict(new District {
                    Label = "Ducos"
                });
                noumea.AddDistrict(new District {
                    Label = "Magenta"
                });
                noumea.AddDistrict(new District {
                    Label = "Haut-Magenta"
                });
                noumea.AddDistrict(new District {
                    Label = "Aérodrome"
                });
                noumea.AddDistrict(new District {
                    Label = "PK4"
                });
                noumea.AddDistrict(new District {
                    Label = "PK6"
                });
                noumea.AddDistrict(new District {
                    Label = "PK7"
                });
                noumea.AddDistrict(new District {
                    Label = "Tina"
                });
                noumea.AddDistrict(new District {
                    Label = "Normandie"
                });
                noumea.AddDistrict(new District {
                    Label = "Vallée des Colons"
                });
                noumea.AddDistrict(new District {
                    Label = "Faubourg Blanchot"
                });
                noumea.AddDistrict(new District {
                    Label = "Montravel"
                });
                noumea.AddDistrict(new District {
                    Label = "Montagne Coupée"
                });
                noumea.AddDistrict(new District {
                    Label = "Vallée du Tir"
                });
                noumea.AddDistrict(new District {
                    Label = "Doniambo"
                });
                noumea.AddDistrict(new District {
                    Label = "Ouémo"
                });
                noumea.AddDistrict(new District {
                    Label = "Portes de Fer"
                });
                provinceSud.AddCity(noumea);
                _repository.Save(noumea);

                City dumbea = new City();
                dumbea.Label        = "Dumbéa";
                dumbea.LabelUrlPart = "Dumbea";
                dumbea.AddDistrict(new District {
                    Label = "Auteuil"
                });
                dumbea.AddDistrict(new District {
                    Label = "Centre"
                });
                dumbea.AddDistrict(new District {
                    Label = "Dumbéa sur Mer"
                });
                dumbea.AddDistrict(new District {
                    Label = "Koghi"
                });
                dumbea.AddDistrict(new District {
                    Label = "Koutio"
                });
                dumbea.AddDistrict(new District {
                    Label = "Nakutakoin"
                });
                dumbea.AddDistrict(new District {
                    Label = "Plaine de Koé"
                });
                dumbea.AddDistrict(new District {
                    Label = "Pointe à la Dorade"
                });
                dumbea.AddDistrict(new District {
                    Label = "ZAC Panda"
                });
                provinceSud.AddCity(dumbea);
                _repository.Save(dumbea);

                City montDor = new City();
                montDor.Label        = "Mont-Dore";
                montDor.LabelUrlPart = "Mont-Dore";
                montDor.AddDistrict(new District {
                    Label = "Boulari"
                });
                montDor.AddDistrict(new District {
                    Label = "La Conception"
                });
                montDor.AddDistrict(new District {
                    Label = "La Coulée"
                });
                montDor.AddDistrict(new District {
                    Label = "Mont-Dore Sud"
                });
                montDor.AddDistrict(new District {
                    Label = "Plum"
                });
                montDor.AddDistrict(new District {
                    Label = "Pont des Francais"
                });
                montDor.AddDistrict(new District {
                    Label = "Robinson"
                });
                montDor.AddDistrict(new District {
                    Label = "Saint-Louis"
                });
                montDor.AddDistrict(new District {
                    Label = "Saint-Michel"
                });
                montDor.AddDistrict(new District {
                    Label = "Vallon-Dore"
                });
                montDor.AddDistrict(new District {
                    Label = "Yahoué"
                });
                provinceSud.AddCity(montDor);
                _repository.Save(montDor);

                City paita = new City();
                paita.Label        = "Païta";
                paita.LabelUrlPart = "Paita";
                paita.AddDistrict(new District {
                    Label = "Val Boisé"
                });
                paita.AddDistrict(new District {
                    Label = "Tontouta"
                });
                paita.AddDistrict(new District {
                    Label = "Tamoa"
                });
                paita.AddDistrict(new District {
                    Label = "Savannah"
                });
                paita.AddDistrict(new District {
                    Label = "Centre"
                });
                paita.AddDistrict(new District {
                    Label = "Naia"
                });
                paita.AddDistrict(new District {
                    Label = "Mont Mou"
                });
                paita.AddDistrict(new District {
                    Label = "Beauvallon"
                });

                provinceSud.AddCity(paita);
                _repository.Save(paita);

                provinceSud.AddCity(new City {
                    LabelUrlPart = "Thio", Label = "Thio"
                });
                provinceSud.AddCity(new City {
                    LabelUrlPart = "Yate", Label = "Yaté"
                });
                provinceSud.AddCity(new City {
                    LabelUrlPart = "Ile-des-Pins", Label = "Ile des Pins"
                });
                provinceSud.AddCity(new City {
                    LabelUrlPart = "Boulouparis", Label = "Boulouparis"
                });
                provinceSud.AddCity(new City {
                    LabelUrlPart = "La-Foa", Label = "La Foa"
                });
                provinceSud.AddCity(new City {
                    LabelUrlPart = "Sarramea", Label = "Sarraméa"
                });
                provinceSud.AddCity(new City {
                    LabelUrlPart = "Farino", Label = "Farino"
                });
                provinceSud.AddCity(new City {
                    LabelUrlPart = "Moindou", Label = "Moindou"
                });
                provinceSud.AddCity(new City {
                    LabelUrlPart = "Bourail", Label = "Bourail"
                });
                provinceSud.AddCity(new City {
                    LabelUrlPart = "Poya-Sud", Label = "Poya Sud"
                });
                _repository.Save(provinceSud);

                Province ilesLoyaute = new Province();
                ilesLoyaute.Label = "Iles Loyauté";
                ilesLoyaute.AddCity(new City {
                    LabelUrlPart = "Ouvea", Label = "Ouvéa"
                });
                ilesLoyaute.AddCity(new City {
                    LabelUrlPart = "Lifou", Label = "Lifou"
                });
                ilesLoyaute.AddCity(new City {
                    LabelUrlPart = "Mare", Label = "Maré"
                });
                _repository.Save(ilesLoyaute);

                _repository.Flush();
            }
        }