Esempio n. 1
0
        public void TestGetRouteDirectionsAsyncWithCanceledCancellationToken()
        {
            // Arrange
            var client = new BusTrackerClient(UrlBase, WebAppConfig.ApiKey);

            var expectedModel = this.repository.GetAs <GetRouteDirectionsResponse>(ResourceFiles.GetRouteDirectionsResponse);

            var cts = new CancellationTokenSource();

            cts.Cancel();

            OperationCanceledException exception = null;

            // Act
            StartOwinTest(
                async() =>
            {
                try
                {
                    var directions = await client.GetRouteDirectionsAsync(Guid.NewGuid().ToString(), cts.Token);
                }
                catch (OperationCanceledException ex)
                {
                    exception = ex;
                }
            });

            // Assert
            Assert.IsNotNull(exception);
        }
Esempio n. 2
0
        public void TestGetRouteDirectionsAsyncInvalidApiToken()
        {
            // Arrange
            const string InvalidApiToken = "INVALID_API_TOKEN";
            var          client          = new BusTrackerClient(UrlBase, InvalidApiToken);

            var expectedModel = this.repository.GetAs <GetRouteDirectionsResponse>(ResourceFiles.GetRouteDirectionsResponseInvalidApiAccess);

            Exception exception = null;

            // Act
            StartOwinTest(
                async() =>
            {
                try
                {
                    var directions = await client.GetRouteDirectionsAsync(Guid.NewGuid().ToString());
                    Assert.Fail("Exception thrown exception");
                }
                catch (Exception ex)
                {
                    exception = ex;
                }
            });

            // Assert
            Assert.IsNotNull(exception);
            Assert.AreEqual(expectedModel.Errors.Select(e => e.Message).First(), exception.Message);
        }
Esempio n. 3
0
        public void TestGetRouteDirectionsAsyncInvalidApiTokenWithCancelledCancellationToken()
        {
            // Arrange
            const string InvalidApiToken = "INVALID_API_TOKEN";
            var          client          = new BusTrackerClient(UrlBase, InvalidApiToken);

            var expectedModel = this.repository.GetAs <GetRouteDirectionsResponse>(ResourceFiles.GetRouteDirectionsResponseInvalidApiAccess);

            Exception exception = null;

            var cts = new CancellationTokenSource();

            cts.Cancel();

            // Act
            StartOwinTest(
                async() =>
            {
                try
                {
                    var directions = await client.GetRouteDirectionsAsync(Guid.NewGuid().ToString(), cts.Token);
                    Assert.Fail("Exception thrown exception");
                }
                catch (OperationCanceledException ex)
                {
                    exception = ex;
                }
            });

            // Assert
            Assert.IsNotNull(exception);
        }
        public void TestGetVehiclesInvalidApiToken()
        {
            // Arrange
            const string InvalidApiToken = "INVALID_API_TOKEN";
            var client = new BusTrackerClient(UrlBase, InvalidApiToken);

            var expectedModel = this.repository.GetAs<GetVehiclesResponse>(ResourceFiles.GetVehiclesResponseInvalidApiAccess);

            Exception exception = null;

            // Act
            StartOwinTest(
                () =>
                {
                    try
                    {
                        var vehicles = client.GetVehicles(Enumerable.Empty<string>(), Enumerable.Empty<string>());
                        Assert.Fail("Exception thrown exception");
                    }
                    catch (Exception ex)
                    {
                        exception = ex;
                    }

                    return Task.FromResult(true);
                });

            // Assert
            Assert.IsNotNull(exception);
            Assert.AreEqual(expectedModel.Errors.Select(e => e.Message).First(), exception.Message);
        }
        public void TestGetVehiclesAsyncInvalidApiToken()
        {
            // Arrange
            const string InvalidApiToken = "INVALID_API_TOKEN";
            var client = new BusTrackerClient(UrlBase, InvalidApiToken);

            var expectedModel = this.repository.GetAs<GetVehiclesResponse>(ResourceFiles.GetVehiclesResponseInvalidApiAccess);

            Exception exception = null;

            // Act
            StartOwinTest(
                async () =>
                {
                    try
                    {
                        var vehicles = await client.GetVehiclesAsync(null, null);
                        Assert.Fail("Exception thrown exception");
                    }
                    catch (Exception ex)
                    {
                        exception = ex;
                    }
                });

            // Assert
            Assert.IsNotNull(exception);
            Assert.AreEqual(expectedModel.Errors.Select(e => e.Message).First(), exception.Message);
        }
Esempio n. 6
0
        public void TestGetPredictionsAsyncInvalidApiTokenWithCancellationToken()
        {
            // Arrange
            const string InvalidApiToken = "INVALID_API_TOKEN";
            var          client          = new BusTrackerClient(UrlBase, InvalidApiToken);

            var expectedModel = this.repository.GetAs <GetPredictionsResponse>(ResourceFiles.GetPredictionsResponseInvalidApiAccess);

            Exception exception = null;

            var cts = new CancellationTokenSource();

            // Act
            StartOwinTest(
                async() =>
            {
                try
                {
                    var predictions = await client.GetPredictionsAsync(Enumerable.Empty <int>(), Enumerable.Empty <string>(), Enumerable.Empty <string>(), null, cts.Token);
                    Assert.Fail("Exception thrown exception");
                }
                catch (Exception ex)
                {
                    exception = ex;
                }
            });

            // Assert
            Assert.IsNotNull(exception);
            Assert.AreEqual(expectedModel.Errors.Select(e => e.Message).First(), exception.Message);
        }
Esempio n. 7
0
        public void TestGetPredictionsInvalidApiToken()
        {
            // Arrange
            const string InvalidApiToken = "INVALID_API_TOKEN";
            var          client          = new BusTrackerClient(UrlBase, InvalidApiToken);

            var expectedModel = this.repository.GetAs <GetPredictionsResponse>(ResourceFiles.GetPredictionsResponseInvalidApiAccess);

            Exception exception = null;

            // Act
            StartOwinTest(
                () =>
            {
                try
                {
                    var predictions = client.GetPredictions(Enumerable.Empty <int>(), Enumerable.Empty <string>(), Enumerable.Empty <string>(), null);
                    Assert.Fail("Exception thrown exception");
                }
                catch (Exception ex)
                {
                    exception = ex;
                }

                return(Task.FromResult(true));
            });

            // Assert
            Assert.IsNotNull(exception);
            Assert.AreEqual(expectedModel.Errors.Select(e => e.Message).First(), exception.Message);
        }
Esempio n. 8
0
        public void TestGetPredictionsAsyncWithCancelledCancellationToken()
        {
            // Arrange
            var client = new BusTrackerClient(UrlBase, WebAppConfig.ApiKey);

            var expectedModel = this.repository.GetAs <GetPredictionsResponse>(ResourceFiles.GetPredictionsResponse);

            var cts = new CancellationTokenSource();

            cts.Cancel();

            OperationCanceledException exception = null;

            // Act
            StartOwinTest(
                async() =>
            {
                try
                {
                    var predictions = await client.GetPredictionsAsync(Enumerable.Empty <int>(), Enumerable.Empty <string>(), Enumerable.Empty <string>(), null, cts.Token);
                    Assert.Fail();
                }
                catch (OperationCanceledException ex)
                {
                    exception = ex;
                }
            });

            // Assert
            Assert.IsNotNull(exception);
        }
Esempio n. 9
0
        public void TestCreateGetRouteDirectionsQueryString()
        {
            // Arrange
            var routeId = "88 N";

            // Act
            var collection = BusTrackerClient.CreateGetRouteDirectionsQueryString(routeId);

            // Assert
            Assert.IsNotNull(collection);
            Assert.AreEqual("rt=88+N", collection.ToString());
        }
        public void TestCreateGetVehiclesQueryWhenRoutesIsNull()
        {
            // Arrange
            IEnumerable <string> vehicledIds = Enumerable.Empty <string>();
            IEnumerable <string> routeIds    = null;

            // Act
            var collection = BusTrackerClient.CreateGetVehiclesQueryString(vehicledIds, routeIds);

            // Assert
            Assert.IsNotNull(collection);
            Assert.AreEqual("", collection.ToString());
        }
        public void TestCreateGetStopsQueryString()
        {
            // Arrange
            var routeId   = "88 N";
            var direction = "North Bound";

            // Act
            var collection = BusTrackerClient.CreateGetStopsQueryString(routeId, direction);

            // Assert
            Assert.IsNotNull(collection);
            Assert.AreEqual("rt=88+N&dir=North+Bound", collection.ToString());
        }
        public void TestCreateGetServiceBulletinsQueryStringWhenNull()
        {
            // Arrange
            IEnumerable <string> routeIds    = null;
            string            routeDirection = null;
            IEnumerable <int> stopIds        = null;

            // Act
            var collection = BusTrackerClient.CreateGetServiceBulletinsQueryString(routeIds, routeDirection, stopIds);

            // Assert
            Assert.IsNotNull(collection);
            Assert.AreEqual("", collection.ToString());
        }
        public void TestCreateGetServiceBulletinsQueryString()
        {
            // Arrange
            IEnumerable <string> routeIds    = new[] { "1123 J" };
            string            routeDirection = "North Bound";
            IEnumerable <int> stopIds        = new[] { 123, 555 };

            // Act
            var collection = BusTrackerClient.CreateGetServiceBulletinsQueryString(routeIds, routeDirection, stopIds);

            // Assert
            Assert.IsNotNull(collection);
            Assert.AreEqual("rt=1123+J&rtdir=North+Bound&stpid=123%2c555", collection.ToString());
        }
Esempio n. 14
0
        public void TestCreateGetPredictionsQueryStringWhenEmpty()
        {
            // Arrange
            var stopIds    = Enumerable.Empty <int>();
            var routeIds   = Enumerable.Empty <string>();
            var vehicleIds = Enumerable.Empty <string>();
            int?top        = null;

            // Act
            var collection = BusTrackerClient.CreateGetPredictionsQueryString(stopIds, routeIds, vehicleIds, top);

            // Assert
            Assert.IsNotNull(collection);
            Assert.AreEqual("", collection.ToString());
        }
Esempio n. 15
0
        public void TestCreateGetPredictionsQueryString()
        {
            // Arrange
            IEnumerable <int>    stopIds    = null;
            IEnumerable <string> routeIds   = new[] { "apple jacks" };
            IEnumerable <string> vehicleIds = new[] { "foo", "bar" };;
            int?top = 343;

            // Act
            var collection = BusTrackerClient.CreateGetPredictionsQueryString(stopIds, routeIds, vehicleIds, top);

            // Assert
            Assert.IsNotNull(collection);
            Assert.AreEqual("rt=apple+jacks&vid=foo%2cbar&top=343", collection.ToString());
        }
Esempio n. 16
0
        public void TestCreateGetPredictionsQueryStringWhenNull()
        {
            // Arrange
            IEnumerable <int>    stopIds    = null;
            IEnumerable <string> routeIds   = null;
            IEnumerable <string> vehicleIds = null;
            int?top = null;

            // Act
            var collection = BusTrackerClient.CreateGetPredictionsQueryString(stopIds, routeIds, vehicleIds, top);

            // Assert
            Assert.IsNotNull(collection);
            Assert.AreEqual("", collection.ToString());
        }
        public void TestCreateGetVehiclesQueryWhenSingleRouteId()
        {
            // Arrange
            var vehicledIds = Enumerable.Empty <string>();
            var routeIds    = new[]
            {
                "123123"
            };

            // Act
            var collection = BusTrackerClient.CreateGetVehiclesQueryString(vehicledIds, routeIds);

            // Assert
            Assert.IsNotNull(collection);
            Assert.AreEqual("rt=123123", collection.ToString());
        }
        public void TestCreateGetVehiclesQueryWhenMultipleVehicleId()
        {
            // Arrange
            var vehicledIds = new[]
            {
                "1111",
                "2222",
                "N 333"
            };
            var routeIds = Enumerable.Empty <string>();

            // Act
            var collection = BusTrackerClient.CreateGetVehiclesQueryString(vehicledIds, routeIds);

            // Assert
            Assert.IsNotNull(collection);
            Assert.AreEqual("vid=1111%2c2222%2cN+333", collection.ToString());
        }
        public void TestGetTimeAsync()
        {
            // Arrange
            var client = new BusTrackerClient(UrlBase, WebAppConfig.ApiKey);

            var expectedModel = this.repository.GetAs <GetTimeResponse>(ResourceFiles.GetTimeResponse);

            string time = null;

            // Act
            StartOwinTest(
                async() =>
            {
                time = await client.GetTimeAsync();
            });

            // Assert
            Assert.AreEqual(time, expectedModel.Time);
        }
        public void TestGetTime()
        {
            // Arrange
            var client = new BusTrackerClient(UrlBase, WebAppConfig.ApiKey);

            var expectedModel = this.repository.GetAs<GetTimeResponse>(ResourceFiles.GetTimeResponse);

            string time = null;

            // Act
            StartOwinTest(
                () =>
                {
                    time = client.GetTime();

                    return Task.FromResult(true);
                });

            // Assert
            Assert.AreEqual(time, expectedModel.Time);
        }
Esempio n. 21
0
        public void TestGetRouteDirectionsAsync()
        {
            // Arrange
            var client = new BusTrackerClient(UrlBase, WebAppConfig.ApiKey);

            var expectedModel = this.repository.GetAs <GetRouteDirectionsResponse>(ResourceFiles.GetRouteDirectionsResponse);

            IEnumerable <string> directions = null;

            // Act
            StartOwinTest(
                async() =>
            {
                directions = await client.GetRouteDirectionsAsync(Guid.NewGuid().ToString());
            });

            // Assert
            var expectedDirections = expectedModel.Directions.ToList();
            var actualDirections   = directions.ToList();

            CollectionAssert.AreEqual(expectedDirections, actualDirections);
        }
Esempio n. 22
0
        public void TestGetPredictionsAsync()
        {
            // Arrange
            var client = new BusTrackerClient(UrlBase, WebAppConfig.ApiKey);

            var expectedModel = this.repository.GetAs <GetPredictionsResponse>(ResourceFiles.GetPredictionsResponse);

            IEnumerable <Prediction> predictions = null;

            // Act
            StartOwinTest(
                async() =>
            {
                predictions = await client.GetPredictionsAsync(Enumerable.Empty <int>(), Enumerable.Empty <string>(), Enumerable.Empty <string>(), null);
            });

            // Assert
            var expectedPredictionTimes = expectedModel.Predictions.Select(x => x.Timestamp).ToList();
            var actualPredictionTimes   = predictions.Select(v => v.Timestamp).ToList();

            CollectionAssert.AreEqual(expectedPredictionTimes, actualPredictionTimes);
        }
        public void TestGetStopsAsync()
        {
            // Arrange
            var client = new BusTrackerClient(UrlBase, WebAppConfig.ApiKey);

            var expectedModel = this.repository.GetAs <GetStopsResponse>(ResourceFiles.GetStopsResponse);

            IEnumerable <Stop> stops = null;

            // Act
            StartOwinTest(
                async() =>
            {
                stops = await client.GetStopsAsync(Guid.NewGuid().ToString(), Guid.NewGuid().ToString());
            });

            // Assert
            var expectedStopIds = expectedModel.Stops.Select(x => x.StopId).ToList();
            var actualStopIds   = stops.Select(x => x.StopId).ToList();

            CollectionAssert.AreEqual(expectedStopIds, actualStopIds);
        }
        public void TestGetServiceBulletinsAsync()
        {
            // Arrange
            var client = new BusTrackerClient(UrlBase, WebAppConfig.ApiKey);

            var expectedModel = this.repository.GetAs <GetServiceBulletinResponse>(ResourceFiles.GetServiceBulletinsResponse);

            IEnumerable <ServiceBulletin> serviceBulletins = null;

            // Act
            StartOwinTest(
                async() =>
            {
                serviceBulletins = await client.GetServiceBulletinsAsync(Enumerable.Empty <string>(), null, Enumerable.Empty <int>());
            });

            // Assert
            var expectedServiceBulletinNames = expectedModel.ServiceBulletins.Select(x => x.Name).ToList();
            var actualServiceBulletinNames   = serviceBulletins.Select(x => x.Name).ToList();

            CollectionAssert.AreEqual(expectedServiceBulletinNames, actualServiceBulletinNames);
        }
Esempio n. 25
0
        public void TestGetRoutesAsync()
        {
            // Arrange
            var client = new BusTrackerClient(UrlBase, WebAppConfig.ApiKey);

            var expectedModel = this.repository.GetAs <GetRoutesResponse>(ResourceFiles.GetRoutesResponse);

            Route[] routes = null;

            // Act
            StartOwinTest(
                async() =>
            {
                routes = (await client.GetRoutesAsync()).ToArray();
            });

            // Assert
            var expectedVehicleIds = expectedModel.Routes.Select(v => v.RouteId).ToList();
            var actualVehicleIds   = routes.Select(v => v.RouteId).ToList();

            CollectionAssert.AreEqual(expectedVehicleIds, actualVehicleIds);
        }
Esempio n. 26
0
        public void TestGetRoutes()
        {
            // Arrange
            var client = new BusTrackerClient(UrlBase, WebAppConfig.ApiKey);

            var expectedModel = this.repository.GetAs <GetRoutesResponse>(ResourceFiles.GetRoutesResponse);

            IEnumerable <Route> routes = null;

            // Act
            StartOwinTest(
                () =>
            {
                routes = client.GetRoutes();

                return(Task.FromResult(true));
            });

            // Assert
            var expectedVehicleIds = expectedModel.Routes.Select(v => v.RouteId).ToList();
            var actualVehicleIds   = routes.Select(v => v.RouteId).ToList();

            CollectionAssert.AreEqual(expectedVehicleIds, actualVehicleIds);
        }
        public void TestGetPredictions()
        {
            // Arrange
            var client = new BusTrackerClient(UrlBase, WebAppConfig.ApiKey);

            var expectedModel = this.repository.GetAs<GetPredictionsResponse>(ResourceFiles.GetPredictionsResponse);

            IEnumerable<Prediction> predictions = null;

            // Act
            StartOwinTest(
                () =>
                {
                    predictions = client.GetPredictions(Enumerable.Empty<int>(), Enumerable.Empty<string>(), Enumerable.Empty<string>(), null);

                    return Task.FromResult(true);
                });

            // Assert
            var expectedPredictionTimes = expectedModel.Predictions.Select(x => x.Timestamp).ToList();
            var actualPredictionTimes = predictions.Select(v => v.Timestamp).ToList();

            CollectionAssert.AreEqual(expectedPredictionTimes, actualPredictionTimes);
        }
        public void TestGetRouteDirections()
        {
            // Arrange
            var client = new BusTrackerClient(UrlBase, WebAppConfig.ApiKey);

            var expectedModel = this.repository.GetAs<GetRouteDirectionsResponse>(ResourceFiles.GetRouteDirectionsResponse);

            IEnumerable<string> directions = null;

            // Act
            StartOwinTest(
                () =>
                {
                    directions = client.GetRouteDirections(Guid.NewGuid().ToString());

                    return Task.FromResult(true);
                });

            // Assert
            var expectedDirections = expectedModel.Directions.ToList();
            var actualDirections = directions.ToList();

            CollectionAssert.AreEqual(expectedDirections, actualDirections);
        }
        public void TestGetVehiclesAsyncWithCancellationToken()
        {
            // Arrange
            var client = new BusTrackerClient(UrlBase, WebAppConfig.ApiKey);

            var expectedModel = this.repository.GetAs <GetVehiclesResponse>(ResourceFiles.GetVehiclesResponse);

            var cts = new CancellationTokenSource();

            Vehicle[] vehicles = null;

            // Act
            StartOwinTest(
                async() =>
            {
                vehicles = (await client.GetVehiclesAsync(null, null, cts.Token)).ToArray();
            });

            // Assert
            var expectedVehicleIds = expectedModel.Vehicles.Select(v => v.VehicleId).ToList();
            var actualVehicleIds   = vehicles.Select(v => v.VehicleId).ToList();

            CollectionAssert.AreEqual(expectedVehicleIds, actualVehicleIds);
        }
        public void TestGetStops()
        {
            // Arrange
            var client = new BusTrackerClient(UrlBase, WebAppConfig.ApiKey);

            var expectedModel = this.repository.GetAs<GetStopsResponse>(ResourceFiles.GetStopsResponse);

            IEnumerable<Stop> stops = null;

            // Act
            StartOwinTest(
                () =>
                {
                    stops = client.GetStops(Guid.NewGuid().ToString(), Guid.NewGuid().ToString());

                    return Task.FromResult(true);
                });

            // Assert
            var expectedStopIds = expectedModel.Stops.Select(x => x.StopId).ToList();
            var actualStopIds = stops.Select(x => x.StopId).ToList();

            CollectionAssert.AreEqual(expectedStopIds, actualStopIds);
        }
        public void TestGetServiceBulletins()
        {
            // Arrange
            var client = new BusTrackerClient(UrlBase, WebAppConfig.ApiKey);

            var expectedModel = this.repository.GetAs<GetServiceBulletinResponse>(ResourceFiles.GetServiceBulletinsResponse);

            IEnumerable<ServiceBulletin> serviceBulletins = null;

            // Act
            StartOwinTest(
                () =>
                {
                    serviceBulletins = client.GetServiceBulletins(Enumerable.Empty<string>(), null, Enumerable.Empty<int>());

                    return Task.FromResult(true);
                });

            // Assert
            var expectedServiceBulletinNames = expectedModel.ServiceBulletins.Select(x => x.Name).ToList();
            var actualServiceBulletinNames = serviceBulletins.Select(x => x.Name).ToList();

            CollectionAssert.AreEqual(expectedServiceBulletinNames, actualServiceBulletinNames);
        }
        public void TestGetVehicles()
        {
            // Arrange
            var client = new BusTrackerClient(UrlBase, WebAppConfig.ApiKey);

            var expectedModel = this.repository.GetAs<GetVehiclesResponse>(ResourceFiles.GetVehiclesResponse);

            IEnumerable<Vehicle> vehicles = null;

            // Act
            StartOwinTest(
                () =>
                {
                    vehicles = client.GetVehicles(Enumerable.Empty<string>(), Enumerable.Empty<string>());

                    return Task.FromResult(true);
                });

            // Assert
            var expectedVehicleIds = expectedModel.Vehicles.Select(v => v.VehicleId).ToList();
            var actualVehicleIds = vehicles.Select(v => v.VehicleId).ToList();

            CollectionAssert.AreEqual(expectedVehicleIds, actualVehicleIds);
        }
        public void TestGetRoutesAsync()
        {
            // Arrange
            var client = new BusTrackerClient(UrlBase, WebAppConfig.ApiKey);

            var expectedModel = this.repository.GetAs<GetRoutesResponse>(ResourceFiles.GetRoutesResponse);

            Route[] routes = null;

            // Act
            StartOwinTest(
                async () =>
                {
                    routes = (await client.GetRoutesAsync()).ToArray();
                });

            // Assert
            var expectedVehicleIds = expectedModel.Routes.Select(v => v.RouteId).ToList();
            var actualVehicleIds = routes.Select(v => v.RouteId).ToList();

            CollectionAssert.AreEqual(expectedVehicleIds, actualVehicleIds);
        }
        public void TestGetTimeAsyncWithCancellationToken()
        {
            // Arrange
            var client = new BusTrackerClient(UrlBase, WebAppConfig.ApiKey);

            var expectedModel = this.repository.GetAs<GetTimeResponse>(ResourceFiles.GetTimeResponse);

            var cts = new CancellationTokenSource();

            string time = null;

            // Act
            StartOwinTest(
                async () =>
                {
                    time = await client.GetTimeAsync(cts.Token);
                });

            // Assert
            Assert.AreEqual(time, expectedModel.Time);
        }
        public void TestGetStopsAsyncWithCancellationToken()
        {
            // Arrange
            var client = new BusTrackerClient(UrlBase, WebAppConfig.ApiKey);

            var expectedModel = this.repository.GetAs<GetStopsResponse>(ResourceFiles.GetStopsResponse);

            var cts = new CancellationTokenSource();

            IEnumerable<Stop> stops = null;

            // Act
            StartOwinTest(
                async () =>
                {
                    stops = await client.GetStopsAsync(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), cts.Token);
                });

            // Assert
            var expectedStopIds = expectedModel.Stops.Select(x => x.StopId).ToList();
            var actualStopIds = stops.Select(x => x.StopId).ToList();

            CollectionAssert.AreEqual(expectedStopIds, actualStopIds);
        }
        public void TestGetPredictionsAsyncWithCancellationToken()
        {
            // Arrange
            var client = new BusTrackerClient(UrlBase, WebAppConfig.ApiKey);

            var expectedModel = this.repository.GetAs<GetPredictionsResponse>(ResourceFiles.GetPredictionsResponse);

            var cts = new CancellationTokenSource();

            IEnumerable<Prediction> predictions = null;

            // Act
            StartOwinTest(
                async () =>
                {
                    predictions = await client.GetPredictionsAsync(Enumerable.Empty<int>(), Enumerable.Empty<string>(), Enumerable.Empty<string>(), null, cts.Token);
                });

            // Assert
            var expectedPredictionTimes = expectedModel.Predictions.Select(x => x.Timestamp).ToList();
            var actualPredictionTimes = predictions.Select(v => v.Timestamp).ToList();

            CollectionAssert.AreEqual(expectedPredictionTimes, actualPredictionTimes);
        }
        public void TestGetVehiclesAsyncWithCancelledCancellationToken()
        {
            // Arrange
            var client = new BusTrackerClient(UrlBase, WebAppConfig.ApiKey);

            var expectedModel = this.repository.GetAs<GetVehiclesResponse>(ResourceFiles.GetVehiclesResponse);

            var cts = new CancellationTokenSource();
            cts.Cancel();

            OperationCanceledException exception = null;

            // Act
            StartOwinTest(
                async () =>
                {
                    try
                    {
                        var vehicles = (await client.GetVehiclesAsync(null, null, cts.Token)).ToArray();
                        Assert.Fail();
                    }
                    catch (OperationCanceledException ex)
                    {
                        exception = ex;
                    }
                });

            // Assert
            Assert.IsNotNull(exception);
        }
        public void TestGetVehiclesAsyncWithCancellationToken()
        {
            // Arrange
            var client = new BusTrackerClient(UrlBase, WebAppConfig.ApiKey);

            var expectedModel = this.repository.GetAs<GetVehiclesResponse>(ResourceFiles.GetVehiclesResponse);

            var cts = new CancellationTokenSource();

            Vehicle[] vehicles = null;

            // Act
            StartOwinTest(
                async () =>
                {
                    vehicles = (await client.GetVehiclesAsync(null, null, cts.Token)).ToArray();
                });

            // Assert
            var expectedVehicleIds = expectedModel.Vehicles.Select(v => v.VehicleId).ToList();
            var actualVehicleIds = vehicles.Select(v => v.VehicleId).ToList();

            CollectionAssert.AreEqual(expectedVehicleIds, actualVehicleIds);
        }
        public void TestGetRouteDirectionsAsyncWithCancellationToken()
        {
            // Arrange
            var client = new BusTrackerClient(UrlBase, WebAppConfig.ApiKey);

            var expectedModel = this.repository.GetAs<GetRouteDirectionsResponse>(ResourceFiles.GetRouteDirectionsResponse);

            var cts = new CancellationTokenSource();

            IEnumerable<string> directions = null;

            // Act
            StartOwinTest(
                async () =>
                {
                    directions = await client.GetRouteDirectionsAsync(Guid.NewGuid().ToString(), cts.Token);
                });

            // Assert
            var expectedDirections = expectedModel.Directions.ToList();
            var actualDirections = directions.ToList();

            CollectionAssert.AreEqual(expectedDirections, actualDirections);
        }
        public void TestGetVehiclesAsyncInvalidApiTokenWithCancelledCancellationToken()
        {
            // Arrange
            const string InvalidApiToken = "INVALID_API_TOKEN";
            var client = new BusTrackerClient(UrlBase, InvalidApiToken);

            var expectedModel = this.repository.GetAs<GetVehiclesResponse>(ResourceFiles.GetVehiclesResponseInvalidApiAccess);

            OperationCanceledException exception = null;

            var cts = new CancellationTokenSource();
            cts.Cancel();

            // Act
            StartOwinTest(
                async () =>
                {
                    try
                    {
                        var time = await client.GetVehiclesAsync(null, null, cts.Token);
                        Assert.Fail();
                    }
                    catch (OperationCanceledException ex)
                    {
                        exception = ex;
                    }
                });

            // Assert
            Assert.IsNotNull(exception);
        }
        public void TestGetRouteDirectionsAsyncWithCanceledCancellationToken()
        {
            // Arrange
            var client = new BusTrackerClient(UrlBase, WebAppConfig.ApiKey);

            var expectedModel = this.repository.GetAs<GetRouteDirectionsResponse>(ResourceFiles.GetRouteDirectionsResponse);

            var cts = new CancellationTokenSource();
            cts.Cancel();

            OperationCanceledException exception = null;

            // Act
            StartOwinTest(
                async () =>
                {
                    try
                    {
                        var directions = await client.GetRouteDirectionsAsync(Guid.NewGuid().ToString(), cts.Token);
                    }
                    catch (OperationCanceledException ex)
                    {
                        exception = ex;
                    }
                });

            // Assert
            Assert.IsNotNull(exception);
        }
        public void TestGetRouteDirectionsAsyncInvalidApiTokenWithCancellationToken()
        {
            // Arrange
            const string InvalidApiToken = "INVALID_API_TOKEN";
            var client = new BusTrackerClient(UrlBase, InvalidApiToken);

            var expectedModel = this.repository.GetAs<GetRouteDirectionsResponse>(ResourceFiles.GetRouteDirectionsResponseInvalidApiAccess);

            Exception exception = null;

            var cts = new CancellationTokenSource();

            // Act
            StartOwinTest(
                async () =>
                {
                    try
                    {
                        var directions = await client.GetRouteDirectionsAsync(Guid.NewGuid().ToString(), cts.Token);
                        Assert.Fail("Exception thrown exception");
                    }
                    catch (Exception ex)
                    {
                        exception = ex;
                    }
                });

            // Assert
            Assert.IsNotNull(exception);
            Assert.AreEqual(expectedModel.Errors.Select(e => e.Message).First(), exception.Message);
        }
        public void TestGetServiceBulletinsAsyncWithCancelledCancellationToken()
        {
            // Arrange
            var client = new BusTrackerClient(UrlBase, WebAppConfig.ApiKey);

            var expectedModel = this.repository.GetAs<GetServiceBulletinResponse>(ResourceFiles.GetServiceBulletinsResponse);

            var cts = new CancellationTokenSource();
            cts.Cancel();

            OperationCanceledException exception = null;

            // Act
            StartOwinTest(
                async () =>
                {
                    try
                    {
                        var serviceBulletins = await client.GetServiceBulletinsAsync(Enumerable.Empty<string>(), null, Enumerable.Empty<int>(), cts.Token);
                    }
                    catch (OperationCanceledException ex)
                    {
                        exception = ex;
                    }

                });

            // Assert
            Assert.IsNotNull(exception);
        }