public void UploadToWebonaryReportsSuccess() { var success = "Upload successful."; using (var controller = new MockUploadToWebonaryController(Cache, m_propertyTable, m_mediator, null, Encoding.UTF8.GetBytes(success))) { var view = new MockWebonaryDlg() { Model = new UploadToWebonaryModel(m_propertyTable) { UserName = "******", Password = "******" } }; controller.UploadToWebonary("../../Src/xWorks/xWorksTests/lubwisi-d-new.zip", view.Model, view); //view.StatusStrings.ForEach(Console.WriteLine); // Debugging output Assert.That(view.StatusStrings.Any(s => s.Contains("Upload successful"))); } }
public void UploadToWebonaryErrorInProcessingHandled() { var webonaryProcessingErrorContent = Encoding.UTF8.GetBytes("Error processing data: bad data."); using (var controller = new MockUploadToWebonaryController(Cache, m_mediator, null, webonaryProcessingErrorContent)) { var view = new MockWebonaryDlg { Model = new UploadToWebonaryModel(m_mediator) { UserName = "******", Password = "******" } }; // Contains a filename in the zip that isn't correct, so no data will be found by webonary. controller.UploadToWebonary("fakebaddata.zip", view.Model, view); //view.StatusStrings.ForEach(Console.WriteLine); // Debugging output Assert.That(view.StatusStrings.Any(s => s.IndexOf("Error", StringComparison.OrdinalIgnoreCase) >= 0), "Should be an error reported"); } }
public void UploadToWebonaryReportsLackingPermissionsToUpload() { var ex = new WebonaryClient.WebonaryException(new WebException("Unable to connect to Webonary. Please check your username and password and your Internet connection.")); ex.StatusCode = HttpStatusCode.BadRequest; using (var controller = new MockUploadToWebonaryController(Cache, m_mediator, ex, null)) { var view = new MockWebonaryDlg() { Model = new UploadToWebonaryModel(m_mediator) { SiteName = "test-india", UserName = "******", Password = "******" } }; controller.UploadToWebonary("../../Src/xWorks/xWorksTests/lubwisi-d-new.zip", view.Model, view); Assert.That(view.StatusStrings.Any(s => s.Contains("Unable to connect to Webonary. Please check your username and password and your Internet connection."))); } }
public void UploadToWebonaryReportsIncorrectSiteName() { // Test for a successful response indicating that a redirect should happen using (var controller = new MockUploadToWebonaryController(Cache, m_mediator, null, new byte[] {}, HttpStatusCode.Found)) { var view = new MockWebonaryDlg() { Model = new UploadToWebonaryModel(m_mediator) { SiteName = "test", UserName = "******", Password = "******" } }; controller.UploadToWebonary("fakefile.zip", view.Model, view); Assert.That(view.StatusStrings.Any(s => s.Contains("Error: There has been an error accessing webonary. Is your sitename correct?"))); } // Test with an exception which indicates a redirect should happen var redirectException = new WebonaryClient.WebonaryException(new WebException("Redirected.")); redirectException.StatusCode = HttpStatusCode.Redirect; using (var controller = new MockUploadToWebonaryController(Cache, m_mediator, redirectException, new byte[] { })) { var view = new MockWebonaryDlg() { Model = new UploadToWebonaryModel(m_mediator) { SiteName = "test", UserName = "******", Password = "******" } }; controller.UploadToWebonary("fakefile.zip", view.Model, view); Assert.That(view.StatusStrings.Any(s => s.Contains("Error: There has been an error accessing webonary. Is your sitename correct?"))); } }
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); } }