Beispiel #1
0
        public void AddRoadTrip_RoadTripOverlapingSchedule_ShouldThrowBusinessException()
        {
            //Arrange

            RoadTrip firstRoadTrip = new RoadTrip();

            firstRoadTrip.departureTime = new TimeSpan(4, 10, 0);
            firstRoadTrip.arrivalTime   = new TimeSpan(5, 10, 0);

            RoadTrip secondRoadTrip = new RoadTrip();

            secondRoadTrip.departureTime = new TimeSpan(6, 10, 0);
            secondRoadTrip.arrivalTime   = new TimeSpan(7, 10, 0);

            List <RoadTrip> roadList = new List <RoadTrip>();

            roadList.Add(firstRoadTrip);
            roadList.Add(secondRoadTrip);

            SystemUnderTest.schedule = roadList;


            RoadTrip overlappingRoadTrip = new RoadTrip();

            overlappingRoadTrip.departureTime = new TimeSpan(5, 20, 0);
            overlappingRoadTrip.arrivalTime   = new TimeSpan(8, 20, 0);
            //Act
            AssertionExtensions.ShouldThrow <BusinessException>(() => SystemUnderTest.AddRoadTrip(overlappingRoadTrip));
        }
Beispiel #2
0
        public void AddRoadTrip_WhenAllCondiontsAreFullfield_ShouldNotThrowBusinessException()
        {
            //Arrange

            RoadTrip firstRoadTrip = new RoadTrip();

            firstRoadTrip.departureTime = new TimeSpan(4, 10, 0);
            firstRoadTrip.arrivalTime   = new TimeSpan(5, 10, 0);
            firstRoadTrip.distance      = 40;
            RoadTrip secondRoadTrip = new RoadTrip();

            secondRoadTrip.departureTime = new TimeSpan(6, 10, 0);
            secondRoadTrip.arrivalTime   = new TimeSpan(7, 10, 0);
            secondRoadTrip.distance      = 50;
            List <RoadTrip> roadList = new List <RoadTrip>();

            roadList.Add(firstRoadTrip);
            roadList.Add(secondRoadTrip);

            SystemUnderTest.AddRoadTrip(firstRoadTrip);
            SystemUnderTest.AddRoadTrip(secondRoadTrip);

            RoadTrip thirdRoadTrip = new RoadTrip();

            thirdRoadTrip.departureTime = new TimeSpan(10, 20, 0);
            thirdRoadTrip.arrivalTime   = new TimeSpan(11, 20, 0);
            thirdRoadTrip.distance      = 5;
            //Act
            AssertionExtensions.ShouldNotThrow <BusinessException>(() => SystemUnderTest.AddRoadTrip(thirdRoadTrip));
        }
Beispiel #3
0
        public void RoadTripOverlapsAnotherRoadTrip_RoadTripOverlapsSchedule_ShouldReturnTrue()
        {
            //Arrange

            RoadTrip firstRoadTrip = new RoadTrip();

            firstRoadTrip.departureTime = new TimeSpan(4, 10, 0);
            firstRoadTrip.arrivalTime   = new TimeSpan(5, 10, 0);

            RoadTrip secondRoadTrip = new RoadTrip();

            secondRoadTrip.departureTime = new TimeSpan(6, 10, 0);
            secondRoadTrip.arrivalTime   = new TimeSpan(7, 10, 0);

            List <RoadTrip> roadList = new List <RoadTrip>();

            roadList.Add(firstRoadTrip);
            roadList.Add(secondRoadTrip);

            SystemUnderTest.schedule = roadList;


            RoadTrip overlappingRoadTrip = new RoadTrip();

            overlappingRoadTrip.departureTime = new TimeSpan(6, 20, 0);
            overlappingRoadTrip.arrivalTime   = new TimeSpan(8, 20, 0);
            //Act
            var result = SystemUnderTest.RoadTripOverlapsAnotherRoadTrip(overlappingRoadTrip);

            //Assert
            result.Should().BeTrue();
        }
Beispiel #4
0
        public void Test_Equal_ReturnsTrueIfDescriptionsAreTheSame()
        {
            RoadTrip firstRoadTrip  = new RoadTrip("awesome adventure", "awesome adventure to somewhere");
            RoadTrip secondRoadTrip = new RoadTrip("awesome adventure", "awesome adventure to somewhere");

            Assert.Equal(firstRoadTrip, secondRoadTrip);
        }
Beispiel #5
0
        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);
        }
Beispiel #6
0
        public async Task <RoadTrip> UpdateRoadTrip([FromBody] RoadTrip roadTrip)
        {
            var entityContext = roadTripDbContext.Update(roadTrip);
            await roadTripDbContext.SaveChangesAsync();

            return(entityContext.Entity);
        }
Beispiel #7
0
        public void AddRoadTrip_WhenBusMilageExceds_ShouldThrowBusinessException()
        {
            //Arrange

            RoadTrip firstRoadTrip = new RoadTrip();

            firstRoadTrip.departureTime = new TimeSpan(4, 10, 0);
            firstRoadTrip.arrivalTime   = new TimeSpan(5, 10, 0);
            firstRoadTrip.distance      = 40;
            RoadTrip secondRoadTrip = new RoadTrip();

            secondRoadTrip.departureTime = new TimeSpan(6, 10, 0);
            secondRoadTrip.arrivalTime   = new TimeSpan(7, 10, 0);
            secondRoadTrip.distance      = 50;
            List <RoadTrip> roadList = new List <RoadTrip>();

            roadList.Add(firstRoadTrip);
            roadList.Add(secondRoadTrip);

            SystemUnderTest.AddRoadTrip(firstRoadTrip);
            SystemUnderTest.AddRoadTrip(secondRoadTrip);

            RoadTrip excedingDistanceRoadTrip = new RoadTrip();

            excedingDistanceRoadTrip.departureTime = new TimeSpan(10, 20, 0);
            excedingDistanceRoadTrip.arrivalTime   = new TimeSpan(11, 20, 0);
            excedingDistanceRoadTrip.distance      = 20;
            //Act
            AssertionExtensions.ShouldThrow <BusinessException>(() => SystemUnderTest.AddRoadTrip(excedingDistanceRoadTrip));
        }
        public ActionResult DeleteConfirmed(Guid id)
        {
            RoadTrip roadTrip = db.RoadTrips.Find(id);

            db.RoadTrips.Remove(roadTrip);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #9
0
        public void Test_UpdateRoadTripName()
        {
            RoadTrip newTrip = new RoadTrip("awesome adventure", "awesome adventure to somewhere");

            newTrip.Save();
            newTrip.SetName("Extreme");
            newTrip.Update();

            Assert.Equal(newTrip.GetName(), "Extreme");
        }
 public ActionResult Edit([Bind(Include = "Id,Name,Description,StartDate,EndDate,CreatedDate,ModifiedDate,UserName")] RoadTrip roadTrip)
 {
     if (ModelState.IsValid)
     {
         db.Entry(roadTrip).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(roadTrip));
 }
Beispiel #11
0
        public void AddRoadTrip_WhenBusIsFullyScheduled_ShouldThrowBusinessException()
        {
            //Arrange

            SystemUnderTest.isFullyScheduled = true;

            RoadTrip roadTrip = new RoadTrip();

            roadTrip.departureTime = new TimeSpan(10, 20, 0);
            roadTrip.departureTime = new TimeSpan(11, 20, 0);
            //Act
            AssertionExtensions.ShouldThrow <BusinessException>(() => SystemUnderTest.AddRoadTrip(roadTrip));
        }
        public ActionResult Create([Bind(Include = "Id,Name,Description,StartDate,EndDate,CreatedDate,ModifiedDate,UserName")] RoadTrip roadTrip)
        {
            if (ModelState.IsValid)
            {
                roadTrip.Id       = Guid.NewGuid();
                roadTrip.UserName = User.Identity.Name;
                db.RoadTrips.Add(roadTrip);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(roadTrip));
        }
Beispiel #13
0
        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);
        }
Beispiel #14
0
        public void Test_SaveRoadTripToDatabase()
        {
            RoadTrip newTrip = new RoadTrip("awesome adventure", "awesome adventure to somewhere");

            newTrip.Save();

            List <RoadTrip> allTrips = RoadTrip.GetAll();

            List <RoadTrip> testTrips = new List <RoadTrip> {
                newTrip
            };

            Assert.Equal(testTrips, allTrips);
        }
        // GET: RoadTrips/Delete/5
        public ActionResult Delete(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            RoadTrip roadTrip = db.RoadTrips.Find(id);

            if (roadTrip == null)
            {
                return(HttpNotFound());
            }
            return(View(roadTrip));
        }
Beispiel #16
0
        static void Main(string[] args)
        {
            Console.WriteLine("I bought a new Camaro!");
            var myCamaro = new Camaro();  // Instantiate an object from the Camaro class (which is a child of "Car")

            Console.WriteLine("It goes {0}", myCamaro.GoVroom());
            Console.WriteLine("It is the color {0}", myCamaro.color);

            var brothersIrocz = new IROCZ();  // instantiate an object from the IROCZ class (which is a child of Camaro)

            Console.WriteLine("When I was at the dealership, they tried to sell my brother an IROCZ with low miles.");
            Console.WriteLine("It went {0}", brothersIrocz.GoVroom());
            Console.WriteLine("And it was the color {0}", brothersIrocz.color);
            Console.WriteLine("My brother bought it, and he wanted to change the color.");

            var newPaintColor = "yellow";

            Console.WriteLine("So we painted it");
            brothersIrocz.PaintCar(newPaintColor);
            Console.WriteLine("And now it is {0}", brothersIrocz.color);

            Console.WriteLine("I told him it needed to be even faster, so we installed a turbo.");
            brothersIrocz.InstallTurboCharger();
            Console.WriteLine("And now it goes {0}", brothersIrocz.GoVroom());

            Console.WriteLine("But mine is still the color {0}", myCamaro.color);
            Console.WriteLine("And only goes {0}", myCamaro.GoVroom());

            Console.WriteLine("We decided to take my car on a road trip (it got better gas mileage).");
            var ourRoadtrip = new RoadTrip(myCamaro); // create a new RoadTrip and pass in ANY car.  Liskov subsitution example.  A Camaro is a Car.

            ourRoadtrip.AddDestination("Las Vegas");
            ourRoadtrip.AddDestination("Seattle");
            ourRoadtrip.AddDestination("Juno");

            Console.WriteLine("We marked off the cities on the map, bought some snacks, and drove off!");
            ourRoadtrip.Travel();

            Console.WriteLine("When we got home, we took my brother's IROCZ to the dragstrip to do burnouts in the parkinglot!");
            var dragstripTrip = new TripToDragStrip(brothersIrocz);

            Console.WriteLine("We decided to do 7 burnouts.  This is what happened:");
            for (var i = 0; i < 7; i++)
            {
                dragstripTrip.RockAndRoll();
            }
        }
Beispiel #17
0
        public void Test_DeleteRoadTrip()
        {
            RoadTrip firstTrip = new RoadTrip("awesome adventure", "awesome adventure to somewhere");

            firstTrip.Save();
            RoadTrip secondTrip = new RoadTrip("extreme adventure", "extreme adventure to somewhere");

            secondTrip.Save();

            secondTrip.Delete();
            List <RoadTrip> allTrips  = RoadTrip.GetAll();
            List <RoadTrip> testTrips = new List <RoadTrip> {
                firstTrip
            };

            Assert.Equal(testTrips, allTrips);
        }
Beispiel #18
0
        public void Test_DatabaseEmptyAtFirst()
        {
            int result = RoadTrip.GetAll().Count;

            Assert.Equal(0, result);
        }
 public void Dispose()
 {
     Destination.DeleteAll();
     RoadTrip.DeleteAll();
     Scrubber.DeleteAll();
 }
Beispiel #20
0
 public void Dispose()
 {
     RoadTrip.DeleteAll();
     Destination.DeleteAll();
 }
Beispiel #21
0
        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]);
            };
        }