public void AddTrip_ShouldThrowValidationError() { // Arrange Exception caugthException = null; var trip = new Trip { User = _currentUser, Date = new DateTime(2014, 08, 01), AddressOrigin = null, AddressDestination = null, Car = null }; var tripService = new TripService(_fakeApplicationDbContext, _mockCurrentUserService.Object, _mockIDistanceCalculatorService.Object); // Act try { trip = tripService.AddTrip(trip); } catch (DbEntityValidationException ex) { caugthException = ex; } // Assert Assert.IsNull(trip); Assert.IsNotNull(caugthException); }
public void AddTrip_CanAdd() { // Arrange var addressOrigin = new Address { Id = 1, User = _currentUser}; var addressDestination = new Address { Id = 2, User = _currentUser }; var car = new Car { Id = 1, User = _currentUser }; _fakeApplicationDbContext.Addresses.Add(addressOrigin); _fakeApplicationDbContext.Addresses.Add(addressDestination); _fakeApplicationDbContext.Cars.Add(car); var trip = new Trip { User = _currentUser, Date = new DateTime(2014, 08, 01), AddressOrigin = addressOrigin, AddressDestination = addressDestination, Car = car }; var tripService = new TripService(_fakeApplicationDbContext, _mockCurrentUserService.Object, _mockIDistanceCalculatorService.Object); // Act trip = tripService.AddTrip(trip); // Assert Assert.IsNotNull(trip); Assert.IsNotNull(trip.AddressOrigin); Assert.IsNotNull(trip.AddressDestination); Assert.IsNotNull(trip.Car); Assert.AreEqual(addressOrigin.Id, trip.AddressOrigin.Id); Assert.AreEqual(addressDestination.Id, trip.AddressDestination.Id); Assert.AreEqual(car.Id, trip.Car.Id); Assert.AreEqual(trip.DistanceInKm, 42); }