public void Initialize() { DapperTypeHandlerRegistration.Register(FifthweekAssembliesResolver.Assemblies); this.connectionFactory = new Mock <IFifthweekDbConnectionFactory>(MockBehavior.Strict); this.target = new GetNewsfeedDbStatement(this.connectionFactory.Object); }
public async Task ItShouldReturnNothingWhenUserHasNoPostsWithLiveDateInPastOrNow() { await this.DatabaseTestAsync(async testDatabase => { this.target = new GetNewsfeedDbStatement(testDatabase); await this.CreateEntitiesAsync(testDatabase, createLivePosts: false, createFuturePosts: true); await testDatabase.TakeSnapshotAsync(); await this.ParameterizedTestAsync(async(userId, creatorId, channelIds, collectionIds, origin, searchForwards, startIndex, count, expectedPosts, expectedAccountBalance) => { var result = await this.target.ExecuteAsync(userId, creatorId, channelIds, Now, origin, searchForwards, startIndex, count); Assert.AreEqual(result.Posts.Count, 0); }); return(ExpectedSideEffects.None); }); }
public async Task ItShouldReturnPostsForUser() { await this.DatabaseTestAsync(async testDatabase => { this.target = new GetNewsfeedDbStatement(testDatabase); await this.CreateEntitiesAsync(testDatabase, createLivePosts: true, createFuturePosts: true); await testDatabase.TakeSnapshotAsync(); await this.ParameterizedTestAsync(async(userId, creatorId, channelIds, collectionIds, origin, searchForwards, startIndex, count, expectedPosts, expectedAccountBalance) => { var result = await this.target.ExecuteAsync(userId, creatorId, channelIds, Now, origin, searchForwards, startIndex, count); CollectionAssert.AreEquivalent(expectedPosts.ToList(), result.Posts.ToList()); }); return(ExpectedSideEffects.None); }); }
public async Task ItShouldOrderPostsCorrectly() { await this.DatabaseTestAsync(async testDatabase => { this.target = new GetNewsfeedDbStatement(testDatabase); await this.CreateEntitiesAsync(testDatabase, createLivePosts: true, createFuturePosts: true); await testDatabase.TakeSnapshotAsync(); await this.ParameterizedTestAsync(async(userId, creatorId, channelIds, collectionIds, origin, searchForwards, startIndex, count, expectedPosts, expectedAccountBalance) => { var result = await this.target.ExecuteAsync(userId, creatorId, channelIds, Now, origin, searchForwards, startIndex, count); Func <NewsfeedPost, NewsfeedPost> 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); _.CreatorId = new UserId(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; }); var expectedOrder = expectedPosts.Select(removeSortInsensitiveValues).ToList(); var actualOrder = result.Posts.Select(removeSortInsensitiveValues).ToList(); CollectionAssert.AreEqual(expectedOrder, actualOrder); }); return(ExpectedSideEffects.None); }); }
public async Task ItShouldReturnPostsWithDatesAsUtc() { await this.DatabaseTestAsync(async testDatabase => { this.target = new GetNewsfeedDbStatement(testDatabase); await this.CreateEntitiesAsync(testDatabase, createLivePosts: true, createFuturePosts: true); await testDatabase.TakeSnapshotAsync(); await this.ParameterizedTestAsync(async(userId, creatorId, channelIds, collectionIds, origin, searchForwards, startIndex, count, expectedPosts, expectedAccountBalance) => { var result = await this.target.ExecuteAsync(userId, creatorId, channelIds, Now, origin, searchForwards, startIndex, count); foreach (var item in result.Posts) { Assert.AreEqual(DateTimeKind.Utc, item.LiveDate.Kind); Assert.AreEqual(DateTimeKind.Utc, item.CreationDate.Kind); } }); return(ExpectedSideEffects.None); }); }