public static async Task MetadataApi_GetDownloadUriAsync_Returns_File_Download_Uri_Which_Downloads_Correct_File()
        {
            // Arrange
            MetadataApi target = CreateAuthorizedService();

            AvailablePackagesReply packages = await target.GetAvailablePackagesAsync();

            DataFile dataFile = packages.PackageGroups
                                .SelectMany((p) => p.Packages)
                                .First()
                                .Files
                                .First();

            // Act
            Uri result = await target.GetDownloadUriAsync(dataFile.FileName, dataFile.MD5Hash);

            // Assert
            Assert.NotNull(result);
            Assert.True(result.IsAbsoluteUri);

            string tempPath = Path.Combine(Path.GetTempPath(), dataFile.FileName);

            try
            {
                using (WebClient client = new WebClient())
                {
                    await client.DownloadFileTaskAsync(result, tempPath);
                }

                Assert.True(File.Exists(tempPath));

                byte[] hash;

                using (Stream stream = File.OpenRead(tempPath))
                {
                    Assert.Equal(dataFile.Size, stream.Length);

                    using (HashAlgorithm algorithm = HashAlgorithm.Create("MD5"))
                    {
                        hash = algorithm.ComputeHash(stream);
                    }
                }

                string hashString = string.Concat(hash.Select((p) => p.ToString("x2", CultureInfo.InvariantCulture)));

                Assert.Equal(dataFile.MD5Hash, hashString);
            }
            finally
            {
                if (File.Exists(tempPath))
                {
                    File.Delete(tempPath);
                }
            }
        }
        public static async Task MetadataApi_GetDownloadUriAsync_Throws_MetadataApiException_If_Error_Occurs()
        {
            // Arrange
            Uri         serviceUri = new Uri("https://ws.updates.qas.com/metadata/V1/");
            MetadataApi target     = new MetadataApi(serviceUri);

            string fileName    = "MyFile.txt";
            string fileHash    = "7039d49e15fd4e164e2c07fe76fd61a2";
            long?  startAtByte = null;
            long?  endAtByte   = null;

            // Act and Assert - Should throw as no credentials configured
            await Assert.ThrowsAsync <MetadataApiException>(() => target.GetDownloadUriAsync(fileName, fileHash, startAtByte, endAtByte));
        }