public void Should_Success_Get_Data_By_Id() { var dbContext = _dbContext(GetCurrentMethod()); UnitReceiptNoteFacade facade = new UnitReceiptNoteFacade(_ServiceProvider.Object, dbContext); var dataUtil = _dataUtil(facade, dbContext).GetTestData(USERNAME).Result; var Response = facade.ReadById((int)dataUtil.Id); Assert.NotNull(Response); }
public IActionResult Get(int id) { try { var indexAcceptPdf = Request.Headers["Accept"].ToList().IndexOf("application/pdf"); UnitReceiptNote model = _facade.ReadById(id); UnitReceiptNoteViewModel viewModel = _mapper.Map <UnitReceiptNoteViewModel>(model); if (viewModel == null) { throw new Exception("Invalid Id"); } if (indexAcceptPdf < 0) { return(Ok(new { apiVersion = ApiVersion, statusCode = General.OK_STATUS_CODE, message = General.OK_MESSAGE, data = viewModel, })); } else { UnitReceiptNotePDFTemplate PdfTemplate = new UnitReceiptNotePDFTemplate(); MemoryStream stream = PdfTemplate.GeneratePdfTemplate(viewModel); return(new FileStreamResult(stream, "application/pdf") { FileDownloadName = $"{viewModel.no}.pdf" }); } } 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)); } }