예제 #1
0
        private void CreateUsers()
        {
            for (var i = 0; i < Users; i++)
            {
                var user = UserTests.UniqueEntity(Random);

                if (Random.Next(1) == 1)
                {
                    var file = FileTests.UniqueEntity(Random);
                    file.UserId             = user.Id;
                    user.ProfileImageFile   = file;
                    user.ProfileImageFileId = file.Id;
                }

                this.users.Add(user);

                if (i < Creators)
                {
                    this.CreateBlogs(user);
                }
                else
                {
                    this.CreateFreeAccess(user);
                    this.CreateSubscriptions(user);
                }

                this.CreateRefreshTokens(user);

                if (i > 0)
                {
                    this.CreatePaymentInformation(user, this.users[i - 1].Id, i);
                }

                if (i % 2 == 0)
                {
                    this.userPaymentOrigins.Add(
                        new UserPaymentOrigin(
                            user.Id,
                            user,
                            Guid.NewGuid().ToString(),
                            (PaymentOriginKeyType)Random.Next(1, 1 + (int)PaymentOriginKeyType.Stripe),
                            "USA",
                            "123243",
                            "1.2.3.4",
                            Guid.NewGuid().ToString(),
                            (PaymentStatus)Random.Next(0, 1 + (int)PaymentStatus.Failed)));
                }
            }

            // Create some records for deleted users.
            this.CreateAppendOnlyLedgerRecord(Guid.NewGuid(), Guid.NewGuid());
            this.CreateAppendOnlyLedgerRecord(Guid.NewGuid(), Guid.NewGuid());
            this.uncommittedSubscriptionPayment.Add(new UncommittedSubscriptionPayment(Guid.NewGuid(), Guid.NewGuid(), DateTime.Now.AddMinutes(-30), DateTime.Now, 10m, Guid.NewGuid()));
            this.uncommittedSubscriptionPayment.Add(new UncommittedSubscriptionPayment(Guid.NewGuid(), Guid.NewGuid(), DateTime.Now.AddMinutes(-30), DateTime.Now, 10m, Guid.NewGuid()));
        }
예제 #2
0
        private void CreatePosts(Blog blog, IReadOnlyList <Channel> userChannels, IReadOnlyList <Queue> userQueues)
        {
            for (var postIndex = 0; postIndex < NotesPerChannel; postIndex++)
            {
                var post = PostTests.UniqueNote(Random);
                post.Channel   = userChannels[postIndex % userChannels.Count];
                post.ChannelId = userChannels[postIndex % userChannels.Count].Id;
                post.Queue     = userQueues[postIndex % userQueues.Count];
                post.QueueId   = userQueues[postIndex % userQueues.Count].Id;
                this.posts.Add(post);
            }

            for (var postIndex = 0; postIndex < ImagesPerCollection; postIndex++)
            {
                var post = PostTests.UniqueFileOrImage(Random);
                post.Channel   = userChannels[postIndex % userChannels.Count];
                post.ChannelId = userChannels[postIndex % userChannels.Count].Id;
                post.Queue     = userQueues[postIndex % userQueues.Count];
                post.QueueId   = userQueues[postIndex % userQueues.Count].Id;

                var file = FileTests.UniqueEntity(Random);
                file.UserId         = blog.Creator.Id;
                post.PreviewImage   = file;
                post.PreviewImageId = file.Id;

                var postFile = new PostFile(post.Id, post, file.Id, file);

                this.posts.Add(post);
                this.files.Add(file);
                this.postFiles.Add(postFile);
            }

            for (var postIndex = 0; postIndex < FilesPerCollection; postIndex++)
            {
                var post = PostTests.UniqueFileOrImage(Random);
                post.Channel   = userChannels[postIndex % userChannels.Count];
                post.ChannelId = userChannels[postIndex % userChannels.Count].Id;
                post.Queue     = userQueues[postIndex % userQueues.Count];
                post.QueueId   = userQueues[postIndex % userQueues.Count].Id;

                var file = FileTests.UniqueEntity(Random);
                file.UserId = blog.Creator.Id;

                var postFile = new PostFile(post.Id, post, file.Id, file);

                this.posts.Add(post);
                this.files.Add(file);
                this.postFiles.Add(postFile);
            }

            this.comments.Add(new Comment(Guid.NewGuid(), this.posts.Last().Id, null, this.users.First().Id, null, "Test comment", DateTime.UtcNow));
            this.likes.Add(new Like(this.posts.Last().Id, null, this.users.First().Id, null, DateTime.UtcNow));
            this.freePosts.Add(new FreePost(this.users.First().Id, this.posts.Last().Id, null, DateTime.UtcNow));
        }
예제 #3
0
        public static Task CreateTestBlogAsync(this IFifthweekDbContext databaseContext, Guid newUserId, Guid newBlogId, Guid?headerImageFileId = null, Random random = null, string username = null, string blogName = null)
        {
            if (random == null)
            {
                random = new Random();
            }

            var creator = UserTests.UniqueEntity(random);

            creator.Id = newUserId;
            if (username != null)
            {
                creator.UserName = username;
            }

            var blog = UniqueEntity(random);

            blog.Id        = newBlogId;
            blog.Creator   = creator;
            blog.CreatorId = creator.Id;

            if (blogName != null)
            {
                blog.Name = blogName;
            }

            if (headerImageFileId.HasValue)
            {
                var file = FileTests.UniqueEntity(random);
                file.Id     = headerImageFileId.Value;
                file.UserId = creator.Id;

                blog.HeaderImageFile   = file;
                blog.HeaderImageFileId = file.Id;
            }

            databaseContext.Blogs.Add(blog);
            return(databaseContext.SaveChangesAsync());
        }