public void SetUp() { _configuration = Substitute.For <IApiConfiguration>(); _webFactory = new TestWebRequestFactory(); _service = new TestInvoiceService(_configuration, _webFactory, null); _configuration.ApiBaseUrl.Returns(ApiRequestHandler.ApiRequestUri.AbsoluteUri); _uid = Guid.NewGuid(); }
public void GetPdf_AsyncWithDelegates_ThrowsWebException() { // Arrange var cf = new CompanyFile { Uri = new Uri("https://dc1.api.myob.com/accountright/7D5F5516-AF68-4C5B-844A-3F054E00DF10") }; var uri = cf.Uri.AbsoluteUri + "/" + Route + "/" + _uid + "?templatename=tn"; _webFactory.RegisterExceptionForUri <WebException>(uri); var iis = new TestInvoiceService(_configuration, _webFactory, null); // Act iis.GetPdf(cf, _uid, null, "tn", (c, s) => Assert.Fail("Exception Expected"), ( u, e) => Assert.IsNotNull(e as WebException)); }
public void GetPdf_Sync_ThrowsInvalidOperationException() { // Arrange var cf = new CompanyFile { Uri = new Uri("https://dc1.api.myob.com/accountright/7D5F5516-AF68-4C5B-844A-3F054E00DF10") }; var uri = cf.Uri.AbsoluteUri + "/" + Route + "/" + _uid + "?templatename=tn"; _webFactory.RegisterExceptionForUri <WebException>(uri); var iis = new TestInvoiceService(_configuration, _webFactory, null); // Act var ex = Assert.Throws <ApiCommunicationException>(() => iis.GetPdf(cf, _uid, null, "tn")); // Assert Assert.AreEqual(uri.ToLower(), ex.URI.AbsoluteUri.ToLower()); Assert.IsInstanceOf <InvalidOperationException>(ex.InnerException); }
public void GetPdf_AsyncWithTask_ThrowsWebException() { // Arrange var cf = new CompanyFile { Uri = new Uri("https://dc1.api.myob.com/accountright/7D5F5516-AF68-4C5B-844A-3F054E00DF10") }; var uri = cf.Uri.AbsoluteUri + "/" + Route + "/" + _uid + "?templatename=tn"; _webFactory.RegisterExceptionForUri <WebException>(uri); var iis = new TestInvoiceService(_configuration, _webFactory, null); // Act var task = iis.GetPdfAsync(cf, _uid, null, "tn").ContinueWith(t => { Assert.IsNotNull(t.Exception); Assert.IsNotNull(t.Exception.InnerException); Assert.IsInstanceOf <WebException>(t.Exception.InnerException); }); // Assert Task.WaitAll(new[] { task }); }
public void GetPdf_UsesCorrectMimeType_ToCreate_WebRequestObject( [ValueSource("_getFormPdfActions")] Tuple <string, Func <TestInvoiceService, CompanyFile, Stream> > action) { // arrange var cf = new CompanyFile { Uri = new Uri("https://dc1.api.myob.com/accountright/7D5F5516-AF68-4C5B-844A-3F054E00DF10") }; var stream = new MemoryStream(new byte[] { 0, 1, 2, 3 }); var uri = cf.Uri.AbsoluteUri + "/" + Route + "/" + _uid + "?templatename=tn"; _webFactory.RegisterResultForUri(uri, stream); var webRequestFactory = Substitute.For <IWebRequestFactory>(); webRequestFactory.Create(Arg.Any <Uri>(), Arg.Any <string>()).Returns(x => _webFactory.Create((Uri)x[0], (string)x[1])); var iis = new TestInvoiceService(_configuration, webRequestFactory, null); // Act action.Item2(iis, cf); // assert webRequestFactory.Received(1).Create(Arg.Any <Uri>(), "application/pdf"); }