public void Test_CreateUpdateDeleteThread()
        {
            ArticleGroup articleGroup = Test_ArticleGroups.Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, this.Random);

            ArticleGroupThreadManager manager = new ArticleGroupThreadManager(this.DataStore);
            ArticleGroupThread        record  = Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, articleGroup, this.Random);

            ArticleGroupThread recordToCompare;

            for (int i = 0; i < this.DefaultUpdateTestIterations; i++)
            {
                PopulateWithRandomValues(record, this.DummyDataManager, this.Random);
                recordToCompare = record;

                manager.Update(record);
                record = manager.GetArticleGroupThread(record.ArticleGroupThreadId);

                string errors = string.Empty;
                // TODO (Roman): relax datetime comparisons
                Assert.IsTrue(DebugUtility.ArePropertyValuesEqual(record, recordToCompare, out errors), errors);
                Trace.WriteLine("Update test successfull.");
            }

            Delete(this.DataStore, record);
            Test_ArticleGroups.Delete(this.DataStore, articleGroup);
        }
        internal static void Delete(IDataStore dataStore, ArticleGroupThread articleGroupThread)
        {
            ArticleGroupThreadManager manager = new ArticleGroupThreadManager(dataStore);

            BusinessObjectActionReport <DataRepositoryActionStatus> report = manager.Delete(articleGroupThread);

            Assert.AreEqual(DataRepositoryActionStatus.Success, report.Status);
            Assert.IsNull(manager.GetArticleGroupThread(articleGroupThread.ArticleGroupThreadId));

            Trace.WriteLine("Successfully deleted articleGroupThread " + articleGroupThread.Name);
        }
示例#3
0
        public void Test_Delete_ArticleGroup()
        {
            IUserBasic   userBasic    = Test_WorkmateMembershipProvider.CreateUser(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, this.DummyDataManager);
            MessageBoard messageBoard = Test_MessageBoards.Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, this.Random);

            ArticleGroup       articleGroup       = Test_ArticleGroups.Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, this.Random);
            ArticleGroupThread articleGroupThread = Test_ArticleGroupThreads.Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, articleGroup, this.Random);
            Article            article            = Test_Articles.Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, userBasic
                                                                         , articleGroupThread, messageBoard, this.Random);

            Test_ArticleGroups.Delete(this.DataStore, articleGroup);

            ArticleGroupThreadManager articleGroupThreadManager = new ArticleGroupThreadManager(this.DataStore);
            ArticleManager            articleManager            = new ArticleManager(this.DataStore);

            Assert.IsNull(articleGroupThreadManager.GetArticleGroupThread(articleGroupThread.ArticleGroupThreadId));
            Assert.IsNull(articleManager.GetArticle(article.ArticleId));
        }
示例#4
0
        internal static Article Create(IDataStore dataStore, IApplicationSettings applicationSettings, IApplication application
                                       , IUserBasic author, ArticleGroupThread articleGroupThread
                                       , MessageBoard messageBoard
                                       , Random random)
        {
            ArticleManager manager = new ArticleManager(dataStore);

            Article article = new Article(
                author
                , articleGroupThread
                , DebugUtility.GetRandomEnum <ArticleStatus>(random)
                , DebugUtility.GetRandomEnum <ArticleType>(random)
                , "Article Subject" + random.Next(1000000, 10000000)
                , "Article Body" + random.Next(1000000, 10000000)
                , "URLName" + random.Next(1000000, 10000000)
                , DebugUtility.FlipCoin(random));

            int count = random.Next(0, 10);

            for (int i = 0; i < count; i++)
            {
                article.ContentLevelNodeNames.Add("Category " + i + (DebugUtility.FlipRiggedCoin(random, .2) ? " " + random.Next(10000, 100000) : string.Empty));
            }

            BusinessObjectActionReport <DataRepositoryActionStatus> report = manager.Create(article, messageBoard.MessageBoardId, DebugUtility.FlipCoin(random));

            Assert.AreEqual(DataRepositoryActionStatus.Success, report.Status);
            Assert.Greater(article.ArticleId, 0);

            Article dsArticle = manager.GetArticle(article.ArticleId);

            Assert.IsNotNull(dsArticle);

            IArticleModel articelModel = manager.GetArticleModel(dsArticle.ArticleId);

            Assert.AreEqual(article.ContentLevelNodeNames.Count, articelModel.ContentLevelNodes.Count);
            for (int i = 0; i < article.ContentLevelNodeNames.Count; i++)
            {
                Assert.AreEqual(article.ContentLevelNodeNames[i], articelModel.ContentLevelNodes[i]);
            }

            return(dsArticle);
        }
        internal static ArticleGroupThread Create(IDataStore dataStore, IApplicationSettings applicationSettings, IApplication application, ArticleGroup articleGroup, Random random)
        {
            ArticleGroupThreadManager manager = new ArticleGroupThreadManager(dataStore);

            ArticleGroupThread articleGroupThread = new ArticleGroupThread(
                articleGroup
                , ArticleGroupThreadStatus.Enabled
                , "TestThread " + random.Next(1000000, 10000000));

            BusinessObjectActionReport <DataRepositoryActionStatus> report = manager.Create(articleGroupThread);

            Assert.AreEqual(DataRepositoryActionStatus.Success, report.Status);
            Assert.Greater(articleGroupThread.ArticleGroupThreadId, 0);

            ArticleGroupThread dsThread = manager.GetArticleGroupThread(articleGroupThread.ArticleGroupThreadId);

            Assert.IsNotNull(dsThread);

            return(dsThread);
        }
 internal static void PopulateWithRandomValues(ArticleGroupThread record, DummyDataManager dtm, Random random)
 {
     record.Name       = "TestThread " + random.Next(1000000, 10000000);
     record.IsApproved = DebugUtility.FlipCoin(random);
     record.IsLocked   = DebugUtility.FlipCoin(random);
 }
示例#7
0
        private void RefreshApplicationData()
        {
            // TODO (Roman): try/catch errorhandling?
            IApplicationContext context = InstanceContainer.ApplicationContext;

            #region context data
            context.Refresh(context.BaseDirectory);
            #endregion

            #region database content
            // TODO (Roman): this must be done at the windows service, not at a web client app

            Dictionary <string, List <IWikiLanguageThreadLookupItem> > wikiLanguageThreadIdLookup = new Dictionary <string, List <IWikiLanguageThreadLookupItem> >();

            Dictionary <string, IWikiLanguageThreadLookupItem> wikiLanguageThreadIds = new Dictionary <string, IWikiLanguageThreadLookupItem>();
            IApplicationManager        applicationManger         = InstanceContainer.ApplicationManager;
            IArticleGroupManager       articleGroupManager       = InstanceContainer.ArticleGroupManager;
            IArticleGroupThreadManager articleGroupThreadManager = InstanceContainer.ArticleGroupThreadManager;
            ISystemProfileImageManager systemProfileImageManager = InstanceContainer.SystemProfileImageManager;
            IApplication         application;
            IStaticContentLookup staticContentLookup;
            ArticleGroupThread   articleGroupThread;
            ArticleGroup         articleGroup;

            IApplicationThemeInfo[]        applicationThemeInfos = context.GetAllApplicationThemeInfos();
            Dictionary <int, IApplication> applicationLookup     = new Dictionary <int, IApplication>();

            #region applications
            foreach (IApplicationThemeInfo applicationThemeInfo in applicationThemeInfos)
            {
                application = applicationManger.GetApplication(applicationThemeInfo.ApplicationName);
                if (application == null)
                {
                    application = new Workmate.Components.Entities.Application(applicationThemeInfo.ApplicationName, "Generated on Application Data Refresh at " + DateTime.UtcNow.ToString() + " (UTC)");

                    #region do default settings - we really want this to be prepopulated by sql scripts
                    application.DefaultAdminSenderEmailAddress = "admin@" + applicationThemeInfo.ApplicationName + ".com";
                    #endregion

                    var report = applicationManger.Create(application);
                    if (report.Status != DataRepositoryActionStatus.Success)
                    {
                        // TODO (Roman): error handling?
                        continue;
                    }
                }
                // this was not set yet as the context refresh above did not have all data available, so we have to do it here
                applicationThemeInfo.ApplicationId = application.ApplicationId;
                applicationThemeInfo.Application   = application;

                applicationLookup[application.ApplicationId] = application;
            }
            #endregion

            #region Userroles
            string[] userRoles = Enum.GetNames(typeof(UserRole));
            foreach (int applicationId in applicationLookup.Keys)
            {
                InstanceContainer.WorkmateRoleProvider.CreateRolesIfNotExist(applicationId, userRoles);
            }
            #endregion

            IThemeFolderLookup themeFolderLookup;
            Dictionary <string, SystemProfileImage> systemProfileImageLookup;
            HashSet <int> usedApplicationIds = new HashSet <int>();
            foreach (IApplicationThemeInfo applicationThemeInfo in applicationThemeInfos.Where(c => c.ApplicationGroup == MagicStrings.APPLICATIONGROUP_NAME_WORKMATE))
            {
                themeFolderLookup = context.GetThemeFolderLookup(applicationThemeInfo.ApplicationGroup);

                #region profile images
                if (!usedApplicationIds.Contains(applicationThemeInfo.ApplicationId))
                {
                    systemProfileImageLookup = systemProfileImageManager.GetSystemProfileImages(applicationThemeInfo.ApplicationId);

                    if (!systemProfileImageLookup.ContainsKey(MagicStrings.PROFILE_IMAGE_MALE_FILENAME))
                    {
                        if (File.Exists(applicationThemeInfo.Images.DefaultThemeImageFolderServerPath + MagicStrings.PROFILE_IMAGE_MALE_FILENAME))
                        {
                            TryCreateSystemProfileImage(themeFolderLookup, applicationThemeInfo
                                                        , applicationThemeInfo.Images.DefaultThemeImageFolderServerPath + MagicStrings.PROFILE_IMAGE_MALE_FILENAME
                                                        , MagicStrings.PROFILE_IMAGE_MALE_FILENAME);
                        }
                    }
                    if (!systemProfileImageLookup.ContainsKey(MagicStrings.PROFILE_IMAGE_FEMALE_FILENAME))
                    {
                        if (File.Exists(applicationThemeInfo.Images.DefaultThemeImageFolderServerPath + MagicStrings.PROFILE_IMAGE_FEMALE_FILENAME))
                        {
                            TryCreateSystemProfileImage(themeFolderLookup, applicationThemeInfo
                                                        , applicationThemeInfo.Images.DefaultThemeImageFolderServerPath + MagicStrings.PROFILE_IMAGE_FEMALE_FILENAME
                                                        , MagicStrings.PROFILE_IMAGE_FEMALE_FILENAME);
                        }
                    }

                    // now reload in case we've created profile images for the first time
                    systemProfileImageLookup = systemProfileImageManager.GetSystemProfileImages(applicationThemeInfo.ApplicationId);
                    foreach (SystemProfileImage systemProfileImage in systemProfileImageLookup.Values)
                    {
                        TrySaveProfileImage(systemProfileImage, applicationThemeInfo, MagicStrings.FOLDER_IMAGES_PROFILE_NORMAL, MagicNumbers.PROFILEIMAGE_SIZE_NORMAL);
                        TrySaveProfileImage(systemProfileImage, applicationThemeInfo, MagicStrings.FOLDER_IMAGES_PROFILE_TINY, MagicNumbers.PROFILEIMAGE_SIZE_TINY);
                    }

                    usedApplicationIds.Add(applicationThemeInfo.ApplicationId);
                }

                systemProfileImageLookup = systemProfileImageManager.GetSystemProfileImages(applicationThemeInfo.ApplicationId);
                foreach (SystemProfileImage systemProfileImage in systemProfileImageLookup.Values)
                {
                    switch (systemProfileImage.FriendlyFileName)
                    {
                    case MagicStrings.PROFILE_IMAGE_MALE_FILENAME: applicationThemeInfo.Images.MaleSystemProfileImageId = systemProfileImage.ImageId; break;

                    case MagicStrings.PROFILE_IMAGE_FEMALE_FILENAME: applicationThemeInfo.Images.FemaleSystemProfileImageId = systemProfileImage.ImageId; break;
                    }
                }
                #endregion

                #region create wiki language threads
                articleGroup = articleGroupManager.GetArticleGroup(applicationThemeInfo.ApplicationId, MagicStrings.WIKI_LANGUAGE_SECTION);
                if (articleGroup == null)
                {
                    articleGroup             = new ArticleGroup(applicationThemeInfo.ApplicationId, MagicStrings.WIKI_LANGUAGE_SECTION, true);
                    articleGroup.Description = "Generated on Application Data Refresh at " + DateTime.UtcNow.ToString() + " (UTC)";

                    var report = articleGroupManager.Create(articleGroup);
                    if (report.Status != DataRepositoryActionStatus.Success)
                    {
                        // TODO (Roman): error handling?
                        continue;
                    }
                }

                wikiLanguageThreadIds = new Dictionary <string, IWikiLanguageThreadLookupItem>();
                staticContentLookup   = context.GetStaticContentLookup(applicationThemeInfo.ApplicationGroup);
                foreach (string theme in themeFolderLookup.ThemeNames)
                {
                    foreach (Language language in staticContentLookup.GetLanguages(theme))
                    {
                        if (wikiLanguageThreadIds.ContainsKey(language.ShortCode))
                        {
                            continue;
                        }

                        articleGroupThread = articleGroupThreadManager.GetArticleGroupThread(language.ShortCode);
                        if (articleGroupThread == null)
                        {
                            articleGroupThread            = new ArticleGroupThread(articleGroup, ArticleGroupThreadStatus.Enabled, language.ShortCode);
                            articleGroupThread.IsApproved = true;
                            articleGroupThread.IsLocked   = false;

                            var report = articleGroupThreadManager.Create(articleGroupThread);
                            if (report.Status != DataRepositoryActionStatus.Success)
                            {
                                // TODO (Roman): error handling?
                                continue;
                            }
                        }

                        wikiLanguageThreadIds[language.ShortCode] = new WikiLanguageThreadLookupItem(language.ShortCode, language.Name, articleGroupThread.ArticleGroupThreadId);
                    }
                }

                wikiLanguageThreadIdLookup[applicationThemeInfo.ApplicationName.ToLowerInvariant()] = wikiLanguageThreadIds.Values
                                                                                                      .ToList();

                #endregion
            }

            IApplicationDataCache applicationDataCache = InstanceContainer.ApplicationDataCache;
            applicationDataCache.Refresh(wikiLanguageThreadIdLookup);

            #endregion

            #region routes
            RouteCollection routes = RouteTable.Routes;

            // TODO (Roman): get read lock as well?
            using (IDisposable writeLock = routes.GetWriteLock())
            {
                routes.Clear();

                routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

                ISitemapLookup sitemapLookup;
                Menu           topMenu;
                MenuInfo       menuInfo;
                Dictionary <string, Breadcrumb> breadCrumbs = new Dictionary <string, Breadcrumb>();
                foreach (string applicationGroup in context.GetApplicationGroups())
                {
                    sitemapLookup = context.GetSitemapLookup(applicationGroup);

                    breadCrumbs.Clear();
                    CreateBreadcrumbs(breadCrumbs, sitemapLookup);

                    foreach (RouteTag routeTag in sitemapLookup.RouteTags)
                    {
                        topMenu = sitemapLookup.GetMenu(routeTag.TopMenuName);

                        #region data tokens extensions
                        routeTag.DataTokens[MagicStrings.DATATOKENS_BREADCRUMB] = breadCrumbs[routeTag.Name];
                        routeTag.DataTokens[MagicStrings.DATATOKENS_ROUTENAME]  = routeTag.Name;

                        menuInfo             = new MenuInfo();
                        menuInfo.TopMenuName = routeTag.TopMenuName;
                        if (topMenu != null)
                        {
                            foreach (MenuItem item in topMenu.MenuItems)
                            {
                                if (item.RouteName == routeTag.Name)
                                {
                                    menuInfo.TopMenuItemName = item.Name;
                                }

                                foreach (MenuItem subItem in item.Children)
                                {
                                    if (subItem.RouteName == routeTag.Name)
                                    {
                                        menuInfo.TopMenuItemName    = subItem.Parent.Name;
                                        menuInfo.TopMenuSubItemName = subItem.Name;
                                        break;
                                    }
                                }
                                foreach (MenuItem subItem in item.DropdownMenuItems)
                                {
                                    foreach (MenuItem dropdownSubItem in subItem.Children)
                                    {
                                        if (dropdownSubItem.RouteName == routeTag.Name)
                                        {
                                            menuInfo.TopMenuItemName    = dropdownSubItem.Parent.Name;
                                            menuInfo.TopMenuSubItemName = dropdownSubItem.Name;
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                        routeTag.DataTokens[MagicStrings.DATATOKENS_MENUINFO] = menuInfo;
                        #endregion

                        routes.Add(
                            MagicStrings.FormatRouteName(applicationGroup, routeTag.Name)
                            , new Route(routeTag.Url
                                        , routeTag.Defaults
                                        , routeTag.Constraints
                                        , routeTag.DataTokens
                                        , routeTag.RouteHandler));
                    }
                }
            }
            #endregion
        }
 public BusinessObjectActionReport <DataRepositoryActionStatus> Delete(ArticleGroupThread articleGroupThread)
 {
     return(_CMSThreadManager.Delete(articleGroupThread.CMSThread, true));
 }
示例#9
0
        public void Test_CreateUpdateDeleteArticle()
        {
            IUserBasic         userBasic          = Test_WorkmateMembershipProvider.CreateUser(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, this.DummyDataManager);
            MessageBoard       messageBoard       = Test_MessageBoards.Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, this.Random);
            ArticleGroup       articleGroup       = Test_ArticleGroups.Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, this.Random);
            ArticleGroupThread articleGroupThread = Test_ArticleGroupThreads.Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, articleGroup, this.Random);

            ArticleManager manager = new ArticleManager(this.DataStore);
            Article        record  = Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, userBasic
                                            , articleGroupThread, messageBoard, this.Random);

            MessageBoardThreadManager messageBoardThreadManager = new MessageBoardThreadManager(this.DataStore);

            Article recordToCompare;

            for (int i = 0; i < this.DefaultUpdateTestIterations; i++)
            {
                PopulateWithRandomValues(record, this.DummyDataManager, this.Random);
                recordToCompare = record;

                manager.Update(record);
                record = manager.GetArticle(record.ArticleId);

                string errors = string.Empty;
                // TODO (Roman): relax datetime comparisons
                Assert.IsTrue(DebugUtility.ArePropertyValuesEqual(record, recordToCompare, out errors), errors);
                Trace.WriteLine("Update test successfull.");
            }

            IArticleModel articleModel = manager.GetArticleModel(record.ArticleId);

            Assert.AreEqual(0, articleModel.TotalComments);

            #region messageboards
            MessageBoardThread messageBoardThread = messageBoardThreadManager.GetMessageBoardThread(articleModel.MessageBoardThreadId);
            Assert.IsNotNull(messageBoardThread);

            MessageManager messageManager = new MessageManager(this.DataStore);

            messageManager.Create(new Message(userBasic, messageBoardThread, "Test Message Subject 1", "Body1"));
            messageManager.Create(new Message(userBasic, messageBoardThread, "Test Message Subject 2", "Body2"));

            Message message = new Message(userBasic, messageBoardThread, "Test Message Subject 3", "Body3");
            messageManager.Create(message);

            articleModel = manager.GetArticleModel(record.ArticleId);
            Assert.AreEqual(3, articleModel.TotalComments);

            Assert.AreEqual(DataRepositoryActionStatus.Success, messageManager.Delete(message).Status);
            articleModel = manager.GetArticleModel(record.ArticleId);
            Assert.AreEqual(2, articleModel.TotalComments);
            #endregion

            #region attachments
            IArticleAttachmentModel articleAttachmentModel = AddAttachment(this.DataStore, this.Application.ApplicationId, articleModel, userBasic, this.Random);
            AddAttachment(this.DataStore, this.Application.ApplicationId, articleModel, userBasic, this.Random);

            DeleteAttachment(this.DataStore, articleModel, articleAttachmentModel.AttachmentId, this.Random);

            AddAttachment(this.DataStore, this.Application.ApplicationId, articleModel, userBasic, this.Random);
            AddAttachment(this.DataStore, this.Application.ApplicationId, articleModel, userBasic, this.Random);

            articleAttachmentModel = AddAttachment(this.DataStore, this.Application.ApplicationId, articleModel, userBasic, this.Random);
            DeleteAttachment(this.DataStore, articleModel, articleAttachmentModel.AttachmentId, this.Random);

            AddAttachment(this.DataStore, this.Application.ApplicationId, articleModel, userBasic, this.Random);
            #endregion

            #region contentnodelevels
            if (articleModel.ContentLevelNodeId.HasValue)
            {
                string newName = "Some Name" + this.Random.Next(10000, 100000);
                CMSContentLevelNodeManager contentLevelNodeManager = new CMSContentLevelNodeManager(this.DataStore);
                contentLevelNodeManager.RenameContentLevelNode(articleModel.ContentLevelNodeId.Value, newName);

                articleModel = manager.GetArticleModel(record.ArticleId);
                Assert.AreEqual(articleModel.ContentLevelNodes[articleModel.ContentLevelNodes.Count - 1], newName);
            }
            #endregion

            Delete(this.DataStore, record);
            Test_ArticleGroups.Delete(this.DataStore, articleGroup);

            Assert.IsNull(messageBoardThreadManager.GetMessageBoardThread(articleModel.MessageBoardThreadId));

            ArticleAttachmentManager articleAttachmentManager = new ArticleAttachmentManager(this.DataStore);
            Assert.IsEmpty(articleAttachmentManager.GetArticleAttachments(articleModel.ArticleId));
        }