public void Test_Add_File_To_Content_Item_Without_Metadata()
        {
            var dataService = DataServiceFactory();

            dataService.Setup(ds => ds.AddContentItem(It.IsAny <ContentItem>(), It.IsAny <int>()))
            .Returns(Constants.CONTENT_AddContentItemId);

            // Return empty set of metadata.
            dataService.Setup(ds => ds.GetMetaData(It.IsAny <int>())).Returns(MockHelper.CreateEmptyMetaDataReader);

            var content = ContentTestHelper.CreateValidContentItem();

            content.Metadata.Clear();

            var contentId = Util.GetContentController().AddContentItem(content);

            Assert.AreEqual(contentId, Constants.CONTENT_AddContentItemId);
            Assert.IsEmpty(content.Metadata);

            dataService.Setup(ds => ds.GetContentItem(It.IsAny <int>()))
            .Returns <int>(y => MockHelper.CreateValidContentItemReader(content));

            var fileController = ComponentFactory.GetComponent <IAttachmentController>();

            fileController.AddFileToContent(contentId, ContentTestHelper.CreateValidFile(0));

            dataService.Verify(
                ds => ds.AddMetaData(It.IsAny <ContentItem>(), FileController.FilesKey, new[] { 0 }.ToJson()));
        }
        public void Test_Load_Attachments_From_DataService()
        {
            var files = new List <IFileInfo>
            {
                ContentTestHelper.CreateValidFile(0),
                ContentTestHelper.CreateValidFile(1),
                ContentTestHelper.CreateValidFile(2),
            };

            var dataService = DataServiceFactory();

            dataService.Setup(ds => ds.GetContentItem(It.IsAny <int>())).Returns(MockHelper.CreateValidContentItemReader);

            dataService.Setup(
                ds =>
                ds.GetMetaData(It.IsAny <int>())).Returns(
                () => MockHelper.CreateMetaDataReaderWithFiles(files, new IFileInfo[0], new IFileInfo[0]));

            var contentItem = Util.GetContentController().GetContentItem(Constants.CONTENT_ValidContentItemId);

            Assert.IsNotNull(contentItem);

            var serialized = contentItem.Metadata[FileController.FilesKey];

            Assert.IsNotEmpty(serialized);

            Assert.IsNotEmpty(contentItem.Files);
            Assert.AreEqual(contentItem.Files.Count, 3);
            Assert.AreEqual(contentItem.Files[0].FileId, 0);
            Assert.AreEqual(contentItem.Files[1].FileId, 1);
            Assert.AreEqual(contentItem.Files[2].FileId, 2);
        }
        public void CategorizeHccModule(string moduleName)
        {
            var  objDesktopModule   = DesktopModuleController.GetDesktopModuleByModuleName(moduleName, Null.NullInteger);
            var  vocabularyId       = -1;
            var  termController     = Util.GetTermController();
            Term moduleCategoryTerm = null;

            foreach (var term in termController.GetTermsByVocabulary("Module_Categories"))
            {
                vocabularyId = term.VocabularyId;
                if (term.Name == MODULE_CATEGORY)
                {
                    moduleCategoryTerm = term;
                    break;
                }
            }
            if (moduleCategoryTerm == null)
            {
                moduleCategoryTerm      = new Term(vocabularyId);
                moduleCategoryTerm.Name = MODULE_CATEGORY;
                termController.AddTerm(moduleCategoryTerm);
            }
            var contentItem        = Util.GetContentController().GetContentItem(objDesktopModule.ContentItemId);
            var contentItemTermIds = contentItem.Terms.Select(t => t.TermId).ToList();

            if (!contentItemTermIds.Contains(moduleCategoryTerm.TermId))
            {
                termController.AddTermToContent(moduleCategoryTerm, contentItem);
            }
        }
        public void Test_Add_Attachments_With_FileController()
        {
            var dataService = DataServiceFactory();

            dataService.Setup(
                ds =>
                ds.GetContentItem(It.IsAny <int>())).Returns(MockHelper.CreateValidContentItemReader);

            // Use a closure to store the metadata locally in this method.
            var data = new Dictionary <string, string>();

            dataService.Setup(
                ds =>
                ds.GetMetaData(It.IsAny <int>())).Returns(
                () => MockHelper.CreateMetaDataReaderFromDictionary(data));

            dataService.Setup(
                ds =>
                ds.AddMetaData(
                    It.IsAny <ContentItem>(),
                    It.IsAny <string>(),
                    It.IsAny <string>()))
            .Callback <ContentItem, string, string>((ci, name, value) => data[name] = value);

            var contentController = Util.GetContentController();

            var contentItem = contentController.GetContentItem(Constants.CONTENT_ValidContentItemId);

            Assert.IsNotNull(contentItem);

            var serialized = contentItem.Metadata[FileController.FilesKey];

            Assert.IsNull(serialized);
            Assert.IsEmpty(contentItem.Files);

            var fileManager = ComponentFactory.GetComponent <IFileManager>();

            // Add some files.
            var fileController = ComponentFactory.GetComponent <IAttachmentController>();

            fileController.AddFileToContent(contentItem.ContentItemId, fileManager.GetFile(0));
            fileController.AddFileToContent(contentItem.ContentItemId, fileManager.GetFile(1));

            contentItem = contentController.GetContentItem(Constants.CONTENT_ValidContentItemId);

            Assert.AreEqual(contentItem.Files.Count, 2);
            Assert.AreEqual(contentItem.Files[0].FileId, 0);
            Assert.AreEqual(contentItem.Files[1].FileId, 1);

            dataService.Verify(
                ds => ds.DeleteMetaData(It.IsAny <ContentItem>(), FileController.FilesKey, "[0]"), Times.Once());

            dataService.Verify(
                ds => ds.AddMetaData(It.IsAny <ContentItem>(), FileController.FilesKey, "[0]"), Times.Once());

            dataService.Verify(
                ds => ds.AddMetaData(It.IsAny <ContentItem>(), FileController.FilesKey, "[0,1]"), Times.Once());
        }
        public void Set_MetaData_To_Empty_Value_Deletes_Row()
        {
            var data = new Dictionary <string, string>();

            var dataService = DataServiceFactoryWithLocalMetaData(ref data);

            dataService.Setup(ds => ds.GetContentItem(It.IsAny <int>())).Returns(MockHelper.CreateValidContentItemReader);

            var contentController = Util.GetContentController();

            var fileManager = ComponentFactory.GetComponent <IFileManager>();

            var contentItem = contentController.GetContentItem(Constants.CONTENT_ValidContentItemId);

            Assert.IsNotNull(contentItem);

            var serialized = contentItem.Metadata[FileController.FilesKey];

            Assert.IsNull(serialized);
            Assert.IsEmpty(contentItem.Files);

            // Add some files.
            var fileController = ComponentFactory.GetComponent <IAttachmentController>();

            fileController.AddFileToContent(contentItem.ContentItemId, fileManager.GetFile(0));
            fileController.AddFileToContent(contentItem.ContentItemId, fileManager.GetFile(1));

            contentItem = contentController.GetContentItem(Constants.CONTENT_ValidContentItemId);

            Assert.AreEqual(contentItem.Files.Count, 2);
            Assert.AreEqual(contentItem.Files[0].FileId, 0);
            Assert.AreEqual(contentItem.Files[1].FileId, 1);
            Assert.IsNotEmpty(contentItem.Metadata[FileController.FilesKey]);

            contentItem.Files.Clear();

            contentController.UpdateContentItem(contentItem);

            dataService.Verify(ds => ds.DeleteMetaData(It.IsAny <ContentItem>(), FileController.FilesKey, "[0]"), Times.Once());
            dataService.Verify(ds => ds.DeleteMetaData(It.IsAny <ContentItem>(), FileController.FilesKey, "[0,1]"), Times.Once());
            dataService.Verify(ds => ds.AddMetaData(It.IsAny <ContentItem>(), FileController.FilesKey, "[0]"), Times.Once());
            dataService.Verify(ds => ds.AddMetaData(It.IsAny <ContentItem>(), FileController.FilesKey, "[0,1]"), Times.Once());

            var emptyFiles = fileController.GetFilesByContent(contentItem.ContentItemId);

            Assert.AreEqual(0, emptyFiles.Count);
        }
Exemplo n.º 6
0
        /// <summary>
        ///  Sets the Page Meta information for the Question.ascx view.
        /// </summary>
        /// <param name="defaultPage"></param>
        /// <param name="objQuestion"></param>
        /// <param name="modContext"></param>
        /// <remarks>Need to wire in page to accept page param in URL.</remarks>
        public static void SetQuestionPageMeta(CDefault defaultPage, AlbumInfo objQuestion, ModuleInstanceContext modContext)
        {
            var title    = TruncateString(objQuestion.Title + " - " + modContext.PortalSettings.PortalName, Constants.SeoTitleLimit, false);
            var content  = TruncateString(objQuestion.Body, Constants.SeoDescriptionLimit, false);
            var link     = Links.ViewQuestion(objQuestion.PostId, objQuestion.Title, modContext.PortalSettings.ActiveTab, modContext.PortalSettings);
            var keyWords = "";
            var keyCount = 1;
            var count    = keyCount;

            var terms = UtilContent.GetContentController().GetContentItem(objQuestion.ContentItemId).Terms;

            foreach (var term in terms.TakeWhile(term => count <= Constants.SeoKeywordsLimit))
            {
                keyWords += "," + term.Name;
                keyCount += 1;
            }

            SetPageMetaAndOpenGraph(defaultPage, modContext, title, content, keyWords, link);
        }
        public void Set_MetaData_To_Same_Value_Doesnt_Update_Database_Entry()
        {
            var metadata = new Dictionary <string, string>();

            var dataService = DataServiceFactoryWithLocalMetaData(ref metadata);

            var contentController = Util.GetContentController();

            var contentItem = ContentTestHelper.CreateValidContentItem();

            contentController.AddContentItem(contentItem);

            dataService.Verify(ds => ds.AddMetaData(contentItem, FileController.TitleKey, It.IsAny <string>()), Times.Never());
            dataService.Verify(ds => ds.DeleteMetaData(contentItem, FileController.TitleKey, It.IsAny <string>()), Times.Never());

            contentItem.ContentTitle = "Foobar";

            contentController.UpdateContentItem(contentItem);

            dataService.Verify(ds => ds.AddMetaData(contentItem, FileController.TitleKey, It.IsAny <string>()), Times.Once());
            dataService.Verify(ds => ds.DeleteMetaData(contentItem, FileController.TitleKey, It.IsAny <string>()), Times.Never());

            contentItem.ContentTitle = "Foobar";

            contentController.UpdateContentItem(contentItem);

            // Should be a no-op since no real data changed
            dataService.Verify(ds => ds.AddMetaData(contentItem, FileController.TitleKey, It.IsAny <string>()), Times.Once());
            dataService.Verify(ds => ds.DeleteMetaData(contentItem, FileController.TitleKey, It.IsAny <string>()), Times.Never());

            // Really update
            contentItem.ContentTitle = "SNAFU";

            contentController.UpdateContentItem(contentItem);

            dataService.Verify(ds => ds.AddMetaData(contentItem, FileController.TitleKey, It.IsAny <string>()), Times.Exactly(2));
            dataService.Verify(ds => ds.DeleteMetaData(contentItem, FileController.TitleKey, It.IsAny <string>()), Times.Once());
        }