Esempio n. 1
0
        public void PostTripAddInvalidTraveler_Fails()
        {
            using (IDbContext idtoFakeContext = new IDTOFakeContext())
                using (IUnitOfWork unitOfWork = new UnitOfWork(idtoFakeContext))
                {
                    unitOfWork.Repository <Traveler>().Insert(new Traveler {
                        Id = 1, FirstName = "TestFN", LastName = "TestLN", ObjectState = ObjectState.Added
                    });
                    unitOfWork.Save();
                    var controller = new TripController(idtoFakeContext);
                    SetupControllerForTests(controller);

                    TripModel m = new TripModel
                    {
                        TravelerId    = 50,
                        Origination   = "Neverland",
                        Destination   = "Montana",
                        TripStartDate = DateTime.Parse("10/2/2012"),
                        TripEndDate   = DateTime.Parse("10/2/2013"),
                        MobilityFlag  = true,
                        BicycleFlag   = true,
                        PriorityCode  = "1"
                    };
                    List <StepModel> steps     = new List <StepModel>();
                    StepModel        stepmodel = new StepModel();
                    stepmodel.StartDate      = DateTime.Parse("1/1/2014 10:02");
                    stepmodel.EndDate        = DateTime.Parse("1/1/2014 10:40");
                    stepmodel.FromName       = "Quartz Street";
                    stepmodel.FromProviderId = (int)Providers.COTA;
                    stepmodel.FromStopCode   = "1001";
                    stepmodel.ModeId         = (int)Modes.Bus;
                    stepmodel.RouteNumber    = "039";
                    stepmodel.Distance       = (decimal)12.2;
                    stepmodel.ToName         = "Slate Run Road";
                    stepmodel.ToProviderId   = (int)Providers.COTA;
                    stepmodel.ToStopCode     = "2002";
                    steps.Add(stepmodel);
                    m.Steps = steps;
                    try
                    {
                        var actionResult = controller.PostTrip(m);
                        Assert.AreEqual(true, false, "Test should have thrown an exception and not executed this line.");
                    }
                    catch (HttpResponseException ex)
                    {
                        Assert.AreEqual(HttpStatusCode.NotFound, ex.Response.StatusCode);
                    }

                    //               var response = actionResult as OkNegotiatedContentResult<IEnumerable<Trip>>;
                    //     Assert.IsNotNull(response);
                    //    var books = response.Content;
                    //Assert.AreEqual(5, books.Count());


                    //      var response = actionResult as NotFoundResult;
                    //             Assert.IsNotNull(response);
                }
        }
Esempio n. 2
0
        public void PostTripAdd_Passes()
        {
            using (IDbContext idtoFakeContext = new IDTOFakeContext())
                using (IUnitOfWork unitOfWork = new UnitOfWork(idtoFakeContext))
                {
                    unitOfWork.Repository <Traveler>().Insert(new Traveler {
                        Id = 1, FirstName = "TestFN", LastName = "TestLN", ObjectState = ObjectState.Added
                    });
                    unitOfWork.Save();
                    var controller = new TripController(idtoFakeContext);
                    SetupControllerForTests(controller);

                    TripModel m = new TripModel
                    {
                        TravelerId    = 1,
                        Origination   = "Neverland",
                        Destination   = "Montana",
                        TripStartDate = DateTime.Parse("1/2/2014"),
                        TripEndDate   = DateTime.Parse("1/3/2014"),
                        MobilityFlag  = true,
                        BicycleFlag   = true,
                        PriorityCode  = "1"
                    };
                    List <StepModel> steps     = new List <StepModel>();
                    StepModel        stepmodel = new StepModel();
                    stepmodel.StartDate      = DateTime.Parse("1/1/2014 10:02");
                    stepmodel.EndDate        = DateTime.Parse("1/1/2014 10:40");
                    stepmodel.FromName       = "Quartz Street";
                    stepmodel.FromProviderId = (int)Providers.COTA;
                    stepmodel.FromStopCode   = "1001";
                    stepmodel.ModeId         = (int)Modes.Bus;
                    stepmodel.RouteNumber    = "039";
                    stepmodel.Distance       = (decimal)12.2;
                    stepmodel.ToName         = "Slate Run Road";
                    stepmodel.ToProviderId   = (int)Providers.COTA;
                    stepmodel.ToStopCode     = "2002";
                    steps.Add(stepmodel);
                    m.Steps = steps;
                    try
                    {
                        var actionResult = controller.PostTrip(m);
                        var response     = actionResult as CreatedAtRouteNegotiatedContentResult <TripModel>;
                        Assert.IsNotNull(response);
                        var trips = response.Content;
                        Assert.AreEqual("Neverland", trips.Origination);
                    }
                    catch (HttpResponseException ex)
                    {
                        Assert.Fail();
                    }
                }
        }
Esempio n. 3
0
        public void PostTripLoadLikeGSON_Passes()
        {
            using (IDbContext idtoFakeContext = new IDTOFakeContext())
                using (IUnitOfWork unitOfWork = new UnitOfWork(idtoFakeContext))
                {
                    unitOfWork.Repository <Traveler>().Insert(new Traveler {
                        Id = 1003, FirstName = "TestFN", LastName = "TestLN", ObjectState = ObjectState.Added
                    });
                    unitOfWork.Save();
                    var controller = new TripController(idtoFakeContext);
                    SetupControllerForTests(controller);

                    //TripModel m = new TripModel
                    //{
                    //    TravelerId = 1,
                    //    Origination = "Neverland",
                    //    Destination = "Montana",
                    //    TripStartDate = DateTime.Parse("1/2/2014"),
                    //    TripEndDate = DateTime.Parse("1/3/2014"),
                    //    MobilityFlag = true,
                    //    BicycleFlag = true,
                    //    PriorityCode = "1"
                    //};

                    //StepModel


                    // convert string to stream
                    byte[] byteArray = Encoding.UTF8.GetBytes(GSONcontents);
                    //byte[] byteArray = Encoding.ASCII.GetBytes(contents);
                    MemoryStream jsonStream = new MemoryStream(byteArray);

                    DataContractJsonSerializer serializer =
                        new DataContractJsonSerializer(typeof(TripModel));

                    // TripModel trip = (TripModel)serializer.ReadObject(jsonStream);
                    TripModel trip = Deserialize <TripModel>(GSONcontents);
                    try
                    {
                        var actionResult = controller.PostTrip(trip);
                        var response     = actionResult as CreatedAtRouteNegotiatedContentResult <TripModel>;
                        Assert.IsNotNull(response);
                        var trips = response.Content;
                        Assert.AreEqual("DCSC", trips.Origination);
                    }
                    catch (HttpResponseException ex)
                    {
                        Assert.Fail();
                    }
                }
        }