private async Task CreateEntitiesAsync(TestDatabaseContext testDatabase) { using (var databaseContext = testDatabase.CreateContext()) { var random = new Random(); var creator = UserTests.UniqueEntity(random); var blog = BlogTests.UniqueEntity(random); blog.Creator = creator; blog.CreatorId = creator.Id; var orignalChannel = ChannelTests.UniqueEntity(random); orignalChannel.Id = ChannelId.Value; orignalChannel.Blog = blog; orignalChannel.BlogId = blog.Id; var collection = QueueTests.UniqueEntity(random); collection.Id = QueueId.Value; collection.Blog = blog; collection.BlogId = blog.Id; databaseContext.Queues.Add(collection); await databaseContext.SaveChangesAsync(); } }
private async Task CreateEntitiesAsync(TestDatabaseContext testDatabase) { using (var databaseContext = testDatabase.CreateContext()) { var random = new Random(); var creator = UserTests.UniqueEntity(random); var blog = BlogTests.UniqueEntity(random); blog.Creator = creator; blog.CreatorId = creator.Id; var channel = ChannelTests.UniqueEntity(random); channel.Id = ChannelId.Value; channel.Blog = blog; channel.BlogId = blog.Id; var queue = QueueTests.UniqueEntity(random); queue.Id = QueueId.Value; queue.Blog = blog; queue.BlogId = blog.Id; var weeklyReleaseTimes = new[] { ExistingReleaseA, ExistingReleaseB, ExistingReleaseC }.Select( _ => new WeeklyReleaseTime(QueueId.Value, (byte)_.Value)); databaseContext.Queues.Add(queue); await databaseContext.SaveChangesAsync(); await databaseContext.Database.Connection.InsertAsync(weeklyReleaseTimes); } }
private async Task <IReadOnlyList <Post> > CreatePostsAsync( TestDatabaseContext testDatabase, QueueId queueId, IReadOnlyList <DateTime> liveDates, bool scheduledByQueue) { using (var databaseContext = testDatabase.CreateContext()) { var user = UserTests.UniqueEntity(Random); await databaseContext.Database.Connection.InsertAsync(user); var file = FileTests.UniqueEntity(Random); file.UserId = user.Id; await databaseContext.Database.Connection.InsertAsync(file); var blog = BlogTests.UniqueEntity(Random); blog.CreatorId = user.Id; await databaseContext.Database.Connection.InsertAsync(blog); var channel = ChannelTests.UniqueEntity(Random); channel.BlogId = blog.Id; await databaseContext.Database.Connection.InsertAsync(channel); var collection = QueueTests.UniqueEntity(Random); collection.Id = queueId.Value; collection.BlogId = blog.Id; await databaseContext.Database.Connection.InsertAsync(collection); var postsInCollection = new List <Post>(); foreach (var liveDate in liveDates) { var post = PostTests.UniqueNote(Random); post.ChannelId = channel.Id; post.QueueId = scheduledByQueue ? queueId.Value : (Guid?)null; post.LiveDate = liveDate; // Clip dates as we will be comparing from these entities. post.LiveDate = new SqlDateTime(post.LiveDate).Value; post.CreationDate = new SqlDateTime(post.CreationDate).Value; postsInCollection.Add(post); } await databaseContext.Database.Connection.InsertAsync(postsInCollection); return(postsInCollection); } }
static void Main(string[] args) { ExtensionsTests.Run(); ArrayTests.Run(); ParameterTests.Run(); ExampleTests.Run(); ClassifierTests.Run(); ChannelTests.Run(); ControlTests.Run(); SyncTests.Run(); RandomizedQueueTests.Run(); "Finished!".Print(); while (true) { System.Threading.Thread.Sleep(30000); } }
private async Task CreateDataAsync(TestDatabaseContext testDatabase) { using (var databaseContext = testDatabase.CreateContext()) { var random = new Random(); var creator = UserTests.UniqueEntity(random); creator.Id = CreatorId1.Value; var subscription = BlogTests.UniqueEntity(random); subscription.Creator = creator; subscription.CreatorId = creator.Id; var channel1 = ChannelTests.UniqueEntity(random); channel1.Id = ChannelId1.Value; channel1.Blog = subscription; channel1.BlogId = subscription.Id; var channel2 = ChannelTests.UniqueEntity(random); channel2.Id = ChannelId2.Value; channel2.Blog = subscription; channel2.BlogId = subscription.Id; var post1 = PostTests.UniqueNote(random); post1.Id = PostId1.Value; post1.LiveDate = PostDate1; post1.Channel = channel1; post1.ChannelId = channel1.Id; var post2 = PostTests.UniqueNote(random); post2.Id = PostId2.Value; post2.LiveDate = PostDate2; post2.Channel = channel2; post2.ChannelId = channel2.Id; databaseContext.Posts.Add(post1); databaseContext.Posts.Add(post2); await databaseContext.SaveChangesAsync(); } }
private async Task CreateChannelsAndCollectionsAsync(TestDatabaseContext testDatabase) { var random = new Random(); var channel1 = ChannelTests.UniqueEntity(random); channel1.Id = ChannelId1.Value; ConfigureChannel(channel1); var channel2 = ChannelTests.UniqueEntity(random); channel2.Id = ChannelId2.Value; ConfigureChannel(channel2); var channel3 = ChannelTests.UniqueEntity(random); channel3.Id = ChannelId3.Value; ConfigureChannel(channel3); // Forth channel is not visible. var channel4 = ChannelTests.UniqueEntity(random); channel4.Id = ChannelId4.Value; ConfigureChannel(channel4); channel4.IsVisibleToNonSubscribers = false; using (var connection = testDatabase.CreateConnection()) { await connection.InsertAsync(channel1); await connection.InsertAsync(channel2); await connection.InsertAsync(channel3); await connection.InsertAsync(channel4); } }
private async Task CreateEntitiesAsync(TestDatabaseContext testDatabase, bool createLivePosts, bool createFuturePosts) { using (var databaseContext = testDatabase.CreateContext()) { await this.CreateUserAsync(databaseContext, UnsubscribedUserId); await this.CreateUserAsync(databaseContext, SubscribedUserId); await this.CreateUserAsync(databaseContext, GuestListUserId); var channelSubscriptions = new List <ChannelSubscription>(); var calculatedAccountBalances = new List <CalculatedAccountBalance>(); var freeAccessUsers = new List <FreeAccessUser>(); var channels = new List <ChannelId>(); var queues = new List <QueueId>(); var files = new List <FileId>(); var images = new List <FileId>(); var channelEntities = new List <Channel>(); var queueEntities = new List <Queue>(); var postEntities = new List <Post>(); var origins = new List <UserPaymentOrigin>(); var likes = new List <Like>(); var comments = new List <Persistence.Comment>(); if (createLivePosts || createFuturePosts) { channelSubscriptions.Add(new ChannelSubscription(ChannelIds[0].Value, null, SubscribedUserId.Value, null, ChannelPrice, Now, Now)); channelSubscriptions.Add(new ChannelSubscription(ChannelIds[1].Value, null, SubscribedUserId.Value, null, ChannelPrice, Now, Now)); calculatedAccountBalances.Add(new CalculatedAccountBalance(SubscribedUserId.Value, LedgerAccountType.FifthweekCredit, Now, 10)); calculatedAccountBalances.Add(new CalculatedAccountBalance(SubscribedUserId.Value, LedgerAccountType.FifthweekCredit, Now.AddDays(-1), 0)); channelSubscriptions.Add(new ChannelSubscription(ChannelIds[0].Value, null, GuestListUserId.Value, null, 0, Now, Now)); channelSubscriptions.Add(new ChannelSubscription(ChannelIds[1].Value, null, GuestListUserId.Value, null, 0, Now, Now)); freeAccessUsers.Add(new FreeAccessUser(BlogId.Value, GuestListUserId.Value + "@test.com")); foreach (var newsfeedPost in SortedNewsfeedPosts) { if (createLivePosts && !createFuturePosts && newsfeedPost.LiveDate > Now) { continue; } if (!createLivePosts && createFuturePosts && newsfeedPost.LiveDate <= Now) { continue; } if (newsfeedPost.ImageId != null) { images.Add(newsfeedPost.ImageId); } if (!channels.Contains(newsfeedPost.ChannelId)) { channels.Add(newsfeedPost.ChannelId); } postEntities.Add(new Post( newsfeedPost.PostId.Value, newsfeedPost.ChannelId.Value, null, (Guid?)null, null, newsfeedPost.ImageId == null ? (Guid?)null : newsfeedPost.ImageId.Value, null, newsfeedPost.PreviewText == null ? null : newsfeedPost.PreviewText.Value, "content", newsfeedPost.PreviewWordCount, newsfeedPost.WordCount, newsfeedPost.ImageCount, newsfeedPost.FileCount, newsfeedPost.VideoCount, newsfeedPost.LiveDate, newsfeedPost.CreationDate)); for (int i = 0; i < newsfeedPost.LikesCount; i++) { likes.Add( new Like( newsfeedPost.PostId.Value, null, UserIds[i].Value, null, DateTime.UtcNow)); } for (int i = 0; i < newsfeedPost.CommentsCount; i++) { comments.Add( new Persistence.Comment( Guid.NewGuid(), newsfeedPost.PostId.Value, null, UserIds[i].Value, null, "Comment " + this.random.Next(), DateTime.UtcNow)); } } } foreach (var channelId in channels) { var channel = ChannelTests.UniqueEntity(Random); channel.Id = channelId.Value; channel.BlogId = BlogId.Value; channel.Price = ChannelPrice; channelEntities.Add(channel); } foreach (var queueId in queues) { var queue = QueueTests.UniqueEntity(Random); queue.Id = queueId.Value; queue.BlogId = BlogId.Value; queueEntities.Add(queue); } var fileEntities = files.Select(fileId => { var file = FileTests.UniqueEntity(Random); file.Id = fileId.Value; file.UserId = CreatorId.Value; file.FileNameWithoutExtension = FileName; file.FileExtension = FileExtension; file.BlobSizeBytes = FileSize; return(file); }); var imageEntities = images.Select(fileId => { var file = FileTests.UniqueEntity(Random); file.Id = fileId.Value; file.UserId = CreatorId.Value; file.FileNameWithoutExtension = FileName; file.FileExtension = FileExtension; file.BlobSizeBytes = FileSize; file.RenderWidth = FileWidth; file.RenderHeight = FileHeight; return(file); }); await databaseContext.CreateTestBlogAsync(CreatorId.Value, BlogId.Value, null, Random); await databaseContext.Database.Connection.InsertAsync(channelEntities); await databaseContext.Database.Connection.InsertAsync(queueEntities); await databaseContext.Database.Connection.InsertAsync(fileEntities); await databaseContext.Database.Connection.InsertAsync(imageEntities); await databaseContext.Database.Connection.InsertAsync(postEntities); await databaseContext.Database.Connection.InsertAsync(channelSubscriptions); await databaseContext.Database.Connection.InsertAsync(calculatedAccountBalances); await databaseContext.Database.Connection.InsertAsync(freeAccessUsers); await databaseContext.Database.Connection.InsertAsync(origins); await databaseContext.Database.Connection.InsertAsync(likes); await databaseContext.Database.Connection.InsertAsync(comments); } }
private async Task <IEnumerable <IIdentityEquatable> > AddUser(DbConnection connection, Random random, UserId userId, DateTime registrationDate, bool isTestUser, UserId subscriberId = null, ChannelId subscribedToId = null) { var users = new List <FifthweekUser>(); var user = UserTests.UniqueEntity(random); user.Id = userId.Value; user.RegistrationDate = registrationDate; users.Add(user); await connection.InsertAsync(users, false); var userRoles = new List <FifthweekUserRole>(); userRoles.Add(new FifthweekUserRole(FifthweekRole.CreatorId, user.Id)); if (isTestUser) { userRoles.Add(new FifthweekUserRole(FifthweekRole.TestUserId, user.Id)); } await connection.InsertAsync(userRoles, false); var blogs = new List <Blog>(); var blog = BlogTests.UniqueEntity(random); blog.CreatorId = userId.Value; blogs.Add(blog); await connection.InsertAsync(blogs); var channels = new List <Channel>(); var channel = ChannelTests.UniqueEntity(random); channel.BlogId = blog.Id; channels.Add(channel); await connection.InsertAsync(channels); var queues = new List <Queue>(); var queue = QueueTests.UniqueEntity(random); queue.BlogId = blog.Id; queues.Add(queue); await connection.InsertAsync(queues); var files = new List <File>(); var file = FileTests.UniqueEntity(random); file.ChannelId = channel.Id; file.UserId = userId.Value; files.Add(file); await connection.InsertAsync(files); var posts = new List <Post>(); var post = PostTests.UniqueFileOrImage(random); post.ChannelId = channel.Id; post.PreviewImageId = file.Id; post.ChannelId = channel.Id; posts.Add(post); await connection.InsertAsync(posts); var postFiles = new List <PostFile>(); postFiles.Add(new PostFile(post.Id, file.Id)); await connection.InsertAsync(postFiles); var channelSubscriptions = new List <ChannelSubscription>(); if (subscriberId != null) { channelSubscriptions.Add(new ChannelSubscription(channel.Id, null, subscriberId.Value, null, 100, Now, Now)); await connection.InsertAsync(channelSubscriptions); } if (subscribedToId != null) { channelSubscriptions.Add(new ChannelSubscription(subscribedToId.Value, null, userId.Value, null, 100, Now, Now)); await connection.InsertAsync(channelSubscriptions); } var calculatedAccountBalances = new List <CalculatedAccountBalance> { new CalculatedAccountBalance(user.Id, LedgerAccountType.FifthweekCredit, Now), }; await connection.InsertAsync(calculatedAccountBalances); var subscriberSnapshots = new List <SubscriberSnapshot> { new SubscriberSnapshot(Now, user.Id, "email"), }; await connection.InsertAsync(subscriberSnapshots); var subscriberChannelSnapshots = new List <SubscriberChannelsSnapshot> { new SubscriberChannelsSnapshot(Guid.NewGuid(), Now, user.Id), }; await connection.InsertAsync(subscriberChannelSnapshots); var subscriberChannelSnapshotItems = new List <SubscriberChannelsSnapshotItem> { new SubscriberChannelsSnapshotItem(subscriberChannelSnapshots[0].Id, null, channel.Id, user.Id, 100, Now), }; await connection.InsertAsync(subscriberChannelSnapshotItems); var creatorChannelSnapshots = new List <CreatorChannelsSnapshot> { new CreatorChannelsSnapshot(Guid.NewGuid(), Now, user.Id), }; await connection.InsertAsync(creatorChannelSnapshots); var creatorChannelSnapshotItems = new List <CreatorChannelsSnapshotItem> { new CreatorChannelsSnapshotItem(creatorChannelSnapshots[0].Id, null, channel.Id, 100), }; await connection.InsertAsync(creatorChannelSnapshotItems); var creatorFreeAccessUsersSnapshots = new List <CreatorFreeAccessUsersSnapshot> { new CreatorFreeAccessUsersSnapshot(Guid.NewGuid(), Now, user.Id), }; await connection.InsertAsync(creatorFreeAccessUsersSnapshots); var creatorFreeAccessUsersSnapshotItems = new List <CreatorFreeAccessUsersSnapshotItem> { new CreatorFreeAccessUsersSnapshotItem(creatorFreeAccessUsersSnapshots[0].Id, null, "email"), }; await connection.InsertAsync(creatorFreeAccessUsersSnapshotItems); var userPaymentOrigins = new List <UserPaymentOrigin> { new UserPaymentOrigin(userId.Value, null, "paymentOriginKey", PaymentOriginKeyType.Stripe, null, null, null, null, PaymentStatus.None), }; await connection.InsertAsync(userPaymentOrigins); return(users.Cast <IIdentityEquatable>() .Concat(userRoles) .Concat(blogs) .Concat(channels) .Concat(queues) .Concat(files) .Concat(posts) .Concat(channelSubscriptions) .Concat(calculatedAccountBalances) .Concat(subscriberSnapshots) .Concat(subscriberChannelSnapshots) .Concat(subscriberChannelSnapshotItems) .Concat(creatorChannelSnapshots) .Concat(creatorChannelSnapshotItems) .Concat(creatorFreeAccessUsersSnapshots) .Concat(creatorFreeAccessUsersSnapshotItems) .Concat(userPaymentOrigins) .Concat(postFiles)); }
private async Task CreateEntitiesAsync(TestDatabaseContext testDatabase) { using (var databaseContext = testDatabase.CreateContext()) { // Create header file var blogId = BlogId.Random(); var headerImageFileId = FileId.Random(); await databaseContext.CreateTestBlogAsync(UserId.Value, blogId.Value, headerImageFileId.Value); var headerImageFile = databaseContext.Files.First(v => v.Id == headerImageFileId.Value); headerImageFile.UploadStartedDate = IncludedDate; var channelId = ChannelId.Random(); var channel = ChannelTests.UniqueEntity(Random); channel.BlogId = blogId.Value; channel.Blog = databaseContext.Blogs.First(v => v.Id == blogId.Value); channel.Id = channelId.Value; databaseContext.Channels.Add(channel); // Create profile image file var user = databaseContext.Users.First(v => v.Id == UserId.Value); var profileImageFileId = FileId.Random(); var profileImageFile = this.CreateTestFileWithExistingUserAsync(UserId.Value, profileImageFileId.Value, IncludedDate); databaseContext.Files.Add(profileImageFile); user.ProfileImageFileId = profileImageFileId.Value; // Create image post file. var post1 = PostTests.UniqueFileOrImage(Random); var imageFileId = FileId.Random(); var image = this.CreateTestFileWithExistingUserAsync(UserId.Value, imageFileId.Value, IncludedDate); databaseContext.Files.Add(image); post1.PreviewImageId = imageFileId.Value; post1.PreviewImage = image; post1.ChannelId = channelId.Value; post1.Channel = channel; databaseContext.Posts.Add(post1); var post1File = new PostFile(post1.Id, post1, imageFileId.Value, image); databaseContext.PostFiles.Add(post1File); // Create file post file. var post2 = PostTests.UniqueFileOrImage(Random); var fileFileId = FileId.Random(); var file = this.CreateTestFileWithExistingUserAsync(UserId.Value, fileFileId.Value, IncludedDate); databaseContext.Files.Add(file); post2.ChannelId = channelId.Value; post2.Channel = channel; databaseContext.Posts.Add(post2); var post2File = new PostFile(post2.Id, post2, fileFileId.Value, file); databaseContext.PostFiles.Add(post2File); // Create files excluded because of date. var lateFile1 = this.CreateTestFileWithExistingUserAsync(UserId.Value, FileId.Random().Value, EndDate); databaseContext.Files.Add(lateFile1); var lateFile2 = this.CreateTestFileWithExistingUserAsync(UserId.Value, FileId.Random().Value, Now); databaseContext.Files.Add(lateFile2); // Create orphaned files. var orphanedFile1 = this.CreateTestFileWithExistingUserAsync(UserId.Value, OrphanedFileId1.Value, IncludedDate); databaseContext.Files.Add(orphanedFile1); var orphanedFile2 = this.CreateTestFileWithExistingUserAsync(UserId.Value, OrphanedFileId2.Value, IncludedDate); databaseContext.Files.Add(orphanedFile2); await databaseContext.SaveChangesAsync(); } }
private async Task CreateEntitiesAsync(TestDatabaseContext testDatabase, bool likePost = false, bool isFreePost = false) { using (var databaseContext = testDatabase.CreateContext()) { await databaseContext.CreateTestBlogAsync(CreatorId.Value, BlogId.Value, null, Random, CreatorUsername, BlogId.ToString()); await databaseContext.Database.Connection.UpdateAsync( new Blog { Id = BlogId.Value, Introduction = Introduction.Value }, Blog.Fields.Introduction); var channel = ChannelTests.UniqueEntity(Random); channel.BlogId = BlogId.Value; channel.Name = ChannelId.ToString(); channel.Id = ChannelId.Value; await databaseContext.Database.Connection.InsertAsync(channel); var file1 = FileTests.UniqueEntity(Random); file1.BlobSizeBytes = FileSize1; file1.ChannelId = ChannelId.Value; file1.FileExtension = FileExtension1; file1.FileNameWithoutExtension = FileName1; file1.Id = FileId1.Value; file1.Purpose = FilePurpose1; file1.RenderHeight = FileHeight1; file1.RenderWidth = FileWidth1; file1.UserId = CreatorId.Value; await databaseContext.Database.Connection.InsertAsync(file1); var file2 = FileTests.UniqueEntity(Random); file2.BlobSizeBytes = FileSize2; file2.ChannelId = ChannelId.Value; file2.FileExtension = FileExtension2; file2.FileNameWithoutExtension = FileName2; file2.Id = FileId2.Value; file2.Purpose = FilePurpose2; file2.RenderHeight = FileHeight2; file2.RenderWidth = FileWidth2; file2.UserId = CreatorId.Value; await databaseContext.Database.Connection.InsertAsync(file2); var post = PostTests.UniqueFileOrImage(Random); post.ChannelId = ChannelId.Value; post.PreviewText = PreviewText.Value; post.Content = Content.Value; post.CreationDate = CreationDate; post.FileCount = FileCount; post.Id = PostId.Value; post.ImageCount = ImageCount; post.VideoCount = VideoCount; post.LiveDate = LiveDate; post.PreviewImageId = FileId1.Value; post.PreviewWordCount = PreviewWordCount; post.WordCount = WordCount; await databaseContext.Database.Connection.InsertAsync(post); await databaseContext.Database.Connection.InsertAsync(new PostFile(post.Id, file1.Id)); await databaseContext.Database.Connection.InsertAsync(new PostFile(post.Id, file2.Id)); await databaseContext.CreateTestUserAsync(UserId.Value, Random); var user2 = await databaseContext.CreateTestUserAsync(Guid.NewGuid(), Random); await databaseContext.Database.Connection.InsertAsync(new Like(post.Id, null, user2.Id, null, CreationDate)); await databaseContext.Database.Connection.InsertAsync(new Persistence.Comment(Guid.NewGuid(), post.Id, null, user2.Id, null, "coment", CreationDate)); if (likePost) { await databaseContext.Database.Connection.InsertAsync(new Like(post.Id, null, UserId.Value, null, CreationDate)); } if (isFreePost) { await databaseContext.Database.Connection.InsertAsync(new FreePost(UserId.Value, post.Id, null, Now)); } } }
private async Task <IReadOnlyList <Post> > CreatePostsAsync( TestDatabaseContext testDatabase, UserId userId, QueueId queueId, bool liveDateInFuture, bool scheduledByQueue) { using (var databaseContext = testDatabase.CreateContext()) { var user = UserTests.UniqueEntity(Random); user.Id = userId.Value; await databaseContext.Database.Connection.InsertAsync(user); var file = FileTests.UniqueEntity(Random); file.Id = FileId.Value; file.UserId = user.Id; await databaseContext.Database.Connection.InsertAsync(file); var blog = BlogTests.UniqueEntity(Random); blog.CreatorId = user.Id; await databaseContext.Database.Connection.InsertAsync(blog); var channel = ChannelTests.UniqueEntity(Random); channel.BlogId = blog.Id; await databaseContext.Database.Connection.InsertAsync(channel); var queue = QueueTests.UniqueEntity(Random); queue.Id = queueId.Value; queue.BlogId = blog.Id; await databaseContext.Database.Connection.InsertAsync(queue); var notes = new List <Post>(); for (var i = 0; i < CollectionTotal; i++) { // Notes are not covered by this feature as they do not belong in a collection, but we add them to create a more realistic test state. var post = PostTests.UniqueNote(Random); post.ChannelId = channel.Id; notes.Add(post); } var postsInCollection = new List <Post>(); for (var i = 0; i < CollectionTotal; i++) { var post = PostTests.UniqueFileOrImage(Random); post.ChannelId = channel.Id; post.QueueId = scheduledByQueue ? queueId.Value : (Guid?)null; post.PreviewImageId = file.Id; post.LiveDate = Now.AddDays((1 + Random.Next(100)) * (liveDateInFuture ? 1 : -1)); // Clip dates as we will be comparing from these entities. post.LiveDate = new SqlDateTime(post.LiveDate).Value; post.CreationDate = new SqlDateTime(post.CreationDate).Value; postsInCollection.Add(post); } await databaseContext.Database.Connection.InsertAsync(notes.Concat(postsInCollection)); return(postsInCollection); } }
private async Task CreateEntitiesAsync(TestDatabaseContext testDatabase, bool createLivePosts, bool createFuturePosts) { using (var databaseContext = testDatabase.CreateContext()) { var channels = new List <ChannelId>(); var queues = new List <QueueId>(); var files = new List <FileId>(); var images = new List <FileId>(); var channelEntities = new List <Channel>(); var queueEntities = new List <Queue>(); var postEntities = new List <Post>(); if (createLivePosts) { var channelId = new ChannelId(Guid.NewGuid()); var queueId = new QueueId(Guid.NewGuid()); channels.Add(channelId); queues.Add(queueId); for (var i = 1; i <= 10; i++) { var post = PostTests.UniqueFileOrImage(Random); post.ChannelId = channelId.Value; post.QueueId = queueId.Value; post.LiveDate = DateTime.UtcNow.AddDays(i * -1); postEntities.Add(post); } } if (createFuturePosts) { foreach (var backlogPost in SortedBacklogPosts) { if (backlogPost.ImageId != null) { images.Add(backlogPost.ImageId); } if (!channels.Contains(backlogPost.ChannelId)) { channels.Add(backlogPost.ChannelId); } if (backlogPost.QueueId != null) { queues.Add(backlogPost.QueueId); } postEntities.Add(new Post( backlogPost.PostId.Value, backlogPost.ChannelId.Value, null, backlogPost.QueueId == null ? (Guid?)null : backlogPost.QueueId.Value, null, backlogPost.ImageId == null ? (Guid?)null : backlogPost.ImageId.Value, null, backlogPost.PreviewText == null ? null : backlogPost.PreviewText.Value, "content", backlogPost.PreviewWordCount, backlogPost.WordCount, backlogPost.ImageCount, backlogPost.FileCount, backlogPost.VideoCount, backlogPost.LiveDate, backlogPost.CreationDate)); } } foreach (var channelId in channels) { var channel = ChannelTests.UniqueEntity(Random); channel.Id = channelId.Value; channel.BlogId = BlogId.Value; channelEntities.Add(channel); } foreach (var queueId in queues) { var queue = QueueTests.UniqueEntity(Random); queue.Id = queueId.Value; queue.BlogId = BlogId.Value; queueEntities.Add(queue); } var fileEntities = files.Select(fileId => { var file = FileTests.UniqueEntity(Random); file.Id = fileId.Value; file.UserId = UserId.Value; file.FileNameWithoutExtension = FileName; file.FileExtension = FileExtension; file.BlobSizeBytes = FileSize; return(file); }); var imageEntities = images.Select(fileId => { var file = FileTests.UniqueEntity(Random); file.Id = fileId.Value; file.UserId = UserId.Value; file.FileNameWithoutExtension = FileName; file.FileExtension = FileExtension; file.BlobSizeBytes = FileSize; file.RenderWidth = FileWidth; file.RenderHeight = FileHeight; return(file); }); await databaseContext.CreateTestBlogAsync(UserId.Value, BlogId.Value); await databaseContext.Database.Connection.InsertAsync(channelEntities); await databaseContext.Database.Connection.InsertAsync(queueEntities); await databaseContext.Database.Connection.InsertAsync(fileEntities); await databaseContext.Database.Connection.InsertAsync(imageEntities); await databaseContext.Database.Connection.InsertAsync(postEntities); } }
private async Task CreateChannelsAndQueuesAsync(TestDatabaseContext testDatabase) { var random = new Random(); var channel1 = ChannelTests.UniqueEntity(random); channel1.Id = ChannelId1.Value; ConfigureChannel(channel1); var channel2 = ChannelTests.UniqueEntity(random); channel2.Id = ChannelId2.Value; ConfigureChannel(channel2); var channel3 = ChannelTests.UniqueEntity(random); channel3.Id = ChannelId3.Value; ConfigureChannel(channel3); var queue1 = QueueTests.UniqueEntity(random); queue1.Id = QueueId1.Value; ConfigureQueue(queue1); var queue2 = QueueTests.UniqueEntity(random); queue2.Id = QueueId2.Value; ConfigureQueue(queue2); var queue3 = QueueTests.UniqueEntity(random); queue3.Id = QueueId3.Value; ConfigureQueue(queue3); var wrt1 = WeeklyReleaseTimeTests.UniqueEntity(random, queue1.Id); var wrt2a = WeeklyReleaseTimeTests.UniqueEntity(random, queue2.Id); var wrt2b = WeeklyReleaseTimeTests.UniqueEntity(random, queue2.Id); var wrt3a = WeeklyReleaseTimeTests.UniqueEntity(random, queue3.Id); var wrt3b = WeeklyReleaseTimeTests.UniqueEntity(random, queue3.Id); var wrt3c = WeeklyReleaseTimeTests.UniqueEntity(random, queue3.Id); using (var connection = testDatabase.CreateConnection()) { await connection.InsertAsync(channel1); await connection.InsertAsync(channel2); await connection.InsertAsync(channel3); await connection.InsertAsync(queue1); await connection.InsertAsync(queue2); await connection.InsertAsync(queue3); await connection.InsertAsync(wrt1); await connection.InsertAsync(wrt2a); await connection.InsertAsync(wrt2b); await connection.InsertAsync(wrt3a); await connection.InsertAsync(wrt3b); await connection.InsertAsync(wrt3c); } }