Exemplo n.º 1
0
        public void WHEN_no_path_supplied_THEN_argument_exception_thrown(string?path)
        {
            Func <PBIFile> sut = () => PBIReader.OpenFile(path);

            sut.Should().Throw <ArgumentException>();

            Func <Task <PBIFile> > sutAsync = async() => await PBIReader.OpenFileAsync(path);

            sutAsync.Should().Throw <ArgumentException>();
        }
Exemplo n.º 2
0
        public async Task WHEN_pbi_file_is_read_THEN_expected_file_version_is_returned(
            string filename, string expectedVersion)
        {
            var fullPath = Path.Combine(_testFilePath, filename);

            var sut = await PBIReader.OpenFileAsync(fullPath);

            var fileVersion = sut.ReadFileVersion();

            fileVersion.Should().Be(expectedVersion);
        }
Exemplo n.º 3
0
        public async Task WHEN_path_resolves_to_a_pbix_or_pbit_THEN_the_file_is_read_async_nd_pbi_file_object_returned(string filename)
        {
            var fullPath = Path.Combine(_testFilePath, filename);

            var sut = await PBIReader.OpenFileAsync(fullPath);

            sut.Should().NotBeNull();
            sut.CanRead.Should().BeTrue();
            sut.FileLength.Should().BeGreaterThan(0);
            sut.IsValidPbiFile.Should().BeTrue();
        }
        public async Task WHEN_file_supplied_THEN_all_visual_formatting_can_be_read(
            string filename)
        {
            var fullPath = Path.Combine(_testFilePath, filename);

            var sut = await PBIReader.OpenFileAsync(fullPath);

            var reportLayout = sut.ReadReportLayout();

            reportLayout.Should().NotBeNull();

            reportLayout.ReportPages.Should().HaveCount(1);
            var visuals = reportLayout.ReportPages[0].VisualElements;

            visuals.Should().HaveCount(5);
            var textBoxes = visuals.FindAll(x => x.VisualType == "textbox");
            var cards     = visuals.FindAll(x => x.VisualType == "card");
            var barChart  = visuals.Find(x => x.VisualType == "clusteredBarChart");

            textBoxes.Should().HaveCount(2);
            cards.Should().HaveCount(2);
            barChart.Should().NotBeNull();

            var barChartFormatting = new List <ConfigurableProperty>();
            var foundFormatting    = barChart?.TryGetVisualFormatting(out barChartFormatting);

            foundFormatting.Should().BeTrue();
            barChartFormatting.Should().NotBeNull();
            barChartFormatting?.Count.Should().BeGreaterThan(0);

            if (barChartFormatting != null && barChartFormatting.TryGetProperty(new string[3]
            {
                "labels", "properties", "backgroundColor"
            }
                                                                                , out var labelBackground))
            {
                labelBackground.Should().NotBeNull();
                labelBackground?.ChildProperties.Should().HaveCountGreaterThan(0);
                labelBackground?.GetPropertyType()
                .Should()
                .Be(ConfigurablePropertyType.solidColor);
            }

            if (barChartFormatting != null && barChartFormatting.TryGetProperty(new string[3]
            {
                "background", "properties", "show"
            }
                                                                                , out var backgroundShow))
            {
                backgroundShow.Should().NotBeNull();
                backgroundShow?.ChildProperties.Should().HaveCountGreaterThan(0);
            }
        }
        public async Task WHEN_pbi_file_is_read_THEN_report_layout_is_returned(
            string filename)
        {
            var fullPath = Path.Combine(_testFilePath, filename);

            var sut = await PBIReader.OpenFileAsync(fullPath);

            var reportLayout = sut.ReadReportLayout();

            reportLayout.Should().NotBeNull();
            reportLayout.Configuration.Count.Should().BeGreaterThan(0);
            reportLayout.ReportPages.Should().HaveCount(2);

            reportLayout.ReportPages[0].Name.Should().Be("ReportSection");
            reportLayout.ReportPages[0].DisplayName.Should().Be("Page With Shape");
            reportLayout.ReportPages[0].Ordinal.Should().Be(0);
            reportLayout.ReportPages[0]
            .TryGetPageFormatting(out var pageOneFormatting)
            .Should().BeTrue();

            reportLayout.ReportPages[1].Name.Should().Be("ReportSection8ce75128eea8b556229d");
            reportLayout.ReportPages[1].DisplayName.Should().Be("Page With Text");
            reportLayout.ReportPages[1].Ordinal.Should().Be(1);
            reportLayout.ReportPages[1]
            .TryGetPageFormatting(out var pageTwoFormatting)
            .Should().BeTrue();

            pageOneFormatting.Should().HaveCountGreaterThan(0);
            pageTwoFormatting.Should().HaveCountGreaterThan(0);

            reportLayout.ReportPages.ForEach(x =>
            {
                x.Size.Width.Should().Be(1280);
                x.Size.Height.Should().Be(720);
                x.DisplayOption.Should().Be(ReportPageDisplayOption.SixteenByNine);
                x.VisualElements.Should().HaveCount(1);
                x.Configuration.Should().HaveCountGreaterThan(0);

                x.VisualElements[0].Name.Should().BeOneOf("ead243d7cba56d441a8a", "acc05e753689024961e8");
                x.VisualElements[0].VisualType.Should().BeOneOf("shape", "textbox");
                x.VisualElements[0].Configuration.Should().HaveCountGreaterThan(0);
                x.VisualElements[0].Size.Width.Should().BeGreaterThan(0);
                x.VisualElements[0].Size.Height.Should().BeGreaterThan(0);
                x.VisualElements[0].Location.X.Should().BeGreaterThan(0);
                x.VisualElements[0].Location.Y.Should().BeGreaterThan(0);
                x.VisualElements[0].Location.Z.Should().BeGreaterOrEqualTo(0);

                x.VisualElements[0].TryGetVisualFormatting(out var formattingProperties)
                .Should().BeTrue();

                formattingProperties.Should().HaveCountGreaterThan(0);
            });
        }
Exemplo n.º 6
0
        public async Task WHEN_pbi_file_is_read_THEN_diagram_layout_is_returned(
            string filename, int numberOfDiagrams, string version)
        {
            var fullPath = Path.Combine(_testFilePath, filename);

            var sut = await PBIReader.OpenFileAsync(fullPath);

            var diagramLayout = sut.ReadDiagramLayout();

            diagramLayout.Should().NotBeNull();
            diagramLayout?.Diagrams.Count.Should().Be(numberOfDiagrams);
            diagramLayout?.Version.Should().Be(version);
        }
Exemplo n.º 7
0
        public async Task WHEN_stream_contains_pbix_or_pbit_data_THEN_the_file_is_read_async_and_pbi_file_object_returned(string filename)
        {
            var fullPath = Path.Combine(_testFilePath, filename);

            using var asyncFileStream = new FileStream(fullPath, FileMode.Open);

            var sutAsync = await PBIReader.OpenFileAsync(asyncFileStream);

            sutAsync.Should().NotBeNull();
            sutAsync.CanRead.Should().BeTrue();
            sutAsync.FileLength.Should().Be(asyncFileStream.Length);
            sutAsync.IsValidPbiFile.Should().BeTrue();
        }
Exemplo n.º 8
0
        public void WHEN_stream_is_null_THEN_an_argument_exception_is_thrown()
        {
            Stream?stream = null;

            Func <PBIFile> sut = () => PBIReader.OpenFile(stream);

            sut.Should().Throw <ArgumentException>()
            .WithMessage("'fileStream' cannot be null.");

            Func <Task <PBIFile> > sutAsync = async() => await PBIReader.OpenFileAsync(stream);

            sutAsync.Should().Throw <ArgumentException>()
            .WithMessage($"'fileStream' cannot be null.");
        }
Exemplo n.º 9
0
        public void WHEN_path_does_not_resolve_to_a_file_THEN_file_not_found_exception_thrown(string filename)
        {
            var fullPath = Path.Combine(_testFilePath, filename);

            Func <PBIFile> sut = () => PBIReader.OpenFile(fullPath);

            sut.Should().Throw <FileNotFoundException>()
            .WithMessage($"file: '{fullPath}' was not found.");

            Func <Task <PBIFile> > sutAsync = async() => await PBIReader.OpenFileAsync(fullPath);

            sutAsync.Should().Throw <FileNotFoundException>()
            .WithMessage($"file: '{fullPath}' was not found.");
        }
Exemplo n.º 10
0
        public void WHEN_stream_contains_pbix_or_pbit_data_THEN_the_file_is_read_and_pbi_file_object_returned(string filename)
        {
            var fullPath = Path.Combine(_testFilePath, filename);

            using var fileStream = new FileStream(fullPath, FileMode.Open);
            var length = fileStream.Length;

            var sut = PBIReader.OpenFile(fileStream);

            sut.Should().NotBeNull();
            sut.CanRead.Should().BeTrue();
            sut.FileLength.Should().Be(length);
            sut.IsValidPbiFile.Should().BeTrue();
        }
Exemplo n.º 11
0
        public void WHEN_stream_cannot_be_read_THEN_an_argument_exception_is_thrown()
        {
            var stream = new WriteOnlyStream();

            Func <PBIFile> sut = () => PBIReader.OpenFile(stream);

            sut.Should().Throw <ArgumentException>()
            .WithMessage("'fileStream' cannot be read.");

            Func <Task <PBIFile> > sutAsync = async() => await PBIReader.OpenFileAsync(stream);

            sutAsync.Should().Throw <ArgumentException>()
            .WithMessage($"'fileStream' cannot be read.");
        }
Exemplo n.º 12
0
        public async Task WHEN_diagram_layout_returned_THEN_it_contains_expected_values(string filename)
        {
            var fullPath = Path.Combine(_testFilePath, filename);

            var sut = await PBIReader.OpenFileAsync(fullPath);

            var diagramLayout = sut.ReadDiagramLayout();

            diagramLayout.Should().NotBeNull();

            var diagramOne   = diagramLayout?.Diagrams.First(x => x.Ordinal == 0);
            var diagramTwo   = diagramLayout?.Diagrams.First(x => x.Ordinal == 1);
            var diagramThree = diagramLayout?.Diagrams.First(x => x.Ordinal == 2);

            diagramLayout?.DefaultDiagram.Should().Be(AllTables);
            diagramLayout?.SelectedDiagram.Should().Be(SelectedDiagram);

            diagramOne?.Name.Should().Be(AllTables);
            diagramOne?.Nodes.Should().HaveCount(2);
            diagramOne?.Nodes.First().NodeIndex.Should().Be(TableOne);
            diagramOne?.Nodes.First().Location.Should().NotBeNull();
            diagramOne?.Nodes.First().Size.Should().NotBeNull();
            diagramOne?.Nodes.Last().NodeIndex.Should().Be(TableTwo);
            diagramOne?.Nodes.Last().Location.Should().NotBeNull();
            diagramOne?.Nodes.Last().Size.Should().NotBeNull();

            diagramTwo?.Name.Should().Be(LayoutOne);
            diagramTwo?.Nodes.Should().HaveCount(1);
            diagramTwo?.Nodes.First().NodeIndex.Should().Be(TableOne);
            diagramTwo?.Nodes.First().Location.Should().NotBeNull();
            diagramTwo?.Nodes.First().Size.Should().NotBeNull();

            diagramThree?.Name.Should().Be(LayoutTwo);
            diagramThree?.Nodes.Should().HaveCount(1);
            diagramThree?.Nodes.First().NodeIndex.Should().Be(TableTwo);
            diagramThree?.Nodes.First().Location.Should().NotBeNull();
            diagramThree?.Nodes.First().Size.Should().NotBeNull();
        }