Esempio n. 1
0
        public void Write_GivenNullTableDefinitions_ReturnsNull()
        {
            //Arrange
            DatasetDefinition datasetDefinition = new DatasetDefinition();

            DataDefinitionExcelWriter writer = new DataDefinitionExcelWriter();

            //Act
            byte[] excelBytes = writer.Write(datasetDefinition);

            //Assert
            excelBytes
            .Should()
            .BeNull();
        }
Esempio n. 2
0
        public void Write_GivenValidDefinitionWithTwoTableDefinitions_CreatesExcelBytes()
        {
            //Arrange
            DatasetDefinition datasetDefinition = CreateDatasetDefinitionWithTwoTableDefinitions();

            DataDefinitionExcelWriter writer = new DataDefinitionExcelWriter();

            //Act
            byte[] excelBytes = writer.Write(datasetDefinition);

            //Assert
            excelBytes
            .Should()
            .NotBeNull();

            excelBytes
            .Length
            .Should()
            .BeGreaterThan(0);

            using (Stream excelStream = new MemoryStream(excelBytes))
            {
                ExcelPackage excelPackage = new ExcelPackage(excelStream);

                excelPackage.Workbook.Should().NotBeNull();
                excelPackage.Workbook.Worksheets.Count.Should().Be(2);
                excelPackage.Workbook.Worksheets.First().Name.Should().Be("Test Table Def 1");
                excelPackage.Workbook.Worksheets.First().Cells.Count().Should().Be(2);
                excelPackage.Workbook.Worksheets.First().Cells[1, 1].Value.Should().Be("Test field name 1");
                excelPackage.Workbook.Worksheets.First().Cells[1, 1].Comment.Should().NotBeNull();
                excelPackage.Workbook.Worksheets.First().Cells[1, 1].Comment.Text.Should().Be("Description: Test description 1\n Required: No\n Type: String");
                excelPackage.Workbook.Worksheets.First().Cells[1, 2].Value.Should().Be("Test field name 2");
                excelPackage.Workbook.Worksheets.First().Cells[1, 2].Comment.Should().NotBeNull();
                excelPackage.Workbook.Worksheets.First().Cells[1, 2].Comment.Text.Should().Be("Description: Test description 2\n Required: No\n Type: String");
                excelPackage.Workbook.Worksheets.Last().Name.Should().Be("Test Table Def 2");
                excelPackage.Workbook.Worksheets.Last().Cells.Count().Should().Be(2);
                excelPackage.Workbook.Worksheets.Last().Cells[1, 1].Value.Should().Be("Test field name 3");
                excelPackage.Workbook.Worksheets.Last().Cells[1, 1].Comment.Should().NotBeNull();
                excelPackage.Workbook.Worksheets.Last().Cells[1, 1].Comment.Text.Should().Be("Description: Test description 3\n Required: No\n Type: String");
                excelPackage.Workbook.Worksheets.Last().Cells[1, 2].Value.Should().Be("Test field name 4");
                excelPackage.Workbook.Worksheets.Last().Cells[1, 2].Comment.Should().NotBeNull();
                excelPackage.Workbook.Worksheets.Last().Cells[1, 2].Comment.Text.Should().Be("Description: Test description 4\n Required: No\n Type: String");
            }
        }