Example #1
0
        public static BlogEntitiesResult UniqueEntityWithForeignEntities(
            Guid newUserId,
            Guid newChannelId,
            Guid newQueueId,
            Guid newBlogId = default(Guid))
        {
            var random  = new Random();
            var creator = UserTests.UniqueEntity(random);

            creator.Id = newUserId;

            var blog = UniqueEntity(random);

            if (newBlogId != default(Guid))
            {
                blog.Id = newBlogId;
            }

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

            var channel = ChannelTests.UniqueEntity(random);

            channel.Id     = newChannelId;
            channel.Blog   = blog;
            channel.BlogId = blog.Id;

            var queue = QueueTests.UniqueEntity(random);

            queue.Id     = newQueueId;
            queue.Blog   = blog;
            queue.BlogId = blog.Id;

            return(new BlogEntitiesResult(creator, blog, channel, queue));
        }
        public static async Task <IReadOnlyList <Channel> > CreateTestChannelsAsync(
            this IFifthweekDbContext databaseContext,
            Guid newUserId,
            Guid newBlogId,
            params Guid[] newChannelIds)
        {
            var creator = UserTests.UniqueEntity(Random);

            creator.Id = newUserId;

            var blog = BlogTests.UniqueEntity(Random);

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

            var channels = new List <Channel>();

            foreach (var newChannelId in newChannelIds)
            {
                var channel = ChannelTests.UniqueEntity(Random);
                channel.Id     = newChannelId;
                channel.Blog   = blog;
                channel.BlogId = blog.Id;
                databaseContext.Channels.Add(channel);
                channels.Add(channel);
            }

            await databaseContext.SaveChangesAsync();

            return(channels);
        }
Example #3
0
        public static Task CreateTestNoteAsync(this IFifthweekDbContext databaseContext, Guid newUserId, Guid newPostId, Random random = null)
        {
            if (random == null)
            {
                random = new Random();
            }

            var creator = UserTests.UniqueEntity(random);

            creator.Id = newUserId;

            var subscription = BlogTests.UniqueEntity(random);

            subscription.Creator   = creator;
            subscription.CreatorId = creator.Id;

            var channel = ChannelTests.UniqueEntity(random);

            channel.Blog   = subscription;
            channel.BlogId = subscription.Id;

            var post = UniqueNote(random);

            post.Id        = newPostId;
            post.Channel   = channel;
            post.ChannelId = channel.Id;

            databaseContext.Posts.Add(post);
            return(databaseContext.SaveChangesAsync());
        }
        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()));
        }
Example #5
0
        public static async Task <FifthweekUser> CreateTestUserAsync(this IFifthweekDbContext databaseContext, Guid newUserId, Random random = null)
        {
            random = random ?? new Random();
            var creator = UserTests.UniqueEntity(random);

            creator.Id = newUserId;

            databaseContext.Users.Add(creator);
            await databaseContext.SaveChangesAsync();

            return(creator);
        }
Example #6
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());
        }