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

            var validTime = new DateTime(2018, 10, 10, 10, 10, 10);

            this.userMock.Setup(u => u.AdministeredEvents).Returns(new List <Trip>());

            converterMock.Setup(c => c.Convert(It.IsAny <DateTime>(), It.IsAny <DateTime>()))
            .Returns(validTime);

            usersServiceMock.Setup(x => x.GetCurrentUser())
            .Returns(this.userMock.Object);

            //Act
            service.AddTrip(this.trip, It.IsAny <DateTime>(), It.IsAny <DateTime>());

            //Assert
            Assert.IsTrue(this.trip.Creator.AdministeredEvents.Any(x => x == trip));
        }
Esempio n. 2
0
        public void SetsCorrectStartingTime()
        {
            //Arrange
            var service = new TripsService(
                this.tripsRepositoryMock.Object,
                this.usersServiceMock.Object,
                this.commentsServiceMock.Object,
                this.unitOfWorkMock.Object,
                this.converterMock.Object,
                this.identifierProviderMock.Object);

            var validTime = new DateTime(2018, 10, 10, 10, 10, 10);

            converterMock.Setup(c => c.Convert(It.IsAny <DateTime>(), It.IsAny <DateTime>()))
            .Returns(validTime);

            usersServiceMock.Setup(x => x.GetCurrentUser())
            .Returns(this.userMock.Object);

            //Act
            service.AddTrip(this.trip, It.IsAny <DateTime>(), It.IsAny <DateTime>());

            //Assert
            Assert.AreEqual(validTime, this.trip.StartingTime);
        }
Esempio n. 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 validTime = new DateTime(2018, 10, 10, 10, 10, 10);

            converterMock.Setup(c => c.Convert(It.IsAny <DateTime>(), It.IsAny <DateTime>()))
            .Returns(validTime);

            usersServiceMock.Setup(x => x.GetCurrentUser())
            .Returns(this.userMock.Object);

            //Act
            service.AddTrip(this.trip, It.IsAny <DateTime>(), It.IsAny <DateTime>());

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

            var validTime = new DateTime(2018, 10, 10, 10, 10, 10);

            converterMock.Setup(c => c.Convert(It.IsAny <DateTime>(), It.IsAny <DateTime>()))
            .Returns(validTime);

            usersServiceMock.Setup(x => x.GetCurrentUser())
            .Returns(this.userMock.Object);

            //Act
            service.AddTrip(this.trip, It.IsAny <DateTime>(), It.IsAny <DateTime>());

            //Assert
            Assert.IsTrue(this.trip.Participants.Any(x => x == this.userMock.Object));
        }
        public IActionResult AddTrip([FromForm] AddTripViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            tripsService.AddTrip(model.Destination, model.Arrival, model.ArrivalTime, model.DestinationTime);

            return(Redirect(Url.Action("Index", "SearchTrip")));
        }
Esempio n. 6
0
        public void ThrowIfPassedDateIsEarlierThanNow()
        {
            //Arrange
            var service = new TripsService(
                this.tripsRepositoryMock.Object,
                this.usersServiceMock.Object,
                this.commentsServiceMock.Object,
                this.unitOfWorkMock.Object,
                this.converterMock.Object,
                this.identifierProviderMock.Object);

            var timeInThePast = new DateTime(2010, 10, 10, 10, 10, 10);

            this.userMock.Setup(u => u.AdministeredEvents).Returns(new List <Trip>());

            converterMock.Setup(c => c.Convert(It.IsAny <DateTime>(), It.IsAny <DateTime>()))
            .Returns(timeInThePast);

            //Act / Assert
            Assert.That(() =>
                        service.AddTrip(this.trip, It.IsAny <DateTime>(), It.IsAny <DateTime>()),
                        Throws.TypeOf <ArgumentException>()
                        .With.Message.Contains(ErrorMessageConstants.TripHasPassed));
        }