Example #1
0
        public void FlagsDeletedTrueOfTrip()
        {
            //Arrange
            var service = new TripsService(
                this.tripsRepositoryMock.Object,
                this.usersServiceMock.Object,
                this.commentsServiceMock.Object,
                this.unitOfWorkMock.Object,
                this.converterMock.Object,
                this.identifierProviderMock.Object);

            var userMock = new Mock <User>();
            var tripMock = new Mock <Trip>();

            this.usersServiceMock.Setup(s => s.GetCurrentUser())
            .Returns(userMock.Object);
            tripMock.Setup(t => t.Creator)
            .Returns(userMock.Object);
            tripMock.Setup(t => t.Comments)
            .Returns(new List <Comment>());

            Assert.IsFalse(tripMock.Object.IsDeleted);

            //Act
            service.DeleteTrip(tripMock.Object);

            //Assert
            Assert.IsTrue(tripMock.Object.IsDeleted);
        }
Example #2
0
        public void CallCommentsServiceDeleteAllMethodOnceIfCommentsExist()
        {
            var commentsServiceMock = new Mock <ICommentsService>();
            //Arrange
            var service = new TripsService(
                this.tripsRepositoryMock.Object,
                this.usersServiceMock.Object,
                commentsServiceMock.Object,
                this.unitOfWorkMock.Object,
                this.converterMock.Object,
                this.identifierProviderMock.Object);

            var userMock    = new Mock <User>();
            var tripMock    = new Mock <Trip>();
            var commentMock = new Mock <Comment>();

            this.usersServiceMock.Setup(s => s.GetCurrentUser())
            .Returns(userMock.Object);
            tripMock.Setup(t => t.Creator)
            .Returns(userMock.Object);
            tripMock.Setup(t => t.Comments)
            .Returns(new List <Comment>()
            {
                commentMock.Object
            });

            //Act
            service.DeleteTrip(tripMock.Object);

            //Assert
            commentsServiceMock.Verify(x => x.DeleteAllComments(tripMock.Object.Comments), Times.Once);
        }
Example #3
0
        public void CallUnitOfWorkCommitMethodOnce()
        {
            var unitOfWorkMock = new Mock <IUnitOfWork>();
            //Arrange
            var service = new TripsService(
                this.tripsRepositoryMock.Object,
                this.usersServiceMock.Object,
                this.commentsServiceMock.Object,
                unitOfWorkMock.Object,
                this.converterMock.Object,
                this.identifierProviderMock.Object);

            var userMock = new Mock <User>();
            var tripMock = new Mock <Trip>();

            this.usersServiceMock.Setup(s => s.GetCurrentUser())
            .Returns(userMock.Object);
            tripMock.Setup(t => t.Creator)
            .Returns(userMock.Object);
            tripMock.Setup(t => t.Comments)
            .Returns(new List <Comment>());

            //Act
            service.DeleteTrip(tripMock.Object);

            //Assert
            unitOfWorkMock.Verify(u => u.Commit(), Times.Once);
        }
Example #4
0
        public void ThrowIfCurrentUserDifferentThanTripCreator()
        {
            //Arrange
            var service = new TripsService(
                this.tripsRepositoryMock.Object,
                this.usersServiceMock.Object,
                this.commentsServiceMock.Object,
                this.unitOfWorkMock.Object,
                this.converterMock.Object,
                this.identifierProviderMock.Object);

            var firstUser  = new Mock <User>();
            var secondUser = new Mock <User>();
            var trip       = new Mock <Trip>();

            this.usersServiceMock.Setup(s => s.GetCurrentUser())
            .Returns(firstUser.Object);
            trip.Setup(t => t.Creator)
            .Returns(secondUser.Object);

            //Act / Assert
            Assert.That(() =>
                        service.DeleteTrip(trip.Object),
                        Throws.TypeOf <UnauthorizedAccessException>()
                        .With.Message.Contains(ErrorMessageConstants.NotCreator));
        }
 public IActionResult DeleteTrip(Guid id)
 {
     tripsService.DeleteTrip(id);
     return(Redirect(Url.Action("Index", "SearchTrip")));
 }