mirror of
https://github.com/Biarity/Sieve.git
synced 2024-11-21 21:12:50 +01:00
Add unit tests for filtering and sorting null members.
This commit is contained in:
parent
7a24bc8f27
commit
b8f92bccfc
@ -31,6 +31,7 @@ namespace SieveUnitTests
|
|||||||
LikeCount = 100,
|
LikeCount = 100,
|
||||||
IsDraft = true,
|
IsDraft = true,
|
||||||
CategoryId = null,
|
CategoryId = null,
|
||||||
|
TopComment = new Comment { Id = 0, Text = "A1" },
|
||||||
FeaturedComment = new Comment { Id = 4, Text = "A2" }
|
FeaturedComment = new Comment { Id = 4, Text = "A2" }
|
||||||
},
|
},
|
||||||
new Post() {
|
new Post() {
|
||||||
@ -56,7 +57,7 @@ namespace SieveUnitTests
|
|||||||
LikeCount = 3,
|
LikeCount = 3,
|
||||||
IsDraft = true,
|
IsDraft = true,
|
||||||
CategoryId = 2,
|
CategoryId = 2,
|
||||||
TopComment = new Comment { Id = 1 },
|
TopComment = new Comment { Id = 1, Text = "D1" },
|
||||||
FeaturedComment = new Comment { Id = 7, Text = "D2" }
|
FeaturedComment = new Comment { Id = 7, Text = "D2" }
|
||||||
},
|
},
|
||||||
}.AsQueryable();
|
}.AsQueryable();
|
||||||
@ -387,10 +388,11 @@ namespace SieveUnitTests
|
|||||||
};
|
};
|
||||||
|
|
||||||
var result = _processor.Apply(model, _posts);
|
var result = _processor.Apply(model, _posts);
|
||||||
Assert.AreEqual(2, result.Count());
|
Assert.AreEqual(3, result.Count());
|
||||||
var posts = result.ToList();
|
var posts = result.ToList();
|
||||||
Assert.IsTrue(posts[0].TopComment.Text.Contains("B"));
|
Assert.IsTrue(posts[0].TopComment.Text.Contains("B"));
|
||||||
Assert.IsTrue(posts[1].TopComment.Text.Contains("C"));
|
Assert.IsTrue(posts[1].TopComment.Text.Contains("C"));
|
||||||
|
Assert.IsTrue(posts[2].TopComment.Text.Contains("D"));
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
@ -429,5 +431,67 @@ namespace SieveUnitTests
|
|||||||
result = _processor.Apply(model, _posts);
|
result = _processor.Apply(model, _posts);
|
||||||
Assert.AreEqual(1, result.Count());
|
Assert.AreEqual(1, result.Count());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void FilteringNullsWorks()
|
||||||
|
{
|
||||||
|
var posts = new List<Post>
|
||||||
|
{
|
||||||
|
new Post() {
|
||||||
|
Id = 1,
|
||||||
|
Title = null,
|
||||||
|
LikeCount = 0,
|
||||||
|
IsDraft = false,
|
||||||
|
CategoryId = null,
|
||||||
|
TopComment = null,
|
||||||
|
FeaturedComment = null
|
||||||
|
},
|
||||||
|
}.AsQueryable();
|
||||||
|
|
||||||
|
var model = new SieveModel()
|
||||||
|
{
|
||||||
|
Filters = "FeaturedComment.Text!@=Some value",
|
||||||
|
};
|
||||||
|
|
||||||
|
var result = _processor.Apply(model, posts);
|
||||||
|
Assert.AreEqual(0, result.Count());
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void SortingNullsWorks()
|
||||||
|
{
|
||||||
|
var posts = new List<Post>
|
||||||
|
{
|
||||||
|
new Post() {
|
||||||
|
Id = 1,
|
||||||
|
Title = null,
|
||||||
|
LikeCount = 0,
|
||||||
|
IsDraft = false,
|
||||||
|
CategoryId = null,
|
||||||
|
TopComment = new Comment { Id = 1 },
|
||||||
|
FeaturedComment = null
|
||||||
|
},
|
||||||
|
new Post() {
|
||||||
|
Id = 2,
|
||||||
|
Title = null,
|
||||||
|
LikeCount = 0,
|
||||||
|
IsDraft = false,
|
||||||
|
CategoryId = null,
|
||||||
|
TopComment = null,
|
||||||
|
FeaturedComment = null
|
||||||
|
},
|
||||||
|
}.AsQueryable();
|
||||||
|
|
||||||
|
var model = new SieveModel()
|
||||||
|
{
|
||||||
|
Sorts = "TopComment.Id",
|
||||||
|
};
|
||||||
|
|
||||||
|
var result = _processor.Apply(model, posts);
|
||||||
|
Assert.AreEqual(2, result.Count());
|
||||||
|
var sortedPosts = result.ToList();
|
||||||
|
Assert.AreEqual(sortedPosts[0].Id, 2);
|
||||||
|
Assert.AreEqual(sortedPosts[1].Id, 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user