Beispiel #1
0
        // Lägga till nya bilannonser.
        public void CarAdFormView_InsertItem(CarAd carAd)
        {
            //DropDownList för att hitta rättt dropdownlist och sen kolla nogga vilket bilmärka man har valt.
            var          carBrandsIDs = 0;
            DropDownList cb           = (DropDownList)CarAdFormView.FindControl("CarBrandDropDownList");

            foreach (ListItem bm in cb.Items)
            {
                if (bm.Selected)
                {
                    // int sen lägger den .
                    carBrandsIDs = int.Parse(bm.Value);
                }
            }
            if (ModelState.IsValid)
            {
                try
                {
                    Service service = new Service();
                    carAd.CarBrandID = CarBrandID;
                    service.SaveCarAd(carAd, carBrandsIDs);
                    Page.SetTempData("Message", "Bilannonsen har lades till.");
                    Response.RedirectToRoute("CarAdDetails", new { id = carAd.CarAdID });
                    Context.ApplicationInstance.CompleteRequest();
                }
                catch (Exception)
                {
                    ModelState.AddModelError(String.Empty, "Fel inträffade då Bilannonsen skulle läggas till.");
                }
            }
        }
Beispiel #2
0
        //Uppdaterar en CarAd
        public void UpdateCarAd(CarAd carAd, int id)
        {
            // Skapar och initierar ett anslutningsobjekt.
            using (SqlConnection conn = CreateConnection())
            {
                try
                {
                    // Skapar ett SqlCommand-objekt för att exekvera specifierad lagrad procedur.
                    SqlCommand cmd = new SqlCommand("appSchema.uspUpdateCarAd", conn);
                    cmd.CommandType = CommandType.StoredProcedure;

                    // Lägger till de paramterar den lagrade proceduren kräver.
                    cmd.Parameters.Add("@CarAdID", SqlDbType.Int, 4).Value           = carAd.CarAdID;
                    cmd.Parameters.Add("@Header", SqlDbType.VarChar, 25).Value       = carAd.Header;
                    cmd.Parameters.Add("@CarColor", SqlDbType.VarChar, 25).Value     = carAd.CarColor;
                    cmd.Parameters.Add("@ModelYear", SqlDbType.Char, 4).Value        = carAd.ModelYear;
                    cmd.Parameters.Add("@Description", SqlDbType.VarChar, 500).Value = carAd.Description;
                    cmd.Parameters.Add("@Price", SqlDbType.Decimal).Value            = carAd.Price;
                    cmd.Parameters.Add("@CarBrandID", SqlDbType.TinyInt, 1).Value    = id;


                    // Öppnar anslutningen till databasen.
                    conn.Open();

                    // ExecuteNonQuery används för att exekvera den lagrade proceduren
                    cmd.ExecuteNonQuery();
                }
                catch
                {
                    // Kastar ett eget undantag om ett undantag kastas.
                    throw new ApplicationException("An error occured in the data access layer.");
                }
            }
        }
Beispiel #3
0
        public void Init()
        {
            this.carAdsRepoMock         = new Mock <IEfRepostory <CarAd> >();
            this.carBrandsRepoMock      = new Mock <IEfRepostory <CarBrand> >().Object;
            this.carModelsRepoMock      = new Mock <IEfRepostory <CarModel> >().Object;
            this.carFeatureServicesMock = new Mock <ICarFeatureServices>().Object;
            this.unitOfWorkMocked       = new Mock <IEfUnitOfWork>().Object;

            this.carAds = new List <CarAd>
            {
                new CarAd {
                    Title = "Awesome car!"
                },
                new CarAd {
                    Title = "Wohoo. Can be yours"
                },
                new CarAd {
                    Title = "Be fast!"
                },
            };

            this.expectedCarAd = new CarAd
            {
                Title = "Wohooo"
            };

            carAds.Add(expectedCarAd);

            var carAdsQuarable = this.carAds.AsQueryable();

            this.carAdsRepoMock.Setup(x => x.All).Returns(carAdsQuarable);
        }
        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));
            }
        }
Beispiel #5
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();
            }
        }
        public async Task <ActionResult <CreateCarAdOutputModel> > Create(CarAdInputModel input)
        {
            var dealer = await this.dealers.FindByUser(this.currentUser.UserId);

            var category = await this.categories.Find(input.Category);

            if (category == null)
            {
                return(BadRequest(Result.Failure("Category does not exist.")));
            }

            var manufacturer = await this.manufacturers.FindByName(input.Manufacturer);

            manufacturer ??= new Manufacturer
            {
                Name = input.Manufacturer
            };

            var carAd = new CarAd
            {
                Dealer       = dealer,
                Manufacturer = manufacturer,
                Model        = input.Model,
                Description  = input.Description,
                Category     = category,
                ImageUrl     = input.ImageUrl,
                PricePerDay  = input.PricePerDay,
                Options      = new Options
                {
                    HasClimateControl = input.HasClimateControl,
                    NumberOfSeats     = input.NumberOfSeats,
                    TransmissionType  = input.TransmissionType
                }
            };

            this.carAds.Add(carAd);

            var message = new CarAdCreatedMessage
            {
                CarAdId      = carAd.Id,
                Manufacturer = carAd.Manufacturer.Name,
                Model        = carAd.Model,
                PricePerDay  = carAd.PricePerDay,
                ImageUrl     = carAd.ImageUrl
            };

            await this.carAds.Save(message);

            await this.fullTextSearch.Index(new CarAdFullTextSearchModel
            {
                CarAdId     = carAd.Id,
                Description = carAd.Description
            });

            return(new CreateCarAdOutputModel(carAd.Id));
        }
Beispiel #7
0
        public AdCarCreateModel(CarAd ad)
            : base(ad)
        {
            this.Type = (int)AdTypeEnum.CarAd;

            if (ad.Fuel != null)
            {
                this.SelectedFuelId = ad.Fuel.Id;
            }
            if (ad.Brand != null)
            {
                this.SelectedBrandId = ad.Brand.Id;
            }
        }
Beispiel #8
0
        public CarAdDetailsModel(CarAd ad)
            : base(ad as BaseAd)
        {
            Year       = ad.Year;
            Kilometers = ad.Kilometers;
            GearType   = ad.IsAutomatic ? "Automatique" : "Manuelle";
            Fuel       = ad.Fuel == null ? String.Empty : ad.Fuel.Label;

            if (!String.IsNullOrEmpty(ad.OtherBrand))
            {
                Brand = ad.OtherBrand;
            }
            else
            {
                Brand = ad.Brand == null ? String.Empty : ad.Brand.Label;
            }
        }
        public void AddNewCarAd(
            string title,
            Guid carModelId,
            CarType carType,
            int manufactureYear,
            int mileage,
            FuelType fuelType,
            TransmissionType transmissionType,
            IEnumerable <string> carFeatures,
            Guid townId,
            double price,
            string additionalInfo,
            string carImageUrl,
            string userId)
        {
            var allCarFeaturesFromDB = this.carFeatureServices.GetAllCarFeatures();

            var carFeaturesIn = new List <CarFeature>();

            foreach (var featureId in carFeatures)
            {
                var futureIdGuid = Guid.Parse(featureId);
                var feature      = allCarFeaturesFromDB.FirstOrDefault(x => x.Id == futureIdGuid);
                carFeaturesIn.Add(feature);
            }

            var newCarAd = new CarAd
            {
                Title            = title,
                CarModelId       = carModelId,
                CarType          = carType,
                ManufactureYear  = manufactureYear,
                Mileage          = mileage,
                FuelType         = fuelType,
                TransmissionType = transmissionType,
                CarFeatures      = carFeaturesIn,
                TownId           = townId,
                Price            = price,
                AdditionalInfo   = additionalInfo,
                CarImageURL      = carImageUrl,
                UserId           = userId
            };

            this.carsAdsRepo.Add(newCarAd);
            this.unitOfWork.Commit();
        }
Beispiel #10
0
 public AdCarCreateModel(CarAd ad, AdCreateModel model)
 {
     this.Body               = ad.Body;
     this.IsOffer            = ad.IsOffer;
     this.Price              = ad.Price;
     this.SelectedCategoryId = model.SelectedCategoryId;
     this.SelectedCityId     = model.SelectedCityId;
     this.SelectedProvinceId = model.SelectedProvinceId;
     this.Telephone          = ad.PhoneNumber;
     this.Title              = ad.Title;
     this.Km = ad.Kilometers;
     if (ad.Fuel != null)
     {
         this.SelectedFuelId = ad.Fuel.Id;
     }
     if (ad.Brand != null)
     {
         this.SelectedBrandId = ad.Brand.Id;
     }
 }
        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);
        }
        public void GetAdDetails_CarAdExists_GetAdFromRepoAndReturnCarAdModel()
        {
            // Given
            CarAd ad = new CarAd()
            {
                Id = 17
            };

            ad.CreationDate = new DateTime(2012, 02, 18);
            ad.CreatedBy    = new User {
                Firstname = "Michel"
            };
            ad.City = new City {
                Label = "Ville"
            };

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

            repoMock.Setup(x => x.Get <BaseAd>(17)).Returns(ad as BaseAd);

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

            adRepoMock.Setup(r => r.GetAdType(17)).Returns(AdTypeEnum.CarAd);
            adRepoMock.Setup(r => r.GetAdById <CarAd>(17)).Returns(ad);

            var helperMock = new Moq.Mock <IHelperService>();

            helperMock.Setup(s => s.GetCurrentDateTime()).Returns(new DateTime(2012, 02, 20));

            AdDetailsServices service = new AdDetailsServices(adRepoMock.Object, helperMock.Object);

            // When
            AdDetailsModel actual = service.GetAdDetails(17);

            // Then
            Assert.AreEqual(17, actual.AdId);
            Assert.IsTrue(actual is CarAdDetailsModel);
        }
Beispiel #13
0
        //Skapar en ny CarAd i tabellen CarAd.
        public void InsertCarAd(CarAd carAd, int id)
        {
            // Skapar och initierar ett anslutningsobjekt.
            using (SqlConnection conn = CreateConnection())
            {
                try
                {
                    // Skapar ett SqlCommand-objekt för att exekvera specifierad lagrad procedur.
                    SqlCommand cmd = new SqlCommand("appSchema.uspInsertCarAd", conn);
                    cmd.CommandType = CommandType.StoredProcedure;

                    // Lägger till de paramterar den lagrade proceduren kräver.
                    cmd.Parameters.Add("@Header", SqlDbType.VarChar, 25).Value       = carAd.Header;
                    cmd.Parameters.Add("@CarColor", SqlDbType.VarChar, 25).Value     = carAd.CarColor;
                    cmd.Parameters.Add("@ModelYear", SqlDbType.Char, 4).Value        = carAd.ModelYear;
                    cmd.Parameters.Add("@Description", SqlDbType.VarChar, 500).Value = carAd.Description;
                    cmd.Parameters.Add("@Price", SqlDbType.Decimal).Value            = carAd.Price;
                    cmd.Parameters.Add("@CarBrandID", SqlDbType.TinyInt, 1).Value    = id;
                    // Lägger till de paramterar den lagrade proceduren kräver.
                    cmd.Parameters.Add("@CarAdID", SqlDbType.Int, 4).Direction = ParameterDirection.Output;


                    // Öppnar anslutningen till databasen.
                    conn.Open();

                    // Exekvera den lagrade proceduren
                    cmd.ExecuteNonQuery();

                    // Hämtar primärnyckelns värde för den nya posten och tilldelar CarAd-objektet värdet.
                    carAd.CarAdID = (int)cmd.Parameters["@CarAdID"].Value;
                }
                catch
                {
                    throw new ApplicationException("An error occured in the data access layer.");
                }
            }
        }
        public void AdDetailsModel_ctor_WithCarAd_Manuelle()
        {
            // 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   = 200000,
                Year         = 1997,
                IsAutomatic  = false
            };

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

            // Then
            Assert.AreEqual(17, model.AdId);
            Assert.AreEqual(200000, model.Kilometers);
            Assert.AreEqual(1997, model.Year);
            Assert.AreEqual("Manuelle", model.GearType);
        }
Beispiel #15
0
        // The id parameter name should match the DataKeyNames value set on the control
        public void CarAdFormView_UpdateItem(CarAd carAd)
        {
            var carBrandsIDs = 0;

            DropDownList cb = (DropDownList)CarAdFormView.FindControl("DropDownList1");

            foreach (ListItem bm in cb.Items)
            {
                if (bm.Selected)
                {
                    carBrandsIDs = int.Parse(bm.Value);
                }
            }
            try
            {
                if (carAd == null)
                {
                    // The item wasn't found
                    ModelState.AddModelError(String.Empty, String.Format("CarAd with id {0} was not found", carAd));
                    return;
                }

                if (TryUpdateModel(carAd))
                {
                    carAd.CarBrandID = CarBrandID;
                    Service.SaveCarAd(carAd, carBrandsIDs);
                    Page.SetTempData("Message", "Bilannonsen har uppdaterats.");
                    Response.RedirectToRoute("CarAdDetails", new { id = carAd.CarAdID });
                    Context.ApplicationInstance.CompleteRequest();
                }
            }
            catch (Exception)
            {
                ModelState.AddModelError(String.Empty, "Fel inträffade då bilannonsen skulle uppdateras.");
            }
        }
Beispiel #16
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]);
            }
        }
Beispiel #17
0
 public void AddCarAd(CarAd carAd) => this.carAds.Add(carAd);
        public async Task <string> saveCarAd(Ad ad, bool update = false)
        {
            //  ad.category = "Vehicles";
            //  ad.subcategory = "Cars";
            CarAd mobileAd = new CarAd();

            mobileAd.color = Request["color"];
            if (Request["year"] != "" && Request["year"] != null)
            {
                mobileAd.year = short.Parse(Request["year"]);
            }
            mobileAd.fuelType = Request["fuelType"];
            mobileAd.assembly = Request["assembly"];
            if (Request["kmDriven"] != null && Request["kmDriven"] != "")
            {
                mobileAd.kmDriven = int.Parse(Request["kmDriven"]);
            }
            if (Request["engineCapacity"] != null && Request["engineCapacity"] != "")
            {
                mobileAd.engineCapacity = int.Parse(Request["engineCapacity"]);
            }
            mobileAd.adId = ad.Id;
            if (Request["noOfOwners"] != null && Request["noOfOwners"] != "")
            {
                mobileAd.noOfOwners = short.Parse(Request["noOfOwners"]);
            }
            if (Request["registeredCity"] != null && Request["registeredCity"] != "")
            {
                var city = Request["registeredCity"];
                mobileAd.registeredCity = await SaveCity(city);
            }
            mobileAd.transmission = Request["transmission"];
            IdStatus idstatus = SaveCarsBrandModel(ad);

            mobileAd.carModel = idstatus.id;
            ad.status         = idstatus.status;
            if (update)
            {
                db.Entry(mobileAd).State = EntityState.Modified;
            }
            else
            {
                db.CarAds.Add(mobileAd);
            }
            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbEntityValidationException e)
            {
                string        s             = e.ToString();
                List <string> errorMessages = new List <string>();
                foreach (DbEntityValidationResult validationResult in e.EntityValidationErrors)
                {
                    string entityName = validationResult.Entry.Entity.GetType().Name;
                    foreach (DbValidationError error in validationResult.ValidationErrors)
                    {
                        errorMessages.Add(entityName + "." + error.PropertyName + ": " + error.ErrorMessage);
                    }
                }
            }
            return(ad.status);
        }
Beispiel #19
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]);
            }
        }