private MediaImage CreateFakeImage(ISession session)
        {
            var image = TestDataProvider.CreateNewMediaImage();

            session.SaveOrUpdate(image);
            session.Flush();
            session.Clear();

            return(image);
        }
Пример #2
0
        protected override SaveAuthorModel GetCreateModel(ISession session)
        {
            var image = TestDataProvider.CreateNewMediaImage();

            session.SaveOrUpdate(image);

            return(new SaveAuthorModel
            {
                Name = TestDataProvider.ProvideRandomString(MaxLength.Name),
                ImageId = image.Id
            });
        }
Пример #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));
            });
        }
Пример #4
0
        public void Should_Retrieve_AllField_If_Image_Is_Null()
        {
            RunActionInTransaction(
                session =>
            {
                var testAuthor             = TestDataProvider.CreateNewAuthor();
                testAuthor.Image           = TestDataProvider.CreateNewMediaImage();
                testAuthor.Image.IsDeleted = true;
                session.SaveOrUpdate(testAuthor);
                session.Flush();
                session.Clear();

                var repository = new DefaultRepository(new DefaultUnitOfWork(session));

                var model = repository.AsQueryable <Author>()
                            .Where(f => !f.IsDeleted)
                            .Where(f => f.Id == testAuthor.Id)
                            .Select(author => new AuthorModel
                {
                    Id             = author.Id,
                    Version        = author.Version,
                    CreatedBy      = author.CreatedByUser,
                    CreatedOn      = author.CreatedOn,
                    LastModifiedBy = author.ModifiedByUser,
                    LastModifiedOn = author.ModifiedOn,

                    Name = author.Name,

                    ImageId           = author.Image != null && !author.Image.IsDeleted ? author.Image.Id : (Guid?)null,
                    ImageUrl          = author.Image != null && !author.Image.IsDeleted ? author.Image.PublicUrl : (string)null,
                    ImageThumbnailUrl = author.Image != null && !author.Image.IsDeleted ? author.Image.PublicThumbnailUrl : (string)null,
                    ImageCaption      = author.Image != null && !author.Image.IsDeleted ? author.Image.Caption : (string)null
                }).FirstOne();

                Assert.IsNotNull(model);
                Assert.AreEqual(testAuthor.Id, model.Id);
                Assert.IsNull(model.ImageId);
            });
        }
Пример #5
0
        public void Should_Insert_And_Retrieve_MediaImage_Successfully()
        {
            var entity = TestDataProvider.CreateNewMediaImage();

            RunEntityMapTestsInTransaction(entity);
        }
Пример #6
0
        protected override SavePagePropertiesModel GetCreateModel(ISession session)
        {
            var categoryTree = TestDataProvider.CreateNewCategoryTree();
            var category     = TestDataProvider.CreateNewCategory(categoryTree);
            var image        = TestDataProvider.CreateNewMediaImage();

            session.SaveOrUpdate(category);
            session.SaveOrUpdate(image);
            session.Flush();
            session.Clear();

            return(new SavePagePropertiesModel
            {
                Title = TestDataProvider.ProvideRandomString(MaxLength.Name),
                Tags = new[] { this.TestDataProvider.ProvideRandomString(MaxLength.Name), this.TestDataProvider.ProvideRandomString(MaxLength.Name) },
                AccessRules = new[]
                {
                    new AccessRuleModel
                    {
                        AccessLevel = AccessLevel.ReadWrite,
                        Identity = TestDataProvider.ProvideRandomString(20),
                        IsForRole = false
                    },
                    new AccessRuleModel
                    {
                        AccessLevel = AccessLevel.Deny,
                        Identity = TestDataProvider.ProvideRandomString(20),
                        IsForRole = true
                    }
                },
                CustomCss = TestDataProvider.ProvideRandomString(MaxLength.Text),
                CustomJavaScript = TestDataProvider.ProvideRandomString(MaxLength.Text),
                Description = TestDataProvider.ProvideRandomString(MaxLength.Text),
                Categories = new List <Guid>()
                {
                    category.Id
                },
                FeaturedImageId = image.Id,
                IsArchived = false,
                IsMasterPage = false,
                IsPublished = true,
                LanguageGroupIdentifier = null,
                ForceAccessProtocol = ForceProtocolType.ForceHttps,
                LanguageId = null,
                LayoutId = layout != null ? layout.Id : (Guid?)null,
                MasterPageId = masterPage != null ? masterPage.Id : (Guid?)null,
                SecondaryImageId = image.Id,
                MainImageId = image.Id,
                MetaData = new MetadataModel
                {
                    MetaTitle = TestDataProvider.ProvideRandomString(MaxLength.Name),
                    MetaDescription = TestDataProvider.ProvideRandomString(MaxLength.Text),
                    MetaKeywords = TestDataProvider.ProvideRandomString(MaxLength.Text)
                },
                PageOptions = new List <OptionValueModel>
                {
                    new OptionValueModel
                    {
                        DefaultValue = TestDataProvider.ProvideRandomString(100),
                        Value = TestDataProvider.ProvideRandomString(100),
                        Key = TestDataProvider.ProvideRandomString(100),
                        Type = OptionType.Text,
                        UseDefaultValue = false
                    },
                    new OptionValueModel
                    {
                        DefaultValue = Guid.NewGuid().ToString(),
                        Value = Guid.NewGuid().ToString(),
                        Key = TestDataProvider.ProvideRandomString(100),
                        Type = OptionType.Custom,
                        CustomTypeIdentifier = MediaManagerFolderOptionProvider.Identifier,
                        UseDefaultValue = false
                    }
                },
                PageUrl = string.Format("/{0}/", TestDataProvider.ProvideRandomString(200)),
                PublishedOn = TestDataProvider.ProvideRandomDateTime(),
                UseCanonicalUrl = TestDataProvider.ProvideRandomBooleanValue(),
                UseNoFollow = TestDataProvider.ProvideRandomBooleanValue(),
                UseNoIndex = TestDataProvider.ProvideRandomBooleanValue()
            });
        }
        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);
        }