Ejemplo n.º 1
0
        public void SchaffnerService_HappyPath()
        {
            var timeTable = Substitute.For <ITransportationTimeTableService>();

            StopsController sc = new StopsController(timeTable);

            IActionResult result = sc.GetAllStopPredictions();

            Assert.IsType <OkObjectResult>(result);
        }
Ejemplo n.º 2
0
        public void SchaffnerService_CallErrors_ReturnsErrorResult()
        {
            var timeTable = Substitute.For <ITransportationTimeTableService>();

            timeTable.When(x => x.GetAllStopPredictions(Arg.Any <int>(), Arg.Any <DateTime>()))
            .Do(x => { throw new Exception(); });

            StopsController sc = new StopsController(timeTable);

            IActionResult result = sc.GetAllStopPredictions();

            Assert.IsType <BadRequestObjectResult>(result);
        }
Ejemplo n.º 3
0
        public void GetAllStopsReturnsListOfStops()
        {
            var controller = new StopsController(_context);

            var result = controller.Get() as OkObjectResult;

            Assert.NotNull(result);
            var stops = result.Value as IEnumerable <StopDto>;

            Assert.NotNull(stops);
            Assert.Collection(stops, p => {
                Assert.Equal("Test Stop", p.Name);
                Assert.Equal(50.0f, p.Lat);
                Assert.Equal(20.0f, p.Lon);
            });
        }
Ejemplo n.º 4
0
        public async Task StopNotStartingWithDot()
        {
            string AccessToken = "4cf77fe1-573f-3792-8c87-f1a0c2a4520d";
            var    response    = await StopsController.DoStopsRequestAsync(AccessToken, "asd");

            string ResponseString = await response.Content.ReadAsStringAsync();

            var jsonData = JsonConvert.DeserializeObject <StopsObject>(ResponseString);

            var stops = new List <StopLocation>(jsonData.LocationList.StopLocation);

            stops.RemoveAll(s => s.Name.StartsWith("."));

            foreach (var stop in stops)
            {
                Assert.AreNotEqual(".", stop.Name.Substring(0, 1));
            }
        }
Ejemplo n.º 5
0
        public void SchaffnerService_GetPredictionForStopCallErrors_WithKnownError_ReturnsErrorResult_WithExpectedMessage()
        {
            Fixture f       = new Fixture();
            string  message = f.Create <string>();

            var timeTable = Substitute.For <ITransportationTimeTableService>();

            timeTable.When(x => x.GetStopPredictions(Arg.Any <int>(), Arg.Any <int>(), Arg.Any <DateTime>()))
            .Do(x => { throw new InvalidOperationException(message); });

            StopsController sc = new StopsController(timeTable);

            IActionResult result = sc.Get(f.Create <int>());

            var result2 = result as BadRequestObjectResult;

            Assert.IsType <BadRequestObjectResult>(result);
            Assert.Equal(result2.Value, message);
        }