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; } }
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); }
public List <Post> GetByThread(ConvThread thread) { return(_dbContext.Posts .AsNoTracking() .Where(p => p.ThreadId == thread.Id) .OrderByDescending(p => p.Published) .ToList()); }
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); }
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); }
public void GetSubscribersCount() { int expected = 4; ConvThread thread = new ConvThread() { Id = 2 }; int actual = ThreadRepository.GetSubscribersCount(thread); Assert.AreEqual(expected, actual); }
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 }); }
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); }
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); }
/* * Thread */ /// <summary> /// Map using Automapper /// </summary> public static ThreadDto MapToDtoEntity(this ConvThread Thread) { return(Mapper.Map <ConvThread, ThreadDto>(Thread)); }