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); } }
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 <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); } }