public void Test_CtorWithAd()
        {
            // Given
            SailingBoatAd ad = new SailingBoatAd
            {
                Title = "title",
                SailingBoatType = new Bea.Domain.Reference.SailingBoatType { Label = "type" },
                HullType = new Bea.Domain.Reference.SailingBoatHullType { Label = "hull" },
                Year = 2012,
                Length = 15.75000,
                City = new City(),
                CreatedBy = new User()
            };

            var helperMock = new Moq.Mock<IHelperService>();
            helperMock.Setup(x => x.GetCulture()).Returns(new System.Globalization.CultureInfo("Fr"));

            // When
            SailingBoatAdDetailsModel actual = new SailingBoatAdDetailsModel(ad, helperMock.Object);

            // Then
            Assert.AreEqual(ad.Title, actual.Title);
            Assert.AreEqual(ad.SailingBoatType.Label, actual.BoatType);
            Assert.AreEqual(ad.HullType.Label, actual.HullType);
            Assert.AreEqual(ad.Year, actual.Year);
            Assert.AreEqual("15,75 Mtr", actual.Length);
        }
        public void Test_CtorWithAd_NoTypes()
        {
            // Given
            SailingBoatAd ad = new SailingBoatAd
            {
                Title = "title",
                City = new City(),
                CreatedBy = new User()
            };

            // When
            SailingBoatAdDetailsModel actual = new SailingBoatAdDetailsModel(ad, null);

            // Then
            Assert.AreEqual(ad.Title, actual.Title);
            Assert.AreEqual(String.Empty, actual.BoatType);
            Assert.AreEqual(String.Empty, actual.HullType);
            Assert.AreEqual(null, actual.Year);
            Assert.AreEqual(String.Empty, actual.Length);
        }
Exemplo n.º 3
0
        protected AdDetailsModel CreateAdDetailsModelFromAd(AdTypeEnum adType, long adId)
        {
            AdDetailsModel model = null;
            BaseAd ad = null;

            // Get the right Ad based on its type
            switch (adType)
            {
                case AdTypeEnum.Ad:
                    ad = _adRepository.GetAdById<Ad>(adId);
                    model = new AdDetailsModel(ad);
                    break;

                case AdTypeEnum.CarAd:
                    ad = _adRepository.GetAdById<CarAd>(adId);
                    model = new CarAdDetailsModel(ad as CarAd);
                    break;

                case AdTypeEnum.MotoAd:
                    ad = _adRepository.GetAdById<MotoAd>(adId);
                    model = new MotoAdDetailsModel(ad as MotoAd);
                    break;

                case AdTypeEnum.OtherVehiculeAd:
                    ad = _adRepository.GetAdById<OtherVehicleAd>(adId);
                    model = new OtherVehicleAdDetailsModel(ad as OtherVehicleAd);
                    break;

                case AdTypeEnum.SailingBoatAd:
                    ad = _adRepository.GetAdById<SailingBoatAd>(adId);
                    model = new SailingBoatAdDetailsModel(ad as SailingBoatAd, _helperService);
                    break;

                case AdTypeEnum.MotorBoatAd:
                    ad = _adRepository.GetAdById<MotorBoatAd>(adId);
                    model = new MotorBoatAdDetailsModel(ad as MotorBoatAd, _helperService);
                    break;

                case AdTypeEnum.MotorBoatEngineAd:
                    ad = _adRepository.GetAdById<MotorBoatEngineAd>(adId);
                    model = new MotorBoatEngineAdDetailsModel(ad as MotorBoatEngineAd);
                    break;

                case AdTypeEnum.WaterSportAd:
                    ad = _adRepository.GetAdById<WaterSportAd>(adId);
                    model = new WaterSportAdDetailsModel(ad as WaterSportAd);
                    break;

                case AdTypeEnum.RealEstateAd:
                    ad = _adRepository.GetAdById<RealEstateAd>(adId);
                    model = new RealEstateAdDetailsModel(ad as RealEstateAd);
                    break;

                default:
                    return null;
            }

            // Compute whether or not this Ad is new (less than 3 days)
            model.IsNew = ad.CreationDate > _helperService.GetCurrentDateTime().AddHours(-72);

            return model;
        }