public async Task Integration_Valid_ReturnsExpected() { // ARRANGE string b = Container.GetBaseAddress(); HttpClient c = Container.ResolveHttpClient(); var m = Container.ResolveImageTypeToUriMap(); IEEFluxClient <HttpResponseMessage> sut = new EEFluxClientWebApi(c, b, m); CafEEFluxParameters p = getCafEEFluxParametersValid(); // ACT Dictionary <int, EEFluxImageMetadata> imageMetas = await sut.GetImageMetadataAsync(p); Dictionary <EEFluxImageTypes, EEFluxImage> image = await sut.GetImageUriAsync( p, imageMetas[0].ImageId, EEFluxImageTypes.Ndvi); Uri imageUrl = new Uri(image[EEFluxImageTypes.Ndvi].Url); string fullPath = Path.GetFullPath(p.OutputDirectoryPath); if (!Directory.Exists(fullPath)) { Directory.CreateDirectory(fullPath); } // await sut.DownloadImageAsync(fullPath, imageUrl); Task <HttpResponseMessage> download = sut.DownloadImageAsync(imageUrl); var response = await download; string filePath = $"{p.OutputDirectoryPath}\\{response.Content.Headers.ContentDisposition.FileName}"; using (Stream readStream = await response.Content.ReadAsStreamAsync()) { using (Stream writeStream = File.Open( filePath, FileMode.Create)) { await readStream.CopyToAsync(writeStream); } } // ASSERT Assert.True( File.Exists("Output/LE70440272015152EDC00_NDVI.zip")); double expectedLength = new FileInfo("Assets/LE70440272015152EDC00_NDVI.zip").Length; double actualLength = new FileInfo("Output/LE70440272015152EDC00_NDVI.zip").Length; Assert.Equal( expectedLength, actualLength); }
/// <summary> /// Wires up all dependencies, called by composition root /// </summary> /// <returns>Engine that runs the program</returns> public static Engine ResolveCafEEFluxCli() { string b = GetBaseAddress(); HttpClient c = ResolveHttpClient(); var m = ResolveImageTypeToUriMap(); IEEFluxClient <HttpResponseMessage> f = new EEFluxClientWebApi(c, b, m); CommandLineApplication a = getConfiguredCli(); IParseParameters <CommandOption> p = new CommandLineUtilParameterParser(); return(new Engine(f, a, p)); }
public async Task GetImageMetadata_ValidParams_ReturnsDictionaryOfEEFluxImageMetadata() { // ARRANGE var parameters = Arranger.GetCafEEFluxParametersValid(); var expected = Arranger.GetEEFluxImageMetadataActual(); var actual = new Dictionary <int, EEFluxImageMetadata>(); EEFluxClientWebApi sut = arrangeEEFluxClientWebApi( "landsat", getEEFluxResponseLandsatValid()); // ACT actual = await sut.GetImageMetadataAsync(parameters); // ASSERT Assert.Equal(actual, expected); }
public async Task GetImageUri_Etof_ReturnsDictionaryOfEEFluxImages() { // ARRANGE string imageId = "LE70420282015170EDC00"; var parameters = Arranger.GetCafEEFluxParametersValid(); var expected = Arranger.GetEEFluxResponseDownloadEtofValid(); EEFluxClientWebApi sut = arrangeEEFluxClientWebApi( "download_etof", "{\"etof\": {\"url\": \"https://earthengine.googleapis.com/api/download?docid=6277fdbbcb5e4e0bc2f2d5562f4d1c4a&token=da96164b598072a0163f34ceaac8f5b6\"}}"); // ACT var actual = await sut.GetImageUriAsync( parameters, imageId, EEFluxImageTypes.Etof); // ASSERT Assert.Equal(actual, expected); }
private EEFluxClientWebApi arrangeEEFluxClientWebApi( string path, string mockResponse) { // From: https://github.com/richardszalay/mockhttp // And: https://stackoverflow.com/questions/36425008/mocking-httpclient-in-unit-tests var mockHttpMessageHandler = new MockHttpMessageHandler(); mockHttpMessageHandler .When($"https://eeflux-level1.appspot.com/{path}") .Respond("application/json", mockResponse); var httpClient = new HttpClient(mockHttpMessageHandler); var baseAddress = Container.GetBaseAddress(); var map = Container.ResolveImageTypeToUriMap(); EEFluxClientWebApi r = new EEFluxClientWebApi( httpClient, baseAddress, map); return(r); }