public void AddTrip_NonExistingEntity_Added() { Mock<ITripRepository> TripRepository = new Mock<ITripRepository>(); Mock<ILoggerService> loggerService = new Mock<ILoggerService>(); TripRepository.Setup(o => o.Insert(It.IsAny<Trip>())); TripService Service = new TripService(TripRepository.Object, loggerService.Object); Trip trip = new Trip() { ID = Guid.NewGuid() }; bool flag = Service.AddTrip(new Trip()); Assert.IsTrue(flag); }
public void Delete_ExistingEntity_ReturnsTrue() { Trip trip = new Trip() { ID = Guid.NewGuid() }; Mock<ITripRepository> TripRepository = new Mock<ITripRepository>(); Mock<ILoggerService> loggerService = new Mock<ILoggerService>(); TripRepository.Setup(o => o.Delete(It.IsAny<Trip>())); TripRepository.SetupSequence(o => o.GetByID(trip.ID)).Returns(trip); TripService Service = new TripService(TripRepository.Object, loggerService.Object); Assert.IsTrue(Service.DeleteTrip(trip)); }
/// <summary> /// Passes a trip to the data access layer to persist /// </summary> /// <param name="trip">Trip to save</param> /// <returns>flag indicating if operation was successful</returns> public bool AddTrip(Trip trip) { if (trip == null) { return false; } try { this._tripRepository.Insert(trip); return true; } catch (Exception e) { this._loggerService.Log(new Log(e.Message, true)); return false; } }
/// <summary> /// Deletes a trip /// </summary> /// <param name="trip">trip to delete</param> /// <returns>flag indicating if trip was successfull</returns> public bool DeleteTrip(Trip trip) { if (trip == null || this._tripRepository.GetByID(trip.ID) == null) { return false; } try { this._tripRepository.Delete(trip); return true; } catch (Exception e) { this._loggerService.Log(new Log(e.Message, true)); return false; } }
/// <summary> /// Passes an existing trip to update /// </summary> /// <param name="trip"></param> /// <returns>Updated trip, when does not exist returns null</returns> public Trip EditTrip(Trip trip) { if (trip == null) { return null; } try { if (this._tripRepository.GetByID(trip.ID) != null) { this._tripRepository.Update(trip, true); return trip; } } catch (Exception e) { this._loggerService.Log(new Log(e.Message, true)); } return null; }
public void GetTrips_Existing_ListReturned() { IList<Trip> trips = new List<Trip>(); for (int i = 0; i < 3; i++) { Trip trip = new Trip(); trip.ID = new Guid(); trip.TripName = i.ToString(); trips.Add(trip); } Mock<ITripRepository> TripRepository = new Mock<ITripRepository>(); Mock<ILoggerService> loggerService = new Mock<ILoggerService>(); TripRepository.Setup(o => o.GetTrips(It.IsAny<Guid>())).Returns(trips); TripService Service = new TripService(TripRepository.Object, loggerService.Object); IList<Trip> list = Service.GetTrips(Guid.NewGuid()); Assert.AreEqual(trips, list); }
public void GetLocations_TripWithNoLocations_EmptyList() { Guid tripID = Guid.NewGuid(); Trip trip = new Trip() { ID = tripID, Posts = new List<Post>(), }; Mock<ITripRepository> TripRepository = new Mock<ITripRepository>(); Mock<ILoggerService> loggerService = new Mock<ILoggerService>(); TripRepository.Setup(o => o.GetByID(It.IsAny<Guid>())).Returns(trip); TripService Service = new TripService(TripRepository.Object, loggerService.Object); IList<Location> Locations = Service.GetLocations(tripID); Assert.IsEmpty(Locations); }
public void GetLocations_TripExistsWithLocations_ReturnsList() { Guid tripID = Guid.NewGuid(); Trip trip = new Trip() { ID = tripID, Posts = new List<Post>(), }; Post Posts1 = new Post() { ID = Guid.NewGuid(), PostLat = "123", PostLong = "145", PostDate = DateTime.Now }; Post Posts2 = new Post() { ID = Guid.NewGuid(), PostLat = "123", PostLong = "145", PostDate = DateTime.Now }; trip.Posts.Add(Posts1); trip.Posts.Add(Posts2); Mock<ITripRepository> TripRepository = new Mock<ITripRepository>(); Mock<ILoggerService> loggerService = new Mock<ILoggerService>(); TripRepository.Setup(o => o.GetByID(It.IsAny<Guid>())).Returns(trip); TripService Service = new TripService(TripRepository.Object, loggerService.Object); IList<Location> Locations = Service.GetLocations(Guid.NewGuid()); CollectionAssert.IsNotEmpty(Locations); }
public void EditTrip_NonExistingEntity_NotEdited() { Trip trip = new Trip() { ID = Guid.NewGuid() }; Mock<ITripRepository> TripRepository = new Mock<ITripRepository>(); Mock<ILoggerService> loggerService = new Mock<ILoggerService>(); TripRepository.Setup(o => o.Update(It.IsAny<Trip>(), true)); TripRepository.SetupSequence(o => o.GetByID(It.IsAny<Guid>())).Returns(null); TripService Service = new TripService(TripRepository.Object, loggerService.Object); Trip Result = Service.EditTrip(trip); Assert.AreEqual(null, Result); }
public void SetUp() { Configuration config = new Configuration(); config.DataBaseIntegration(db => { db.Dialect<MsSql2012Dialect>(); db.Driver<SqlClientDriver>(); db.ConnectionString = "Data Source=DESKTOP-0II3UCP\\MAINSERVER;Initial Catalog=travelme;Integrated Security=True"; }); var mapper = new ModelMapper(); mapper.AddMappings(Assembly.GetExecutingAssembly().GetExportedTypes()); HbmMapping mapping = mapper.CompileMappingForAllExplicitlyAddedEntities(); config.AddMapping(mapping); MockConfig = new Mock<IDatabaseConfig>(); MockConfig.SetupSequence(o => o.GetConfig()).Returns(config); helper = new NhibernateHelper(MockConfig.Object); TestUser = new UserEntity() { ID = Guid.Parse("9fc0b724-d55f-441d-a1ae-ec726d7737f7"), FirstName = "Kiran", LastName = "Patel", DateOfBirth = new DateTime(1994, 08, 05, 10, 0, 0), Email = "*****@*****.**", UserPassword = "******", Registered = DateTime.Now, LastLogin = DateTime.Now, InvalidPasswordDate = DateTime.Now }; TestTrip = new Trip() { ID = Guid.Parse("209F9526-3611-4F30-A79C-55557FFBECF5"), TripName = "Australia", TripDescription = "Aussies", TripLocation = "Backpacking", RelationID = Guid.Parse("9fc0b724-d55f-441d-a1ae-ec726d7737f7") }; TestTrip2 = new Trip() { ID = Guid.Parse("6D8BCE5C-5681-472E-A1DC-97C5EA0C23FA"), TripName = "Thailand", TripDescription = "Thai!", TripLocation = "Backpacking", RelationID = Guid.Parse("9fc0b724-d55f-441d-a1ae-ec726d7737f7") }; TestPost = new Post() { ID = Guid.Parse("832B97D6-F958-497A-952D-0224F27C4E1A"), PostData = "PostName", PostLat = "Lat", PostLong = "Long", PostDate = new DateTime(2012,08,09,10,0,0), RelationID = Guid.Parse("209F9526-3611-4F30-A79C-55557FFBECF5") }; TestTrip.Posts.Add(TestPost); TestUser.Trips.Add(TestTrip); TestUser.Trips.Add(TestTrip2); toDeleteUser = new UserEntity() { ID = Guid.NewGuid(), FirstName = "Deleted", LastName = "Deleted", DateOfBirth = new DateTime(1994, 08, 05, 10, 0, 0), Email = "*****@*****.**", UserPassword = "******", InvalidPasswordDate = DateTime.Now, LastLogin = DateTime.Now, Registered = DateTime.Now }; UserEntityRepository ForDelete = new UserEntityRepository(helper); ForDelete.Insert(toDeleteUser); ForDelete = null; }
public void InsertSubList_ExistingEntity_Successfull() { UserEntity Entity = new UserEntity() { ID = Guid.Parse("B42B1A1E-9DD5-4904-B7CE-9D55FD9A547A"), FirstName = "SecondEntity", LastName = "SecondEntity", DateOfBirth = new DateTime(1994, 08, 05, 10, 0, 0), Email = "SecondEntity", UserPassword = "******", Registered = DateTime.Now, LastLogin = DateTime.Now, InvalidPasswordDate = DateTime.Now }; Trip trip = new Trip() { ID = Guid.Parse("053340CE-EE99-48B2-9687-693879933AFE"), TripName = "Trip", TripDescription = "Desc", TripLocation = "Location", RelationID = this.TestUser.ID }; UserEntityRepository Repository = new UserEntityRepository(helper); Entity.Trips.Add(trip); Repository.Update(Entity, true); IList<Trip> trips = Repository.GetByID(this.TestUser.ID).Trips .Where(o => o.ID == trip.ID) .ToList(); Assert.That(Entity.Trips.Any(o => o.ID == trip.ID)); TripRepository RepositoryTrip = new TripRepository(helper); RepositoryTrip.Delete(trip); }