public void ReturnUpdatedTripInfo() { // Arrange var mockedTripRepo = new Mock<IProjectableRepositoryEf<Trip>>(); var mockedUserTripRepo = new Mock<IProjectableRepositoryEf<UsersTrips>>(); var mockedTripService = new Mock<ITripService>(); var mockedUnitOfWork = new Mock<IUnitOfWorkEF>(); var service = new UserDashboardService( () => mockedUnitOfWork.Object, mockedUserTripRepo.Object, mockedTripService.Object, mockedTripRepo.Object); var userId = "userid"; var tripId = 1; mockedTripService.Setup(x => x.SignOutOfTrip(tripId, userId)); var expected = new TripInfoWithUserRequests(); mockedTripRepo.Setup(x => x.GetFirstMapped<TripInfoWithUserRequests>(It.IsAny<Expression<Func<Trip, bool>>>())) .Returns(expected); // Act var result = service.RejectUserToJoinTrip(userId, tripId); // Assert mockedTripService.Verify(x => x.SignOutOfTrip(tripId, userId), Times.Once); Assert.AreSame(expected, result); }
public void Render_TripSharedByUserInfoPartial_WithCorrectDataFromTheService() { // Arrange var mockedTripService = new Mock <ITripService>(); var mockedUserDashboardService = new Mock <IUserDashboardService>(); var controller = new DashboardController(mockedTripService.Object, mockedUserDashboardService.Object); var userId = "userId"; var tripId = 1; var data = new TripInfoWithUserRequests(); mockedUserDashboardService.Setup(x => x.JoinUserToTrip(userId, tripId)) .Returns(data); // Act and Assert controller.WithCallTo(x => x.AcceptUserInTrip(userId, tripId)) .ShouldRenderPartialView("_TripSharedByUserInfo") .WithModel(data); }
public void ReturnTheTrip_WhenJoiningToItWasSuccessfull() { // Arrange var mockedTripRepo = new Mock <IProjectableRepositoryEf <Trip> >(); var mockedUserTripRepo = new Mock <IProjectableRepositoryEf <UsersTrips> >(); var mockedTripService = new Mock <ITripService>(); var mockedUnitOfWork = new Mock <IUnitOfWorkEF>(); var service = new UserDashboardService( () => mockedUnitOfWork.Object, mockedUserTripRepo.Object, mockedTripService.Object, mockedTripRepo.Object); var userId = "userId"; int tripId = 1; var trip = new Trip() { Id = tripId, TotalSeats = 4, TakenSeats = 3 }; mockedTripService.Setup(x => x.IsUserOwnerOfTrip(userId, tripId)) .Returns(false); mockedTripRepo.Setup(x => x.GetFirst(It.IsAny <Expression <Func <Trip, bool> > >())) .Returns(trip); var expected = new TripInfoWithUserRequests(); mockedTripRepo.Setup(x => x.GetFirstMapped <TripInfoWithUserRequests>(It.IsAny <Expression <Func <Trip, bool> > >())) .Returns(expected); // Act var result = service.JoinUserToTrip(userId, tripId); //Assert Assert.AreSame(expected, result); }