private void Image_Drop(object sender, DragEventArgs e) { UploadListViewModel uploadListViewModel = (UploadListViewModel)((MainWindowViewModel)this.DataContext).CurrentViewModel; string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); List <Upload> uploads = new List <Upload>(); foreach (string file in files) { uploads.Add(new Upload(file)); } uploadListViewModel.AddUploads(uploads); }
public static void Add2UploadsWithAndWithoutTemplateMatch() { UploadList uploadList; TemplateList templateList; PlaylistList playlistList; MainWindowViewModel mainWindowViewModel = new MainWindowViewModel(BaseSettings.UserSuffix, BaseSettings.SubFolder, out uploadList, out templateList, out playlistList); UploadListViewModel uploadListViewModel = (UploadListViewModel)mainWindowViewModel.CurrentViewModel; List <Upload> uploads = new List <Upload>(); Upload uploadWithoutTemplateMatch = new Upload(BasicTests.video2TargetFilePath); uploads.Add(uploadWithoutTemplateMatch); Upload uploadWithTemplateMatch = new Upload(BasicTests.video1TargetFilePath); uploads.Add(uploadWithTemplateMatch); uploadListViewModel.AddUploads(uploads); Assert.IsTrue(uploadWithoutTemplateMatch.Template == null); Assert.IsTrue(uploadWithoutTemplateMatch.Description == null); Assert.IsTrue(Path.GetFullPath(uploadWithoutTemplateMatch.ImageFilePath) == Path.GetFullPath(BasicTests.defaultTemplateRenderingImageFilePath)); Assert.IsTrue(uploadWithoutTemplateMatch.Playlist == null); Assert.IsTrue(uploadWithoutTemplateMatch.Tags.Count == 0); Assert.IsTrue(uploadWithoutTemplateMatch.ThumbnailFilePath == null); Assert.IsTrue(uploadWithoutTemplateMatch.Title == "video2"); Assert.IsTrue(uploadWithoutTemplateMatch.YtTitle == "video2"); Assert.IsTrue(uploadWithoutTemplateMatch.Visibility == Visibility.Private); Assert.IsTrue(uploadWithTemplateMatch.Template == templateList.GetTemplate(0)); Assert.IsTrue(uploadWithTemplateMatch.Description == BasicTests.testTemplateDescription); Assert.IsTrue(Path.GetFullPath(uploadWithTemplateMatch.ImageFilePath) == Path.GetFullPath(BasicTests.defaultTemplateRenderingImageFilePath)); Assert.IsTrue(uploadWithTemplateMatch.Playlist == playlistList.GetPlaylist(0)); Assert.IsTrue(uploadWithTemplateMatch.Tags.Count == 2); Assert.IsTrue(uploadWithTemplateMatch.Tags[0] == BasicTests.testTemplateTag1); Assert.IsTrue(uploadWithTemplateMatch.Tags[1] == BasicTests.testTemplateTag2); Assert.IsTrue(uploadWithTemplateMatch.ThumbnailFilePath == null); //todo: add video with # placeholder Assert.IsTrue(uploadWithTemplateMatch.Title == BasicTests.testTemplateTitle); Assert.IsTrue(uploadWithTemplateMatch.YtTitle == BasicTests.testTemplateTitle); Assert.IsTrue(uploadWithTemplateMatch.Visibility == Visibility.Private); uploadList = null; templateList = null; playlistList = null; mainWindowViewModel = null; Assert.IsTrue(File.Exists(Path.Combine(BaseSettings.StorageFolder, "uploads.json"))); Assert.IsTrue(File.Exists(Path.Combine(BaseSettings.StorageFolder, "uploadlist.json"))); JArray jArray = (JArray)JsonConvert.DeserializeObject(File.ReadAllText(Path.Combine(BaseSettings.StorageFolder, "uploads.json"))); Assert.IsTrue(jArray.Count == 2); bool foundUploadWithoutTemplateMatch = false; bool foundUploadWithTemplateMatch = false; int uploadsCount = 0; string uploadWithoutTemplateMatchGuid = null; string uploadWithTemplateMatchGuid = null; foreach (JObject jsonUpload in jArray.SelectTokens("$.[*]")) { uploadsCount++; string filePath = jsonUpload["filePath"].Value <string>(); string templateGuid = jsonUpload["template"].Value <string>(); string playlist = jsonUpload["playlist"].Value <string>(); int tagCount = ((JArray)jsonUpload["tags"]).Count; string thumbnailFilePath = jsonUpload["thumbnailFilePath"].Value <string>(); string title = jsonUpload["title"].Value <string>(); string visibility = jsonUpload["visibility"].Value <string>(); if (filePath == BasicTests.video2TargetFilePath) { uploadWithoutTemplateMatchGuid = jsonUpload["guid"].Value <string>(); foundUploadWithoutTemplateMatch = true; Assert.IsTrue(templateGuid == null); Assert.IsTrue(playlist == null); Assert.IsTrue(tagCount == 0); Assert.IsTrue(thumbnailFilePath == null); Assert.IsTrue(title == "video2"); Assert.IsTrue(visibility == BasicTests.privateVisibility); } if (filePath == BasicTests.video1TargetFilePath) { uploadWithTemplateMatchGuid = jsonUpload["guid"].Value <string>(); foundUploadWithTemplateMatch = true; string tag1 = ((JArray)jsonUpload["tags"])[0].Value <string>(); string tag2 = ((JArray)jsonUpload["tags"])[1].Value <string>(); Assert.IsTrue(templateGuid == BasicTests.testTemplateGuid); Assert.IsTrue(playlist == BasicTests.testPlaylistId); Assert.IsTrue(tagCount == 2); Assert.IsTrue(tag1 == BasicTests.testTemplateTag1); Assert.IsTrue(tag2 == BasicTests.testTemplateTag2); Assert.IsTrue(thumbnailFilePath == null); Assert.IsTrue(title == BasicTests.testTemplateTitle); Assert.IsTrue(visibility == BasicTests.privateVisibility); } } Assert.IsTrue(uploadsCount == 2); Assert.IsTrue(foundUploadWithoutTemplateMatch); Assert.IsTrue(foundUploadWithTemplateMatch); jArray = (JArray)((JObject)JsonConvert.DeserializeObject(File.ReadAllText(Path.Combine(BaseSettings.StorageFolder, "uploadlist.json"))))["uploads"]; Assert.IsTrue(jArray.Count == 2); foundUploadWithoutTemplateMatch = false; foundUploadWithTemplateMatch = false; uploadsCount = 0; foreach (JValue guid in jArray.SelectTokens("$.[*]")) { uploadsCount++; string jsonGuid = guid.Value <string>(); if (jsonGuid == uploadWithoutTemplateMatchGuid) { foundUploadWithoutTemplateMatch = true; } if (jsonGuid == uploadWithTemplateMatchGuid) { foundUploadWithTemplateMatch = true; } } Assert.IsTrue(uploadsCount == 2); Assert.IsTrue(foundUploadWithoutTemplateMatch); Assert.IsTrue(foundUploadWithTemplateMatch); }
public static void AddFirstUpload() { UploadList uploadList; TemplateList templateList; PlaylistList playlistList; MainWindowViewModel mainWindowViewModel = new MainWindowViewModel(BaseSettings.UserSuffix, BaseSettings.SubFolder, out uploadList, out templateList, out playlistList); UploadListViewModel uploadListViewModel = (UploadListViewModel)mainWindowViewModel.CurrentViewModel; List <Upload> uploads = new List <Upload>(); uploads.Add(new Upload(BasicTests.video1TargetFilePath)); uploadListViewModel.AddUploads(uploads); Assert.IsTrue(uploadList.UploadCount == 1); Assert.IsTrue(uploadList.GetUpload(0).FilePath == BasicTests.video1TargetFilePath); Assert.IsTrue(templateList.TemplateCount == 0); Assert.IsTrue(playlistList.PlaylistCount == 0); uploadList = null; templateList = null; playlistList = null; mainWindowViewModel = null; Assert.IsTrue(File.Exists(Path.Combine(BaseSettings.StorageFolder, "uploads.json"))); Assert.IsTrue(File.Exists(Path.Combine(BaseSettings.StorageFolder, "uploadlist.json"))); Assert.IsTrue(!File.Exists(Path.Combine(BaseSettings.StorageFolder, "templatelist.json"))); Assert.IsTrue(!File.Exists(Path.Combine(BaseSettings.StorageFolder, "playlistlist.json"))); JArray jArray = (JArray)JsonConvert.DeserializeObject(File.ReadAllText(Path.Combine(BaseSettings.StorageFolder, "uploads.json"))); Assert.IsTrue(jArray.Count == 1); bool found = false; int uploadsCount = 0; string newUploadGuid = null; foreach (JObject upload in jArray.SelectTokens("$.[*]")) { uploadsCount++; string filePath = upload["filePath"].Value <string>(); if (filePath == BasicTests.video1TargetFilePath) { newUploadGuid = upload["guid"].Value <string>(); found = true; } } Assert.IsTrue(uploadsCount == 1); Assert.IsTrue(found); jArray = (JArray)((JObject)JsonConvert.DeserializeObject(File.ReadAllText(Path.Combine(BaseSettings.StorageFolder, "uploadlist.json"))))["uploads"]; Assert.IsTrue(jArray.Count == 1); found = false; uploadsCount = 0; foreach (JValue guid in jArray.SelectTokens("$.[*]")) { uploadsCount++; string jsonGuid = guid.Value <string>(); if (jsonGuid == newUploadGuid) { found = true; } } Assert.IsTrue(uploadsCount == 1); Assert.IsTrue(found); }