mirror of
				https://github.com/Biarity/Sieve.git
				synced 2025-11-04 02:39:00 +01:00 
			
		
		
		
	Unit tests for #51
This commit is contained in:
		@@ -30,5 +30,7 @@ namespace SieveUnitTests.Entities
 | 
				
			|||||||
        public string ThisHasNoAttributeButIsAccessible { get; set; }
 | 
					        public string ThisHasNoAttributeButIsAccessible { get; set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public int OnlySortableViaFluentApi { get; set; }
 | 
					        public int OnlySortableViaFluentApi { get; set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public Comment TopComment { get; set; }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -19,7 +19,7 @@ namespace SieveUnitTests
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        public General()
 | 
					        public General()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            _processor = new SieveProcessor(new SieveOptionsAccessor(),
 | 
					            _processor = new ApplicationSieveProcessor(new SieveOptionsAccessor(),
 | 
				
			||||||
                new SieveCustomSortMethods(),
 | 
					                new SieveCustomSortMethods(),
 | 
				
			||||||
                new SieveCustomFilterMethods());
 | 
					                new SieveCustomFilterMethods());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -31,6 +31,7 @@ namespace SieveUnitTests
 | 
				
			|||||||
                    LikeCount = 100,
 | 
					                    LikeCount = 100,
 | 
				
			||||||
                    IsDraft = true,
 | 
					                    IsDraft = true,
 | 
				
			||||||
                    CategoryId = null,
 | 
					                    CategoryId = null,
 | 
				
			||||||
 | 
					                    TopComment = new Comment { Id = 0, Text = "A" }
 | 
				
			||||||
                },
 | 
					                },
 | 
				
			||||||
                new Post() {
 | 
					                new Post() {
 | 
				
			||||||
                    Id = 1,
 | 
					                    Id = 1,
 | 
				
			||||||
@@ -38,12 +39,14 @@ namespace SieveUnitTests
 | 
				
			|||||||
                    LikeCount = 50,
 | 
					                    LikeCount = 50,
 | 
				
			||||||
                    IsDraft = false,
 | 
					                    IsDraft = false,
 | 
				
			||||||
                    CategoryId = 1,
 | 
					                    CategoryId = 1,
 | 
				
			||||||
 | 
					                    TopComment = new Comment { Id = 3, Text = "A" }
 | 
				
			||||||
                },
 | 
					                },
 | 
				
			||||||
                new Post() {
 | 
					                new Post() {
 | 
				
			||||||
                    Id = 2,
 | 
					                    Id = 2,
 | 
				
			||||||
                    Title = "C",
 | 
					                    Title = "C",
 | 
				
			||||||
                    LikeCount = 0,
 | 
					                    LikeCount = 0,
 | 
				
			||||||
                    CategoryId = 1,
 | 
					                    CategoryId = 1,
 | 
				
			||||||
 | 
					                    TopComment = new Comment { Id = 2, Text = "Z" }
 | 
				
			||||||
                },
 | 
					                },
 | 
				
			||||||
                new Post() {
 | 
					                new Post() {
 | 
				
			||||||
                    Id = 3,
 | 
					                    Id = 3,
 | 
				
			||||||
@@ -51,6 +54,7 @@ namespace SieveUnitTests
 | 
				
			|||||||
                    LikeCount = 3,
 | 
					                    LikeCount = 3,
 | 
				
			||||||
                    IsDraft = true,
 | 
					                    IsDraft = true,
 | 
				
			||||||
                    CategoryId = 2,
 | 
					                    CategoryId = 2,
 | 
				
			||||||
 | 
					                    TopComment = new Comment { Id = 1, Text = "Z" }
 | 
				
			||||||
                },
 | 
					                },
 | 
				
			||||||
            }.AsQueryable();
 | 
					            }.AsQueryable();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -329,5 +333,37 @@ namespace SieveUnitTests
 | 
				
			|||||||
            Assert.AreEqual(1, result.Count());
 | 
					            Assert.AreEqual(1, result.Count());
 | 
				
			||||||
            Assert.AreEqual(2, result.FirstOrDefault().Id);
 | 
					            Assert.AreEqual(2, result.FirstOrDefault().Id);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        [TestMethod]
 | 
				
			||||||
 | 
					        public void NestedFilteringWorks()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            var model = new SieveModel()
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                Filters = "TopComment.Text!@=A",
 | 
				
			||||||
 | 
					            };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            var result = _processor.Apply(model, _posts);
 | 
				
			||||||
 | 
					            Assert.AreEqual(2, result.Count());
 | 
				
			||||||
 | 
					            var posts = result.ToList();
 | 
				
			||||||
 | 
					            Assert.IsTrue(posts[0].TopComment.Text.Contains("Z"));
 | 
				
			||||||
 | 
					            Assert.IsTrue(posts[1].TopComment.Text.Contains("Z"));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        [TestMethod]
 | 
				
			||||||
 | 
					        public void NestedSortingWorks()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            var model = new SieveModel()
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                Sorts = "TopComment.Id",
 | 
				
			||||||
 | 
					            };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            var result = _processor.Apply(model, _posts);
 | 
				
			||||||
 | 
					            Assert.AreEqual(4, result.Count());
 | 
				
			||||||
 | 
					            var posts = result.ToList();
 | 
				
			||||||
 | 
					            Assert.AreEqual(posts[0].Id, 0);
 | 
				
			||||||
 | 
					            Assert.AreEqual(posts[1].Id, 3);
 | 
				
			||||||
 | 
					            Assert.AreEqual(posts[2].Id, 2);
 | 
				
			||||||
 | 
					            Assert.AreEqual(posts[3].Id, 1);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -22,6 +22,12 @@ namespace SieveUnitTests.Services
 | 
				
			|||||||
                .CanFilter()
 | 
					                .CanFilter()
 | 
				
			||||||
                .HasName("shortname");
 | 
					                .HasName("shortname");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            mapper.Property<Post>(p => p.TopComment.Text)
 | 
				
			||||||
 | 
					                .CanFilter();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            mapper.Property<Post>(p => p.TopComment.Id)
 | 
				
			||||||
 | 
					                .CanSort();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            mapper.Property<Post>(p => p.OnlySortableViaFluentApi)
 | 
					            mapper.Property<Post>(p => p.OnlySortableViaFluentApi)
 | 
				
			||||||
                .CanSort();
 | 
					                .CanSort();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user