示例#1
0
        public async Task SaveTestAsync()
        {
            var             coverPicPath = @"C:\temp\cutePuppy.jpg";
            PhotoLibraryObj library      = await PhotoLibraryObj.CreatePhotoLibraryAsync(Guid.NewGuid().ToString(), coverPicPath);

            await library.AddPhotoPathAsync("C:\\Users\\lentochka\\Desktop\\eden.jpg");

            await library.AddPhotoPathAsync("C:\\Users\\lentochka\\Desktop\\karen.jpg");

            await library.SelectCoverPhotoAsync("C:\\Users\\lentochka\\Desktop\\karen.jpg");

            var loadLibrary = await PhotoLibraryObj.LoadPhotoLibraryAsync(library.Name);

            Photo photo1 = library.GetPhotos().FirstOrDefault(p => p.Path == "C:\\Users\\lentochka\\Desktop\\eden.jpg");
            Photo photo2 = library.GetPhotos().FirstOrDefault(p => p.Path == "C:\\Users\\lentochka\\Desktop\\karen.jpg");
            Photo photo3 = loadLibrary.GetPhotos().FirstOrDefault(p => p.Path == "C:\\Users\\lentochka\\Desktop\\eden.jpg");
            Photo photo4 = loadLibrary.GetPhotos().FirstOrDefault(p => p.Path == "C:\\Users\\lentochka\\Desktop\\karen.jpg");
            var   numberOfPhotosLibrary     = library.GetPhotos().Count();
            var   numberOfPhotosLoadLibrary = loadLibrary.GetPhotos().Count();

            Assert.AreEqual(library.Name, loadLibrary.Name);
            Assert.AreEqual(library.CoverPhotoPath, loadLibrary.CoverPhotoPath);
            Assert.IsNotNull(photo1);
            Assert.IsNotNull(photo2);
            Assert.IsNotNull(photo3);
            Assert.IsNotNull(photo4);
            Assert.AreEqual(photo1.Path, photo3.Path);
            Assert.AreEqual(photo2.Path, photo4.Path);
            Assert.AreEqual(numberOfPhotosLibrary, numberOfPhotosLoadLibrary);
        }
        public void CanAddNewLibraryToLibraryManager()
        {
            var photoLibraryManager = PhotoLibraryManager.GetInstance();

            photoLibraryManager.Initialize().Wait();

            var coverPicPath = @"C:\temp\cutePuppy.jpg";
            var libraryName1 = "Test1";
            var library1     = PhotoLibraryObj.CreatePhotoLibraryAsync(libraryName1, coverPicPath).Result;

            var libraryName2 = "Test2";
            var library2     = PhotoLibraryObj.CreatePhotoLibraryAsync(libraryName2, coverPicPath).Result;

            try
            {
                photoLibraryManager.AddPhotoLibraryAsync(library1).Wait();
                photoLibraryManager.AddPhotoLibraryAsync(library2).Wait();

                // Assert.IsTrue(File.Exists(photoLibraryManager.PhotoLibraryManagerFile));
                var libraries = GetPhotoLibraryNames().Result;
                Assert.AreEqual(2, libraries.Count);
                Assert.IsTrue(libraries.ContainsKey(libraryName1));
                Assert.IsTrue(libraries.ContainsKey(libraryName2));
            }
            finally
            {
                photoLibraryManager.ClearAsync().Wait();
            }
        }
示例#3
0
        public async Task AddRemovePhotoPathTest()
        {
            var             coverPicPath = @"C:\temp\cutePuppy.jpg";
            PhotoLibraryObj library      = await PhotoLibraryObj.CreatePhotoLibraryAsync("eden", coverPicPath);

            await library.AddPhotoPathAsync("C:\\Users\\lentochka\\Desktop\\eden.jpg");

            await library.AddPhotoPathAsync("C:\\Users\\lentochka\\Desktop\\karen.jpg");

            Photo photo1 = library.GetPhotos().FirstOrDefault(p => p.Path == "C:\\Users\\lentochka\\Desktop\\eden.jpg");
            Photo photo2 = library.GetPhotos().FirstOrDefault(p => p.Path == "C:\\Users\\lentochka\\Desktop\\karen.jpg");

            Assert.IsNotNull(photo1);
            Assert.IsNotNull(photo2);
            Assert.AreEqual(photo1.Path, "C:\\Users\\lentochka\\Desktop\\eden.jpg");
            Assert.AreEqual(photo2.Path, "C:\\Users\\lentochka\\Desktop\\karen.jpg");

            await library.RemovePhotoPathAsync("C:\\Users\\lentochka\\Desktop\\karen.jpg");

            photo2 = library.GetPhotos().FirstOrDefault(p => p.Path == "C:\\Users\\lentochka\\Desktop\\karen.jpg");
            Assert.IsNull(photo2);
        }
        public void CanRemoveLibraryFromLibraryManager()
        {
            var photoLibraryManager = PhotoLibraryManager.GetInstance();

            photoLibraryManager.Initialize().Wait();

            var coverPicPath = @"C:\temp\cutePuppy.jpg";
            var libraryName1 = "TestA";
            var library1     = PhotoLibraryObj.CreatePhotoLibraryAsync(libraryName1, coverPicPath).Result;

            var libraryName2 = "TestB";
            var library2     = PhotoLibraryObj.CreatePhotoLibraryAsync(libraryName2, coverPicPath).Result;

            try
            {
                photoLibraryManager.AddPhotoLibraryAsync(library1).Wait();
                photoLibraryManager.AddPhotoLibraryAsync(library2).Wait();

                var libraries = GetPhotoLibraryNames().Result;
                Assert.AreEqual(2, libraries.Count);
                Assert.IsTrue(libraries.ContainsKey(libraryName1));
                Assert.IsTrue(libraries.ContainsKey(libraryName2));

                // remove library1
                photoLibraryManager.RemovePhotoLibraryAsync(library1.Name).Wait();

                var upadtedLibraries = GetPhotoLibraryNames().Result;
                Assert.AreEqual(1, upadtedLibraries.Count);
                Assert.IsFalse(upadtedLibraries.ContainsKey(libraryName1));
                Assert.IsTrue(upadtedLibraries.ContainsKey(libraryName2));
            }
            finally
            {
                photoLibraryManager.ClearAsync().Wait();
            }
        }