コード例 #1
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);
        }
コード例 #2
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);
        }
コード例 #3
0
        public void Read()
        {
            zipBundleReader.ReadExportSummary();

            zipBundleReader.Read();

            Assert.AreEqual(2, actualDataSources.Count);
            Assert.AreEqual(4, actualFolders.Count);
            Assert.AreEqual(3, actualReports.Count);
        }
コード例 #4
0
        public void Read_DirectoryDoesntExist()
        {
            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 directory to delete on disk to simulate a folder not extracted
            string expectedFailedFolderName = Path.Combine(actualUnPackDir, "Export\\SSRSMigrate_AW_Tests\\Reports\\Sub Folder");

            // Delete this directory from the extraction directory, for the purpose of testing for a folder that does not exist
            Directory.Delete(expectedFailedFolderName, true);

            // Set expected values
            int    expectedSuccessfulFolders = 2;
            int    expectedFailedFolders     = 1;
            int    actualSuccessfulFolders   = 0;
            int    actualFailedFolders       = 0;
            string actualFailedFoldersName   = null;

            actualReader.OnFolderRead += delegate(IBundleReader sender, ItemReadEvent e)
            {
                if (e.Success)
                {
                    actualSuccessfulFolders++;
                }
                else
                {
                    actualFailedFolders++;
                    actualFailedFoldersName = e.FileName;
                }
            };

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

            Assert.AreEqual(expectedSuccessfulFolders, actualSuccessfulFolders, "Successful Folders");
            Assert.AreEqual(expectedFailedFolders, actualFailedFolders, "Failed Folders");
            Assert.AreEqual(expectedFailedFolderName, actualFailedFoldersName, "Folders Name");
        }
コード例 #5
0
        public void Read_DirectoryDoesntExist()
        {
            string entryName = "ExportSummary.json";
            int    expectedSuccessfulDirectories = 4;
            int    expectedFailedDirectories     = 1;
            string expectedFailedDirectoryName   = "C:\\temp\\Export\\SSRSMigrate_AW_Tests\\Folder Doesnt Exist";
            int    actualSuccessfulDirectories   = 0;
            int    actualFailedDirectories       = 0;
            string actualFailedDirectoryName     = null;

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

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

            serializeMock.Setup(
                s => s.DeserializeObject <BundleSummary>(exportSummaryDirectoryDoesntExist))
            .Returns(() => bundleSummaryDirectoryDoesntExist);

            var logger = new MockLogger();

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

            reader.ReadExportSummary();

            reader.OnFolderRead += delegate(IBundleReader sender, ItemReadEvent e)
            {
                if (e.Success)
                {
                    actualSuccessfulDirectories++;
                }
                else
                {
                    actualFailedDirectories++;
                    actualFailedDirectoryName = e.FileName;
                }
            };

            reader.Read();

            Assert.AreEqual(expectedSuccessfulDirectories, actualSuccessfulDirectories);
            Assert.AreEqual(expectedFailedDirectories, actualFailedDirectories);
            Assert.AreEqual(expectedFailedDirectoryName, actualFailedDirectoryName);
        }