public void SearchAdCache_CopyCtorWithBaseAd_NoImages_CopyBaseAdProperties() { // Given BaseAd ad = new Ad() { Id = 1245, Title = "title", Body = "body", City = new City { Id = 45, Province = new Province { Id = 11 } }, Category = new Category { Id = 89 }, Price = 200457, CreationDate = new DateTime(2013, 01, 05) }; // When SearchAdCache actual = new SearchAdCache(ad); // Then Assert.AreEqual(ad.Id, actual.AdId); Assert.AreEqual(ad.Title, actual.Title); Assert.AreEqual(ad.Body, actual.Body); Assert.AreEqual(ad.City, actual.City); Assert.AreEqual(ad.City.Province, actual.Province); Assert.AreEqual(ad.Category, actual.Category); Assert.AreEqual(ad.Price, actual.Price); Assert.AreEqual(ad.CreationDate, actual.CreationDate); Assert.AreEqual(ad.Category.Type, actual.AdType); Assert.IsNull(actual.AdImageId); }
public void SearchAdCache_CopyCtorWithBaseAd_WithImages_CopyBaseAdProperties() { // Given BaseAd ad = new Ad() { Id = 1245, Title = "title", Body = "body", City = new City { Id = 45, Province = new Province { Id = 11 } }, Category = new Category { Id = 89 }, Images = new List <AdImage>() { new AdImage { Id = Guid.Parse("b9da8b1e-aa77-401b-84e0-a1290130b7b7"), IsPrimary = false }, new AdImage { Id = Guid.Parse("e9da8b1e-aa77-401b-84e0-a1290130b7b7"), IsPrimary = true }, } }; // When SearchAdCache actual = new SearchAdCache(ad); // Then Assert.AreEqual("e9da8b1e-aa77-401b-84e0-a1290130b7b7", actual.AdImageId); }
public void AdSearchResultModel_ConstructorTest() { // Given SearchAdCache ad = new SearchAdCache() { AdId = 19, Title = "the title", CreationDate = new DateTime(2012, 12, 21), City = new City { Label = "Nouméa" }, Price = 127, AdImageId = "456", Category = new Category { Label = "category" } }; // When AdSearchResultItemModel model = new AdSearchResultItemModel(ad); // Then Assert.AreEqual(ad.AdId, model.AdId); Assert.AreEqual(ad.Title, model.Title); Assert.AreEqual(ad.CreationDate, model.CreationDate); Assert.AreEqual(ad.City.Label, model.Location); Assert.AreEqual("127 Francs", model.Price); Assert.AreEqual(ad.AdImageId, model.MainImageId); Assert.AreEqual(ad.Category.Label, model.Category); }
public void PerformDeleteAd_AdExists_PasswordMatchesNoReasonAndNoSearchAdCache_MarkAdAsDeleted() { // Given DeleteAdModel model = new DeleteAdModel { AdId = 56, Password = "******", NbTry = 1, SelectedDeletionReasonId = null }; SearchAdCache adc = new SearchAdCache() { AdId = 56 }; User creator = new User() { Password = "******" }; BaseAd ad = new Ad() { CreatedBy = creator }; var adRepoMock = new Moq.Mock <IAdRepository>(); adRepoMock.Setup(r => r.GetAdById <BaseAd>(model.AdId)).Returns(ad); var repoMock = new Moq.Mock <IRepository>(); repoMock.Setup(x => x.Get <SearchAdCache>(model.AdId)).Returns(adc); repoMock.Setup(x => x.Save <BaseAd>(ad)); repoMock.Setup(x => x.Delete <SearchAdCache>(adc)); var helperMock = new Moq.Mock <IHelperService>(); helperMock.Setup(x => x.GetCurrentDateTime()).Returns(new DateTime(2013, 01, 26)); AdDeletionServices service = new AdDeletionServices(adRepoMock.Object, repoMock.Object, helperMock.Object); // When DeleteAdModel result = service.DeleteAd(model); // Then Assert.AreEqual(model.AdId, result.AdId); Assert.IsNull(result.Password); Assert.IsNull(result.SelectedDeletionReasonId); Assert.AreEqual(0, result.NbTry); Assert.AreEqual("Votre annonce a correctement été supprimée. Elle n'est plus disponible à la recherche.", result.InfoMessage); Assert.IsFalse(result.CanDeleteAd); Assert.IsTrue(result.IsDeleted); Assert.AreEqual(new DateTime(2013, 01, 26), ad.DeletionDate); Assert.IsTrue(ad.IsDeleted); Assert.IsNull(ad.DeletedReason); repoMock.Verify(x => x.Save <BaseAd>(ad), Times.Once()); repoMock.Verify(x => x.Delete <SearchAdCache>(adc), Times.Never()); }
public AdSearchResultItemModel(SearchAdCache ad) { AdId = ad.AdId; Title = ad.Title; Location = ad.City.Label; Category = ad.Category.Label; Price = String.Format("{0} Francs", ad.Price); CreationDate = ad.CreationDate; MainImageId = ad.AdImageId; }
public AdSearchResultItemModel(SearchAdCache ad) { AdId = ad.AdId; Title = ad.Title; Location = ad.City.Label; Category = ad.Category.Label; Price = String.Format("{0} Francs", ad.Price.ToString("N0", CultureInfo.CreateSpecificCulture("sv-SE"))); CreationDate = ad.CreationDate; MainImageId = ad.AdImageId; }
public AdSearchResultItemModel(SearchAdCache ad) { AdId = ad.AdId; Title = ad.Title; Location = ad.City.Label; Category = ad.Category.Label; Price = String.Format("{0} Francs", ad.Price.ToString("N0",CultureInfo.CreateSpecificCulture("sv-SE"))); CreationDate = ad.CreationDate; MainImageId = ad.AdImageId; }
public DeleteAdModel DeleteAd(DeleteAdModel model) { DeleteAdModel result = new DeleteAdModel(); result.AdId = model.AdId; BaseAd ad = _adRepository.GetAdById <BaseAd>(model.AdId); if (ad == null || ad.IsDeleted) { result.InfoMessage = "Cette annonce n'existe pas ou plus."; result.CanDeleteAd = false; return(result); } if (model.Password != ad.CreatedBy.Password) { result.NbTry = ++model.NbTry; result.SelectedDeletionReasonId = model.SelectedDeletionReasonId; result.CanDeleteAd = true; return(result); } using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { ad.IsDeleted = true; ad.DeletionDate = _helper.GetCurrentDateTime(); if (model.SelectedDeletionReasonId.HasValue) { ad.DeletedReason = _repository.Get <DeletionReason>(model.SelectedDeletionReasonId); } _repository.Save <BaseAd>(ad); SearchAdCache adCache = _repository.Get <SearchAdCache>(ad.Id); if (adCache != null) { _repository.Delete <SearchAdCache>(adCache); } result.IsDeleted = true; result.InfoMessage = "Votre annonce a correctement été supprimée. Elle n'est plus disponible à la recherche."; scope.Complete(); } return(result); }
public AdActivationResultModel ActivateAd(long adId, String activationToken) { AdActivationResultModel model = new AdActivationResultModel(); model.AdId = adId; BaseAd adToValidate = _repository.Get <BaseAd>(adId); if (adToValidate == null) { model.InfoMessage = "Cette annonce n'existe pas ou a expiré."; model.IsActivated = false; return(model); } if (adToValidate.IsActivated) { model.InfoMessage = "Cette annonce a déjà été activée."; model.IsActivated = true; return(model); } if (!adToValidate.ActivationToken.Equals(activationToken)) { model.InfoMessage = "Vous ne pouvez pas activer cette annonce."; model.IsActivated = false; return(model); } // Actually activate the ad using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew)) { adToValidate.IsActivated = true; _repository.Save(adToValidate); SearchAdCache searchAdCache = new SearchAdCache(adToValidate); _repository.Save(searchAdCache); _repository.Flush(); scope.Complete(); } model.InfoMessage = "Merci d'avoir activé votre annonce."; model.IsActivated = true; return(model); }
public AdActivationResultModel ActivateAd(long adId, String activationToken) { AdActivationResultModel model = new AdActivationResultModel(); model.AdId = adId; BaseAd adToValidate = _repository.Get<BaseAd>(adId); if (adToValidate == null) { model.InfoMessage = "Cette annonce n'existe pas ou a expiré."; model.IsActivated = false; return model; } if (adToValidate.IsActivated) { model.InfoMessage = "Cette annonce a déjà été activée."; model.IsActivated = true; return model; } if (!adToValidate.ActivationToken.Equals(activationToken)) { model.InfoMessage = "Vous ne pouvez pas activer cette annonce."; model.IsActivated = false; return model; } // Actually activate the ad using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew)) { adToValidate.IsActivated = true; _repository.Save(adToValidate); SearchAdCache searchAdCache = new SearchAdCache(adToValidate); _repository.Save(searchAdCache); _repository.Flush(); scope.Complete(); } model.InfoMessage = "Merci d'avoir activé votre annonce."; model.IsActivated = true; return model; }
public void SearchAdCache_CopyCtorWithBaseAd_WithImages_CopyBaseAdProperties() { // Given BaseAd ad = new Ad() { Id = 1245, Title = "title", Body = "body", City = new City { Id = 45, Province = new Province { Id = 11 } }, Category = new Category { Id = 89 }, Images = new List<AdImage>() { new AdImage { Id = Guid.Parse("b9da8b1e-aa77-401b-84e0-a1290130b7b7"), IsPrimary = false }, new AdImage { Id = Guid.Parse("e9da8b1e-aa77-401b-84e0-a1290130b7b7"), IsPrimary = true }, } }; // When SearchAdCache actual = new SearchAdCache(ad); // Then Assert.AreEqual("e9da8b1e-aa77-401b-84e0-a1290130b7b7", actual.AdImageId); }
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]); } }
public void AdvancedSearchAds_MotorBoatAd_MotorBoatProperties_ReturnMotorBoatAd() { ISessionFactory sessionFactory = NhibernateHelper.SessionFactory; Repository repo = new Repository(sessionFactory); SearchRepository adRepo = new SearchRepository(sessionFactory); using (ITransaction transaction = sessionFactory.GetCurrentSession().BeginTransaction()) { // Given #region test data Province p1 = new Province { Label = "p1" }; User u = new User { Email = "*****@*****.**", Password = "******" }; repo.Save <User>(u); City c = new City { Label = "city", LabelUrlPart = "city" }; p1.AddCity(c); Category cat = new Category { Label = "Bateau à moteur", LabelUrlPart = "Bateau" }; SearchAdCache a = new SearchAdCache { AdId = 1, Title = "bateau", Body = "la desc du bateau", City = c, CreationDate = new DateTime(2012, 01, 16, 23, 52, 18), Category = cat }; MotorBoatType mbt = new MotorBoatType() { Id = 5, Label = "Bois" }; MotorBoatEngineType mt = new MotorBoatEngineType() { Id = 7, Label = "4 temps" }; MotorBoatAd bat = new MotorBoatAd { Id = 1, Title = "bateau", Body = "la desc du bateau", City = c, CreationDate = new DateTime(2012, 01, 16, 23, 52, 18), Category = cat, CreatedBy = u, Price = 1000, Hp = 100, Length = 6, MotorBoatType = mbt, MotorType = mt, Year = 2005 }; repo.Save(mbt); repo.Save(mt); repo.Save(p1); repo.Save(c); repo.Save(cat); repo.Save(u); repo.Save(bat); repo.Save(a); repo.Flush(); #endregion AdSearchParameters param = new AdSearchParameters { MotorBoatTypeId = 1, MotorEngineTypeId = 1, MinHp = 99, MaxHp = 100, MinLength = 6, MaxLength = 10, MinYear = 2004, MaxYear = 2006 }; // When IList <SearchAdCache> result = adRepo.AdvancedSearchAds <MotorBoatAd>(param); // Then Assert.AreEqual(1, result.Count); Assert.AreEqual(a, result[0]); } }
public void SearchAds_SearchByTitleAndBodyAndCity() { 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" }, cityId: c2.Id); // Then Assert.AreEqual(1, result.Count); Assert.AreEqual(a2, result[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]); } }
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]); } }
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]); } }
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]); } }
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]); } }
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); } }
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]); } }
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]); } }
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]); } }
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); } }
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]); } }
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]); } }
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]); } }
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]); } }
public void PerformDeleteAd_AdExists_PasswordMatches_MarkAdAsDeletedAndRemoveFromSearchAdCache() { // Given DeleteAdModel model = new DeleteAdModel { AdId = 56, Password = "******", NbTry = 1, SelectedDeletionReasonId = 7 }; DeletionReason dr = new DeletionReason() { Id = 7 }; SearchAdCache adc = new SearchAdCache() { AdId = 56 }; User creator = new User() { Password = "******" }; BaseAd ad = new Ad() { Id = 56, CreatedBy = creator }; var adRepoMock = new Moq.Mock<IAdRepository>(); adRepoMock.Setup(r => r.GetAdById<BaseAd>(model.AdId)).Returns(ad); var repoMock = new Moq.Mock<IRepository>(); repoMock.Setup(x => x.Get<DeletionReason>(7)).Returns(dr); repoMock.Setup(x => x.Get<SearchAdCache>(model.AdId)).Returns(adc); repoMock.Setup(x => x.Save<BaseAd>(ad)); repoMock.Setup(x => x.Delete<SearchAdCache>(adc)); var helperMock = new Moq.Mock<IHelperService>(); helperMock.Setup(x => x.GetCurrentDateTime()).Returns(new DateTime(2013, 01, 26)); AdDeletionServices service = new AdDeletionServices(adRepoMock.Object, repoMock.Object, helperMock.Object); // When DeleteAdModel result = service.DeleteAd(model); // Then Assert.AreEqual(model.AdId, result.AdId); Assert.IsNull(result.Password); Assert.IsNull(result.SelectedDeletionReasonId); Assert.AreEqual(0, result.NbTry); Assert.AreEqual("Votre annonce a correctement été supprimée. Elle n'est plus disponible à la recherche.", result.InfoMessage); Assert.IsFalse(result.CanDeleteAd); Assert.IsTrue(result.IsDeleted); Assert.AreEqual(new DateTime(2013, 01, 26), ad.DeletionDate); Assert.IsTrue(ad.IsDeleted); Assert.AreEqual(dr, ad.DeletedReason); repoMock.Verify(x => x.Save<BaseAd>(ad), Times.Once()); repoMock.Verify(x => x.Delete<SearchAdCache>(adc), Times.Once()); }
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]); } }