mirror of
				https://github.com/Biarity/Sieve.git
				synced 2025-11-03 18:29:02 +01:00 
			
		
		
		
	Unit tests for #51
This commit is contained in:
		@@ -30,5 +30,7 @@ namespace SieveUnitTests.Entities
 | 
			
		||||
        public string ThisHasNoAttributeButIsAccessible { get; set; }
 | 
			
		||||
 | 
			
		||||
        public int OnlySortableViaFluentApi { get; set; }
 | 
			
		||||
 | 
			
		||||
        public Comment TopComment { get; set; }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -19,7 +19,7 @@ namespace SieveUnitTests
 | 
			
		||||
 | 
			
		||||
        public General()
 | 
			
		||||
        {
 | 
			
		||||
            _processor = new SieveProcessor(new SieveOptionsAccessor(),
 | 
			
		||||
            _processor = new ApplicationSieveProcessor(new SieveOptionsAccessor(),
 | 
			
		||||
                new SieveCustomSortMethods(),
 | 
			
		||||
                new SieveCustomFilterMethods());
 | 
			
		||||
 | 
			
		||||
@@ -31,6 +31,7 @@ namespace SieveUnitTests
 | 
			
		||||
                    LikeCount = 100,
 | 
			
		||||
                    IsDraft = true,
 | 
			
		||||
                    CategoryId = null,
 | 
			
		||||
                    TopComment = new Comment { Id = 0, Text = "A" }
 | 
			
		||||
                },
 | 
			
		||||
                new Post() {
 | 
			
		||||
                    Id = 1,
 | 
			
		||||
@@ -38,12 +39,14 @@ namespace SieveUnitTests
 | 
			
		||||
                    LikeCount = 50,
 | 
			
		||||
                    IsDraft = false,
 | 
			
		||||
                    CategoryId = 1,
 | 
			
		||||
                    TopComment = new Comment { Id = 3, Text = "A" }
 | 
			
		||||
                },
 | 
			
		||||
                new Post() {
 | 
			
		||||
                    Id = 2,
 | 
			
		||||
                    Title = "C",
 | 
			
		||||
                    LikeCount = 0,
 | 
			
		||||
                    CategoryId = 1,
 | 
			
		||||
                    TopComment = new Comment { Id = 2, Text = "Z" }
 | 
			
		||||
                },
 | 
			
		||||
                new Post() {
 | 
			
		||||
                    Id = 3,
 | 
			
		||||
@@ -51,6 +54,7 @@ namespace SieveUnitTests
 | 
			
		||||
                    LikeCount = 3,
 | 
			
		||||
                    IsDraft = true,
 | 
			
		||||
                    CategoryId = 2,
 | 
			
		||||
                    TopComment = new Comment { Id = 1, Text = "Z" }
 | 
			
		||||
                },
 | 
			
		||||
            }.AsQueryable();
 | 
			
		||||
 | 
			
		||||
@@ -329,5 +333,37 @@ namespace SieveUnitTests
 | 
			
		||||
            Assert.AreEqual(1, result.Count());
 | 
			
		||||
            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()
 | 
			
		||||
                .HasName("shortname");
 | 
			
		||||
 | 
			
		||||
            mapper.Property<Post>(p => p.TopComment.Text)
 | 
			
		||||
                .CanFilter();
 | 
			
		||||
 | 
			
		||||
            mapper.Property<Post>(p => p.TopComment.Id)
 | 
			
		||||
                .CanSort();
 | 
			
		||||
 | 
			
		||||
            mapper.Property<Post>(p => p.OnlySortableViaFluentApi)
 | 
			
		||||
                .CanSort();
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user