public void Initialize()
        {
            DapperTypeHandlerRegistration.Register(FifthweekAssembliesResolver.Assemblies);

            this.connectionFactory = new Mock <IFifthweekDbConnectionFactory>(MockBehavior.Strict);

            this.target = new GetCreatorBacklogDbStatement(this.connectionFactory.Object);
        }
        public async Task ItShouldReturnPostsForUser()
        {
            await this.DatabaseTestAsync(async testDatabase =>
            {
                this.target = new GetCreatorBacklogDbStatement(testDatabase);
                await this.CreateEntitiesAsync(testDatabase, createLivePosts: true, createFuturePosts: true);
                await testDatabase.TakeSnapshotAsync();

                var result = await this.target.ExecuteAsync(UserId, Now);

                CollectionAssert.AreEquivalent(SortedBacklogPosts.ToList(), result.ToList());

                return(ExpectedSideEffects.None);
            });
        }
        public async Task ItShouldReturnNothingWhenUserHasNoPostsWithLiveDateInFuture()
        {
            await this.DatabaseTestAsync(async testDatabase =>
            {
                this.target = new GetCreatorBacklogDbStatement(testDatabase);
                await this.CreateEntitiesAsync(testDatabase, createLivePosts: true, createFuturePosts: false);
                await testDatabase.TakeSnapshotAsync();

                var result = await this.target.ExecuteAsync(UserId, Now);

                Assert.AreEqual(result.Count, 0);

                return(ExpectedSideEffects.None);
            });
        }
        public async Task ItShouldReturnPostsWithLiveDateInFuture()
        {
            await this.DatabaseTestAsync(async testDatabase =>
            {
                this.target = new GetCreatorBacklogDbStatement(testDatabase);
                await this.CreateEntitiesAsync(testDatabase, createLivePosts: true, createFuturePosts: true);
                await testDatabase.TakeSnapshotAsync();

                var result = await this.target.ExecuteAsync(UserId, Now);

                foreach (var backlogPost in result)
                {
                    Assert.IsTrue(backlogPost.LiveDate > Now);
                }

                return(ExpectedSideEffects.None);
            });
        }
        public async Task ItShouldReturnPostsWithLiveDatesAsUtc()
        {
            await this.DatabaseTestAsync(async testDatabase =>
            {
                this.target = new GetCreatorBacklogDbStatement(testDatabase);
                await this.CreateEntitiesAsync(testDatabase, createLivePosts: true, createFuturePosts: true);
                await testDatabase.TakeSnapshotAsync();

                var result = await this.target.ExecuteAsync(UserId, Now);

                foreach (var item in result)
                {
                    Assert.AreEqual(DateTimeKind.Utc, item.LiveDate.Kind);
                }

                return(ExpectedSideEffects.None);
            });
        }
        public async Task ItShouldOrderPostsByLiveDateDescending_ThenByCreationDate()
        {
            await this.DatabaseTestAsync(async testDatabase =>
            {
                this.target = new GetCreatorBacklogDbStatement(testDatabase);
                await this.CreateEntitiesAsync(testDatabase, createLivePosts: true, createFuturePosts: true);
                await testDatabase.TakeSnapshotAsync();

                var result = await this.target.ExecuteAsync(UserId, Now);

                Func <BacklogPost, BacklogPost> removeSortInsensitiveValues = post => post.Copy(_ =>
                {
                    // Required fields. Set to a value that is equal across all elements.
                    _.PostId    = new PostId(Guid.Empty);
                    _.ChannelId = new ChannelId(Guid.Empty);

                    // Non required fields.
                    _.PreviewText       = null;
                    _.PreviewWordCount  = 0;
                    _.WordCount         = 0;
                    _.ImageCount        = 0;
                    _.FileCount         = 0;
                    _.VideoCount        = 0;
                    _.ImageId           = null;
                    _.ImageName         = null;
                    _.ImageExtension    = null;
                    _.ImageSize         = null;
                    _.ImageRenderWidth  = null;
                    _.ImageRenderHeight = null;
                    _.QueueId           = null;
                });

                var expectedOrder = SortedBacklogPosts.Select(removeSortInsensitiveValues).ToList();
                var actualOrder   = result.Select(removeSortInsensitiveValues).ToList();

                CollectionAssert.AreEqual(expectedOrder, actualOrder);

                return(ExpectedSideEffects.None);
            });
        }