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);
        }
Beispiel #2
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());
        }
        public static async Task <Channel> CreateTestChannelAsync(
            this IFifthweekDbContext databaseContext,
            Guid newUserId,
            Guid newBlogId,
            Guid newChannelId)
        {
            var result = await CreateTestChannelsAsync(databaseContext, newUserId, newBlogId, newChannelId);

            return(result.First());
        }
        public void GetLatestFromDatabase(IFifthweekDbContext databaseContext)
        {
            var set = this.setFactory(databaseContext);

            var database  = set.ToList();
            var prototype = database.FirstOrDefault();

            Assert.IsTrue(prototype == null || prototype is IIdentityEquatable, "Entities must implement IIdentityEquatable");

            this.Database = database.OfType <IIdentityEquatable>().ToList();
        }
        public void InitializeSnapshot(IFifthweekDbContext databaseContext)
        {
            var set = this.setFactory(databaseContext);

            var snapshot  = set.ToList();
            var prototype = snapshot.FirstOrDefault();

            Assert.IsTrue(prototype == null || prototype is IIdentityEquatable, "Entities must implement IIdentityEquatable");

            this.Snapshot = snapshot.OfType <IIdentityEquatable>().ToList();
        }
Beispiel #6
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);
        }
Beispiel #7
0
        public static async Task <File> CreateTestFileWithExistingUserAsync(this IFifthweekDbContext databaseContext, Guid existingUserId, Guid newFileId)
        {
            var random = new Random();

            var file = UniqueEntity(random);

            file.Id     = newFileId;
            file.UserId = existingUserId;

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

            return(file);
        }
Beispiel #8
0
        public static async Task <BlogEntitiesResult> CreateTestEntitiesAsync(
            this IFifthweekDbContext databaseContext,
            Guid newUserId,
            Guid newChannelId,
            Guid newCollectionId,
            Guid newBlogId = default(Guid))
        {
            var entites = UniqueEntityWithForeignEntities(newUserId, newChannelId, newCollectionId, newBlogId);

            databaseContext.Channels.Add(entites.Channel);
            databaseContext.Queues.Add(entites.Queue);
            await databaseContext.SaveChangesAsync();

            return(entites);
        }
Beispiel #9
0
        public static Task CreateTestChannelSubscriptionWithExistingReferences(this IFifthweekDbContext databaseContext, Guid existingUserId, Guid existingChannelId, DateTime?subscriptionStartDate = null, int?acceptedPrice = null)
        {
            var random = new Random();

            var item = UniqueEntity(random);

            item.ChannelId = existingChannelId;
            item.UserId    = existingUserId;

            if (subscriptionStartDate != null)
            {
                item.SubscriptionStartDate = subscriptionStartDate.Value;
            }

            if (acceptedPrice != null)
            {
                item.AcceptedPrice = acceptedPrice.Value;
            }

            return(databaseContext.Database.Connection.InsertAsync(item));
        }
Beispiel #10
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());
        }
 public static Task CreateTestChannelAsync(this IFifthweekDbContext databaseContext, Guid newUserId, Guid newChannelId)
 {
     return(CreateTestChannelsAsync(databaseContext, newUserId, Guid.NewGuid(), newChannelId));
 }