internal async Task DownloadData()
        {
            string filePath = @"C:\output.csv";
            var    csv      = new StringBuilder();
            LiveTrafficCamerasResponse result = await LiveTrafficCamerasProcessor.LoadData();

            csv.AppendLine($"type,{result.Type}");
            csv.AppendLine($"copyright,{result.Rights.Copyright}");
            csv.AppendLine($"license,{result.Rights.Licence}");
            csv.AppendLine($"features,{result.Features.Count()}");
            csv.AppendLine($"id,latitude,longitude,region");

            foreach (LiveTrafficCamerasFeatureItem item in result.Features)
            {
                var newLine = $"{item.Id},{item.Geometry.Coordinates[0]},{item.Geometry.Coordinates[1]},{item.Properties.Region}";
                csv.AppendLine(newLine);
            }

            try
            {
                File.AppendAllText(filePath, csv.ToString());
            }
            catch (Exception e)
            {
                Console.WriteLine($"Please Run Visual Studio as an Administrator to avoid this exception.");
                throw e;
            }

            Console.WriteLine($"The file has been downloaded to your C: drive. Please open file output.csv to view data.");
        }
        internal async Task DisplayData()
        {
            LiveTrafficCamerasResponse result = await LiveTrafficCamerasProcessor.LoadData();

            Console.WriteLine("\n");
            Console.WriteLine("Type:" + " " + result.Type);
            Console.WriteLine("Copyright:" + " " + result.Rights.Copyright);
            Console.WriteLine("License:" + " " + result.Rights.Licence);
            Console.WriteLine($"Features: Total number = {result.Features.Count()}.");

            foreach (LiveTrafficCamerasFeatureItem item in result.Features)
            {
                Console.WriteLine("ID: " + item.Id + " Latitude: " + item.Geometry.Coordinates[0] + " Longitude: " + item.Geometry.Coordinates[1] + " Region: " + item.Properties.Region);
            }

            Console.WriteLine("\n");
        }
Exemplo n.º 3
0
        public async Task LoadLiveTrafficCamerasDataMethodShouldReturnValidResponseForValidRequest()
        {
            // First, check if the connection from the client is setup properly
            ApiHelper.InitializeClient();
            Assert.IsNotNull(ApiHelper.ApiClient);
            Assert.AreEqual(ApiHelper.ApiClient.BaseAddress, "https://api.transport.nsw.gov.au/v1/live/cameras");

            // Next, check if we have the required response from the API server
            var results = await LiveTrafficCamerasProcessor.LoadData();

            Assert.IsNotNull(results);
            Assert.IsNotNull(results.Rights);
            Assert.IsNotNull(results.Features);
            Assert.AreEqual(results.Type, Constants.Type);
            Assert.IsTrue(!string.IsNullOrWhiteSpace(results.Rights.Copyright));
            Assert.IsTrue(!string.IsNullOrWhiteSpace(results.Rights.Licence));
            Assert.AreEqual(results.Features[0].Type, Constants.FeatureType);
            Assert.IsTrue(!string.IsNullOrWhiteSpace(results.Features[0].Id));
            Assert.IsTrue(!string.IsNullOrWhiteSpace(results.Features[0].Geometry.Coordinates[0].ToString()));
            Assert.IsTrue(!string.IsNullOrWhiteSpace(results.Features[0].Geometry.Coordinates[1].ToString()));
            Assert.IsTrue(!string.IsNullOrWhiteSpace(results.Features[0].Properties.Direction));
        }