示例#1
0
        public void SetupThreads()
        {
            Progress.Minimum = 0;
            Progress.Maximum = _Files.Count;
            if (Threads != null)
            {
                Threads = null;
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
            }
            Threads = new ConvThread[Environment.ProcessorCount];
            for (int i = 0; i < Threads.Length; i++)
            {
                Threads[i] = new ConvThread();
            }
            int tc = 0;

            foreach (var file in _Files)
            {
                if (tc > Environment.ProcessorCount - 1)
                {
                    tc = 0;
                }
                Threads[tc].AddFile(file);
                ++tc;
            }
        }
示例#2
0
        public void GetByAuthorsOrThreadsTest()
        {
            var authors = new List <User>()
            {
                new User()
                {
                    Id = 1
                }, new User()
                {
                    Id = 2
                }
            };
            var threads = new ConvThread[] { new ConvThread()
                                             {
                                                 Id = 1
                                             }, new ConvThread()
                                             {
                                                 Id = 2
                                             } };
            var expectedPostIds = new int[] { 1, 2, 3, 4, 5, 6, 8, 9, 15 };

            var actualIds = PostRepository.GetByAuthorsOrThreads(authors, threads).Select(p => p.Id).ToArray();

            CollectionAssert.AreEquivalent(expectedPostIds, actualIds);
        }
示例#3
0
 public List <Post> GetByThread(ConvThread thread)
 {
     return(_dbContext.Posts
            .AsNoTracking()
            .Where(p => p.ThreadId == thread.Id)
            .OrderByDescending(p => p.Published)
            .ToList());
 }
示例#4
0
 public static void SubscribeAt(this User u, ConvThread thread)
 {
     thread.Subscribers.Add(u);
     if (u.ThreadSubscriptions is null)
     {
         u.ThreadSubscriptions = new List <ConvThread>();
     }
     u.ThreadSubscriptions.Add(thread);
 }
示例#5
0
 private bool AreEquivalent(ThreadDto threadDto, ConvThread thread)
 {
     return(threadDto.Id == thread.Id &&
            threadDto.AvatarPath == thread.AvatarPath &&
            threadDto.Description == thread.Description &&
            threadDto.ModeratorId == thread.ModeratorId &&
            threadDto.Name == thread.Name &&
            threadDto.Topic == thread.Topic);
 }
示例#6
0
        public void GetSubscribersCount()
        {
            int        expected = 4;
            ConvThread thread   = new ConvThread()
            {
                Id = 2
            };

            int actual = ThreadRepository.GetSubscribersCount(thread);

            Assert.AreEqual(expected, actual);
        }
示例#7
0
 public static Post WritePost(this User u, ConvThread thread, string Text, DateTime Published = new DateTime())
 {
     return(new Post()
     {
         Id = ++_postCounter,
         Author = u,
         AuthorId = u.Id,
         Published = Published == DateTime.MinValue ? GetRandomDateTime() : Published,
         Text = Text,
         Thread = thread,
         ThreadId = thread.Id
     });
 }
示例#8
0
        public void GetByThreadsTest()
        {
            var threads = new ConvThread[] { new ConvThread()
                                             {
                                                 Id = 1
                                             }, new ConvThread()
                                             {
                                                 Id = 3
                                             } };
            var expectedPostIds = new int[] { 1, 4, 6, 9 };

            var actualIds = PostRepository.GetByThreads(threads).Select(p => p.Id).ToArray();

            CollectionAssert.AreEquivalent(expectedPostIds, actualIds);
        }
示例#9
0
        public static ConvThread CreateThread(this User u, string Name, string Description, string Topic)
        {
            var t = new ConvThread()
            {
                Id          = ++_threadCounter,
                Description = Description,
                Moderator   = u,
                ModeratorId = u.Id,
                Name        = Name,
                Topic       = Topic
            };

            t.Subscribers = new List <User>()
            {
                u
            };
            return(t);
        }
示例#10
0
 /*
  * Thread
  */
 /// <summary>
 /// Map using Automapper
 /// </summary>
 public static ThreadDto MapToDtoEntity(this ConvThread Thread)
 {
     return(Mapper.Map <ConvThread, ThreadDto>(Thread));
 }