public async Task Media_Blob_DownloadTest() { var mediaRepo = new DeviceMediaRepo(new AdminLogger(new Utils.LogWriter())); var fileName = $"{Guid.NewGuid().ToId()}.bin"; var imageBytes = new byte[4096]; new Random().NextBytes(imageBytes); var result = await mediaRepo.AddMediaAsync(GetTestDeviceRepo(), imageBytes, fileName, "application/jpeg"); AssertSuccessful(result); Console.WriteLine("Media Item Added."); var downloadResult = await mediaRepo.GetMediaAsync(GetTestDeviceRepo(), fileName); AssertSuccessful(downloadResult.ToInvokeResult()); Assert.AreEqual(imageBytes.Length, downloadResult.Result.Length); for (var idx = 0; idx < imageBytes.Length; ++idx) { Assert.AreEqual(imageBytes[idx], downloadResult.Result[idx], $"Difference in byte array at:{idx}"); } }
public async Task Media_Blob_UploadTest() { var mediaRepo = new DeviceMediaRepo(new AdminLogger(new Utils.LogWriter())); var fileName = $"{Guid.NewGuid().ToId()}.bin"; var imageBytes = new byte[4096]; new Random().NextBytes(imageBytes); var result = await mediaRepo.AddMediaAsync(GetTestDeviceRepo(), imageBytes, fileName, "application/jpeg"); AssertSuccessful(result); }
public async Task Media_Blob_DeleteBlobTest() { var mediaRepo = new DeviceMediaRepo(new AdminLogger(new Utils.LogWriter())); var fileName = $"{Guid.NewGuid().ToId()}.bin"; var imageBytes = new byte[4096]; new Random().NextBytes(imageBytes); var result = await mediaRepo.AddMediaAsync(GetTestDeviceRepo(), imageBytes, fileName, "application/jpeg"); AssertSuccessful(result); Console.WriteLine("Media Item Added."); var deleteResult = await mediaRepo.DeleteMediaAsync(GetTestDeviceRepo(), fileName); AssertSuccessful(deleteResult.ToInvokeResult()); var getResult = await mediaRepo.GetMediaAsync(GetTestDeviceRepo(), fileName); AssertInvalidError(getResult.ToInvokeResult(), "The remote server returned an error: (404) Not Found.", "Unhandled Excpetion"); }