Ejemplo 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;
        }
Ejemplo n.º 2
0
        public void ReportServerWriter_NullRepository()
        {
            MockLogger logger = new MockLogger();

            ArgumentNullException ex = Assert.Throws<ArgumentNullException>(
               delegate
               {
                   ReportServerWriter writer = new ReportServerWriter(null, logger);
               });

            Assert.That(ex.Message, Is.EqualTo("Value cannot be null.\r\nParameter name: repository"));
        }
Ejemplo n.º 3
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>();
        }
        public void TestFixtureSetUp()
        {
            loggerMock = new MockLogger();
            fileSystemMock = new Mock<IFileSystem>();
            serializeWrapperMock = new Mock<ISerializeWrapper>();

            // ISystemIOWrapper.File.ReadAllText Method Mocks
            fileSystemMock.Setup(f => f.File.ReadAllText(expectedAWDataSourceFileName))
                .Returns(() => expectedAWDataSource);

            fileSystemMock.Setup(f => f.File.ReadAllText(expectedAWDataSource_DeserializeException_FileName))
                .Returns(() => expectedAWDataSource_DeserializeException);

            // ISystemIOWrapper.File.Exists Method Mocks
            fileSystemMock.Setup(f => f.File.Exists(expectedAWDataSourceFileName))
                .Returns(() => true);

            fileSystemMock.Setup(f => f.File.Exists(expectedAWDataSource_DeserializeException_FileName))
                .Returns(() => true);

            fileSystemMock.Setup(f => f.File.Exists(expectedDataSourceItem_NotFound_Filename))
                .Returns(() => false);

            // ISystemIOWrapper.Path.GetDirectoryName Method Mocks
            fileSystemMock.Setup(f => f.Path.GetDirectoryName(expectedAWDataSourceFileName))
                .Returns(() => expectedAWDataSourcePath);

            fileSystemMock.Setup(f => f.Path.GetDirectoryName(expectedAWDataSource_DeserializeException_FileName))
               .Returns(() => expectedAWDataSourcePath_DeserializeException);

            // ISerializeWrapper.DeserializeObject<DataSourceItem> Method Mocks
            serializeWrapperMock.Setup(s => s.DeserializeObject<DataSourceItem>(expectedAWDataSource))
                .Returns(() => expectedAWDataSourceItem);

            serializeWrapperMock.Setup(
                s => s.DeserializeObject<DataSourceItem>(expectedAWDataSource_DeserializeException))
                .Throws(
                    new JsonSerializationException(
                        "Unexpected end when deserializing object. Path 'Password', line 10, position 20."));

            importer = new DataSourceItemImporter(serializeWrapperMock.Object, fileSystemMock.Object, loggerMock);
        }
Ejemplo n.º 5
0
        public void Constructor()
        {
            MockLogger logger = new MockLogger();

            ZipBundler actual = new ZipBundler(zipFileMock.Object, checkSumGenMock.Object, logger, serializeWrapperMock.Object);

            Assert.NotNull(actual);
        }
Ejemplo n.º 6
0
        public void TestFixtureSetUp()
        {
            loggerMock = new MockLogger();
            fileSystemMock = new Mock<IFileSystem>();

            // ISystemIOWrapper.Directory.Exists Method Mocks
            fileSystemMock.Setup(f => f.Directory.Exists(expectedFolderItemFileName))
                .Returns(() => true);

            fileSystemMock.Setup(f => f.Directory.Exists(expectedFolderItem_NotFound_FileName))
                .Returns(() => false);

            fileSystemMock.Setup(f => f.Directory.Exists(expectedFolderItem_NoToken_FileName))
                .Returns(() => true);

            // ISystemIOWrapper.Path.GetDirectoryName Method Mocks
            fileSystemMock.Setup(f => f.Path.GetDirectoryName(expectedFolderItemFileName))
                .Returns(() => expectedFolderItemPath);

            fileSystemMock.Setup(f => f.Path.GetDirectoryName(expectedFolderItem_NoToken_FileName))
                .Returns(() => expectedFolderItemPath_NoToken);

            // ISystemIOWrapper.Path.GetFileName Method Mocks
            fileSystemMock.Setup(f => f.Path.GetFileName(expectedFolderItemFileName))
                .Returns(() => expectedFolderItem.Name);

            fileSystemMock.Setup(f => f.Path.GetFileName(expectedFolderItem_NoToken_FileName))
                .Returns(() => expectedFolderItem_NoToken.Name);

            importer = new FolderItemImporter(fileSystemMock.Object, loggerMock);
        }
Ejemplo n.º 7
0
        public void TestFixtureSetUp()
        {
            loggerMock = new MockLogger();
            fileSystemMock = new Mock<IFileSystem>();
            serializeWrapperMock = new Mock<ISerializeWrapper>();

            // ISystemIOWrapper.File.ReadAllBytes Method Mocks
            fileSystemMock.Setup(f => f.File.ReadAllBytes(expectedReportItemFileName))
                .Returns(() => expectedReportItem.Definition);

            fileSystemMock.Setup(f => f.File.ReadAllBytes(expectedReportItem_NoToken_FileName))
                .Returns(() => expectedReportItem_NoToken.Definition);

            // ISystemIOWrapper.File.Exists Method Mocks
            fileSystemMock.Setup(f => f.File.Exists(expectedReportItemFileName))
                .Returns(() => true);

            fileSystemMock.Setup(f => f.File.Exists(expectedReportItem_NotFound_Filename))
                .Returns(() => false);

            fileSystemMock.Setup(f => f.File.Exists(expectedReportItem_NoToken_FileName))
                .Returns(() => true);

            // ISystemIOWrapper.Path.GetDirectoryName Method Mocks
            fileSystemMock.Setup(f => f.Path.GetDirectoryName(expectedReportItemFileName))
                .Returns(() => expectedReportItemPath);

            fileSystemMock.Setup(f => f.Path.GetDirectoryName(expectedReportItem_NoToken_FileName))
                .Returns(() => expectedReportItemPath_NoToken);

            // ISystemIOWrapper.Path.GetFileName Method Mocks
            fileSystemMock.Setup(f => f.Path.GetFileNameWithoutExtension(expectedReportItemFileName))
                .Returns(() => expectedReportItem.Name);

            fileSystemMock.Setup(f => f.Path.GetFileNameWithoutExtension(expectedReportItem_NoToken_FileName))
                .Returns(() => expectedReportItem_NoToken.Name);

            importer = new ReportItemImporter(fileSystemMock.Object, loggerMock);
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
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);
        }
        public void TestFixtureSetUp()
        {
            rootFolderItem = new FolderItem()
            {
                Name = "SSRSMigrate_AW_Tests",
                Path = "/SSRSMigrate_AW_Tests",
            };

            reportsFolderItem = new FolderItem()
            {
                Name = "Reports",
                Path = "/SSRSMigrate_AW_Tests/Reports",
            };

            reportsSubFolderItem = new FolderItem()
            {
                Name = "Sub Folder",
                Path = "/SSRSMigrate_AW_Tests/Reports/Sub Folder",
            };

            rootSubFolderItem = new FolderItem()
            {
                Name = "Data Sources",
                Path = "/SSRSMigrate_AW_Tests/Data Sources",
            };

            alreadyExistsFolderItem = new FolderItem()
            {
                Name = "Already Exists",
                Path = "/SSRSMigrate_AW_Tests/Already Exists"
            };

            invalidPathFolderItem = new FolderItem()
            {
                Name = "SSRSMigrate_AW_Tests.Tests",
                Path = "/SSRSMigrate_AW.Tests",
            };

            errorFolderItem = new FolderItem()
            {
                Name = "ERROR",
                Path = "/SSRSMigrate_AW_Tests/ERROR"
            };

            folderItems = new List<FolderItem>()
            {
                rootFolderItem,
                reportsFolderItem,
                reportsSubFolderItem,
                rootSubFolderItem,
            };

            // Setup IReportServerRepository Mock
            reportServerRepositoryMock = new Mock<IReportServerRepository>();

            // IReportServerRepository.CreateFolder Mocks
            reportServerRepositoryMock.Setup(r => r.CreateFolder(null, It.IsAny<string>()))
                .Throws(new ArgumentException("name"));

            reportServerRepositoryMock.Setup(r => r.CreateFolder("", It.IsAny<string>()))
                .Throws(new ArgumentException("name"));

            reportServerRepositoryMock.Setup(r => r.CreateFolder(It.IsAny<string>(), null))
                .Throws(new ArgumentException("parentPath"));

            reportServerRepositoryMock.Setup(r => r.CreateFolder(It.IsAny<string>(), ""))
               .Throws(new ArgumentException("parentPath"));

            reportServerRepositoryMock.Setup(r => r.CreateFolder(rootFolderItem.Name, TesterUtility.GetParentPath(rootFolderItem)))
                .Returns(() => null);

            reportServerRepositoryMock.Setup(r => r.CreateFolder(reportsFolderItem.Name, TesterUtility.GetParentPath(reportsFolderItem)))
                .Returns(() => null);

            reportServerRepositoryMock.Setup(r => r.CreateFolder(reportsSubFolderItem.Name, TesterUtility.GetParentPath(reportsSubFolderItem)))
                .Returns(() => null);

            reportServerRepositoryMock.Setup(r => r.CreateFolder(rootSubFolderItem.Name, TesterUtility.GetParentPath(rootSubFolderItem)))
               .Returns(() => null);

            reportServerRepositoryMock.Setup(r => r.CreateFolder(alreadyExistsFolderItem.Name, TesterUtility.GetParentPath(alreadyExistsFolderItem)))
               .Returns(() => null);

            reportServerRepositoryMock.Setup(r => r.CreateFolder(errorFolderItem.Name, TesterUtility.GetParentPath(errorFolderItem)))
                .Returns(() => string.Format("Error writing folder '{0}': Error!", errorFolderItem.Path));

            reportServerRepositoryMock.Setup(r => r.ItemExists(alreadyExistsFolderItem.Path, "Folder"))
                .Returns(() => true);

            // IReportServerRepository.ValidatePath Mocks
            reportServerRepositoryMock.Setup(r => r.ValidatePath(rootFolderItem.Path))
               .Returns(() => true);

            reportServerRepositoryMock.Setup(r => r.ValidatePath(rootSubFolderItem.Path))
               .Returns(() => true);

            reportServerRepositoryMock.Setup(r => r.ValidatePath(reportsFolderItem.Path))
               .Returns(() => true);

            reportServerRepositoryMock.Setup(r => r.ValidatePath(reportsSubFolderItem.Path))
                .Returns(() => true);

            reportServerRepositoryMock.Setup(r => r.ValidatePath(rootSubFolderItem.Path))
               .Returns(() => true);

            reportServerRepositoryMock.Setup(r => r.ValidatePath(alreadyExistsFolderItem.Path))
              .Returns(() => true);

            // Validate errorFolderItem.Path so we can mock the error returned by IReportServerRepository.CreateFolder
            reportServerRepositoryMock.Setup(r => r.ValidatePath(errorFolderItem.Path))
              .Returns(() => true);

            reportServerRepositoryMock.Setup(r => r.ValidatePath(null))
               .Returns(() => false);

            reportServerRepositoryMock.Setup(r => r.ValidatePath(""))
               .Returns(() => false);

            reportServerRepositoryMock.Setup(r => r.ValidatePath(It.Is<string>(s => Regex.IsMatch(s ?? "", "[:?;@&=+$,\\*><|.\"]+") == true)))
               .Returns(() => false);

            MockLogger logger = new MockLogger();

            writer = new ReportServerWriter(reportServerRepositoryMock.Object, logger);
        }
        public void TestFixtureSetUp()
        {
            // Setup expected DataSourceItems
            expectedDataSourceItems = new List<DataSourceItem>()
            {
                new DataSourceItem()
                {
                    CreatedBy = "DOMAIN\\user",
                    CreationDate = DateTime.Parse("7/23/2014 8:28:43 AM"),
                    Description = null,
                    ID = Guid.NewGuid().ToString(),
                    ModifiedBy = "DOMAIN\\user",
                    ModifiedDate = DateTime.Parse("7/23/2014 8:28:43 AM"),
                    Size = 414,
                    VirtualPath = null,
                    Name = "AWDataSource",
                    Path = "/SSRSMigrate_AW_Tests/Data Sources/AWDataSource",
                    ConnectString = "Data Source=(local)\\SQL2008;Initial Catalog=AdventureWorks2008",
                    CredentialsRetrieval = "Integrated",
                    Enabled = true,
                    EnabledSpecified = true,
                    Extension = "SQL",
                    ImpersonateUser = false,
                    ImpersonateUserSpecified = true,
                    OriginalConnectStringExpressionBased = false,
                    Password = null,
                    Prompt = "Enter a user name and password to access the data source:",
                    UseOriginalConnectString = false,
                    UserName = null,
                    WindowsCredentials = false
                },
                new DataSourceItem()
                {
                    CreatedBy = "DOMAIN\\user",
                    CreationDate = DateTime.Parse("7/23/2014 8:29:25 AM"),
                    Description = null,
                    ID = Guid.NewGuid().ToString(),
                    ModifiedBy = "DOMAIN\\user",
                    ModifiedDate = DateTime.Parse("7/23/2014 8:29:25 AM"),
                    Size = 414,
                    VirtualPath = null,
                    Name = "Test Data Source",
                    Path = "/SSRSMigrate_AW_Tests/Data Sources/Test Data Source",
                    ConnectString = "Data Source=(local)\\SQL2008;Initial Catalog=AdventureWorks2008",
                    CredentialsRetrieval = "Integrated",
                    Enabled = true,
                    EnabledSpecified = true,
                    Extension = "SQL",
                    ImpersonateUser = false,
                    ImpersonateUserSpecified = true,
                    OriginalConnectStringExpressionBased = false,
                    Password = null,
                    Prompt = "Enter a user name and password to access the data source:",
                    UseOriginalConnectString = false,
                    UserName = null,
                    WindowsCredentials = false
                },
            };

            // Setup IReportServerRepository mock
            var reportServerRepositoryMock = new Mock<IReportServerRepository>();

            // IReportServerRepository.GetDataSource Mocks
            reportServerRepositoryMock.Setup(r => r.GetDataSource(null))
                .Throws(new ArgumentException("dataSourcePath"));

            reportServerRepositoryMock.Setup(r => r.GetDataSource(""))
                .Throws(new ArgumentException("dataSourcePath"));

            reportServerRepositoryMock.Setup(r => r.GetDataSource("/SSRSMigrate_AW_Tests/Data Sources/AWDataSource"))
                .Returns(() => expectedDataSourceItems[0]);

            reportServerRepositoryMock.Setup(r => r.GetDataSource("/SSRSMigrate_AW_Tests/Data Sources/Test Data Source"))
                .Returns(() => expectedDataSourceItems[1]);

            reportServerRepositoryMock.Setup(r => r.GetDataSource("/SSRSMigrate_AW_Tests/Data Sources/Test Data Source Doesnt Exist"))
                .Returns(() => null);

            // IReportServerRepository.GetDataSources Mocks
            reportServerRepositoryMock.Setup(r => r.GetDataSources(null))
                .Throws(new ArgumentException("path"));

            reportServerRepositoryMock.Setup(r => r.GetDataSources(""))
                .Throws(new ArgumentException("path"));

            reportServerRepositoryMock.Setup(r => r.GetDataSources("/SSRSMigrate_AW_Tests"))
                .Returns(() => expectedDataSourceItems);

            reportServerRepositoryMock.Setup(r => r.GetDataSources("/SSRSMigrate_AW_Tests Doesnt Exist"))
                .Returns(() => new List<DataSourceItem>());

            // IReportServerRepository.GetDataSourcesList Mocks
            reportServerRepositoryMock.Setup(r => r.GetDataSourcesList(null))
                .Throws(new ArgumentException("path"));

            reportServerRepositoryMock.Setup(r => r.GetDataSourcesList(""))
                .Throws(new ArgumentException("path"));

            reportServerRepositoryMock.Setup(r => r.GetDataSourcesList("/SSRSMigrate_AW_Tests"))
                .Returns(() => expectedDataSourceItems);

            reportServerRepositoryMock.Setup(r => r.GetDataSourcesList("/SSRSMigrate_AW_Tests Doesnt Exist"))
                .Returns(() => new List<DataSourceItem>());

            // Setup IReportServerRepository.ValidatePath Mocks
            reportServerRepositoryMock.Setup(r => r.ValidatePath("/SSRSMigrate_AW_Tests"))
               .Returns(() => true);

            reportServerRepositoryMock.Setup(r => r.ValidatePath("/SSRSMigrate_AW_Tests Doesnt Exist"))
               .Returns(() => true);

            reportServerRepositoryMock.Setup(r => r.ValidatePath("/SSRSMigrate_AW_Tests/Data Sources/Test Data Source Doesnt Exist"))
               .Returns(() => true);

            reportServerRepositoryMock.Setup(r => r.ValidatePath("/SSRSMigrate_AW_Tests/Data Sources/AWDataSource"))
               .Returns(() => true);

            reportServerRepositoryMock.Setup(r => r.ValidatePath("/SSRSMigrate_AW_Tests/Data Sources/Test Data Source"))
               .Returns(() => true);

            reportServerRepositoryMock.Setup(r => r.ValidatePath(null))
               .Returns(() => false);

            reportServerRepositoryMock.Setup(r => r.ValidatePath(""))
               .Returns(() => false);

            reportServerRepositoryMock.Setup(r => r.ValidatePath(It.Is<string>(s => Regex.IsMatch(s, "[:?;@&=+$,\\*><|.\"]+") == true)))
               .Returns(() => false);

            MockLogger logger = new MockLogger();

            reader = new ReportServerReader(reportServerRepositoryMock.Object, logger);
        }
        public void TestFixtureSetUp()
        {
            // Setup GetReport - Expected ReportItem
            expectedReportItem = new ReportItem()
            {
                Name = "Company Sales",
                Path = "/SSRSMigrate_AW_Tests/Reports/Company Sales",
                CreatedBy = "DOMAIN\\user",
                CreationDate = DateTime.Parse("7/28/2014 12:06:43 PM"),
                Description = null,
                ID = "16d599e6-9c87-4ebc-b45b-5a47e3c73746",
                ModifiedBy = "DOMAIN\\user",
                ModifiedDate = DateTime.Parse("7/28/2014 12:06:43 PM"),
                Size = 10,
                VirtualPath = null,
                Definition = TesterUtility.StringToByteArray(TesterUtility.LoadRDLFile("Test AW Reports\\2010\\Company Sales.rdl"))
            };

            // Setup GetReports - Expected ReportItems
            expectedReportItems = new List<ReportItem>()
            {
                expectedReportItem,
                new ReportItem()
                {
                    Name = "Sales Order Detail",
                    Path = "/SSRSMigrate_AW_Tests/Reports/Sales Order Detail",
                    CreatedBy = "DOMAIN\\user",
                    CreationDate = DateTime.Parse("7/28/2014 12:06:43 PM"),
                    Description = null,
                    ID = "70650568-7dd4-4ef4-aeaa-67502de11b4f",
                    ModifiedBy = "DOMAIN\\user",
                    ModifiedDate =  DateTime.Parse("7/28/2014 12:06:43 PM"),
                    Size = 10,
                    VirtualPath = null,
                    Definition = TesterUtility.StringToByteArray(TesterUtility.LoadRDLFile("Test AW Reports\\2005\\Sales Order Detail.rdl")),
                    SubReports = new List<ReportItem>()
                    {
                        new ReportItem()
                        {
                            Name = "Store Contacts",
                            Path = "/SSRSMigrate_AW_Tests/Reports/Store Contacts",
                            CreatedBy = "DOMAIN\\user",
                            CreationDate = DateTime.Parse("7/28/2014 12:06:43 PM"),
                            Description = null,
                            ID = "18fc782e-dd5f-4c65-95ff-957e1bdc98de",
                            ModifiedBy = "DOMAIN\\user",
                            ModifiedDate =  DateTime.Parse("7/28/2014 12:06:43 PM"),
                            Size = 10,
                            VirtualPath = null,
                            Definition = TesterUtility.StringToByteArray(TesterUtility.LoadRDLFile("Test AW Reports\\2005\\Store Contacts.rdl")),
                        }
                    }
                }
            };

            // Setup IReportServerRepository mock
            var reportServerRepositoryMock = new Mock<IReportServerRepository>();

            // Setup IReportServerRepository.GetReportDefinition Mocks
            reportServerRepositoryMock.Setup(r => r.GetReportDefinition(null))
                .Throws(new ArgumentException("reportPath"));

            reportServerRepositoryMock.Setup(r => r.GetReportDefinition(""))
               .Throws(new ArgumentException("reportPath"));

            reportServerRepositoryMock.Setup(r => r.GetReportDefinition("/SSRSMigrate_AW_Tests/Reports/Company Sales"))
                .Returns(() => expectedReportItem.Definition);

            reportServerRepositoryMock.Setup(r => r.GetReportDefinition("/SSRSMigrate_AW_Tests/Reports/Sales Order Detail"))
                .Returns(() => expectedReportItems[1].Definition);

            reportServerRepositoryMock.Setup(r => r.GetReportDefinition("/SSRSMigrate_AW_Tests/Reports/Store Contacts"))
                .Returns(() => expectedReportItems[1].SubReports[0].Definition);

            // Setup IReportServerRepository.GetReport Mocks
            reportServerRepositoryMock.Setup(r => r.GetReport(null))
                .Throws(new ArgumentException("reportPath"));

            reportServerRepositoryMock.Setup(r => r.GetReport(""))
                .Throws(new ArgumentException("reportPath"));

            reportServerRepositoryMock.Setup(r => r.GetReport("/SSRSMigrate_AW_Tests/Reports/Company Sales"))
                .Returns(() => expectedReportItem);

            reportServerRepositoryMock.Setup(r => r.GetReport("/SSRSMigrate_AW_Tests/Reports/Sales Order Detail"))
                .Returns(() => expectedReportItems[1]);

            reportServerRepositoryMock.Setup(r => r.GetReport("/SSRSMigrate_AW_Tests/Reports/Report Doesnt Exist"))
                .Returns(() => null);

            // Setup IReportServerRepository.GetReports Mocks
            reportServerRepositoryMock.Setup(r => r.GetReports(null))
               .Throws(new ArgumentException("path"));

            reportServerRepositoryMock.Setup(r => r.GetReports(""))
                .Throws(new ArgumentException("path"));

            reportServerRepositoryMock.Setup(r => r.GetReports("/SSRSMigrate_AW_Tests"))
               .Returns(() => expectedReportItems);

            reportServerRepositoryMock.Setup(r => r.GetReports("/SSRSMigrate_AW_Tests Doesnt Exist"))
                .Returns(() => new List<ReportItem>());

            // Setup IReportServerRepository.GetReportsList Mocks
            reportServerRepositoryMock.Setup(r => r.GetReportsList(null))
               .Throws(new ArgumentException("path"));

            reportServerRepositoryMock.Setup(r => r.GetReportsList(""))
                .Throws(new ArgumentException("path"));

            reportServerRepositoryMock.Setup(r => r.GetReportsList("/SSRSMigrate_AW_Tests"))
               .Returns(() => expectedReportItems);

            reportServerRepositoryMock.Setup(r => r.GetReportsList("/SSRSMigrate_AW_Tests Doesnt Exist"))
                .Returns(() => new List<ReportItem>());

            // Setup IReportServerRepository.ValidatePath Mocks
            reportServerRepositoryMock.Setup(r => r.ValidatePath("/SSRSMigrate_AW_Tests"))
               .Returns(() => true);

            reportServerRepositoryMock.Setup(r => r.ValidatePath("/SSRSMigrate_AW_Tests Doesnt Exist"))
              .Returns(() => true);

            reportServerRepositoryMock.Setup(r => r.ValidatePath("/SSRSMigrate_AW_Tests/Reports/Report Doesnt Exist"))
              .Returns(() => true);

            reportServerRepositoryMock.Setup(r => r.ValidatePath(expectedReportItem.Path))
              .Returns(() => true);

            reportServerRepositoryMock.Setup(r => r.ValidatePath("/SSRSMigrate_AW_Tests/Reports/Sales Order Detail"))
              .Returns(() => true);

            reportServerRepositoryMock.Setup(r => r.ValidatePath("/SSRSMigrate_AW_Tests/Reports/Store Contacts"))
              .Returns(() => true);

            reportServerRepositoryMock.Setup(r => r.ValidatePath(null))
               .Returns(() => false);

            reportServerRepositoryMock.Setup(r => r.ValidatePath(""))
               .Returns(() => false);

            reportServerRepositoryMock.Setup(r => r.ValidatePath(It.Is<string>(s => Regex.IsMatch(s ?? "", "[:?;@&=+$,\\*><|.\"]+") == true)))
               .Returns(() => false);

            MockLogger logger = new MockLogger();

            reader = new ReportServerReader(reportServerRepositoryMock.Object, logger);
        }
        public void TestFixtureSetUp()
        {
            SetupReportItems();

            // Setup IReportServerRepository mock
            var reportServerRepositoryMock = new Mock<IReportServerRepository>();

            // Setup IReportServerRepository.WriteReport Mocks
            reportServerRepositoryMock.Setup(r => r.WriteReport(null, It.IsAny<ReportItem>(), It.IsAny<bool>()))
                .Throws(new ArgumentException("reportPath"));

            reportServerRepositoryMock.Setup(r => r.WriteReport("", It.IsAny<ReportItem>(), It.IsAny<bool>()))
                .Throws(new ArgumentException("reportPath"));

            reportServerRepositoryMock.Setup(r => r.WriteReport(It.IsAny<string>(), null, It.IsAny<bool>()))
                .Throws(new ArgumentException("reportItem"));

            reportServerRepositoryMock.Setup(r => r.WriteReport(TesterUtility.GetParentPath(reportItem_NullDefinition), reportItem_NullDefinition, It.IsAny<bool>()))
                .Throws(new InvalidReportDefinitionException(reportItem_NullDefinition.Path));

            reportServerRepositoryMock.Setup(r => r.WriteReport(TesterUtility.GetParentPath(reportItem_CompanySales), reportItem_CompanySales, It.IsAny<bool>()))
                .Returns(() => null);

            reportServerRepositoryMock.Setup(r => r.WriteReport(TesterUtility.GetParentPath(reportItem_SalesOrderDetail), reportItem_SalesOrderDetail, It.IsAny<bool>()))
                .Returns(() => null);

            reportServerRepositoryMock.Setup(r => r.WriteReport(TesterUtility.GetParentPath(reportItem_StoreContacts), reportItem_StoreContacts, It.IsAny<bool>()))
                .Returns(() => null);

            reportServerRepositoryMock.Setup(r => r.WriteReport(TesterUtility.GetParentPath(reportItem_Error), reportItem_Error, It.IsAny<bool>()))
                .Returns(() => new string[] { string.Format("Error writing report '{0}': Error!", reportItem_Error.Path) });

            reportServerRepositoryMock.Setup(r => r.WriteReport(TesterUtility.GetParentPath(reportItem_AlreadyExists), reportItem_AlreadyExists, true))
                .Returns(() => null);

            // Setup IReportServerRepository.ItemExists Mocks
            reportServerRepositoryMock.Setup(r => r.ItemExists(reportItem_AlreadyExists.Path, "Report"))
                .Returns(() => true);

            // Setup IReportServerRepository.ValidatePath Mocks
            reportServerRepositoryMock.Setup(r => r.ValidatePath(reportItem_CompanySales.Path))
              .Returns(() => true);

            reportServerRepositoryMock.Setup(r => r.ValidatePath(reportItem_SalesOrderDetail.Path))
              .Returns(() => true);

            reportServerRepositoryMock.Setup(r => r.ValidatePath(reportItem_StoreContacts.Path))
              .Returns(() => true);

            reportServerRepositoryMock.Setup(r => r.ValidatePath(reportItem_AlreadyExists.Path))
              .Returns(() => true);

            reportServerRepositoryMock.Setup(r => r.ValidatePath(reportItem_NullDefinition.Path))
              .Returns(() => true);

            reportServerRepositoryMock.Setup(r => r.ValidatePath(reportItem_Error.Path))
                .Returns(() => true);

            reportServerRepositoryMock.Setup(r => r.ValidatePath(null))
               .Returns(() => false);

            reportServerRepositoryMock.Setup(r => r.ValidatePath(""))
               .Returns(() => false);

            reportServerRepositoryMock.Setup(r => r.ValidatePath(reportItem_InvalidPath.Path))
               .Returns(() => false);

            reportServerRepositoryMock.Setup(r => r.ValidatePath(It.Is<string>(s => Regex.IsMatch(s ?? "", "[:?;@&=+$,\\*><|.\"]+") == true)))
               .Returns(() => false);

            MockLogger logger = new MockLogger();

            writer = new ReportServerWriter(reportServerRepositoryMock.Object, logger);
        }
Ejemplo n.º 14
0
        public void Constructor_Null_ZipFile()
        {
            MockLogger logger = new MockLogger();
            Mock<ICheckSumGenerator> checkSumMock = null;
            checkSumMock = new Mock<ICheckSumGenerator>();

            ArgumentNullException ex = Assert.Throws<ArgumentNullException>(
                delegate
                {
                    new ZipBundler(null, checkSumMock.Object, logger, serializeWrapperMock.Object);
                });

            Assert.That(ex.Message, Is.EqualTo("Value cannot be null.\r\nParameter name: zipFileWrapper"));
        }
Ejemplo n.º 15
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);
        }
Ejemplo n.º 16
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."));
        }
Ejemplo n.º 17
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;
        }
Ejemplo n.º 18
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));
        }
Ejemplo n.º 19
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");
        }
Ejemplo n.º 20
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);
        }
Ejemplo n.º 21
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);
        }
        public void TestFixtureSetUp()
        {
            // Setup expected FolderItems
            expectedFolderItem = new FolderItem()
            {
                Name = "Reports",
                Path = "/SSRSMigrate_AW_Tests/Reports",
            };

            expectedFolderItems = new List<FolderItem>()
            {
                expectedFolderItem,
                new FolderItem()
                {
                    Name = "Sub Folder",
                    Path = "/SSRSMigrate_AW_Tests/Reports/Sub Folder",
                },
                new FolderItem()
                {
                    Name = "Data Sources",
                    Path = "/SSRSMigrate_AW_Tests/Data Sources",
                }
            };

            // Setup IReportServerRepository mock
            var reportServerRepositoryMock = new Mock<IReportServerRepository>();

            // IReportServerRepository.GetFolder Mocks
            reportServerRepositoryMock.Setup(r => r.GetFolder(null))
                .Throws(new ArgumentException("path"));

            reportServerRepositoryMock.Setup(r => r.GetFolder(""))
                .Throws(new ArgumentException("path"));

            reportServerRepositoryMock.Setup(r => r.GetFolder("/SSRSMigrate_AW_Tests/Reports"))
                .Returns(() => expectedFolderItem);

            reportServerRepositoryMock.Setup(r => r.GetFolder("/SSRSMigrate_AW_Tests/Doesnt Exist"))
                .Returns(() => null);

            // IReportServerRepository.GetFolders Mocks
            reportServerRepositoryMock.Setup(r => r.GetFolders(null))
                .Throws(new ArgumentException("path"));

            reportServerRepositoryMock.Setup(r => r.GetFolders(""))
                .Throws(new ArgumentException("path"));

            reportServerRepositoryMock.Setup(r => r.GetFolders("/SSRSMigrate_AW_Tests"))
                .Returns(() => expectedFolderItems);

            reportServerRepositoryMock.Setup(r => r.GetFolders("/SSRSMigrate_AW_Tests Doesnt Exist"))
                .Returns(() => new List<FolderItem>());

            // IReportServerRepository.GetFolderList Mocks
            reportServerRepositoryMock.Setup(r => r.GetFolderList(null))
                .Throws(new ArgumentException("path"));

            reportServerRepositoryMock.Setup(r => r.GetFolderList(""))
                .Throws(new ArgumentException("path"));

            reportServerRepositoryMock.Setup(r => r.GetFolderList("/SSRSMigrate_AW_Tests"))
                .Returns(() => expectedFolderItems);

            reportServerRepositoryMock.Setup(r => r.GetFolderList("/SSRSMigrate_AW_Tests Doesnt Exist"))
                .Returns(() => new List<FolderItem>());

            // Setup IReportServerRepository.ValidatePath Mocks
            reportServerRepositoryMock.Setup(r => r.ValidatePath("/SSRSMigrate_AW_Tests"))
               .Returns(() => true);

            reportServerRepositoryMock.Setup(r => r.ValidatePath("/SSRSMigrate_AW_Tests Doesnt Exist"))
               .Returns(() => true);

            // For IReportServerRepository.GetFolder doesnt exist test
            reportServerRepositoryMock.Setup(r => r.ValidatePath("/SSRSMigrate_AW_Tests/Doesnt Exist"))
               .Returns(() => true);

            reportServerRepositoryMock.Setup(r => r.ValidatePath("/SSRSMigrate_AW_Tests/Reports"))
               .Returns(() => true);

            reportServerRepositoryMock.Setup(r => r.ValidatePath("/SSRSMigrate_AW_Tests/Reports/Sub Folder"))
               .Returns(() => true);

            reportServerRepositoryMock.Setup(r => r.ValidatePath("/SSRSMigrate_AW_Tests/Data Sources"))
               .Returns(() => true);

            reportServerRepositoryMock.Setup(r => r.ValidatePath(null))
               .Returns(() => false);

            reportServerRepositoryMock.Setup(r => r.ValidatePath(""))
               .Returns(() => false);

            reportServerRepositoryMock.Setup(r => r.ValidatePath(It.Is<string>(s => Regex.IsMatch(s, "[:?;@&=+$,\\*><|.\"]+") == true)))
               .Returns(() => false);

            MockLogger logger = new MockLogger();

            reader = new ReportServerReader(reportServerRepositoryMock.Object, logger);
        }
Ejemplo n.º 23
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;
        }
        public void TestFixtureSetUp()
        {
            dataSourceItem = new DataSourceItem()
            {
                CreatedBy = "DOMAIN\\user",
                CreationDate = DateTime.Parse("7/23/2014 8:28:43 AM"),
                Description = null,
                ID = Guid.NewGuid().ToString(),
                ModifiedBy = "DOMAIN\\user",
                ModifiedDate = DateTime.Parse("7/23/2014 8:28:43 AM"),
                Size = 414,
                VirtualPath = null,
                Name = "AWDataSource",
                Path = "/SSRSMigrate_AW_Tests/Data Sources/AWDataSource",
                ConnectString = "Data Source=(local)\\SQL2008;Initial Catalog=AdventureWorks2008",
                CredentialsRetrieval = "Integrated",
                Enabled = true,
                EnabledSpecified = true,
                Extension = "SQL",
                ImpersonateUser = false,
                ImpersonateUserSpecified = true,
                OriginalConnectStringExpressionBased = false,
                Password = null,
                Prompt = "Enter a user name and password to access the data source:",
                UseOriginalConnectString = false,
                UserName = null,
                WindowsCredentials = false
            };

            dataSourceTwoItem = new DataSourceItem()
            {
                CreatedBy = "DOMAIN\\user",
                CreationDate = DateTime.Parse("7/23/2014 8:29:25 AM"),
                Description = null,
                ID = Guid.NewGuid().ToString(),
                ModifiedBy = "DOMAIN\\user",
                ModifiedDate = DateTime.Parse("7/23/2014 8:29:25 AM"),
                Size = 414,
                VirtualPath = null,
                Name = "Test Data Source",
                Path = "/SSRSMigrate_AW_Tests/Data Sources/Test Data Source",
                ConnectString = "Data Source=(local)\\SQL2008;Initial Catalog=AdventureWorks2008",
                CredentialsRetrieval = "Integrated",
                Enabled = true,
                EnabledSpecified = true,
                Extension = "SQL",
                ImpersonateUser = false,
                ImpersonateUserSpecified = true,
                OriginalConnectStringExpressionBased = false,
                Password = null,
                Prompt = "Enter a user name and password to access the data source:",
                UseOriginalConnectString = false,
                UserName = null,
                WindowsCredentials = false
            };

            alreadyExistsDataSourceItem = new DataSourceItem()
            {
                CreatedBy = "DOMAIN\\user",
                CreationDate = DateTime.Parse("7/23/2014 8:29:25 AM"),
                Description = null,
                ID = Guid.NewGuid().ToString(),
                ModifiedBy = "DOMAIN\\user",
                ModifiedDate = DateTime.Parse("7/23/2014 8:29:25 AM"),
                Size = 414,
                VirtualPath = null,
                Name = "Already Exists Data Source",
                Path = "/SSRSMigrate_AW_Tests/Data Sources/Already Exists Data Source",
                ConnectString = "Data Source=(local)\\SQL2008;Initial Catalog=AdventureWorks2008",
                CredentialsRetrieval = "Integrated",
                Enabled = true,
                EnabledSpecified = true,
                Extension = "SQL",
                ImpersonateUser = false,
                ImpersonateUserSpecified = true,
                OriginalConnectStringExpressionBased = false,
                Password = null,
                Prompt = "Enter a user name and password to access the data source:",
                UseOriginalConnectString = false,
                UserName = null,
                WindowsCredentials = false
            };

            invalidDataSourcePathItem = new DataSourceItem()
            {
                CreatedBy = "DOMAIN\\user",
                CreationDate = DateTime.Parse("7/23/2014 8:29:25 AM"),
                Description = null,
                ID = Guid.NewGuid().ToString(),
                ModifiedBy = "DOMAIN\\user",
                ModifiedDate = DateTime.Parse("7/23/2014 8:29:25 AM"),
                Size = 414,
                VirtualPath = null,
                Name = "Test.Data Source",
                Path = "/SSRSMigrate_AW_Tests/Data Sources/Test.Data Source",
                ConnectString = "Data Source=(local)\\SQL2008;Initial Catalog=AdventureWorks2008",
                CredentialsRetrieval = "Integrated",
                Enabled = true,
                EnabledSpecified = true,
                Extension = "SQL",
                ImpersonateUser = false,
                ImpersonateUserSpecified = true,
                OriginalConnectStringExpressionBased = false,
                Password = null,
                Prompt = "Enter a user name and password to access the data source:",
                UseOriginalConnectString = false,
                UserName = null,
                WindowsCredentials = false
            };

            errorDataSourceItem = new DataSourceItem()
            {
                CreatedBy = "DOMAIN\\user",
                CreationDate = DateTime.Parse("7/23/2014 8:28:43 AM"),
                Description = null,
                ID = Guid.NewGuid().ToString(),
                ModifiedBy = "DOMAIN\\user",
                ModifiedDate = DateTime.Parse("7/23/2014 8:28:43 AM"),
                Size = 414,
                VirtualPath = null,
                Name = "ErrorDataSource",
                Path = "/SSRSMigrate_AW_Tests/Data Sources/ErrorDataSource",
                ConnectString = "Data Source=(local)\\SQL2008;Initial Catalog=AdventureWorks2008",
                CredentialsRetrieval = "Integrated",
                Enabled = true,
                EnabledSpecified = true,
                Extension = "SQL",
                ImpersonateUser = false,
                ImpersonateUserSpecified = true,
                OriginalConnectStringExpressionBased = false,
                Password = null,
                Prompt = "Enter a user name and password to access the data source:",
                UseOriginalConnectString = false,
                UserName = null,
                WindowsCredentials = false
            };

            dataSourceItems = new List<DataSourceItem>()
            {
                dataSourceItem,
                dataSourceTwoItem
            };

            // Setup IReportServerRepository mock
            var reportServerRepositoryMock = new Mock<IReportServerRepository>();

            // Setup IReportServerRepository.WriteDataSource
            reportServerRepositoryMock.Setup(r => r.WriteDataSource(null, It.IsAny<DataSourceItem>(), It.IsAny<bool>()))
                .Throws(new ArgumentException("dataSourcePath"));

            reportServerRepositoryMock.Setup(r => r.WriteDataSource("", It.IsAny<DataSourceItem>(), It.IsAny<bool>()))
                .Throws(new ArgumentException("dataSourcePath"));

            reportServerRepositoryMock.Setup(r => r.WriteDataSource(It.IsAny<string>(), null, It.IsAny<bool>()))
                .Throws(new ArgumentException("dataSource"));

            reportServerRepositoryMock.Setup(r => r.WriteDataSource(TesterUtility.GetParentPath(dataSourceItem), dataSourceItem, It.IsAny<bool>()))
                .Returns(() => null);

            reportServerRepositoryMock.Setup(r => r.WriteDataSource(TesterUtility.GetParentPath(dataSourceTwoItem), dataSourceTwoItem, It.IsAny<bool>()))
                .Returns(() => null);

            reportServerRepositoryMock.Setup(r => r.WriteDataSource(TesterUtility.GetParentPath(errorDataSourceItem), errorDataSourceItem, It.IsAny<bool>()))
                .Returns(() => string.Format("Error writing data source '{0}': Error!", errorDataSourceItem.Path));

            reportServerRepositoryMock.Setup(r => r.WriteDataSource(TesterUtility.GetParentPath(alreadyExistsDataSourceItem), alreadyExistsDataSourceItem, true))
                .Returns(() => null);

            // Setup IReportServerRepository.ItemExists Mocks
            reportServerRepositoryMock.Setup(r => r.ItemExists(alreadyExistsDataSourceItem.Path, "DataSource"))
                .Returns(() => true);

            // Setup IReportServerRepository.ValidatePath Mocks
            reportServerRepositoryMock.Setup(r => r.ValidatePath(dataSourceItem.Path))
               .Returns(() => true);

            reportServerRepositoryMock.Setup(r => r.ValidatePath(dataSourceTwoItem.Path))
               .Returns(() => true);

            reportServerRepositoryMock.Setup(r => r.ValidatePath(alreadyExistsDataSourceItem.Path))
               .Returns(() => true);

            reportServerRepositoryMock.Setup(r => r.ValidatePath("/SSRSMigrate_AW_Tests"))
                .Returns(() => true);

            reportServerRepositoryMock.Setup(r => r.ValidatePath(errorDataSourceItem.Path))
                .Returns(() => true);

            reportServerRepositoryMock.Setup(r => r.ValidatePath(null))
               .Returns(() => false);

            reportServerRepositoryMock.Setup(r => r.ValidatePath(""))
               .Returns(() => false);

            reportServerRepositoryMock.Setup(r => r.ValidatePath(It.Is<string>(s => Regex.IsMatch(s ?? "", "[:?;@&=+$,\\*><|.\"]+") == true)))
               .Returns(() => false);

            MockLogger logger = new MockLogger();

            writer = new ReportServerWriter(reportServerRepositoryMock.Object, logger);
        }
Ejemplo n.º 25
0
        public void SetUp()
        {
            // Recreate ZipBundler for each test, so the CreateSummary tests have fresh data
            MockLogger logger = new MockLogger();

            zipBundler = new ZipBundler(zipFileMock.Object, checkSumGenMock.Object, logger, serializeWrapperMock.Object);
        }