Ejemplo n.º 1
0
        private JsonListCountModel RemoveMobileJobAds(JobAdFolder folder, params JobAd[] jobAds)
        {
            var url      = new ReadOnlyApplicationUrl(_baseFoldersUrl, "mobile/removejobs");
            var response = Post(url, GetParameters(jobAds));

            return(new JavaScriptSerializer().Deserialize <JsonListCountModel>(response));
        }
Ejemplo n.º 2
0
        private JsonListCountModel RemoveAllJobAds(JobAdFolder folder)
        {
            var url      = new ReadOnlyApplicationUrl(_baseFoldersUrl, folder.Id + "/removealljobs");
            var response = Post(url);

            return(new JavaScriptSerializer().Deserialize <JsonListCountModel>(response));
        }
Ejemplo n.º 3
0
        private JsonListCountModel RemoveJobAds(HttpStatusCode expectedStatusCode, JobAdFolder folder, params JobAd[] jobAds)
        {
            var url      = new ReadOnlyApplicationUrl(_baseFoldersUrl, folder.Id + "/removejobs");
            var response = Post(expectedStatusCode, url, GetParameters(jobAds));

            return(new JavaScriptSerializer().Deserialize <JsonListCountModel>(response));
        }
Ejemplo n.º 4
0
        private IEnumerable <JobAdFolder> GetFolders(Guid memberId, ICollection <JobAdFolder> folders)
        {
            // Look for a mobile folder.

            if (!(from f in folders where f.FolderType == FolderType.Mobile select f).Any())
            {
                folders.Add(CreateSpecialFolder(memberId, FolderType.Mobile));
            }

            // Ensure there are enough private folders.

            var privateFolders = (from f in folders where f.FolderType == FolderType.Private select f).ToList();

            if (privateFolders.Count < NumberOfPrivateFolders)
            {
                // Create them in reverse order so Folder 1 appears before Folder 5 in a "last used" scenario.

                var folderNames = (from i in Enumerable.Range(1, NumberOfPrivateFolders)
                                   select string.Format(FolderNameTemplate, i))
                                  .Except(from f in privateFolders select f.Name).Take(NumberOfPrivateFolders - privateFolders.Count).Reverse();

                foreach (var folderName in folderNames)
                {
                    var folder = new JobAdFolder {
                        MemberId = memberId, Name = folderName, FolderType = FolderType.Private
                    };
                    _jobAdListsCommand.CreateList(folder);
                    folders.Add(folder);
                }
            }

            return(folders);
        }
Ejemplo n.º 5
0
        private static bool CanRenameFolder(IMember member, JobAdFolder folder)
        {
            // Must be owner.

            return(CanAccessFolder(member, folder) &&
                   CanBeRenamed(folder) &&
                   folder.MemberId == member.Id);
        }
Ejemplo n.º 6
0
        private JobAdFolder CreateSpecialFolder(Guid memberId, FolderType folderType)
        {
            var folder = new JobAdFolder {
                MemberId = memberId, FolderType = folderType
            };

            _jobAdListsCommand.CreateList(folder);
            return(folder);
        }
Ejemplo n.º 7
0
        public void ListsTestsInitialize()
        {
            Resolve <IDbConnectionFactory>().DeleteAllTestData();

            _blockList = null;
            _flagList  = null;
            _folder1   = null;
            _folder2   = null;
        }
Ejemplo n.º 8
0
        int IMemberJobAdListsCommand.AddJobAdsToFolder(IMember member, JobAdFolder folder, IEnumerable <Guid> jobAdIds)
        {
            if (!CanModifyJobAds(member, folder))
            {
                throw new JobAdFoldersPermissionsException(member, folder.Id);
            }

            AddJobAdsToFolder(member.Id, folder.Id, jobAdIds);
            return(_jobAdListsQuery.GetListedCount(folder.Id, new[] { (int)BlockListType.Permanent }));
        }
Ejemplo n.º 9
0
        int IMemberJobAdListsCommand.RemoveAllJobAdsFromFolder(IMember member, JobAdFolder folder)
        {
            if (!CanModifyJobAds(member, folder))
            {
                throw new JobAdFoldersPermissionsException(member, folder.Id);
            }

            RemoveAllJobAdsFromList(folder.Id);
            return(_jobAdListsQuery.GetListedCount(folder.Id, new[] { (int)BlockListType.Permanent }));
        }
Ejemplo n.º 10
0
        private void CreateLists(IMember member)
        {
            _blockList = _jobAdBlockListsQuery.GetBlockList(member);
            _flagList  = _jobAdFlagListsQuery.GetFlagList(member);

            var folders = _jobAdFoldersQuery.GetFolders(member);

            _folder1 = folders[1];
            _folder2 = folders[2];
        }
Ejemplo n.º 11
0
        private static bool CanModifyJobAds(IMember member, JobAdFolder folder)
        {
            if (!CanAccessFolder(member, folder, false))
            {
                return(false);
            }

            // Must own the folder.

            return(folder.MemberId == member.Id);
        }
Ejemplo n.º 12
0
        void IJobAdFoldersCommand.RenameFolder(IMember member, JobAdFolder folder, string name)
        {
            if (!CanRenameFolder(member, folder))
            {
                throw new JobAdFoldersPermissionsException(member, folder.Id);
            }

            // Validate.

            Validate(member, folder, name);
            folder.Name = name;
            _jobAdListsCommand.UpdateList(folder);
        }
Ejemplo n.º 13
0
 private static bool CanAccessFolder(IHasId <Guid> member, JobAdFolder folder)
 {
     if (member == null)
     {
         return(false);
     }
     if (folder == null)
     {
         return(false);
     }
     if (folder.IsDeleted)
     {
         return(false);
     }
     return(folder.MemberId == member.Id);
 }
Ejemplo n.º 14
0
        protected static void AssertFolder(IMember member, JobAdFolder expectedFolder, JobAdFolder folder)
        {
            Assert.AreNotEqual(Guid.Empty, folder.Id);
            Assert.AreNotEqual(DateTime.MinValue, folder.CreatedTime);

            Assert.AreEqual(expectedFolder.Name, folder.Name);
            Assert.AreEqual(expectedFolder.FolderType, folder.FolderType);

            switch (expectedFolder.FolderType)
            {
            case FolderType.Private:
                Assert.IsNotNull(folder.Name);
                break;
            }

            Assert.AreEqual(member.Id, folder.MemberId);
            Assert.AreEqual(expectedFolder.MemberId, folder.MemberId);
        }
Ejemplo n.º 15
0
        protected void AssertFolderEntries(IMember member, JobAdFolder folder, ICollection <IJobAd> inFolderJobAds, ICollection <IJobAd> notInFolderJobAds)
        {
            // IsInFolder

            foreach (var inFolderJobAd in inFolderJobAds)
            {
                Assert.IsTrue(_jobAdFoldersQuery.IsInFolder(member, folder.Id, inFolderJobAd.Id));
            }
            foreach (var notInFolderJobAd in notInFolderJobAds)
            {
                Assert.IsFalse(_jobAdFoldersQuery.IsInFolder(member, folder.Id, notInFolderJobAd.Id));
            }

            // GetInFolderJobAdIds

            Assert.IsTrue((from m in inFolderJobAds select m.Id).CollectionEqual(_jobAdFoldersQuery.GetInFolderJobAdIds(member, folder.Id)));

            // GetInFolderCounts.

            var counts = _jobAdFoldersQuery.GetInFolderCounts(member);

            Assert.AreEqual(inFolderJobAds.Count, counts.ContainsKey(folder.Id) ? counts[folder.Id] : 0);
        }
Ejemplo n.º 16
0
 protected static void AssertMobileFolder(JobAdFolder folder)
 {
     Assert.AreEqual(FolderType.Mobile, folder.FolderType);
     Assert.IsFalse(folder.IsDeleted);
     Assert.IsNull(folder.Name);
 }
Ejemplo n.º 17
0
 bool IJobAdFoldersCommand.CanRenameFolder(IMember member, JobAdFolder folder)
 {
     return(CanRenameFolder(member, folder));
 }
Ejemplo n.º 18
0
 private static bool CanBeRenamed(JobAdFolder folder)
 {
     return(folder.FolderType != FolderType.Mobile);
 }
Ejemplo n.º 19
0
 private static void AssertPrivateFolder(string expectedName, JobAdFolder folder)
 {
     Assert.AreEqual(FolderType.Private, folder.FolderType);
     Assert.IsFalse(folder.IsDeleted);
     Assert.AreEqual(expectedName, folder.Name);
 }