Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ReportService : Service
- {
- public IReportRepository Repository {get; set;}
- public object Get(GetInvoiceReport request)
- {
- var invoices = Repository.GetInvoices();
- ExcelReport report = new ExcelReport();
- byte[] bytes = report.Generate(invoices);
- return new FileResult(bytes);
- }
- }
- public class FileResult : IHasOptions, IStreamWriter, IDisposable
- {
- private readonly Stream _responseStream;
- public IDictionary<string, string> Options { get; private set; }
- public BinaryFileResult(byte[] data)
- {
- _responseStream = new MemoryStream(data);
- Options = new Dictionary<string, string>
- {
- {"Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"},
- {"Content-Disposition", "attachment; filename="InvoiceFile.xlsx";"}
- };
- }
- public void WriteTo(Stream responseStream)
- {
- if (_responseStream == null)
- return;
- using (_responseStream)
- {
- _responseStream.WriteTo(responseStream);
- responseStream.Flush();
- }
- }
- public void Dispose()
- {
- _responseStream.Close();
- _responseStream.Dispose();
- }
- }
- [Test]
- public void TestInvoiceReport()
- {
- var client = new JsonServiceClient("http://localhost/report/");
- var authResponse = client.Send(new Authenticate
- {
- provider = CredentialsAuthProvider.Name,
- UserName = "[User Name]",
- Password = "[Password]"
- });
- var requestDTO = new GetInvoiceReport();
- var ret = client.Get<FileResult>(requestDTO);
- Assert.IsTrue(ret != null);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement