Exemple #1
0
        public async Task ApplyWhereClause_FilterByGenderRestriction_ReturnsCorrectPredicate()
        {
            const Gender filteredGenderRestriction = Gender.Female;
            var          mockManager       = new QueryMockManager();
            var          expectedPredicate = new CompositePredicate(
                new List <IPredicate>
            {
                new CompositePredicate(
                    new List <IPredicate>
                {
                    new SimplePredicate(nameof(Post.GenderRestriction), ValueComparingOperator.Equal, filteredGenderRestriction),
                    new SimplePredicate(nameof(Post.GenderRestriction), ValueComparingOperator.Equal, Gender.NoInformation)
                }, LogicalOperator.OR)
            }, 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 {
                GenderRestriction = filteredGenderRestriction
            };
            var temp = await postQueryObject.ExecuteQuery(filter);

            Assert.AreEqual(expectedPredicate, mockManager.CapturedPredicate);
        }
Exemple #2
0
        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);
        }
Exemple #3
0
        public async Task ApplyWhereClause_SimpleFilterByGender_ReturnsCorrectPredicate()
        {
            const Gender filteredGender    = Gender.Male;
            var          mockManager       = new QueryMockManager();
            var          expectedPredicate = new CompositePredicate(
                new List <IPredicate>
            {
                new SimplePredicate(nameof(User.Gender), ValueComparingOperator.Equal, filteredGender)
            }, LogicalOperator.AND);
            var mapperMock      = mockManager.ConfigureMapperMock <User, UserDto, UserFilterDto>();
            var queryMock       = mockManager.ConfigureQueryMock <User>();
            var userQueryObject = new UserQueryObject(mapperMock.Object, queryMock.Object);

            var filter = new UserFilterDto {
                Gender = filteredGender
            };
            var temp = await userQueryObject.ExecuteQuery(filter);

            Assert.AreEqual(expectedPredicate, mockManager.CapturedPredicate);
        }