예제 #1
0
        public void ListContentPuedeSuministrarUnItemTemplate()
        {
            // arrange
            var listContent = ListContentWithRowNumber();

            // act
            listContent.ItemTemplates.Add(typeof(ExcelWriter), "15");
            listContent.Write(writer, DatasourceFactory.GetDatasourceList());

            // assert
            this.EndRenderCloseStream();
            var sheet = GetSheet(this.filename);

            for (int i = 0; i < DatasourceFactory.GetDatasourceList().Count; i++)
            {
                // en el template en col 5 empieza la serie 1,2,3,4,5 con alineamineto centrado y border THIN
                sheet.GetRow(i).GetCell(5, NPOIUserModel.MissingCellPolicy.CREATE_NULL_AS_BLANK).NumericCellValue.Should().Be.EqualTo(1);
                sheet.GetRow(i).GetCell(6, NPOIUserModel.MissingCellPolicy.CREATE_NULL_AS_BLANK).NumericCellValue.Should().Be.EqualTo(2);
                sheet.GetRow(i).GetCell(7, NPOIUserModel.MissingCellPolicy.CREATE_NULL_AS_BLANK).NumericCellValue.Should().Be.EqualTo(3);
                sheet.GetRow(i).GetCell(8, NPOIUserModel.MissingCellPolicy.CREATE_NULL_AS_BLANK).NumericCellValue.Should().Be.EqualTo(4);
                sheet.GetRow(i).GetCell(9, NPOIUserModel.MissingCellPolicy.CREATE_NULL_AS_BLANK).NumericCellValue.Should().Be.EqualTo(5);
                for (var j = 0; j < 5; j++)
                {
                    sheet.GetRow(i).GetCell(5 + j, NPOIUserModel.MissingCellPolicy.CREATE_NULL_AS_BLANK).CellStyle.Alignment.
                    Should().Be.EqualTo(NPOIUserModel.HorizontalAlignment.CENTER);
                    sheet.GetRow(i).GetCell(5 + j, NPOIUserModel.MissingCellPolicy.CREATE_NULL_AS_BLANK).CellStyle.
                    BorderBottom.Should().Be.EqualTo(NPOIUserModel.BorderStyle.THIN);
                    sheet.GetRow(i).GetCell(5 + j, NPOIUserModel.MissingCellPolicy.CREATE_NULL_AS_BLANK).CellStyle.BorderTop.
                    Should().Be.EqualTo(NPOIUserModel.BorderStyle.THIN);
                }
            }
        }
예제 #2
0
        public void ListContentEnExcelGeneraCadaItemEnUnaFila()
        {
            // arrange
            var listContent   = new Reporting.ListContent();
            var nombreContent = new ExpressionContent();

            nombreContent.Expression = "model.Nombre";
            listContent.Content.AddContent(nombreContent);
            var fechaContent = new ExpressionContent();

            fechaContent.Expression = "model.Fecha";
            listContent.Content.AddContent(fechaContent);
            var datasource = DatasourceFactory.GetDatasourceList();

            // act
            listContent.Write(writer, datasource);

            // assert
            this.EndRenderCloseStream();
            var sheet = GetSheet(this.filename);
            var i     = 0;

            foreach (var item in datasource)
            {
                var row = sheet.GetRow(i);
                row.Should("cantidad de rows = items").Not.Be.Null();
                row.GetCell(0).StringCellValue.Should().Be.EqualTo(item.Nombre);
                row.GetCell(1).StringCellValue.Should().Be.EqualTo(item.Fecha.ToString());
                i++;
            }
        }
예제 #3
0
        public void ListContentSiElItemTemplateNoTieneNadaGeneraInvalidOperationException()
        {
            // arrange
            var listContent = ListContentWithRowNumber();

            // act
            listContent.ItemTemplates.Add(typeof(ExcelWriter), "100");
            Executing.This(() => listContent.Write(writer, DatasourceFactory.GetDatasourceList())).Should().Throw <InvalidOperationException>();

            this.EndRenderCloseStream();
        }
예제 #4
0
        public void ListContentCreaUnaNuevaFilaPorCadaItem()
        {
            // arrange
            var listContent = ListContentWith1StaticContent();
            var writer      = WriterFactory.MockWriter();

            // act
            listContent.Write(writer, DatasourceFactory.GetDatasourceList());

            // assert
            writer.RowCount.Should().Be.EqualTo(3);
        }
예제 #5
0
        public void ListContentEnElWriteDebeIterarLaLista()
        {
            // arrange
            var listContent = ListContentWith1StaticContent();
            var writer      = WriterFactory.MockWriter();

            // act
            var datasourceList = DatasourceFactory.GetDatasourceList();

            listContent.Write(writer, datasourceList);

            // assert
            writer.WriteCount.Should().Be.EqualTo(datasourceList.Count);
        }
예제 #6
0
        public void LaExpresionDeExpresionContentPuedeIncluirVariablesDeContextoComoFecha()
        {
            // arrange
            var datasource = DatasourceFactory.GetDatasourceSimpleObject();
            var writer     = WriterFactory.MockWriter();

            // act
            var content = new ExpressionContent();

            content.Expression = @"Context.Date.ToString(""dd/MM/yyyy"")";
            content.Write(writer, datasource);

            // assert
            writer.LastWritedText.Should().Be.EqualTo(DateTime.Today.ToString("dd/MM/yyyy"));
        }
예제 #7
0
        public void ListContentEmpiezaARenderizarDesdeUnaPosicionXY()
        {
            // arrange
            var listContent = ListContentWith1StaticContent();
            var writer      = WriterFactory.MockWriter();

            // act
            listContent.X = 5;
            listContent.Y = 2;
            listContent.Write(writer, DatasourceFactory.GetDatasourceList());

            // assert
            writer.WritedElements.First().X.Should().Be.EqualTo(listContent.X);
            writer.WritedElements.First().Y.Should().Be.EqualTo(listContent.Y);
        }
예제 #8
0
        public void ListContentDatasourceConUnaExpresionParaObtenerElListadoDesdeElModelo()
        {
            // arrange
            var listContent = ListContentWith1StaticContent();
            var writer      = WriterFactory.MockWriter();

            // act
            var datasource = DatasourceFactory.GetDatasourceSimpleObject();

            listContent.DataSourceExpression = "model.Hijos";
            listContent.Write(writer, datasource);

            // assert
            writer.WriteCount.Should().Be.EqualTo(datasource.Hijos.Count());
        }
예제 #9
0
        public void HayUnContenidoQueEsUnaExpresionEvaluadaSobreElModelo()
        {
            // arrange
            var datasource = DatasourceFactory.GetDatasourceSimpleObject();
            var writer     = WriterFactory.MockWriter();

            // act
            var content = new ExpressionContent();

            content.Expression = "model.Nombre";
            content.Write(writer, datasource);

            // assert
            writer.LastWritedText.Should().Be.EqualTo(datasource.Nombre);
        }
예제 #10
0
        public void ListContentPuedeIterarHorizontalmente()
        {
            // arrange
            var listContent = ListContentWith1StaticContent();
            var writer      = WriterFactory.MockWriter();

            // act
            listContent.Direction = DirectionEnum.Horinzontal;
            var datasourceList = DatasourceFactory.GetDatasourceList();

            listContent.Write(writer, datasourceList);

            // assert
            writer.RowCount.Should().Be.EqualTo(0);
            writer.WriteCount.Should().Be.EqualTo(datasourceList.Count);
        }
예제 #11
0
        public void UnReportDefinitionSePuedeRenderizarComoExcel()
        {
            // arrange
            var reportDefinition = ReportFactory.GetReport();
            var datasource       = DatasourceFactory.GetDatasourceSimpleObject();
            var renderer         = CreateReportRenderer();

            // act
            renderer.Render(datasource, reportDefinition, this.streamToWrite);
            streamToWrite.Close();

            // assert
            File.Exists(this.filename).Should().Be.True();
            var excelFile = this.GetStreamToWrite();

            Executing.This(() => new HSSFWorkbook(excelFile, true)).Should().NotThrow();
        }
예제 #12
0
        public void RenderizaEnExcelConExpresionesEstaticasCeldasDeterminadas()
        {
            // arrange
            var reportDefinition = ReportFactory.GetReport();
            var datasource       = DatasourceFactory.GetDatasourceSimpleObject();
            var renderer         = CreateReportRenderer();

            // act
            renderer.Render(datasource, reportDefinition, streamToWrite);
            streamToWrite.Close();

            // assert
            var sheet = GetSheet(this.filename);

            foreach (var content in reportDefinition.Contents.Contents.OfType <StaticContent>())
            {
                sheet.GetRow(content.Y.Value).GetCell(content.X.Value).StringCellValue.Should().Be.EqualTo(content.Text);
            }
        }
예제 #13
0
        public void SiElItemTemplateDeListContentTieneCeldasConMergeSeDebeRespetarElMerge()
        {
            // arrange
            var listContent = ListContentWithRowNumber();

            // act
            listContent.ItemTemplates.Add(typeof(ExcelWriter), "15");
            listContent.Write(writer, DatasourceFactory.GetDatasourceList());

            // assert
            this.EndRenderCloseStream();
            var sheet = GetSheet(this.filename);

            for (int i = 0; i < DatasourceFactory.GetDatasourceList().Count; i++)
            {
                sheet.GetRow(i).GetCell(10, NPOIUserModel.MissingCellPolicy.CREATE_NULL_AS_BLANK).NumericCellValue.Should().Be.EqualTo(6);
                sheet.GetRow(i).GetCell(10).IsMergedCell.Should().Be(true);
                sheet.GetRow(i).GetCell(11).IsMergedCell.Should().Be(true);
            }
        }
예제 #14
0
        public void EnExcelSiElContenidoNoTieneCoordenadasDebenIrEnColumnasContiguas()
        {
            // arrange
            var reportDefinition = ReportFactory.GetReportSinCoordenadas();
            var datasource       = DatasourceFactory.GetDatasourceSimpleObject();
            var renderer         = CreateReportRenderer();

            // act
            renderer.Render(datasource, reportDefinition, streamToWrite);
            streamToWrite.Close();

            // assert
            var sheet = GetSheet(this.filename);

            var row = sheet.GetRow(0);

            for (int i = 0; i < reportDefinition.Contents.Contents.Count(); i++)
            {
                row.Cells[i].ColumnIndex.Should("cell" + i).Be.EqualTo(i);
            }
        }
예제 #15
0
        public void ListContentPuedeRenderizarElNumeroDeItemAIterar()
        {
            // arrange
            var listContent = new ListContent();

            listContent.Content.AddContent(new ExpressionContent {
                Expression = "Context.ItemNumber"
            });
            var writer = WriterFactory.MockWriter();

            // act
            var datasourceList = DatasourceFactory.GetDatasourceList();

            listContent.Write(writer, datasourceList);

            // assert
            for (int i = 0; i < writer.TextWrited.Count(); i++)
            {
                writer.WritedElements.ToArray()[i].Text.Should().Be.EqualTo((i + 1).ToString());
            }
        }
예제 #16
0
        public void ListContentEmpiezaARenderizarDesdeUnaPosicionXY()
        {
            // arrange
            var listContent = ListContentWithRowNumber();

            // act
            listContent.X = 5;
            listContent.Y = 2;
            listContent.Write(writer, DatasourceFactory.GetDatasourceList());

            // assert
            this.EndRenderCloseStream();
            var sheet = GetSheet(this.filename);

            sheet.GetRow(listContent.Y.Value).GetCell(listContent.X.Value, NPOIUserModel.MissingCellPolicy.CREATE_NULL_AS_BLANK).StringCellValue.Should().Be.EqualTo(
                "1");
            sheet.GetRow(listContent.Y.Value + 1).GetCell(listContent.X.Value, NPOIUserModel.MissingCellPolicy.CREATE_NULL_AS_BLANK).StringCellValue.Should().Be.EqualTo(
                "2");
            sheet.GetRow(listContent.Y.Value + 2).GetCell(listContent.X.Value, NPOIUserModel.MissingCellPolicy.CREATE_NULL_AS_BLANK).StringCellValue.Should().Be.EqualTo(
                "3");
        }
예제 #17
0
        public void ConListAnidadosDebeMantenerElItemNumberDeCadaListaIndependiente()
        {
            // arrange
            var listContentMaster = new ListContent();

            listContentMaster.Content.AddContent(new ExpressionContent {
                Expression = "Context.ItemNumber"
            });
            var listContentChild = new ListContent();

            listContentMaster.Content.AddContent(listContentChild);
            listContentChild.Content.AddContent(new ExpressionContent {
                Expression = "Context.ItemNumber"
            });
            var datasourceList = DatasourceFactory.GetDatasourceList();

            listContentChild.DataSource = datasourceList;
            var writer = WriterFactory.MockWriter();

            // act
            listContentMaster.Write(writer, datasourceList);

            // assert
            int textWritedCounter = 0;

            for (int i = 0; i < datasourceList.Count; i++)
            {
                Console.WriteLine(textWritedCounter.ToString() + ": " + writer.WritedElements.ToArray()[textWritedCounter].Text);
                writer.WritedElements.ToArray()[textWritedCounter].Text.Should().Be.EqualTo((i + 1).ToString());
                textWritedCounter++;
                for (int j = 0; j < datasourceList.Count; j++)
                {
                    Console.WriteLine(textWritedCounter.ToString() + ": " + writer.WritedElements.ToArray()[textWritedCounter].Text);
                    writer.WritedElements.ToArray()[textWritedCounter].Text.Should().Be.EqualTo((j + 1).ToString());
                    textWritedCounter++;
                }
            }
        }