public void Download_Error_PlaintextResponse() { using (var service = new MockClientService()) { var downloader = new MediaDownloader(service); IList <IDownloadProgress> progressList = new List <IDownloadProgress>(); downloader.ProgressChanged += (p) => { progressList.Add(p); }; var outputStream = new MemoryStream(); downloader.Download(_httpPrefix + "NotFoundPlainText", outputStream); var lastProgress = progressList.LastOrDefault(); Assert.Equal(DownloadStatus.Failed, lastProgress.Status); GoogleApiException exception = Assert.IsType <GoogleApiException>(lastProgress.Exception); Assert.Equal(HttpStatusCode.NotFound, exception.HttpStatusCode); Assert.Equal("The service TestService has thrown an exception. HttpStatusCode is NotFound. No error message was specified.", exception.Message); Assert.Contains( $"The service TestService has thrown an exception.{Environment.NewLine}" + $"HttpStatusCode is NotFound.{Environment.NewLine}" + $"No JSON error details were specified.{Environment.NewLine}" + $"Raw error details are: {NotFoundError}", exception.ToString()); Assert.True(exception.Error.IsOnlyRawContent); } }
public void ConstructorTest() { var name = "TestName_ConstructorTest"; var exception = new GoogleApiException(name, "Test"); Assert.IsInstanceOf<Exception>(exception); Assert.That(exception.ToString(), Contains.Substring(name)); }
public void ConstructorTest() { var service = new MockService(); var exception = new GoogleApiException(service, "Test"); Assert.IsInstanceOf<Exception>(exception); Assert.That(exception.Service, Is.EqualTo(service)); Assert.That(exception.ToString(), Contains.Substring(service.Name)); }
public void ConstructorTest() { var name = "TestName_ConstructorTest"; var exception = new GoogleApiException(name, "Test"); Assert.IsAssignableFrom <Exception>(exception); Assert.Contains(name, exception.ToString()); }
public void ConstructorTest() { var name = "TestName_ConstructorTest"; var exception = new GoogleApiException(name, "Test"); Assert.IsInstanceOf <Exception>(exception); Assert.That(exception.ToString(), Contains.Substring(name)); }
public void ConstructorTest() { var service = new MockService(); var exception = new GoogleApiException(service, "Test"); Assert.IsInstanceOf <Exception>(exception); Assert.That(exception.Service, Is.EqualTo(service)); Assert.That(exception.ToString(), Contains.Substring(service.Name)); }
public void TestErrorDeserialization( [Values(DiscoveryVersion.Version_0_3, DiscoveryVersion.Version_1_0)] DiscoveryVersion version) { const string ErrorResponse = @"{ ""error"": { ""errors"": [ { ""domain"": ""global"", ""reason"": ""required"", ""message"": ""Required"", ""locationType"": ""parameter"", ""location"": ""resource.longUrl"" } ], ""code"": 400, ""message"": ""Required"" } }"; IService impl = CreateService(version); using (var stream = new MemoryStream(Encoding.Default.GetBytes(ErrorResponse))) { // Verify that the response is decoded correctly. GoogleApiException ex = Assert.Throws <GoogleApiException>(() => { impl.DeserializeResponse <MockJsonSchema>(new MockResponse() { Stream = stream }); }); // Check that the contents of the error json was translated into the exception object. // We cannot compare the entire exception as it depends on the implementation and might change. Assert.That(ex.ToString(), Contains.Substring("resource.longUrl")); } using (var stream = new MemoryStream(Encoding.Default.GetBytes(ErrorResponse))) { RequestError error = impl.DeserializeError(new MockResponse() { Stream = stream }); Assert.AreEqual(400, error.Code); Assert.AreEqual("Required", error.Message); Assert.AreEqual(1, error.Errors.Count); } }