public async Task ApplyWhereClause_ComplexFilterByAllParameters_ReturnsCorrectPredicate() { const int filteredUserAge = 30; Gender filteredGenderRestriction = Gender.Female; PostVisibility filteredPostVisibility = PostVisibility.FriendsOnly; Guid filteredUserId = Guid.NewGuid(); var mockManager = new QueryMockManager(); var agePredicates = new List <IPredicate> { new SimplePredicate(nameof(Post.HasAgeRestriction), ValueComparingOperator.Equal, false) }; var innerAgePredicates = new List <IPredicate> { new SimplePredicate(nameof(Post.AgeRestrictionTo), ValueComparingOperator.LessThanOrEqual, filteredUserAge), new SimplePredicate(nameof(Post.AgeRestrictionFrom), ValueComparingOperator.GreaterThanOrEqual, filteredUserAge) }; agePredicates.Add(new CompositePredicate(innerAgePredicates, LogicalOperator.AND)); var genderPredicate = new CompositePredicate( new List <IPredicate> { new SimplePredicate(nameof(Post.GenderRestriction), ValueComparingOperator.Equal, filteredGenderRestriction), new SimplePredicate(nameof(Post.GenderRestriction), ValueComparingOperator.Equal, Gender.NoInformation) }, LogicalOperator.OR); var userIdPredicate = new SimplePredicate(nameof(Post.UserId), ValueComparingOperator.Equal, filteredUserId); var visibilityPredicate = new SimplePredicate(nameof(Post.Visibility), ValueComparingOperator.Equal, filteredPostVisibility); var expectedPredicate = new CompositePredicate( new List <IPredicate> { new CompositePredicate(agePredicates, LogicalOperator.OR), genderPredicate, userIdPredicate, visibilityPredicate }, LogicalOperator.AND); var mapperMock = mockManager.ConfigureMapperMock <Post, PostDto, PostFilterDto>(); var queryMock = mockManager.ConfigureQueryMock <Post>(); var postQueryObject = new PostQueryObject(mapperMock.Object, queryMock.Object); var filter = new PostFilterDto { UserAge = filteredUserAge, GenderRestriction = filteredGenderRestriction, UserId = filteredUserId }; var temp = await postQueryObject.ExecuteQuery(filter); Assert.AreEqual(expectedPredicate, mockManager.CapturedPredicate); }
public async Task ApplyWhereClause_FilterByVisibility_ReturnsCorrectPredicate() { const PostVisibility filteredVisibility = PostVisibility.FriendsOnly; var mockManager = new QueryMockManager(); var expectedPredicate = new CompositePredicate( new List <IPredicate> { new SimplePredicate(nameof(Post.Visibility), ValueComparingOperator.Equal, filteredVisibility) }, LogicalOperator.AND); var mapperMock = mockManager.ConfigureMapperMock <Post, PostDto, PostFilterDto>(); var queryMock = mockManager.ConfigureQueryMock <Post>(); var postQueryObject = new PostQueryObject(mapperMock.Object, queryMock.Object); var filter = new PostFilterDto { }; var temp = await postQueryObject.ExecuteQuery(filter); Assert.AreEqual(expectedPredicate, mockManager.CapturedPredicate); }