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)); }
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); }
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); }
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"))); }
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)); }