public void Test_GetDestinationsOfRoadTrip() { RoadTrip newTrip = new RoadTrip("awesome adventure", "awesome adventure to somewhere"); newTrip.Save(); Console.WriteLine(newTrip.GetName() + " " + newTrip.GetId()); Destination firstDestination = new Destination("multnomah falls", newTrip.GetId()); firstDestination.Save(); Console.WriteLine(firstDestination.GetName() + " " + firstDestination.GetId()); Destination secondDestination = new Destination("mt tabor", newTrip.GetId()); secondDestination.Save(); Console.WriteLine(secondDestination.GetName() + " " + secondDestination.GetId() + " " + secondDestination.GetRoadTripId()); List <Destination> testDestinations = new List <Destination> { firstDestination, secondDestination }; List <Destination> tripDestinations = newTrip.GetDestinations(); Console.WriteLine(tripDestinations); Assert.Equal(testDestinations, tripDestinations); }
public void Test_Find_FindsRoadTripInDataBase() { //Arrange RoadTrip testRoadTrip = new RoadTrip("awsome adventure", "awesome adventure to somewhere"); testRoadTrip.Save(); //Act RoadTrip foundRoadTrip = RoadTrip.Find(testRoadTrip.GetId()); //Assert Assert.Equal(testRoadTrip, foundRoadTrip); }
public HomeModule() { Get["/"] = _ => { Console.WriteLine("Return View"); return(View["index.cshtml"]); }; Get["/roadTrip/{id}"] = x => { Console.WriteLine("View Road Trip"); return(View["viewRoadTrip.cshtml", RoadTrip.Find(int.Parse(x.id))]); }; Get["/getStop/{id}"] = x => { Console.WriteLine("View Stop"); return(View["destination.cshtml", Destination.Find(int.Parse(x.id))]); }; Get["/getAllRoadTrips"] = _ => { return(View["viewAllRoadTrips.cshtml", RoadTrip.GetAll()]); }; Get["/deleteDestination/{id}"] = parameters => { Console.WriteLine("Deleteing: " + parameters.id); Destination selectedDestination = Destination.Find(parameters.id); selectedDestination.Delete(); return(View["empty.cshtml"]); }; Get["/moveUp/{id}"] = parameters => { Console.WriteLine("Move Up: " + parameters.id); Destination selectedDestination = Destination.Find(parameters.id); selectedDestination.MoveUp(); return(View["empty.cshtml"]); }; Get["/moveDown/{id}"] = parameters => { Console.WriteLine("Move Down: " + parameters.id); Destination selectedDestination = Destination.Find(parameters.id); Console.WriteLine("Destination Found, RoadTripId: " + selectedDestination.GetRoadTripId()); selectedDestination.MoveDown(); return(View["empty.cshtml"]); }; Post["/nameTrip"] = _ => { RoadTrip newTrip = RoadTrip.Find(int.Parse(Request.Form["id"])); newTrip.SetName(Request.Form["name"]); newTrip.Update(); return(View["empty.cshtml"]); }; // AJAX ROUTE ONLY RETURNS A PARTIAL HTML VIEW Post["/addStop"] = _ => { Dictionary <string, object> model = new Dictionary <string, object>() { }; // instantiate model int roadTripId = 0; try { roadTripId = int.Parse(Request.Form["roadTripId"]); // get roadtrip id } catch (Exception e) {} string destinationName = Request.Form["command"]; // get new destination name RoadTrip rtrip; if (roadTripId == 0) // there is no road trip yet { rtrip = new RoadTrip("The awesome " + destinationName + " Road Trip!", ""); // so make a road trip rtrip.Save(); // save road trip to db roadTripId = rtrip.GetId(); } else { rtrip = RoadTrip.Find(roadTripId); } Destination newStop = new Destination(destinationName, roadTripId); // make a new destination newStop.Save(); // save the new stop to the database if (newStop.GetStop() == 1) // if theres only one stop in the road trip so far { Console.WriteLine("First Stop"); model.Add("map", Scrubber.GetMapOnLocation(newStop.GetName())); // show the map with only one location } else // there are already multiple stops in the trip { Console.WriteLine("Not First Stop"); model.Add("map", Scrubber.GetMapDirections(rtrip.GetDestinations()[rtrip.GetDestinations().Count - 2].GetName(), newStop.GetName())); // show direciton map } model.Add("images", Scrubber.Search(newStop.GetName(), 6)); model.Add("roadTripId", roadTripId); model.Add("destination", newStop); Console.WriteLine(model); Console.WriteLine("Return View"); return(View["stop.cshtml", model]); }; }