Ejemplo n.º 1
0
        public void MotoAdDetailsModel_ctor_WithMotoAd_OtherBrand()
        {
            // Given
            City c = new City()
            {
                Label = "Nouméa"
            };

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

            MotoAd ad = new MotoAd()
            {
                Id = 17,
                Title = "title",
                Price = 1270,
                City = c,
                CreatedBy = u,
                CreationDate = new DateTime(2012, 05, 12, 17, 26, 08),
                Body = "body",
                Kilometers = 2000,
                Year = 2013,
                Brand = new MotoBrand { Label = "Autre" },
                OtherBrand = "Batmobile",
            };

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

            // Then
            Assert.AreEqual("Batmobile", model.Brand);
        }
        public void OtherVehicleAdDetailsModel_ctor_WithOtherVehicleAd()
        {
            // Given
            City c = new City()
            {
                Label = "Nouméa"
            };

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

            OtherVehicleAd ad = new OtherVehicleAd()
            {
                Id = 17,
                Title = "title",
                Price = 1270,
                City = c,
                CreatedBy = u,
                CreationDate = new DateTime(2012, 05, 12, 17, 26, 08),
                Body = "body",
                Kilometers = 2000,
                Year = 2013
            };

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

            // Then
            Assert.AreEqual(17, model.AdId);
            Assert.AreEqual(2000, model.Kilometers);
            Assert.AreEqual(2013, model.Year);
        }
Ejemplo n.º 3
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));
            }
        }
Ejemplo n.º 4
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();

            }
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        public void AdDetailsModel_ctor_WithCarAd_BrandAndFuel()
        {
            // Given
            City c = new City()
            {
                Label = "Nouméa"
            };

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

            CarAd ad = new CarAd()
            {
                Id = 17,
                Title = "title",
                Price = 1270,
                City = c,
                CreatedBy = u,
                CreationDate = new DateTime(2012, 05, 12, 17, 26, 08),
                Body = "body",
                Kilometers = 2000,
                Year = 2013,
                IsAutomatic = true,
                Brand = new VehicleBrand { Label = "Honda" },
                Fuel = new CarFuel { Label = "Super" }
            };

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

            // Then
            Assert.AreEqual("Honda", model.Brand);
            Assert.AreEqual("Super", model.Fuel);
        }
Ejemplo n.º 7
0
        public void AdDetailsModel_ctor_WithCarAd_Automatique()
        {
            // Given
            City c = new City()
            {
                Label = "Nouméa"
            };

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

            CarAd ad = new CarAd()
            {
                Id = 17,
                Title = "title",
                Price = 1270,
                City = c,
                CreatedBy = u,
                CreationDate = new DateTime(2012, 05, 12, 17, 26, 08),
                Body = "body",
                Kilometers = 2000,
                Year = 2013,
                IsAutomatic = true
            };

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

            // Then
            Assert.AreEqual(17, model.AdId);
            Assert.AreEqual(2000, model.Kilometers);
            Assert.AreEqual(2013, model.Year);
            Assert.AreEqual("Automatique", model.GearType);
        }
Ejemplo n.º 8
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]);
            }
        }
Ejemplo n.º 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]);
            }
        }
Ejemplo n.º 10
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]);
            }
        }
Ejemplo n.º 11
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]);
            }
        }
Ejemplo n.º 12
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]);
            }
        }
Ejemplo n.º 13
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]);
            }
        }
Ejemplo n.º 14
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));
            }
        }
Ejemplo n.º 15
0
        public void SearchAdsFromUrl_CityIsSelected_RunSearchWithCity()
        {
            // Given
            City city = new City { Id = 12, LabelUrlPart = "city-url-label", Label = "Label" };

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

            var adRepoMock = new Moq.Mock<ISearchRepository>();
            adRepoMock.Setup(r => r.SearchAds(null, city.Id, null)).Returns(searchResult);

            var catLocationServiceMock = new Moq.Mock<ILocationServices>();
            catLocationServiceMock.Setup(r => r.GetCityFromLabelUrlPart("city-url-label")).Returns(city);

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

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

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

            adRepoMock.VerifyAll();
        }
Ejemplo n.º 16
0
 public virtual void AddCity(City city)
 {
     this.Cities.Add(city);
     city.Province = this;
 }
Ejemplo n.º 17
0
        public void CountAdsByCity_2Citiesand3Ad_Return2elements()
        {
            ISessionFactory sessionFactory = NhibernateHelper.SessionFactory;
            Repository repo = new Repository(sessionFactory);
            AdRepository adRepo = new AdRepository(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 = "Bateau",
                    LabelUrlPart = "Bateau"
                };

                Ad a = new Ad
                {
                    Title = "titre",
                    Body = "content",
                    CreatedBy = u,
                    City = c,
                    Category = cat
                };
                c.AddAd(a);
                cat.AddAd(a);
                repo.Save<City>(c);
                repo.Save<Category>(cat);
                repo.Save<Ad>(a);

                Ad a2 = new Ad
                {
                    Title = "titre",
                    Body = "content",
                    CreatedBy = u,
                    City = c,
                    Category = cat
                };
                c.AddAd(a2);
                repo.Save<Ad>(a2);

                City c2 = new City
                {
                    Label = "CherzmOi 2",
                    LabelUrlPart = "city2",
                };
                Ad a3 = new Ad
                {
                    Title = "titre",
                    Body = "content",
                    CreatedBy = u,
                    City = c2,
                    Category = cat
                };
                c2.AddAd(a3);
                repo.Save<City>(c2);
                repo.Save<Ad>(a3);

                repo.Flush();

                #endregion

                // When
                IDictionary<City, int> result = adRepo.CountAdsByCity();

                // Then
                Assert.AreEqual(2, result.Count);
                Assert.AreEqual(2, result[c]);
                Assert.AreEqual(1, result[c2]);
            }
        }
Ejemplo n.º 18
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));
            }
        }
Ejemplo n.º 19
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();
            }
        }
Ejemplo n.º 20
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);
            }
        }
Ejemplo n.º 21
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]);
            }
        }
Ejemplo n.º 22
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);
            }
        }
Ejemplo n.º 23
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]);
            }
        }
Ejemplo n.º 24
0
        public void SearchAdsByTitle_SearchStringIsNull_ReturnEverythingOrderedByCreationDate()
        {
            ISessionFactory sessionFactory = NhibernateHelper.SessionFactory;
            Repository repo = new Repository(sessionFactory);
            AdRepository adRepo = new AdRepository(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"
                };

                Ad a = new Ad
                {
                    Title = "titre 1",
                    Body = "content",
                    CreatedBy = u,
                    CreationDate = new DateTime(2012, 01, 16, 23, 52, 12)
                };
                c.AddAd(a);
                cat.AddAd(a);
                repo.Save<City>(c);
                repo.Save<Category>(cat);
                repo.Save<Ad>(a);

                Ad a2 = new Ad
                {
                    Title = "title 2",
                    Body = "content",
                    CreatedBy = u,
                    CreationDate = new DateTime(2012, 01, 16, 23, 52, 18)
                };
                c.AddAd(a2);
                cat.AddAd(a2);
                repo.Save<Ad>(a2);

                repo.Flush();

                #endregion

                // When
                IList<Ad> result = adRepo.SearchAdsByTitle(null);

                // Then
                Assert.AreEqual(2, result.Count);
                Assert.AreEqual(a2, result[0]);
                Assert.AreEqual(a, result[1]);
            }
        }