예제 #1
0
        private async Task <Post> CreatePostWithIdAsync(
            TestDatabaseContext testDatabase,
            DateTime liveDate,
            bool scheduledByQueue,
            bool differentCollection,
            Guid postId)
        {
            using (var databaseContext = testDatabase.CreateContext())
            {
                if (differentCollection)
                {
                    var collection = QueueTests.UniqueEntity(Random);
                    collection.Id     = DifferentQueueId.Value;
                    collection.BlogId = BlogId.Value;
                    await databaseContext.Database.Connection.InsertAsync(collection);
                }

                var post = PostTests.UniqueFileOrImage(Random);
                post.Id        = postId;
                post.ChannelId = ChannelId.Value;
                post.QueueId   = scheduledByQueue ? (differentCollection ? DifferentQueueId.Value : QueueId.Value) : (Guid?)null;
                post.LiveDate  = liveDate;
                await databaseContext.Database.Connection.InsertAsync(post);
            }

            using (var databaseContext = testDatabase.CreateContext())
            {
                return(await databaseContext.Posts.FirstAsync(_ => _.Id == postId));
            }
        }
        private async Task CreateUserAsync(TestDatabaseContext testDatabase)
        {
            var random = new Random();
            var user   = UserTests.UniqueEntity(random);

            user.Id       = CreatorId.Value;
            user.UserName = Username.Value;

            var file = FileTests.UniqueEntity(random);

            file.Id     = ProfileFileId.Value;
            file.UserId = CreatorId.Value;

            using (var databaseContext = testDatabase.CreateContext())
            {
                databaseContext.Users.Add(user);
                await databaseContext.SaveChangesAsync();
            }

            using (var connection = testDatabase.CreateConnection())
            {
                await connection.InsertAsync(file);
            }

            using (var databaseContext = testDatabase.CreateContext())
            {
                file = await databaseContext.Files.FirstAsync(v => v.Id == ProfileFileId.Value);

                user = await databaseContext.Users.FirstAsync(v => v.Id == CreatorId.Value);

                user.ProfileImageFile   = file;
                user.ProfileImageFileId = file.Id;
                await databaseContext.SaveChangesAsync();
            }
        }
예제 #3
0
        private async Task <Tuple <UserId, UserId> > CreateDataAsync(TestDatabaseContext testDatabase, int creatorChannelsSnapshotCount)
        {
            var random       = new Random();
            var testUserId   = Guid.NewGuid();
            var normalUserId = Guid.NewGuid();

            using (var databaseContext = testDatabase.CreateContext())
            {
                var testUser = UserTests.UniqueEntity(random);
                testUser.Id = testUserId;
                databaseContext.Users.Add(testUser);

                var normalUser = UserTests.UniqueEntity(random);
                normalUser.Id = normalUserId;
                databaseContext.Users.Add(normalUser);

                await databaseContext.SaveChangesAsync();
            }

            using (var connection = testDatabase.CreateConnection())
            {
                var userRoles = new List <FifthweekUserRole>();
                userRoles.Add(new FifthweekUserRole(FifthweekRole.CreatorId, normalUserId));
                userRoles.Add(new FifthweekUserRole(FifthweekRole.CreatorId, testUserId));
                userRoles.Add(new FifthweekUserRole(FifthweekRole.TestUserId, testUserId));

                await connection.InsertAsync(userRoles, false);

                return(new Tuple <UserId, UserId>(
                           new UserId(testUserId),
                           new UserId(normalUserId)));
            }
        }
        private async Task CreateDataAsync(UserId newUserId, TestDatabaseContext testDatabase, bool createOrigin)
        {
            var random = new Random();
            var user   = UserTests.UniqueEntity(random);

            user.Id = newUserId.Value;

            UserPaymentOrigin origin = null;

            if (createOrigin)
            {
                origin = new UserPaymentOrigin(
                    UserId.Value,
                    user,
                    "anotherStripeCustomerId",
                    PaymentOriginKeyType.Stripe,
                    "USA",
                    "999999",
                    "9.9.9.999",
                    "anotherKey",
                    PaymentStatus);
            }

            using (var databaseContext = testDatabase.CreateContext())
            {
                databaseContext.Users.Add(user);
                if (createOrigin)
                {
                    databaseContext.UserPaymentOrigins.Add(origin);
                }

                await databaseContext.SaveChangesAsync();
            }
        }
        private async Task CreateQueuedPostsForAnotherCollectionAsync(TestDatabaseContext testDatabase)
        {
            using (var databaseContext = testDatabase.CreateContext())
            {
                var userId    = Guid.NewGuid();
                var channelId = Guid.NewGuid();
                var entities  = await databaseContext.CreateTestEntitiesAsync(userId, channelId, QueueId.Value);

                var otherQueue = QueueTests.UniqueEntity(Random);
                otherQueue.BlogId = entities.Blog.Id;
                await databaseContext.Database.Connection.InsertAsync(otherQueue);

                var posts = new List <Post>();

                for (var i = 0; i < PostCount; i++)
                {
                    var post = PostTests.UniqueFileOrImage(Random);
                    post.ChannelId = channelId;
                    post.QueueId   = otherQueue.Id;
                    post.LiveDate  = Now.AddDays(1);
                    posts.Add(post);
                }

                await databaseContext.Database.Connection.InsertAsync(posts);
            }
        }
 private async Task CreateCollectionAsync(UserId newUserId, QueueId newQueueId, TestDatabaseContext testDatabase)
 {
     using (var databaseContext = testDatabase.CreateContext())
     {
         await databaseContext.CreateTestEntitiesAsync(newUserId.Value, Guid.NewGuid(), newQueueId.Value);
     }
 }
예제 #7
0
        private async Task CreateEntitiesAsync(TestDatabaseContext testDatabase)
        {
            using (var databaseContext = testDatabase.CreateContext())
            {
                var random = new Random();
                await databaseContext.CreateTestEntitiesAsync(CreatorId.Value, ChannelId.Value, QueueId.Value);

                await databaseContext.CreateTestFileWithExistingUserAsync(CreatorId.Value, FileId.Value);

                var post = PostTests.UniqueFileOrImage(random);
                post.Id             = PostId.Value;
                post.ChannelId      = ChannelId.Value;
                post.QueueId        = QueueId.Value;
                post.PreviewImageId = FileId.Value;
                post.CreationDate   = new SqlDateTime(post.CreationDate).Value;
                post.LiveDate       = new SqlDateTime(post.LiveDate).Value;
                await databaseContext.Database.Connection.InsertAsync(post);

                await databaseContext.Database.Connection.InsertAsync(new PostFile(PostId.Value, FileId.Value));

                await databaseContext.CreateTestUserAsync(UserId.Value, random);

                var comment = CommentTests.Unique(random);
                comment.Id     = CommentId.Value;
                comment.PostId = PostId.Value;
                comment.UserId = UserId.Value;
                await databaseContext.Database.Connection.InsertAsync(comment);

                var like = LikeTests.Unique(random);
                like.PostId = PostId.Value;
                like.UserId = UserId.Value;
                await databaseContext.Database.Connection.InsertAsync(like);
            }
        }
        private async Task CreateDataAsync(TestDatabaseContext testDatabase, bool addEmailAddress)
        {
            using (var databaseContext = testDatabase.CreateContext())
            {
                await databaseContext.CreateTestChannelsAsync(
                    CreatorId1.Value,
                    BlogId1.Value,
                    ChannelId1.Value,
                    ChannelId2.Value);

                await databaseContext.CreateTestChannelsAsync(
                    CreatorId2.Value,
                    BlogId2.Value,
                    ChannelId3.Value,
                    ChannelId4.Value);
            }

            await this.CreateUsersAsync(testDatabase);

            if (addEmailAddress)
            {
                using (var connection = testDatabase.CreateConnection())
                {
                    foreach (var item in InitialFreeAccessUsers)
                    {
                        await connection.InsertAsync(item);
                    }
                }
            }
        }
        private async Task CreateUsersAsync(TestDatabaseContext testDatabase)
        {
            var user1 = UserTests.UniqueEntity(this.random);

            user1.Id       = UserId1.Value;
            user1.Email    = UserEmail1.Value;
            user1.UserName = Username1.Value;

            var user2 = UserTests.UniqueEntity(this.random);

            user2.Id       = UserId2.Value;
            user2.Email    = UserEmail2.Value;
            user2.UserName = Username2.Value;

            using (var databaseContext = testDatabase.CreateContext())
            {
                databaseContext.Users.Add(user1);
                databaseContext.Users.Add(user2);
                await databaseContext.SaveChangesAsync();

                await databaseContext.CreateTestChannelSubscriptionWithExistingReferences(UserId2.Value, ChannelId1.Value);

                await databaseContext.CreateTestChannelSubscriptionWithExistingReferences(UserId2.Value, ChannelId2.Value);

                await databaseContext.CreateTestChannelSubscriptionWithExistingReferences(UserId2.Value, ChannelId3.Value);
            }
        }
예제 #10
0
 private async Task CreateEntitiesAsync(TestDatabaseContext testDatabase)
 {
     using (var databaseContext = testDatabase.CreateContext())
     {
         await databaseContext.CreateTestBlogAsync(UserId.Value, BlogId.Value);
     }
 }
예제 #11
0
        private async Task <Post> CreateCollectionAsync(TestDatabaseContext testDatabase, bool createPost)
        {
            using (var databaseContext = testDatabase.CreateContext())
            {
                await databaseContext.CreateTestEntitiesAsync(UserId.Value, ChannelId.Value, QueueId.Value);

                if (createPost)
                {
                    var existingFileId = Guid.NewGuid();
                    await databaseContext.CreateTestFileWithExistingUserAsync(UserId.Value, existingFileId);

                    await databaseContext.CreateTestFileWithExistingUserAsync(UserId.Value, FileId.Value);

                    await databaseContext.CreateTestFileWithExistingUserAsync(UserId.Value, ImageId.Value);

                    var post = PostTests.UniqueFileOrImage(new Random());
                    post.Id             = PostId.Value;
                    post.ChannelId      = ChannelId.Value;
                    post.QueueId        = QueueId.Value;
                    post.PreviewImageId = existingFileId;
                    await databaseContext.Database.Connection.InsertAsync(post);

                    var postFiles = new List <PostFile>();
                    postFiles.Add(new PostFile(post.Id, existingFileId));

                    await databaseContext.Database.Connection.InsertAsync(postFiles);

                    return(post);
                }

                return(null);
            }
        }
예제 #12
0
 private async Task CreatePostAsync(UserId newUserId, PostId newPostId, TestDatabaseContext testDatabase)
 {
     using (var databaseContext = testDatabase.CreateContext())
     {
         await databaseContext.CreateTestNoteAsync(newUserId.Value, newPostId.Value);
     }
 }
        private async Task CreateDataAsync(TestDatabaseContext testDatabase)
        {
            using (var databaseContext = testDatabase.CreateContext())
            {
                var random      = new Random();
                var creator1    = CreateUser(databaseContext, random, CreatorId1);
                var creator2    = CreateUser(databaseContext, random, CreatorId2);
                var subscriber1 = CreateUser(databaseContext, random, SubscriberId1);
                var subscriber2 = CreateUser(databaseContext, random, SubscriberId2);
                var subscriber3 = CreateUser(databaseContext, random, SubscriberId3);
                var subscriber4 = CreateUser(databaseContext, random, SubscriberId4);

                // Add credit
                AddCredit(databaseContext, random, SubscriberId1, 100);
                AddCredit(databaseContext, random, SubscriberId2, 40);
                AddCredit(databaseContext, random, SubscriberId2, 10);
                AddCredit(databaseContext, random, SubscriberId3, 10);
                AddCredit(databaseContext, random, CreatorId1, 5.5m);

                PayCreator(databaseContext, random, SubscriberId1, CreatorId1, 10m);
                PayCreator(databaseContext, random, SubscriberId1, CreatorId2, 20m);
                PayCreator(databaseContext, random, SubscriberId2, CreatorId2, 40m);
                PayCreator(databaseContext, random, CreatorId1, CreatorId2, 10m);

                PayCreatorUncommitted(databaseContext, random, SubscriberId2, CreatorId2, 5m);

                await databaseContext.SaveChangesAsync();
            }
        }
예제 #14
0
 private static async Task InsertRefreshToken(TestDatabaseContext testDatabase)
 {
     using (var context = testDatabase.CreateContext())
     {
         await context.Database.Connection.InsertAsync(RefreshToken);
     }
 }
 private async Task CreateEntitiesAsync(TestDatabaseContext testDatabase)
 {
     using (var databaseContext = testDatabase.CreateContext())
     {
         await databaseContext.CreateTestChannelsAsync(Guid.NewGuid(), Guid.NewGuid(), ChannelIds.Select(v => v.Value).ToArray());
     }
 }
예제 #16
0
        private async Task <List <IIdentityEquatable> > GetExpectedDeletionsAsync(TestDatabaseContext testDatabase)
        {
            using (var databaseContext = testDatabase.CreateContext())
            {
                var channel = await databaseContext.Channels.SingleAsync(v => v.Id == ChannelId.Value);

                var subscription = await databaseContext.ChannelSubscriptions.SingleAsync(v => v.ChannelId == ChannelId.Value && v.UserId == CreatorId.Value);

                var post = await databaseContext.Posts.SingleAsync(v => v.Id == PostId.Value);

                var comment = await databaseContext.Comments.SingleAsync(v => v.Id == CommentId.Value);

                var like = await databaseContext.Likes.SingleAsync(v => v.UserId == UserId.Value && v.PostId == PostId.Value);

                var postFile = await databaseContext.PostFiles.SingleAsync(v => v.PostId == PostId.Value);

                var result = new List <IIdentityEquatable>
                {
                    channel,
                    post,
                    subscription,
                    comment,
                    like,
                    postFile,
                };

                return(result);
            }
        }
예제 #17
0
        private async Task CreateEntitiesAsync(TestDatabaseContext testDatabase)
        {
            using (var databaseContext = testDatabase.CreateContext())
            {
                await databaseContext.CreateTestEntitiesAsync(CreatorId.Value, ChannelId.Value, QueueId.Value, BlogId.Value);

                await databaseContext.SaveChangesAsync();

                var post = PostTests.UniqueFileOrImage(Random);
                post.ChannelId = ChannelId.Value;
                post.Id        = PostId.Value;
                await databaseContext.Database.Connection.InsertAsync(post);

                await this.CreateUserAsync(databaseContext, UnsubscribedUserId);

                await this.CreateUserAsync(databaseContext, SubscribedUserId);

                await this.CreateUserAsync(databaseContext, GuestListUserId);

                var channelSubscriptions = new List <ChannelSubscription>();
                var freeAccessUsers      = new List <FreeAccessUser>();

                channelSubscriptions.Add(new ChannelSubscription(ChannelId.Value, null, SubscribedUserId.Value, null, ChannelPrice, Now, Now));

                freeAccessUsers.Add(new FreeAccessUser(BlogId.Value, GuestListUserId.Value + "@test.com"));

                await databaseContext.Database.Connection.InsertAsync(channelSubscriptions);

                await databaseContext.Database.Connection.InsertAsync(freeAccessUsers);
            }
        }
예제 #18
0
        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();
            }
        }
예제 #19
0
        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);
            }
        }
예제 #20
0
 private async Task CreateUserAsync(UserId newUserId, TestDatabaseContext testDatabase)
 {
     using (var databaseContext = testDatabase.CreateContext())
     {
         await databaseContext.CreateTestUserAsync(newUserId.Value);
     }
 }
        private async Task CreateDataAsync(UserId newUserId, TestDatabaseContext testDatabase, bool createOrigin)
        {
            var random = new Random();
            var user   = UserTests.UniqueEntity(random);

            user.Id = newUserId.Value;

            UserPaymentOrigin origin = null;

            if (createOrigin)
            {
                origin = new UserPaymentOrigin(
                    UserId.Value,
                    user,
                    PaymentOriginType,
                    PaymentOriginKeyType,
                    CountryCode,
                    CreditCardPrefix,
                    IpAddress,
                    TaxamoTransactionKey,
                    PaymentStatus);
            }

            using (var databaseContext = testDatabase.CreateContext())
            {
                databaseContext.Users.Add(user);
                if (createOrigin)
                {
                    databaseContext.UserPaymentOrigins.Add(origin);
                }

                await databaseContext.SaveChangesAsync();
            }
        }
예제 #22
0
        private async Task CreateDataAsync(TestDatabaseContext testDatabase)
        {
            using (var databaseContext = testDatabase.CreateContext())
            {
                var random = new Random();

                var creator1 = UserTests.UniqueEntity(random);
                creator1.Id = CreatorId1.Value;

                var creator2 = UserTests.UniqueEntity(random);
                creator2.Id = CreatorId2.Value;

                var creator3 = UserTests.UniqueEntity(random);
                creator3.Id = CreatorId3.Value;

                var override1 = new CreatorPercentageOverride(
                    CreatorId1.Value,
                    0.9m,
                    Now.AddMonths(1));

                var override2 = new CreatorPercentageOverride(
                    CreatorId2.Value,
                    0.8m,
                    null);

                databaseContext.CreatorPercentageOverrides.Add(override1);
                databaseContext.CreatorPercentageOverrides.Add(override2);
                databaseContext.Users.Add(creator3);

                await databaseContext.SaveChangesAsync();
            }
        }
        private async Task <GetTransactionsResult> CreateDataAsync(TestDatabaseContext testDatabase)
        {
            using (var databaseContext = testDatabase.CreateContext())
            {
                var random = new Random();
                var users  = new List <FifthweekUser>();
                users.Add(CreateUser(databaseContext, random, CreatorId1));
                users.Add(CreateUser(databaseContext, random, CreatorId2));
                users.Add(CreateUser(databaseContext, random, SubscriberId1));
                users.Add(CreateUser(databaseContext, random, SubscriberId2));
                users.Add(CreateUser(databaseContext, random, SubscriberId3));
                users.Add(CreateUser(databaseContext, random, SubscriberId4));

                var records = new List <AppendOnlyLedgerRecord>();

                // Add credit
                var subscriber1Credit = AddCredit(databaseContext, Now.AddDays(-30), SubscriberId1, 100);
                records.AddRange(subscriber1Credit);
                records.AddRange(AddCredit(databaseContext, Now.AddDays(-30), SubscriberId2, 40));
                records.AddRange(AddCredit(databaseContext, Now.AddDays(-30), SubscriberId2, 10));
                records.AddRange(AddCredit(databaseContext, Now.AddDays(-10), SubscriberId3, 10));
                records.AddRange(AddCredit(databaseContext, Now.AddDays(-10), CreatorId1, 5.5m));
                records.AddRange(AddCredit(databaseContext, Now.AddDays(-10), SubscriberId1, -100, new TransactionReference(subscriber1Credit.First().TransactionReference)));

                records.AddRange(PayCreator(databaseContext, Now.AddDays(-30), SubscriberId1, CreatorId1, 10m));
                records.AddRange(PayCreator(databaseContext, Now.AddDays(-30), SubscriberId1, CreatorId2, 20m));
                records.AddRange(PayCreator(databaseContext, Now.AddDays(-10), SubscriberId2, CreatorId2, 40m));
                records.AddRange(PayCreator(databaseContext, Now.AddDays(-10), CreatorId1, CreatorId2, 10m));

                PayCreatorUncommitted(databaseContext, random, SubscriberId2, CreatorId2, 5m);

                await databaseContext.SaveChangesAsync();

                var results = new List <GetTransactionsResult.Item>();
                foreach (var item in records)
                {
                    var accountOwnerUsername = item.AccountOwnerId == Guid.Empty ? null : users.First(v => item.AccountOwnerId == v.Id).UserName;
                    var counterpartyUsername = item.CounterpartyId == Guid.Empty || item.CounterpartyId == null ? null : users.First(v => item.CounterpartyId == v.Id).UserName;

                    results.Add(
                        new GetTransactionsResult.Item(
                            item.Id,
                            new UserId(item.AccountOwnerId),
                            accountOwnerUsername == null ? null : new Username(accountOwnerUsername),
                            item.CounterpartyId == null ? null : new UserId(item.CounterpartyId.Value),
                            counterpartyUsername == null ? null : new Username(counterpartyUsername),
                            item.Timestamp,
                            item.Amount,
                            item.AccountType,
                            item.TransactionType,
                            new TransactionReference(item.TransactionReference),
                            item.InputDataReference,
                            item.Comment,
                            item.StripeChargeId,
                            item.TaxamoTransactionKey));
                }

                return(new GetTransactionsResult(results));
            }
        }
 private async Task <FifthweekUser> GetUserAsync(TestDatabaseContext testDatabase)
 {
     using (var databaseContext = testDatabase.CreateContext())
     {
         databaseContext.Configuration.ProxyCreationEnabled = false;
         return(await databaseContext.Users.SingleAsync(v => v.Id == this.userId.Value));
     }
 }
        private async Task <Blog> CreateBlogAsync(UserId newUserId, BlogId newBlogId, TestDatabaseContext testDatabase)
        {
            using (var databaseContext = testDatabase.CreateContext())
            {
                await databaseContext.CreateTestBlogAsync(newUserId.Value, newBlogId.Value, Guid.NewGuid());

                var newHeaderImage = FileTests.UniqueEntity(new Random());
                newHeaderImage.Id     = HeaderImageFileId.Value;
                newHeaderImage.UserId = newUserId.Value;
                await databaseContext.Database.Connection.InsertAsync(newHeaderImage);
            }

            using (var databaseContext = testDatabase.CreateContext())
            {
                return(await databaseContext.Blogs.SingleAsync(_ => _.Id == newBlogId.Value));
            }
        }
 private async Task CreateCollectionWithoutPostsAsync(TestDatabaseContext testDatabase)
 {
     using (var databaseContext = testDatabase.CreateContext())
     {
         var userId    = Guid.NewGuid();
         var channelId = Guid.NewGuid();
         await databaseContext.CreateTestEntitiesAsync(userId, channelId, QueueId.Value);
     }
 }
        private async Task CreateEntitiesAsync(TestDatabaseContext testDatabase)
        {
            using (var databaseContext = testDatabase.CreateContext())
            {
                await databaseContext.CreateTestEntitiesAsync(UserId.Value, ChannelId.Value, QueueId.Value);

                await databaseContext.Database.Connection.InsertAsync(SortedReleaseTimes);
            }
        }
예제 #28
0
        private async Task <File> CreateEntitiesAsync(TestDatabaseContext testDatabase)
        {
            using (var databaseContext = testDatabase.CreateContext())
            {
                await databaseContext.CreateTestUserAsync(UserId.Value);

                return(await databaseContext.CreateTestFileWithExistingUserAsync(UserId.Value, FileId.Value));
            }
        }
        private async Task <IReadOnlyList <UserId> > CreateDataAsync(TestDatabaseContext testDatabase, int normalUserCount)
        {
            var random        = new Random();
            var testUserIds   = new List <Guid>();
            var normalUserIds = new List <Guid>();

            using (var databaseContext = testDatabase.CreateContext())
            {
                // Create some test users which should be ignored.
                for (int i = 0; i < 3; i++)
                {
                    var user = UserTests.UniqueEntity(random);
                    testUserIds.Add(user.Id);
                    databaseContext.Users.Add(user);
                }

                // Create some normal users which shouldn't be ignored.
                for (int i = 0; i < normalUserCount; i++)
                {
                    var user = UserTests.UniqueEntity(random);
                    normalUserIds.Add(user.Id);
                    databaseContext.Users.Add(user);
                }

                await databaseContext.SaveChangesAsync();
            }

            using (var connection = testDatabase.CreateConnection())
            {
                var userRoles = new List <FifthweekUserRole>();

                foreach (var userId in normalUserIds)
                {
                    // Add some normal users to creator roles.
                    if (random.NextDouble() > 0.5)
                    {
                        userRoles.Add(new FifthweekUserRole(FifthweekRole.CreatorId, userId));
                    }
                }

                foreach (var userId in testUserIds)
                {
                    // Add some test users.
                    userRoles.Add(new FifthweekUserRole(FifthweekRole.TestUserId, userId));

                    if (random.NextDouble() > 0.5)
                    {
                        userRoles.Add(new FifthweekUserRole(FifthweekRole.CreatorId, userId));
                    }
                }

                await connection.InsertAsync(userRoles, false);

                return(normalUserIds.Select(v => new UserId(v)).ToList());
            }
        }
예제 #30
0
        private async Task <FifthweekUser> CreateDataAsync(TestDatabaseContext testDatabase)
        {
            using (var databaseContext = testDatabase.CreateContext())
            {
                var user = await databaseContext.CreateTestUserAsync(SubscriberId.Value);

                await databaseContext.SaveChangesAsync();

                return(user);
            }
        }