Exemplo n.º 1
0
        public void Constructor()
        {
            var logger = new MockLogger();
            var zipReader = kernel.Get<IZipFileReaderWrapper>();
            var checkSumGen = kernel.Get<ICheckSumGenerator>();
            var fileSystem = kernel.Get<IFileSystem>();
            var serializeWrapper = kernel.Get<ISerializeWrapper>();
            string zipFile = Path.Combine(GetTestDataPath(), zipFilename);

            var actualReader = new ZipBundleReader(
                zipFile,
                unpackDir,
                zipReader,
                checkSumGen,
                logger,
                fileSystem,
                serializeWrapper);

            Assert.NotNull(actualReader);

            actualReader = null;
            zipReader = null;
            checkSumGen = null;
            fileSystem = null;
            serializeWrapper = null;
        }
Exemplo n.º 2
0
        public void Read_Report_ChecksumMismatch()
        {
            string entryName = "ExportSummary.json";
            int expectedSuccessful = 2;
            int expectedFailed = 1;
            string expectedFailedFilename = "C:\\temp\\Export\\SSRSMigrate_AW_Tests\\Reports\\Company Sales.rdl";
            string expectedFailedPath = "Export\\SSRSMigrate_AW_Tests\\Reports";
            string expectedFailedChecksum = "BAD CHECKSUM HERE";
            int actualSuccessful = 0;
            int actualFailed = 0;
            string actualFailedChecksum = null;
            string actualFailedFilename = null;
            string actualFailedPath = null;

            var readerMock = new Mock<IZipFileReaderWrapper>();
            var serializeMock = new Mock<ISerializeWrapper>();

            readerMock.Setup(z => z.ReadEntry(entryName))
                .Returns(() => exportSummaryChecksumMismatch);

            serializeMock.Setup(
                s => s.DeserializeObject<BundleSummary>(exportSummaryChecksumMismatch))
                .Returns(() => bundleSummaryChecksumMismatch);

            var logger = new MockLogger();

            var reader = new ZipBundleReader(
                        zipFileName,
                        unPackDirectory,
                        readerMock.Object,
                        checkSumGenMock.Object,
                        logger,
                        fileSystemMock.Object,
                        serializeMock.Object);

            reader.ReadExportSummary();

            reader.OnReportRead += delegate(IBundleReader sender, ItemReadEvent e)
            {
                if (e.Success)
                    actualSuccessful++;
                else
                {
                    actualFailed++;
                    actualFailedPath = e.Path;
                    actualFailedChecksum = e.CheckSum;
                    actualFailedFilename = e.FileName;
                }
            };

            reader.Read();

            Assert.AreEqual(expectedSuccessful, actualSuccessful);
            Assert.AreEqual(expectedFailed, actualFailed);
            Assert.AreEqual(expectedFailedChecksum, actualFailedChecksum);
            Assert.AreEqual(expectedFailedFilename, actualFailedFilename);
            Assert.AreEqual(expectedFailedPath, actualFailedPath);
        }
Exemplo n.º 3
0
        public void Read_FileDoesntExist()
        {
            string entryName = "ExportSummary.json";
            int expectedSuccessfulReports = 3;
            int expectedFailedReports = 1;
            string expectedFailedReportName = "C:\\temp\\Export\\SSRSMigrate_AW_Tests\\Reports\\File Doesnt Exist.rdl";
            int actualSuccessfulReports = 0;
            int actualFailedReports = 0;
            string actualFailedReportName = null;

            var readerMock = new Mock<IZipFileReaderWrapper>();
            var serializeMock = new Mock<ISerializeWrapper>();

            readerMock.Setup(z => z.ReadEntry(entryName))
                .Returns(() => exportSummaryFileDoesntExist);

            serializeMock.Setup(
                s => s.DeserializeObject<BundleSummary>(exportSummaryFileDoesntExist))
                .Returns(() => bundleSummaryFileDoesntExist);

            var logger = new MockLogger();

            var reader = new ZipBundleReader(
                        zipFileName,
                        unPackDirectory,
                        readerMock.Object,
                        checkSumGenMock.Object,
                        logger,
                        fileSystemMock.Object,
                        serializeMock.Object);

            reader.ReadExportSummary();

            reader.OnReportRead += delegate(IBundleReader sender, ItemReadEvent e)
            {
                if (e.Success)
                    actualSuccessfulReports++;
                else
                {
                    actualFailedReports++;
                    actualFailedReportName = e.FileName;
                }
            };

            reader.Read();

            Assert.AreEqual(expectedSuccessfulReports, actualSuccessfulReports);
            Assert.AreEqual(expectedFailedReports, actualFailedReports);
            Assert.AreEqual(expectedFailedReportName, actualFailedReportName);
        }
Exemplo n.º 4
0
        public void ReadExportSummary_EntryDoesntExist()
        {
            string entryName = "ExportSummary.json";

            var readerMock = new Mock<IZipFileReaderWrapper>();

            readerMock.Setup(z => z.ReadEntry(entryName))
                .Throws(new FileNotFoundException(entryName));

            var logger = new MockLogger();

            var reader = new ZipBundleReader(
                        zipFileName,
                        unPackDirectory,
                        readerMock.Object,
                        checkSumGenMock.Object,
                        logger,
                        fileSystemMock.Object,
                        serializeWrapperMock.Object);

            FileNotFoundException ex = Assert.Throws<FileNotFoundException>(
                delegate
                {
                    reader.ReadExportSummary();
                });

            Assert.That(ex.Message, Is.EqualTo(entryName));
        }
Exemplo n.º 5
0
        public void ReadExportSummary_EmptySummary()
        {
            string entryName = "ExportSummary.json";

            var readerMock = new Mock<IZipFileReaderWrapper>();

            readerMock.Setup(z => z.ReadEntry(entryName))
                .Returns(() => null);

            var logger = new MockLogger();

            var reader = new ZipBundleReader(
                        zipFileName,
                        unPackDirectory,
                        readerMock.Object,
                        checkSumGenMock.Object,
                        logger,
                        fileSystemMock.Object,
                        serializeWrapperMock.Object);

            Exception ex = Assert.Throws<Exception>(
                delegate
                {
                    reader.ReadExportSummary();
                });

            Assert.That(ex.Message, Is.EqualTo("No data in export summary."));
            Assert.AreEqual(0, reader.Summary.Entries["DataSources"].Count);
            Assert.AreEqual(0, reader.Summary.Entries["Reports"].Count);
            Assert.AreEqual(0, reader.Summary.Entries["Folders"].Count);
        }
Exemplo n.º 6
0
        public void Constructor_InvalidFileName()
        {
            InvalidFileArchiveException ex = Assert.Throws<InvalidFileArchiveException>(
                delegate
                {
                    var logger = new MockLogger();

                    var reader = new ZipBundleReader(
                                "NotAZip.txt",
                                unPackDirectory,
                                zipReaderMock.Object,
                                checkSumGenMock.Object,
                                logger,
                                fileSystemMock.Object,
                                serializeWrapperMock.Object);
                });

            Assert.That(ex.Message, Is.EqualTo("'NotAZip.txt' is not a valid archive."));
        }
Exemplo n.º 7
0
        public void Constructor()
        {
            var logger = new MockLogger();

            var actual = new ZipBundleReader(
                zipFileName,
                unPackDirectory,
                zipReaderMock.Object,
                checkSumGenMock.Object,
                logger,
                fileSystemMock.Object,
                serializeWrapperMock.Object);

            Assert.NotNull(actual);
        }
Exemplo n.º 8
0
        public void TearDown()
        {
            // Unsubscribe to events after each test
            zipBundleReader.OnDataSourceRead -= OnDataSourceReadEvent;
            zipBundleReader.OnFolderRead -= OnFolderReadEvent;
            zipBundleReader.OnReportRead -= OnReportReadEvent;

            zipBundleReader = null;
        }
Exemplo n.º 9
0
        public void SetUp()
        {
            // Initialize for each test so the entries don't get duplicated in ZipBundleReader
            var logger = new MockLogger();

            zipBundleReader = new ZipBundleReader(
                zipFileName,
                unPackDirectory,
                zipReaderMock.Object,
                checkSumGenMock.Object,
                logger,
                fileSystemMock.Object,
                serializeWrapperMock.Object
                );

            // Subscribe to the events again for each test
            zipBundleReader.OnDataSourceRead += OnDataSourceReadEvent;
            zipBundleReader.OnFolderRead += OnFolderReadEvent;
            zipBundleReader.OnReportRead += OnReportReadEvent;

            // Recreate each a list before each test
            actualReports = new List<string>();
            actualFolders = new List<string>();
            actualDataSources = new List<string>();
        }
Exemplo n.º 10
0
        public void Constructor_ArchiveNotFound()
        {
            var logger = new MockLogger();
            var zipReader = kernel.Get<IZipFileReaderWrapper>();
            var checkSumGen = kernel.Get<ICheckSumGenerator>();
            var fileSystem = kernel.Get<IFileSystem>();
            var serializeWrapper = kernel.Get<ISerializeWrapper>();
            string zipFile = Path.Combine(GetTestDataPath(), "NotFound.zip");

            InvalidFileArchiveException ex = Assert.Throws<InvalidFileArchiveException>(
                delegate
                {
                    var actualReader = new ZipBundleReader(
                       zipFile,
                       unpackDir,
                       zipReader,
                       checkSumGen,
                       logger,
                       fileSystem,
                       serializeWrapper);
                });

            Assert.That(ex.Message, Is.EqualTo(string.Format("'{0}' is not a valid archive.", zipFile)));

            zipReader = null;
            checkSumGen = null;
            fileSystem = null;
            serializeWrapper = null;
        }
Exemplo n.º 11
0
        public void Read_Report_ChecksumMismatch()
        {
            var logger = new MockLogger();
            var zipReader = kernel.Get<IZipFileReaderWrapper>();
            var checkSumGen = kernel.Get<ICheckSumGenerator>();
            var fileSystem = kernel.Get<IFileSystem>();
            var serializeWrapper = kernel.Get<ISerializeWrapper>();
            string zipFile = Path.Combine(GetTestDataPath(), "InvalidChecksum.zip");

            var actualReader = new ZipBundleReader(
                       zipFile,
                       unpackDir,
                       zipReader,
                       checkSumGen,
                       logger,
                       fileSystem,
                       serializeWrapper);

            string actualUnPackDir = actualReader.Extract();

            // This is the file on disk that has an invalid checksum
            string expectedFailedFilename = Path.Combine(actualUnPackDir, "Export\\SSRSMigrate_AW_Tests\\Reports\\Company Sales.rdl");
            string expectedFailedChecksum = "BAD CHECKSUM HERE";

            // Set expected values
            int expectedSuccessful = 2;
            int expectedFailed = 1;

            // Actual values
            int actualSuccessful = 0;
            int actualFailed = 0;
            string actualFailedFilename = null;
            string actualFailedChecksum = null;
            string actualFailedPath = null;

            actualReader.OnReportRead += delegate(IBundleReader sender, ItemReadEvent e)
            {
                if (e.Success)
                    actualSuccessful++;
                else
                {
                    actualFailed++;
                    actualFailedPath = e.Path;
                    actualFailedFilename = e.FileName;
                    actualFailedChecksum = e.CheckSum;
                }
            };

            actualReader.ReadExportSummary();
            actualReader.Read();

            Assert.AreEqual(expectedSuccessful, actualSuccessful);
            Assert.AreEqual(expectedFailed, actualFailed);
            Assert.AreEqual(expectedFailedChecksum, actualFailedChecksum);
            Assert.AreEqual(expectedFailedFilename, actualFailedFilename);
        }
Exemplo n.º 12
0
        public void Read_FileDoesntExist()
        {
            var logger = new MockLogger();
            var zipReader = kernel.Get<IZipFileReaderWrapper>();
            var checkSumGen = kernel.Get<ICheckSumGenerator>();
            var fileSystem = kernel.Get<IFileSystem>();
            var serializeWrapper = kernel.Get<ISerializeWrapper>();
            string zipFile = Path.Combine(GetTestDataPath(), zipFilename);

            var actualReader = new ZipBundleReader(
                       zipFile,
                       unpackDir,
                       zipReader,
                       checkSumGen,
                       logger,
                       fileSystem,
                       serializeWrapper);

            string actualUnPackDir = actualReader.Extract();

            // This is the file to delete on disk to simulate a report not extracted
            string expectedFailedReportName = Path.Combine(actualUnPackDir, "Export\\SSRSMigrate_AW_Tests\\Reports\\Company Sales.rdl");

            // Delete this file from the extraction directory, for the purpose of testing for a file that does not exist
            File.Delete(expectedFailedReportName);

            // Set expected values
            int expectedSuccessfulReports = 2;
            int expectedFailedReports = 1;
            int actualSuccessfulReports = 0;
            int actualFailedReports = 0;
            string actualFailedReportName = null;

            actualReader.OnReportRead += delegate(IBundleReader sender, ItemReadEvent e)
            {
                if (e.Success)
                    actualSuccessfulReports++;
                else
                {
                    actualFailedReports++;
                    actualFailedReportName = e.FileName;
                }
            };

            actualReader.ReadExportSummary();
            actualReader.Read();

            Assert.AreEqual(expectedSuccessfulReports, actualSuccessfulReports, "Successful Reports");
            Assert.AreEqual(expectedFailedReports, actualFailedReports, "Failed Reports");
            Assert.AreEqual(expectedFailedReportName, actualFailedReportName, "Report Name");
        }
Exemplo n.º 13
0
        public void ReadExportSummary_EntryDoesntExist()
        {
            var logger = new MockLogger();
            var zipReader = kernel.Get<IZipFileReaderWrapper>();
            var checkSumGen = kernel.Get<ICheckSumGenerator>();
            var fileSystem = kernel.Get<IFileSystem>();
            var serializeWrapper = kernel.Get<ISerializeWrapper>();
            string zipFile = Path.Combine(GetTestDataPath(), "EntryDoesntExist.zip");

            var actualReader = new ZipBundleReader(
                       zipFile,
                       unpackDir,
                       zipReader,
                       checkSumGen,
                       logger,
                       fileSystem,
                       serializeWrapper);

            FileNotFoundException ex = Assert.Throws<FileNotFoundException>(
                delegate
                {
                    actualReader.ReadExportSummary();
                });

            Assert.That(ex.Message, Is.EqualTo("ExportSummary.json"));

            zipReader = null;
            checkSumGen = null;
            fileSystem = null;
            serializeWrapper = null;
        }