public void Should_Throw_Exception_For_Invalid_Folder_Type()
        {
            RunApiActionInTransaction((api, session) =>
            {
                folder = TestDataProvider.CreateNewMediaFolder(false);
                session.SaveOrUpdate(folder);
                session.Flush();

                Run(session, api.Media.Files.Upload.Post, api.Media.File.Get, api.Media.File.Delete);
            });
        }
        public void Should_Upload_File_From_Stream_Successfully()
        {
            Events.MediaManagerEvents.Instance.MediaFileUploaded += Instance_EntityCreated;
            Events.MediaManagerEvents.Instance.MediaFileDeleted  += Instance_EntityDeleted;

            RunApiActionInTransaction((api, session) =>
            {
                folder = TestDataProvider.CreateNewMediaFolder(false, MediaType.File);
                session.SaveOrUpdate(folder);
                session.Flush();

                Run(session, api.Media.Files.Upload.Post, api.Media.File.Get, api.Media.File.Delete);
            });

            Events.MediaManagerEvents.Instance.MediaFileUploaded -= Instance_EntityCreated;
            Events.MediaManagerEvents.Instance.MediaFileDeleted  -= Instance_EntityDeleted;
        }
Example #3
0
        public void Should_Insert_And_Retrieve_MediaFolder_Files_Successfully()
        {
            var mediaFolder = TestDataProvider.CreateNewMediaFolder();

            var files = new []
            {
                TestDataProvider.CreateNewMediaFile(mediaFolder),
                TestDataProvider.CreateNewMediaImage(mediaFolder),
                TestDataProvider.CreateNewMediaImage(mediaFolder)
            };

            mediaFolder.Medias = files;

            SaveEntityAndRunAssertionsInTransaction(
                mediaFolder,
                result =>
            {
                Assert.AreEqual(mediaFolder, result);
                Assert.AreEqual(files.OrderBy(f => f.Id), result.Medias.OrderBy(f => f.Id));
            });
        }
Example #4
0
        public void Should_Insert_And_Retrieve_MediaFolder_Successfully()
        {
            var entity = TestDataProvider.CreateNewMediaFolder();

            RunEntityMapTestsInTransaction(entity);
        }
        private Media[] CreateFakeMedias(ISession session, bool fakeRoot = true)
        {
            // Files and folders structure:
            // Images1
            //      Images1_1
            //          Images1_1_1
            //          Images1_1_2
            //          FILE:Image1_1__1
            //      Images1_2
            //      FILE:Image1__1
            //      FILE:Image1__2
            // Images2
            //      Images2_1
            // Files1
            //      Files1_1
            //      FILE:File1_1
            // FILE:RootImage1
            // FILE:RootImage2
            // FILE:RootImage3
            // FILE:RootFile1

            MediaFolder rootFolder = null;

            if (fakeRoot)
            {
                rootFolder        = TestDataProvider.CreateNewMediaFolder(false);
                rootFolder.Folder = null;
                rootFolder.Title  = string.Concat("TestFolder_", Guid.NewGuid().ToString());
            }

            var images1     = TestDataProvider.CreateNewMediaFolder(false);
            var images2     = TestDataProvider.CreateNewMediaFolder(false);
            var images1_1   = TestDataProvider.CreateNewMediaFolder(false);
            var images1_2   = TestDataProvider.CreateNewMediaFolder(false);
            var images2_1   = TestDataProvider.CreateNewMediaFolder(false);
            var images1_1_1 = TestDataProvider.CreateNewMediaFolder(false);
            var images1_1_2 = TestDataProvider.CreateNewMediaFolder(false);

            var files1   = TestDataProvider.CreateNewMediaFolder(false, MediaType.File);
            var files1_1 = TestDataProvider.CreateNewMediaFolder(false, MediaType.File);

            images1.Folder     = rootFolder;
            images2.Folder     = rootFolder;
            images1_1.Folder   = images1;
            images1_2.Folder   = images1;
            images2_1.Folder   = images2;
            images1_1_1.Folder = images1_1;
            images1_1_2.Folder = images1_1;
            files1.Folder      = rootFolder;
            files1_1.Folder    = files1;

            images1.Title     = "Images1";
            images2.Title     = "Images2";
            images1_1.Title   = "Images1_1";
            images1_2.Title   = "Images1_2";
            images2_1.Title   = "Images2_1";
            images1_1_1.Title = "Images1_1_1";
            images1_1_2.Title = "Images1_1_2";
            files1.Title      = "Files1";
            files1_1.Title    = "Files1_1";

            var rootImage1  = TestDataProvider.CreateNewMediaImage();
            var rootImage2  = TestDataProvider.CreateNewMediaImage();
            var rootImage3  = TestDataProvider.CreateNewMediaImage();
            var image1__1   = TestDataProvider.CreateNewMediaImage(images1);
            var image1__2   = TestDataProvider.CreateNewMediaImage(images1);
            var image1_1__1 = TestDataProvider.CreateNewMediaImage(images1_1);
            var rootFile1   = TestDataProvider.CreateNewMediaFile();
            var file1_1     = TestDataProvider.CreateNewMediaFile(files1);

            rootImage1.Folder = rootFolder;
            rootImage2.Folder = rootFolder;
            rootImage3.Folder = rootFolder;
            rootFile1.Folder  = rootFolder;

            rootImage1.Title  = "RootImage1";
            rootImage2.Title  = "RootImage2";
            rootImage3.Title  = "RootImage3";
            image1__1.Title   = "Image1__1";
            image1__2.Title   = "Image1__2";
            image1_1__1.Title = "Image1_1__1";
            rootFile1.Title   = "RootFile1";
            file1_1.Title     = "File1_1";

            var medias = new Media[] {
                // Image folders
                images1,
                images2,
                images1_1,
                images1_2,
                images2_1,
                images1_1_1,
                images1_1_2,

                // File folders
                files1,
                files1_1,

                // Images
                rootImage1,
                rootImage2,
                rootImage3,
                image1__1,
                image1__2,
                image1_1__1,

                // Files
                rootFile1,
                file1_1
            };

            if (!fakeRoot)
            {
                var suffix = Guid.NewGuid().ToString();
                medias.ToList().ForEach(m => m.Title = string.Concat(m.Title, "_", suffix));
            }
            medias.ToList().ForEach(m => session.SaveOrUpdate(m));
            session.Flush();
            session.Clear();

            return(medias);
        }