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 mockTrip = new Mock <Trip>();
            var mockUser = new Mock <User>();

            mockTrip.Setup(t => t.Participants).Returns(new List <User>());
            this.usersServiceMock.Setup(x => x.GetCurrentUser()).Returns(mockUser.Object);

            //Act
            service.AddParticipantTo(mockTrip.Object);

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

            this.usersServiceMock.Setup(x => x.GetCurrentUser()).Returns((User)null);

            //Act / Assert
            Assert.That(() => service.AddParticipantTo(It.IsAny <Trip>()),
                        Throws.TypeOf <ArgumentNullException>()
                        .With.Message.Contains("User"));
        }
        public void AddCorrectParticipantToTrip()
        {
            //Arrange
            var service = new TripsService(
                this.tripsRepositoryMock.Object,
                this.usersServiceMock.Object,
                this.commentsServiceMock.Object,
                this.unitOfWorkMock.Object,
                this.converterMock.Object,
                this.identifierProviderMock.Object
                );

            var mockTrip = new Mock <Trip>();
            var mockUser = new Mock <User>();

            mockTrip.Setup(t => t.Participants).Returns(new List <User>());
            this.usersServiceMock.Setup(x => x.GetCurrentUser()).Returns(mockUser.Object);

            //Act
            service.AddParticipantTo(mockTrip.Object);

            //Assert
            Assert.IsTrue(mockTrip.Object.Participants.Any(u => u == mockUser.Object));
        }