Exemplo n.º 1
0
        public void DeleteAd_AdExists_ReturnFilledInModelForDeletion()
        {
            // Given
            long adId = 56;

            var adRepoMock = new Moq.Mock<IAdRepository>();
            adRepoMock.Setup(r => r.CanDeleteAd(adId)).Returns(true);

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

            // When
            DeleteAdModel model = service.DeleteAd(adId);

            // Then
            Assert.AreEqual(adId, model.AdId);
            Assert.IsNull(model.Password);
            Assert.IsNull(model.SelectedDeletionReasonId);
            Assert.AreEqual(0, model.NbTry);
            Assert.IsNull(model.InfoMessage);
            Assert.IsTrue(model.CanDeleteAd);
            Assert.IsFalse(model.IsDeleted);
        }
Exemplo n.º 2
0
        public void DeleteAd_AdDoesNotExist_ReturnMessage()
        {
            // Given
            long adId = 56;

            var adRepoMock = new Moq.Mock<IAdRepository>();
            adRepoMock.Setup(r => r.CanDeleteAd(adId)).Returns(false);

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

            // When
            DeleteAdModel model = service.DeleteAd(adId);

            // Then
            Assert.AreEqual(adId, model.AdId);
            Assert.IsNull(model.Password);
            Assert.IsNull(model.SelectedDeletionReasonId);
            Assert.AreEqual(0, model.NbTry);
            Assert.AreEqual("Cette annonce n'existe pas ou plus.", model.InfoMessage);
            Assert.IsFalse(model.CanDeleteAd);
            Assert.IsFalse(model.IsDeleted);
        }
Exemplo n.º 3
0
        public void PerformDeleteAd_AdDoesNotExists_ReturnMessage()
        {
            // Given
            DeleteAdModel model = new DeleteAdModel
            {
                AdId = 56
            };

            var adRepoMock = new Moq.Mock<IAdRepository>();
            adRepoMock.Setup(r => r.GetAdById<BaseAd>(model.AdId)).Returns((BaseAd)null);

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

            // 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("Cette annonce n'existe pas ou plus.", result.InfoMessage);
            Assert.IsFalse(result.CanDeleteAd);
            Assert.IsFalse(result.IsDeleted);
        }
Exemplo n.º 4
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());
        }
Exemplo n.º 5
0
        public void PerformDeleteAd_AdExists_PasswordDoesNotMatch()
        {
            // Given
            DeleteAdModel model = new DeleteAdModel
            {
                AdId = 56,
                Password = "******",
                NbTry = 1,
                SelectedDeletionReasonId = 7
            };
            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);

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

            // When
            DeleteAdModel result = service.DeleteAd(model);

            // Then
            Assert.AreEqual(model.AdId, result.AdId);
            Assert.IsNull(result.Password);
            Assert.AreEqual(7, result.SelectedDeletionReasonId);
            Assert.AreEqual(2, result.NbTry);
            Assert.IsNull(result.InfoMessage);
            Assert.IsTrue(result.CanDeleteAd);
            Assert.IsFalse(result.IsDeleted);
        }