using NUnit.Framework;
+using System.IO;
namespace Tizen.Content.MediaContent.Tests
{
public void SetUp()
{
_mediaInfoCmd = new MediaInfoCommand(_database);
+
+ TestSupport.ClearDatabase(_database, TestConstants.AudioFile, true);
+
_mediaInfo = _mediaInfoCmd.Add(TestConstants.AudioFile);
var bookmarkCmd = new BookmarkCommand(_database);
[Property("AUTHOR", "JungHo Kim, jhyo.kim@samsung.com")]
public async Task MediaInfoUpdated_INSERT_CHECK()
{
+ TestSupport.ClearDatabase(_database, TestConstants.ImageFile, true);
+
var cmd = new MediaInfoCommand(_database);
- cmd.Delete(cmd.Add(TestConstants.ImageFile).Id);
TaskCompletionSource<OperationType> tcs = new TaskCompletionSource<OperationType>();
[Property("AUTHOR", "JungHo Kim, jhyo.kim@samsung.com")]
public void Delete_RETURN()
{
- Assert.That(() => _cmd.Delete(_mediaInfo.Id), Is.True);
+ var path = TestSupport.BackupFileWithMediaId(_database, _mediaInfo.Id);
+
+ try
+ {
+ Assert.That(() => _cmd.Delete(_mediaInfo.Id), Is.True);
+ }
+ finally
+ {
+ TestSupport.RestoreFile(path);
+ }
}
[Test]
{
var dest = TestConstants.RootPath + "/temp.jpg";
File.Copy(TestConstants.ImageFile, dest, true);
- _cmd.Delete(_cmd.Add(dest).Id);
+
+ var mediaId = _cmd.Add(dest).Id;
+ var path = TestSupport.ClearDatabaseWithMediaId(_database, mediaId);
+ _cmd.Delete(mediaId);
+ TestSupport.RestoreFile(path);
Assert.That(_cmd.Move(_mediaInfo.Id, dest), Is.True);
}
[Property("AUTHOR", "JungHo Kim, jhyo.kim@samsung.com")]
public void CreateThumbnailAsync_THROWS_IF_MEDIA_DELETED()
{
+ var path = TestSupport.ClearDatabaseWithMediaId(_database, _mediaInfo.Id);
_cmd.Delete(_mediaInfo.Id);
- Assert.That(() => _cmd.CreateThumbnailAsync(_mediaInfo.Id), Throws.ArgumentException);
+
+ try
+ {
+ Assert.That(() => _cmd.CreateThumbnailAsync(_mediaInfo.Id), Throws.ArgumentException);
+ }
+ finally
+ {
+ TestSupport.RestoreFile(path);
+ }
}
[Test]
[Property("AUTHOR", "JungHo Kim, jhyo.kim@samsung.com")]
public void CreateThumbnailAsync_WITH_CANCELLATION_THROWS_IF_MEDIA_NOT_EXIST()
{
+ TestSupport.ClearDatabaseWithMediaId(_database, _mediaInfo.Id, true);
_cmd.Delete(_mediaInfo.Id);
Assert.That(() => _cmd.CreateThumbnailAsync(_mediaInfo.Id, CancellationToken.None),
Throws.ArgumentException);
[Property("AUTHOR", "JungHo Kim, jhyo.kim@samsung.com")]
public void DetectFaceAsync_THROWS_IF_MEDIA_DELETED()
{
- _cmd.Delete(_mediaInfo.Id);
- Assert.That(() => _cmd.DetectFaceAsync(_mediaInfo.Id), Throws.ArgumentException);
+ var path = TestSupport.ClearDatabaseWithMediaId(_database, _mediaInfo.Id);
+
+ try
+ {
+ _cmd.Delete(_mediaInfo.Id);
+ Assert.That(() => _cmd.DetectFaceAsync(_mediaInfo.Id), Throws.ArgumentException);
+ }
+ finally
+ {
+ TestSupport.RestoreFile(path);
+ }
}
[Test]
[Property("AUTHOR", "JungHo Kim, jhyo.kim@samsung.com")]
public void DetectFaceAsync_WITH_CANCELLATION_THROWS_IF_MEDIA_NOT_EXIST()
{
- _cmd.Delete(_mediaInfo.Id);
- Assert.That(() => _cmd.DetectFaceAsync(_mediaInfo.Id, CancellationToken.None),
- Throws.ArgumentException);
+ var path = TestSupport.ClearDatabaseWithMediaId(_database, _mediaInfo.Id);
+
+ try
+ {
+ _cmd.Delete(_mediaInfo.Id);
+ Assert.That(() => _cmd.DetectFaceAsync(_mediaInfo.Id, CancellationToken.None),
+ Throws.ArgumentException);
+ }
+ finally
+ {
+ TestSupport.RestoreFile(path);
+ }
}
[Test]
public void SetUp()
{
_mediaInfoCmd = new MediaInfoCommand(_database);
+
+ TestSupport.ClearDatabase(_database, TestConstants.AudioFile, true);
+
_mediaInfo = _mediaInfoCmd.Add(TestConstants.AudioFile);
var bookmarkCmd = new BookmarkCommand(_database);
[SetUp]
public new void SetUpBase()
{
- _mediaInfo = new MediaInfoCommand(_database).Add(TestConstants.AudioFile);
+ var mediaCmd = new MediaInfoCommand(_database);
+
+ TestSupport.ClearDatabase(_database, TestConstants.AudioFile, true);
+
+ _mediaInfo = mediaCmd.Add(TestConstants.AudioFile);
_bookmark = new BookmarkCommand(_database).
Insert(_mediaInfo.Id, Offset, BookmarkName, ThumbnailPath);
{
_cmd = new MediaInfoCommand(_database);
+ TestSupport.ClearDatabase(_database, TestConstants.FaceImageFile, true);
+
_mediaInfo = _cmd.Add(TestConstants.FaceImageFile);
}
}
+using System.IO;
+using System.Collections.Generic;
using NUnit.Framework;
namespace Tizen.Content.MediaContent.Tests
{
protected MediaDatabase _database;
- private void ClearDatabase()
- {
- var mediaInfoCmd = new MediaInfoCommand(_database);
- var reader = mediaInfoCmd.SelectMedia();
-
- while (reader.Read())
- {
- mediaInfoCmd.Delete(reader.Current.Id);
- }
-
- var tagCmd = new TagCommand(_database);
-
- var tagReader = tagCmd.Select();
-
- while (tagReader.Read())
- {
- tagCmd.Delete(tagReader.Current.Id);
- }
- }
-
[SetUp]
public void SetUpBase()
{
{
_database.Dispose();
}
+
+ private void ClearDatabase()
+ {
+ var mediaInfoCmd = new MediaInfoCommand(_database);
+
+ var filter = new SelectArguments
+ {
+ FilterExpression = $"{MediaInfoColumns.Path}='{TestConstants.RootPath}'"
+ };
+
+ var reader = mediaInfoCmd.SelectMedia(filter);
+
+ BackupTestFiles();
+
+ try
+ {
+ while (reader.Read())
+ {
+ mediaInfoCmd.Delete(reader.Current.Id);
+ }
+
+ var tagCmd = new TagCommand(_database);
+
+ var tagReader = tagCmd.Select();
+
+ while (tagReader.Read())
+ {
+ tagCmd.Delete(tagReader.Current.Id);
+ }
+ }
+ finally
+ {
+ RestoreTestFiles();
+ }
+ }
+
+ private void BackupTestFiles()
+ {
+ var _testFiles = new Dictionary<string, string>
+ {
+ { TestConstants.AudioFile, TestConstants.AudioFileBackup},
+ { TestConstants.VideoFile, TestConstants.VideoFileBackup },
+ { TestConstants.ImageFile, TestConstants.ImageFileBackup },
+ { TestConstants.ImageFileForFolder, TestConstants.ImageFileForFolderBackup }
+ };
+
+ foreach (var file in _testFiles)
+ {
+ if (File.Exists(file.Key))
+ {
+ File.Move(file.Key, file.Value);
+ }
+ }
+ }
+
+ private void RestoreTestFiles()
+ {
+ var _testFilesBackup = new Dictionary<string, string>
+ {
+ { TestConstants.AudioFileBackup, TestConstants.AudioFile},
+ { TestConstants.VideoFileBackup, TestConstants.VideoFile },
+ { TestConstants.ImageFileBackup, TestConstants.ImageFile },
+ { TestConstants.ImageFileForFolderBackup, TestConstants.ImageFileForFolder }
+ };
+
+ foreach (var file in _testFilesBackup)
+ {
+ if (File.Exists(file.Key))
+ {
+ File.Move(file.Key, file.Value);
+ }
+ }
+ }
}
}
StorageManager.Storages.Where(s => s.StorageType == StorageArea.External).FirstOrDefault();
internal static readonly string ImageFileName = "image.jpg";
-
internal static readonly string WavFile = RootPath + "/test.wav";
-
internal static readonly string ImageFile = RootPath + "/image.jpg";
-
internal static readonly string FaceImageFile = RootPath + "/face_image.jpg";
-
internal static readonly string FaceImageFileUnSupported = RootPath + "/face_image_unsupported.gif";
-
internal static readonly string AudioFile = RootPath + "/sound.mp3";
-
internal static readonly string VideoFile = RootPath + "/movie.mp4";
-
internal static readonly string PlaylistFile = RootPath + "/tmp.m3u";
-
internal static readonly string FolderPath = RootPath + "/test";
-
internal static readonly string ImageFileForFolder = FolderPath + "/test.jpg";
-
internal static readonly string IgnorePath = RootPath + "/ignore";
-
internal static readonly string HiddenPath = RootPath + "/.hidden";
-
internal static readonly string OtherPath = RootPath + "/other";
-
internal static readonly string OtherFile = OtherPath + "/other.txt";
+ internal static readonly string WavFileBackup = RootPath + "/test.bak";
+ internal static readonly string ImageFileBackup = RootPath + "/image.bak";
+ internal static readonly string FaceImageFileBackup = RootPath + "/face_image.bak";
+ internal static readonly string AudioFileBackup = RootPath + "/sound.bak";
+ internal static readonly string VideoFileBackup = RootPath + "/movie.bak";
+ internal static readonly string PlaylistFileBackup = RootPath + "/tmp.bak";
+ internal static readonly string ImageFileForFolderBackup = FolderPath + "/test.bak";
+ internal static readonly string OtherFileBackup = OtherPath + "/other.bak";
+
internal const string OthersFeature = "http://tizen.org/feature/content.scanning.others";
}
}
using System.Collections.Generic;
+using System.IO;
using System.Threading.Tasks;
using Tizen.System;
{
return Information.TryGetValue(Feature, out bool isSupported) ? isSupported : false;
}
+
+ public static void ClearDatabase(MediaDatabase database, string path, bool needRestore = false)
+ {
+ var mediaInfoCmd = new MediaInfoCommand(database);
+
+ var filter = new SelectArguments
+ {
+ FilterExpression = $"{MediaInfoColumns.Path}='{path}'"
+ };
+
+ var reader = mediaInfoCmd.SelectMedia(filter);
+
+ if (File.Exists(path))
+ {
+ File.Move(path, path + ".bak");
+ }
+
+ while (reader.Read())
+ {
+ mediaInfoCmd.Delete(reader.Current.Id);
+ }
+
+ if (needRestore)
+ {
+ RestoreFile(path);
+ }
+ }
+
+ public static string ClearDatabaseWithMediaId(MediaDatabase database, string mediaId, bool needRestore = false)
+ {
+ var mediaInfoCmd = new MediaInfoCommand(database);
+
+ var reader = mediaInfoCmd.SelectMedia(mediaId);
+ string path = reader.Path;
+
+ if (File.Exists(path))
+ {
+ File.Move(path, path + ".bak");
+ }
+
+ mediaInfoCmd.Delete(reader.Id);
+
+ if (needRestore)
+ {
+ RestoreFile(path);
+ }
+
+ return path;
+ }
+
+ public static string BackupFileWithMediaId(MediaDatabase database, string mediaId)
+ {
+ var mediaInfoCmd = new MediaInfoCommand(database);
+
+ var reader = mediaInfoCmd.SelectMedia(mediaId);
+ string path = reader.Path;
+
+ if (File.Exists(path))
+ {
+ File.Move(path, path + ".bak");
+ }
+
+ return path;
+ }
+
+ public static void RestoreFile(string path)
+ {
+ Log.Info("Tizen.Mediacontent.Tests", path + ".bak");
+ File.Move(path + ".bak", path);
+ }
}
}