예제 #1
0
        public UploadToWebonaryDlg(UploadToWebonaryController controller, UploadToWebonaryModel model, Mediator mediator)
        {
            InitializeComponent();

            if (MiscUtils.IsUnix)
            {
                MinimumSize = new Size(MinimumSize.Width, MinimumSize.Height + m_additionalMinimumHeightForMono);
            }

            m_controller = controller;
            Mediator     = mediator;
            Model        = model;
            LoadFromModel();

            m_helpTopicProvider = mediator.HelpTopicProvider;

            // When a link is clicked, open a web page to the URL.
            explanationLabel.LinkClicked += (sender, args) =>
            {
                using (Process.Start(((LinkLabel)sender).Text.Substring(args.Link.Start, args.Link.Length)))
                {}
            };

            // Restore the location and size from last time we called this dialog.
            if (Mediator != null && Mediator.PropertyTable != null)
            {
                object locWnd = Mediator.PropertyTable.GetValue("UploadToWebonaryDlg_Location");
                object szWnd  = Mediator.PropertyTable.GetValue("UploadToWebonaryDlg_Size");
                if (locWnd != null && szWnd != null)
                {
                    Rectangle rect = new Rectangle((Point)locWnd, (Size)szWnd);
                    ScreenUtils.EnsureVisibleRect(ref rect);
                    DesktopBounds = rect;
                    StartPosition = FormStartPosition.Manual;
                }
            }

            // Start with output log area not shown by default
            // When a user clicks Publish, it is revealed. This is done within the context of having a resizable table of controls, and having
            // the output log area be the vertically growing control when a user increases the height of the dialog
            this.Shown += (sender, args) => { this.Height = this.Height - outputLogTextbox.Height; };

            // Handle localizable explanation area with link.
            var explanationText           = xWorksStrings.toApplyForWebonaryAccountExplanation;
            var explanationTextLink       = xWorksStrings.toApplyForWebonaryAccountLink;
            var explanationTextLinkStart  = explanationText.IndexOf("{", StringComparison.Ordinal);
            var explanationTextLinkLength = explanationTextLink.Length;

            explanationLabel.Text = string.Format(explanationText, explanationTextLink);
            // Don't blow up if a localization didn't allow for the link.
            if (explanationTextLinkStart < 0)
            {
                explanationTextLinkStart  = 0;
                explanationTextLinkLength = 0;
            }
            explanationLabel.LinkArea = new LinkArea(explanationTextLinkStart, explanationTextLinkLength);
        }
        public void UploadFilename_ThrowsForBadInput()
        {
            Assert.Throws <ArgumentNullException>(() => UploadToWebonaryController.UploadFilename(null, null));
            var view  = SetUpView();
            var model = view.Model;

            model.SiteName = null;
            Assert.Throws <ArgumentException>(() => UploadToWebonaryController.UploadFilename(model, view));
            model.SiteName = "";
            Assert.Throws <ArgumentException>(() => UploadToWebonaryController.UploadFilename(model, view));
        }
        public void UploadFilename_UsesSiteName()
        {
            var view  = SetUpView();
            var model = view.Model;

            model.SiteName = "mySiteName";
            var expectedFilename = "mySiteName.zip";
            var actualFilename   = UploadToWebonaryController.UploadFilename(model, view);

            Assert.That(actualFilename, Is.EqualTo(expectedFilename), "Incorrect filename for webonary export.");
        }
        public void UploadFilename_FailsForInvalidCharactersInSitename(string sitename)
        {
            var view  = SetUpView();
            var model = view.Model;

            model.SiteName = sitename;

            // SUT
            var result = UploadToWebonaryController.UploadFilename(model, view);

            Assert.That(result, Is.Null, "Fail on invalid characters.");
            Assert.That(view.StatusStrings.Any(s => s.Contains("Invalid characters found in sitename")), "Inform that there was a problem");
        }
예제 #5
0
        public void IsSupportedWebonaryFile_reportsAccurately()
        {
            Assert.True(UploadToWebonaryController.IsSupportedWebonaryFile("foo.xhtml"));
            Assert.True(UploadToWebonaryController.IsSupportedWebonaryFile("foo.css"));
            Assert.True(UploadToWebonaryController.IsSupportedWebonaryFile("foo.html"));
            Assert.True(UploadToWebonaryController.IsSupportedWebonaryFile("foo.htm"));
            Assert.True(UploadToWebonaryController.IsSupportedWebonaryFile("foo.json"));
            Assert.True(UploadToWebonaryController.IsSupportedWebonaryFile("foo.xml"));

            Assert.True(UploadToWebonaryController.IsSupportedWebonaryFile("foo.jpg"));
            Assert.True(UploadToWebonaryController.IsSupportedWebonaryFile("foo.jpeg"));
            Assert.True(UploadToWebonaryController.IsSupportedWebonaryFile("foo.gif"));
            Assert.True(UploadToWebonaryController.IsSupportedWebonaryFile("foo.png"));

            Assert.True(UploadToWebonaryController.IsSupportedWebonaryFile("foo.mp3"));
            Assert.True(UploadToWebonaryController.IsSupportedWebonaryFile("foo.MP4"));             // avoid failure because of capitalization
            Assert.True(UploadToWebonaryController.IsSupportedWebonaryFile("foo.wav"));
            Assert.True(UploadToWebonaryController.IsSupportedWebonaryFile("foo.webm"));

            Assert.False(UploadToWebonaryController.IsSupportedWebonaryFile("foo.wmf"));
            Assert.False(UploadToWebonaryController.IsSupportedWebonaryFile("foo.tif"));
            Assert.False(UploadToWebonaryController.IsSupportedWebonaryFile("foo.tiff"));
            Assert.False(UploadToWebonaryController.IsSupportedWebonaryFile("foo.ico"));
            Assert.False(UploadToWebonaryController.IsSupportedWebonaryFile("foo.pcx"));
            Assert.False(UploadToWebonaryController.IsSupportedWebonaryFile("foo.cgm"));

            Assert.False(UploadToWebonaryController.IsSupportedWebonaryFile("foo.snd"));
            Assert.False(UploadToWebonaryController.IsSupportedWebonaryFile("foo.au"));
            Assert.False(UploadToWebonaryController.IsSupportedWebonaryFile("foo.aif"));
            Assert.False(UploadToWebonaryController.IsSupportedWebonaryFile("foo.aifc"));
            Assert.False(UploadToWebonaryController.IsSupportedWebonaryFile("foo.wma"));

            Assert.False(UploadToWebonaryController.IsSupportedWebonaryFile("foo.avi"));
            Assert.False(UploadToWebonaryController.IsSupportedWebonaryFile("foo.wmv"));
            Assert.False(UploadToWebonaryController.IsSupportedWebonaryFile("foo.wvx"));
            Assert.False(UploadToWebonaryController.IsSupportedWebonaryFile("foo.mpg"));
            Assert.False(UploadToWebonaryController.IsSupportedWebonaryFile("foo.mpe"));
            Assert.False(UploadToWebonaryController.IsSupportedWebonaryFile("foo.m1v"));
            Assert.False(UploadToWebonaryController.IsSupportedWebonaryFile("foo.mp2"));
            Assert.False(UploadToWebonaryController.IsSupportedWebonaryFile("foo.mpv2"));
            Assert.False(UploadToWebonaryController.IsSupportedWebonaryFile("foo.mpa"));
        }
        public void CompressExportedFiles_IncludesAcceptableMediaTypes()
        {
            var view = new MockWebonaryDlg();

            var tempDirectoryToCompress = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

            Directory.CreateDirectory(tempDirectoryToCompress);
            try
            {
                var zipFileToUpload = Path.Combine(Path.GetTempPath(), Path.GetTempFileName());

                // TIFF
                var tiffFilename    = Path.GetFileName(Path.GetTempFileName() + ".tif");
                var tiffPath        = Path.Combine(tempDirectoryToCompress, tiffFilename);
                var tiffMagicNumber = new byte[] { 0x49, 0x49, 0x2A };
                File.WriteAllBytes(tiffPath, tiffMagicNumber);

                // JPEG
                var jpegFilename    = Path.GetFileName(Path.GetTempFileName() + ".jpg");
                var jpegPath        = Path.Combine(tempDirectoryToCompress, jpegFilename);
                var jpegMagicNumber = new byte[] { 0xff, 0xd8 };
                File.WriteAllBytes(jpegPath, jpegMagicNumber);

                // MP4
                var mp4Filename    = Path.GetFileName(Path.GetTempFileName() + ".mp4");
                var mp4Path        = Path.Combine(tempDirectoryToCompress, mp4Filename);
                var mp4MagicNumber = new byte[] { 0x00, 0x00, 0x00, 0x18, 0x66, 0x74, 0x79, 0x70, 0x6d, 0x70, 0x34, 0x32 };
                File.WriteAllBytes(mp4Path, mp4MagicNumber);

                var xhtmlFilename = Path.GetFileName(Path.GetTempFileName() + ".xhtml");
                var xhtmlPath     = Path.Combine(tempDirectoryToCompress, xhtmlFilename);
                var xhtmlContent  = "<xhtml/>";
                File.WriteAllText(xhtmlPath, xhtmlContent);

                // SUT
                UploadToWebonaryController.CompressExportedFiles(tempDirectoryToCompress, zipFileToUpload, view);

                // Verification
                const string unsupported      = ".*nsupported.*";
                const string unsupportedRegex = ".*{0}" + unsupported;
                using (var uploadZip = new ZipFile(zipFileToUpload))
                {
                    Assert.False(uploadZip.EntryFileNames.Contains(tiffFilename), "Should not have included unsupported TIFF file in file to upload.");
                    Assert.True(uploadZip.EntryFileNames.Contains(jpegFilename), "Should have included supported JPEG file in file to upload.");
                    Assert.True(uploadZip.EntryFileNames.Contains(mp4Filename), "Should have included supported MP4 file in file to upload.");
                }

                var query = string.Format(unsupportedRegex, tiffFilename);
                Assert.True(view.StatusStrings.Exists(statusString => Regex.Matches(statusString, query).Count == 1), "Lack of support for the tiff file should have been reported to the user.");
                query = string.Format(unsupportedRegex, jpegFilename);
                Assert.False(view.StatusStrings.Exists(statusString => Regex.Matches(statusString, query).Count == 1), "Should not have reported lack of support for the jpeg file.");
                query = string.Format(unsupportedRegex, mp4Filename);
                Assert.False(view.StatusStrings.Exists(statusString => Regex.Matches(statusString, query).Count == 1), "Should not have reported lack of support for the mp4 file.");

                Assert.That(view.StatusStrings.Count(statusString => Regex.Matches(statusString, unsupported).Count > 0), Is.EqualTo(1), "Too many unsupported files reported.");
            }
            finally
            {
                DirectoryUtilities.DeleteDirectoryRobust(tempDirectoryToCompress);
            }
        }