public void Create_ShouldCall_GetAddressCoordinates() { var testRoute = new PersonalRoute { Person = _testPerson, PersonId = _testPerson.Id, Points = new List <Point> { new Point { StreetName = "Katrinebjergvej", StreetNumber = "93B", ZipCode = 8200, Town = "Aarhus N" }, new Point { StreetName = "Jens Baggesens Vej", StreetNumber = "44", ZipCode = 8210, Town = "Aarhus V" } } }; _uut.Create(testRoute); _coordinatesMock.ReceivedWithAnyArgs().GetAddressCoordinates(new Address()); }
public void Create_ShouldSet_CorrectPreviousAndNextId() { var testRoute = new PersonalRoute { Person = _testPerson, PersonId = _testPerson.Id, Points = new List <Point> { new Point { StreetName = "Katrinebjergvej", StreetNumber = "93B", ZipCode = 8200, Town = "Aarhus N" }, new Point { StreetName = "Jens Baggesens Vej", StreetNumber = "44", ZipCode = 8210, Town = "Aarhus V" }, new Point { StreetName = "Jens Baggesens Vej", StreetNumber = "46", ZipCode = 8210, Town = "Aarhus V" } } }; var res = _uut.Create(testRoute); Assert.AreEqual(res.Points.ElementAt(1).Id, res.Points.ElementAt(0).NextPointId); Assert.AreEqual(res.Points.ElementAt(0).Id, res.Points.ElementAt(1).PreviousPointId); Assert.AreEqual(res.Points.ElementAt(1).Id, res.Points.ElementAt(2).PreviousPointId); Assert.AreEqual(res.Points.ElementAt(2).Id, res.Points.ElementAt(1).NextPointId); Assert.AreEqual(0, res.Points.ElementAt(0).PreviousPointId); Assert.AreEqual(0, res.Points.ElementAt(2).NextPointId); }
/// <summary> /// Creates and inserts a Personal Route into the database. /// </summary> /// <param name="route">The Route to be inserted.</param> /// <returns>The created Personal Route.</returns> public PersonalRoute Create(PersonalRoute route) { var pointsWithCoordinates = route.Points.Select((t, i) => route.Points.ElementAt(i)) .Select(currentPoint => (Point)_coordinates.GetAddressCoordinates(currentPoint)) .ToList(); route.Points = pointsWithCoordinates; var createdRoute = _routeRepo.Insert(route); _routeRepo.Save(); for (var i = 0; i < createdRoute.Points.Count; i++) { var currentPoint = createdRoute.Points.ElementAt(i); if (i == route.Points.Count - 1) { // last element currentPoint.PreviousPointId = createdRoute.Points.ElementAt(i - 1).Id; } else if (i == 0) { // first element currentPoint.NextPointId = createdRoute.Points.ElementAt(i + 1).Id; } else { // between first and last currentPoint.NextPointId = createdRoute.Points.ElementAt(i + 1).Id; currentPoint.PreviousPointId = createdRoute.Points.ElementAt(i - 1).Id; } } _routeRepo.Save(); return(createdRoute); }