public RealEstateAdDetailsModel(RealEstateAd ad) : base(ad) { RoomNb = ad.RoomsNumber != 0 ? ad.RoomsNumber : (int?) null; Type = ad.Type != null ? ad.Type.Label : String.Empty; District = ad.District != null ? ad.District.Label : String.Empty; SurfaceArea = ad.SurfaceArea != 0 ? String.Format("{0} m²", ad.SurfaceArea) : String.Empty; Furnished = ad.IsFurnished.HasValue ? (ad.IsFurnished.Value ? "Oui" : "Non") : String.Empty; }
public AdRealEstateCreateModel(RealEstateAd ad) : base(ad) { this.Type = (int)AdTypeEnum.RealEstateAd; if (ad.Type != null) this.SelectedTypeId = ad.Type.Id; if (ad.District != null) this.SelectedDistrictId = ad.District.Id; this.RoomNb = ad.RoomsNumber; this.SurfaceArea = ad.SurfaceArea; this.IsFurnished = ad.IsFurnished; }
public void Test_CtorWithAd_NoTypes() { // Given RealEstateAd ad = new RealEstateAd { Title = "title", City = new City(), CreatedBy = new User() }; // When RealEstateAdDetailsModel actual = new RealEstateAdDetailsModel(ad); // Then Assert.AreEqual(ad.Title, actual.Title); Assert.AreEqual(String.Empty, actual.Type); Assert.AreEqual(String.Empty, actual.District); Assert.AreEqual(null, actual.RoomNb); Assert.AreEqual(String.Empty, actual.SurfaceArea); }
public void Test_CtorWithAd() { // Given RealEstateAd ad = new RealEstateAd { Title = "title", Type = new Bea.Domain.Reference.RealEstateType { Label = "tyyype" }, RoomsNumber = 4, District = new District { Label = "quartier" }, SurfaceArea = 80, City = new City(), CreatedBy = new User() }; // When RealEstateAdDetailsModel actual = new RealEstateAdDetailsModel(ad); // Then Assert.AreEqual(ad.Title, actual.Title); Assert.AreEqual(ad.Type.Label, actual.Type); Assert.AreEqual(ad.District.Label, actual.District); Assert.AreEqual(4, actual.RoomNb); Assert.AreEqual("80 m²", actual.SurfaceArea); }
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 GetAdDetails_RealEstateAdExists_GetAdFromRepoAndReturnMotoAdModel() { // Given RealEstateAd ad = new RealEstateAd() { 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.RealEstateAd); adRepoMock.Setup(r => r.GetAdById<RealEstateAd>(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 RealEstateAdDetailsModel); }