public void MakeWidget_SameInput_DoesNotDuplicateFolder() { SetupZip(zip => { }); Assert.That(EditingModel.MakeWidget(_bookFolder.FolderPath, _widgetFile.Path), Is.EqualTo(_firstWidgetSrcPath)); // the same path, to the same folder Assert.That(Directory.GetDirectories(_activityFolder), Has.Length.EqualTo(1)); }
public void OneTimeSetup() { _bookFolder = new TemporaryFolder("MakeWidgetTests"); _widgetFile = TempFile.WithExtension("wdgt"); _activityFolder = Path.Combine(_bookFolder.FolderPath, "activities"); _secondActivityFolder = Path.Combine(_activityFolder, Path.GetFileNameWithoutExtension(_widgetFile.Path) + "2"); SetupZip(zip => { }); _firstWidgetSrcPath = EditingModel.MakeWidget(_bookFolder.FolderPath, _widgetFile.Path); _secondWidgetSrcPath = "activities/" + Path.GetFileNameWithoutExtension(_widgetFile.Path) + "2/" + "index.htm"; }
public void MakeWidget_OneLessFileInZip_MakesNewFolder() { SetupZip(zip => { zip.Delete("base.css"); // remove original file }); Assert.That(EditingModel.MakeWidget(_bookFolder.FolderPath, _widgetFile.Path), Is.EqualTo(_secondWidgetSrcPath)); Assert.That(Directory.GetDirectories(_activityFolder), Has.Length.EqualTo(2)); Assert.That(File.ReadAllText(Path.Combine(_secondActivityFolder, "index.htm")), Is.EqualTo("fake html")); Assert.That(File.ReadAllText(Path.Combine(_secondActivityFolder, "images", "picture.jpg")), Is.EqualTo("fake image")); }
public void MakeWidget_OneExtraFileInExtraFolderInZip_MakesNewFolder() { SetupZip(zip => { zip.Add(new DataFromString("fake audio"), "audio/noise.mp3", CompressionMethod.Deflated); // add an extra file }); Assert.That(EditingModel.MakeWidget(_bookFolder.FolderPath, _widgetFile.Path), Is.EqualTo(_secondWidgetSrcPath)); Assert.That(Directory.GetDirectories(_activityFolder), Has.Length.EqualTo(2)); Assert.That(File.ReadAllText(Path.Combine(_secondActivityFolder, "index.htm")), Is.EqualTo("fake html")); Assert.That(File.ReadAllText(Path.Combine(_secondActivityFolder, "base.css")), Is.EqualTo("fake css")); Assert.That(File.ReadAllText(Path.Combine(_secondActivityFolder, "audio", "noise.mp3")), Is.EqualTo("fake audio")); }
public void MakeWidget_DifferentIndexFile_MakesNewFolder() { SetupZip(zip => { zip.Add(new DataFromString("fake html"), "index.html", CompressionMethod.Deflated); }); // Note that here, the result is in the second folder, but has a different name for the file. Assert.That(EditingModel.MakeWidget(_bookFolder.FolderPath, _widgetFile.Path), Is.EqualTo("activities/" + Path.GetFileNameWithoutExtension(_widgetFile.Path) + "2/" + "index.html")); Assert.That(Directory.GetDirectories(_activityFolder), Has.Length.EqualTo(2)); Assert.That(File.ReadAllText(Path.Combine(_secondActivityFolder, "index.html")), Is.EqualTo("fake html")); Assert.That(File.ReadAllText(Path.Combine(_secondActivityFolder, "base.css")), Is.EqualTo("fake css")); Assert.That(File.ReadAllText(Path.Combine(_secondActivityFolder, "images", "picture.jpg")), Is.EqualTo("fake image")); }
private void HandleChooseWidget(ApiRequest request) { if (!View.Model.CanChangeImages()) { // Enhance: more widget-specific message? MessageBox.Show( LocalizationManager.GetString("EditTab.CantPasteImageLocked", "Sorry, this book is locked down so that images cannot be changed.")); request.ReplyWithText(""); return; } using (var dlg = new DialogAdapters.OpenFileDialogAdapter { Multiselect = false, CheckFileExists = true, Filter = "Widget files|*.wdgt;*.html;*.htm" }) { var result = dlg.ShowDialog(); if (result != DialogResult.OK) { request.ReplyWithText(""); return; } var fullWidgetPath = dlg.FileName; var ext = Path.GetExtension(fullWidgetPath); if (ext.EndsWith("htm") || ext.EndsWith("html")) { fullWidgetPath = EditingModel.CreateWidgetFromHtmlFolder(fullWidgetPath); } string activityName = View.Model.MakeWidget(fullWidgetPath); var url = UrlPathString.CreateFromUnencodedString(activityName); request.ReplyWithText(url.UrlEncodedForHttpPath); // clean up the temporary widget file we created. if (fullWidgetPath != dlg.FileName) { RobustFile.Delete(fullWidgetPath); } } }
public void MakeWidget_OneFileInZipDifferent_MakesNewFolder() { SetupZip(zip => { zip.Add(new DataFromString("fake css modified"), "base.css", CompressionMethod.Deflated); }); Assert.That(EditingModel.MakeWidget(_bookFolder.FolderPath, _widgetFile.Path), Is.EqualTo(_secondWidgetSrcPath)); Assert.That(Directory.GetDirectories(_activityFolder), Has.Length.EqualTo(2)); // and we should have files for the for the new widget folder. Assert.That(File.ReadAllText(Path.Combine(_secondActivityFolder, "index.htm")), Is.EqualTo("fake html")); Assert.That(File.ReadAllText(Path.Combine(_secondActivityFolder, "base.css")), Is.EqualTo("fake css modified")); Assert.That(File.ReadAllText(Path.Combine(_secondActivityFolder, "images", "picture.jpg")), Is.EqualTo("fake image")); ValidateOriginalActivityFiles(); // We could do this in other tests, but I think once is enough. }
public void MakeActivity_OneExtraFileInZip_MakesNewFolder() { SetupZip(zip => { zip.Add(new DataFromString("fake image 2"), "images/another.jpg", CompressionMethod.Deflated); // add an extra file }); Assert.That(EditingModel.MakeActivity(_bookFolder.FolderPath, _widgetFile.Path), Is.EqualTo(_secondWidgetSrcPath)); Assert.That(Directory.GetDirectories(_activityFolder), Has.Length.EqualTo(2)); // and a new set Assert.That(File.ReadAllText(Path.Combine(_secondActivityFolder, "index.htm")), Is.EqualTo("fake html")); Assert.That(File.ReadAllText(Path.Combine(_secondActivityFolder, "base.css")), Is.EqualTo("fake css")); Assert.That(File.ReadAllText(Path.Combine(_secondActivityFolder, "images", "picture.jpg")), Is.EqualTo("fake image")); Assert.That(File.ReadAllText(Path.Combine(_secondActivityFolder, "images", "another.jpg")), Is.EqualTo("fake image 2")); }