Exemplo n.º 1
0
        public async Task Kudos_Should_Return_Excel_File()
        {
            var filter = new KudosLogsFilterDto
            {
                OrganizationId = 2,
                SearchUserId   = null,
                Status         = BusinessLayerConstants.KudosStatusAllFilter,
                SortBy         = "Created",
                SortOrder      = "desc"
            };

            var stream = await _kudosExportService.ExportToExcelAsync(filter);

            using (var excelReader = ExcelReaderFactory.CreateOpenXmlReader(new MemoryStream(stream)))
            {
                excelReader.IsFirstRowAsColumnNames = true;
                var excelData    = excelReader.AsDataSet();
                var excelRows    = excelData.Tables[0].Rows;
                var excelColumns = excelData.Tables[0].Columns;

                Assert.AreEqual(Resources.Models.Kudos.Kudos.ExportColumnSender, excelColumns[0].ColumnName);
                Assert.AreEqual(Resources.Models.Kudos.Kudos.ExportColumnReceiver, excelColumns[1].ColumnName);
                Assert.AreEqual("name surname", excelRows[0].ItemArray[0]);
                Assert.AreEqual("name surname", excelRows[0].ItemArray[1]);
                Assert.AreEqual("name2 surname2", excelRows[1].ItemArray[0]);
                Assert.AreEqual("name surname", excelRows[1].ItemArray[1]);
                Assert.AreEqual(4, excelRows.Count);

                excelReader.Close();
            }
        }
Exemplo n.º 2
0
        public async Task <IHttpActionResult> GetKudosLogAsExcel([FromUri] KudosLogsFilterViewModel filter)
        {
            var filterDto = _mapper.Map <KudosLogsFilterViewModel, KudosLogsFilterDto>(filter);

            SetOrganizationAndUser(filterDto);
            try
            {
                var stream = new ByteArrayContent(await _kudosExportService.ExportToExcelAsync(filterDto));
                var result = new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = stream
                };
                return(ResponseMessage(result));
            }
            catch (ValidationException e)
            {
                return(BadRequest(e.Message));
            }
        }