public MotorBoatEngineAdDetailsModel(MotorBoatEngineAd ad) : base(ad) { MotorType = ad.MotorType != null ? ad.MotorType.Label : String.Empty; Year = ad.Year != 0 ? ad.Year : (int?)null; Hp = ad.Hp != 0 ? String.Format("{0} Cv", ad.Hp) : String.Empty; }
public AdMotorBoatEngineCreateModel(MotorBoatEngineAd ad) : base(ad) { this.Hp = ad.Hp; if (ad.Type != null) this.SelectedTypeId = ad.Type.Id; if (ad.Year != 0) this.SelectedYearId = ad.Year; this.Type = (int)AdTypeEnum.MotorBoatEngineAd; }
public void Test_CtorWithAd_NoTypes() { // Given MotorBoatEngineAd ad = new MotorBoatEngineAd { Title = "title", City = new City(), CreatedBy = new User() }; // When MotorBoatEngineAdDetailsModel actual = new MotorBoatEngineAdDetailsModel(ad); // Then Assert.AreEqual(ad.Title, actual.Title); Assert.AreEqual(String.Empty, actual.MotorType); Assert.AreEqual(null, actual.Year); Assert.AreEqual(String.Empty, actual.Hp); }
public void Test_CtorWithAd() { // Given MotorBoatEngineAd ad = new MotorBoatEngineAd { Title = "title", MotorType = new Bea.Domain.Reference.MotorBoatEngineType { Label = "type" }, Year = 2012, Hp = 89, City = new City(), CreatedBy = new User() }; // When MotorBoatEngineAdDetailsModel actual = new MotorBoatEngineAdDetailsModel(ad); // Then Assert.AreEqual(ad.Title, actual.Title); Assert.AreEqual(ad.MotorType.Label, actual.MotorType); Assert.AreEqual(ad.Year, actual.Year); Assert.AreEqual("89 Cv", actual.Hp); }
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 GetAdDetails_MotorBoatEngineAdExists_GetAdFromRepoAndReturnMotoAdModel() { // Given MotorBoatEngineAd ad = new MotorBoatEngineAd() { 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.MotorBoatEngineAd); adRepoMock.Setup(r => r.GetAdById<MotorBoatEngineAd>(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 MotorBoatEngineAdDetailsModel); }