Ejemplo n.º 1
0
        public SpamAdRequestModel SpamRequestAd(SpamAdRequestModel model)
        {
            SpamAdRequestModel result = CanSpamRequestAd(model.AdId);

            if (!result.CanSignal)
                return result;

            BaseAd ad = _adRepository.GetAdById<BaseAd>(model.AdId);

            this.CanSpamRequestAd(model.AdId);

            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
            {
                SpamAdRequest req = new SpamAdRequest();
                req.Ad = ad;
                req.RequestDate = _helper.GetCurrentDateTime();
                req.RequestorEmailAddress = model.RequestorEmail;
                req.SpamType = _repository.Get<SpamAdType>(model.SelectedSpamAdTypeId);
                req.Description = model.Description;

                _repository.Save(req);
                scope.Complete();
            }

            result.InfoMessage = "Votre signalement a correctement été transmis. Merci de votre précieuse aide dans la chasse aux mauvaises annonces !";
            result.CanSignal = false;

            return result;
        }
Ejemplo n.º 2
0
        public SpamAdRequestModel CanSpamRequestAd(long adId)
        {
            SpamAdRequestModel result = new SpamAdRequestModel();

            if (!_adRepository.CanDeleteAd(adId))
            {
                result.InfoMessage = "Cette annonce n'existe pas ou plus.";
                result.CanSignal = false;
                return result;
            }

            result.CanSignal = true;
            result.AdId = adId;

            return result;
        }
Ejemplo n.º 3
0
        public void SpamRequestAd_AdDoesNotExist_ReturnInfoMessage()
        {
            // Given
            var adRepoMock = new Moq.Mock<IAdRepository>();
            adRepoMock.Setup(x => x.CanDeleteAd(7)).Returns(false);

            SpamAdRequestModel model = new SpamAdRequestModel();
            model.AdId = 7;

            SpamAdServices service = new SpamAdServices(adRepoMock.Object, null, null);

            // When
            SpamAdRequestModel result = service.SpamRequestAd(model);

            // Then
            Assert.IsFalse(result.CanSignal);
            Assert.AreEqual("Cette annonce n'existe pas ou plus.", result.InfoMessage);
        }
Ejemplo n.º 4
0
        public void SpamRequestAd_AdExists_SaveSpamRequest()
        {
            // Given
            var adRepoMock = new Moq.Mock<IAdRepository>();
            adRepoMock.Setup(x => x.CanDeleteAd(7)).Returns(true);

            var repoMock = new Moq.Mock<IRepository>();
            repoMock.Setup(x => x.Get<SpamAdType>(3)).Returns(new SpamAdType() { Id = 3 });

            var hSMock = new Moq.Mock<IHelperService>();
            hSMock.Setup(x => x.GetCurrentDateTime()).Returns(new DateTime(2013, 05, 17, 6, 7, 22));

            SpamAdRequestModel model = new SpamAdRequestModel();
            model.AdId = 7;
            model.Description = "description";
            model.RequestorEmail = "*****@*****.**";
            model.SelectedSpamAdTypeId = 3;

            SpamAdServices service = new SpamAdServices(adRepoMock.Object, repoMock.Object, hSMock.Object);

            // When
            SpamAdRequestModel result = service.SpamRequestAd(model);

            // Then
            Assert.IsFalse(result.CanSignal);
            Assert.AreEqual("Votre signalement a correctement été transmis. Merci de votre précieuse aide dans la chasse aux mauvaises annonces !", result.InfoMessage);

            repoMock.Verify(x => x.Save(Moq.It.Is<SpamAdRequest>(b =>
                b.Description == model.Description
                && b.RequestDate == new DateTime(2013, 05, 17, 6, 7, 22)
                && b.RequestorEmailAddress == model.RequestorEmail
                && b.SpamType.Id == 3)));
        }
Ejemplo n.º 5
0
        public ActionResult SpamAdRequest(SpamAdRequestModel model)
        {
            // This line validates the captcha code and creates a ModelError if not valid
            this.IsCaptchaValid("Code invalide");

            if (!ModelState.IsValid)
            {
                ViewBag.SpamAdTypes = _referenceServices.GetAllReferences<SpamAdType>().Select(x => new SelectListItem { Text = x.Label, Value = x.Id.ToString() }).ToList();
                return View("SpamAdRequest", model);
            }

            var result = _spamAdServices.SpamRequestAd(model);
            return View("SpamAdRequest", result);
        }