public async Task Should_Success_Get_Excel_By_Id() { TransferOutFacade facade = new TransferOutFacade(GetServiceProvider().Object, _dbContext(GetCurrentMethod())); ReturnToCenterFacade returnToCenterFacade = new ReturnToCenterFacade(GetServiceProvider().Object, _dbContext(GetCurrentMethod())); var model = await dataUtil(facade, GetCurrentMethod()).GetNewData(); var viewmodel = dataUtil(facade, GetCurrentMethod()).MapToViewModel(model); await returnToCenterFacade.Create(viewmodel, model, USERNAME); var Response = returnToCenterFacade.GenerateExcel((int)model.Id); Assert.IsType <MemoryStream>(Response); }
public IActionResult GetXls(int id) { //Console.WriteLine("sampai sini"); try { byte[] xlsInBytes; int offset = Convert.ToInt32(Request.Headers["x-timezone-offset"]); string accept = Request.Headers["Accept"]; var xls = facade.GenerateExcel(id); string filename = String.Format("Report RTP - {0}.xlsx", DateTime.UtcNow.ToString("ddMMyyyy")); xlsInBytes = xls.ToArray(); var file = File(xlsInBytes, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", filename); return(file); } catch (Exception e) { Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.INTERNAL_ERROR_STATUS_CODE, e.Message) .Fail(); return(StatusCode(General.INTERNAL_ERROR_STATUS_CODE, Result)); } }