Tests for simple OR logic functionality (#8)

This commit is contained in:
Biarity 2018-04-20 18:46:04 +10:00
parent 3e671f56ad
commit c861ada8fa
2 changed files with 24 additions and 4 deletions

View File

@ -30,10 +30,10 @@ namespace Sieve.Models
if (filter.StartsWith("("))
{
var filterOpAndVal = filter.Substring(filter.LastIndexOf(")") + 1);
filter = filter.Replace(subfilterOpAndVal, "").Replace("(", "").Replace(")","");
foreach (var subfilter in filter.Split("|"))
var subfilters = filter.Replace(filterOpAndVal, "").Replace("(", "").Replace(")","");
foreach (var subfilter in subfilters.Split('|'))
{
value.Add(new FilterTerm(subfilter + filterOpAndVal))
value.Add(new FilterTerm(subfilter + filterOpAndVal));
}
}
else

View File

@ -41,6 +41,12 @@ namespace SieveUnitTests
Title = "C",
LikeCount = 0
},
new Post() {
Id = 3,
Title = "3",
LikeCount = 3,
IsDraft = true
},
}.AsQueryable();
}
@ -129,7 +135,7 @@ namespace SieveUnitTests
var result = _processor.ApplyFiltering(model, _posts);
Assert.IsFalse(result.Any(p => p.Id == 0));
Assert.IsTrue(result.Count() == 2);
Assert.IsTrue(result.Count() == 3);
}
[TestMethod]
@ -153,6 +159,20 @@ namespace SieveUnitTests
Assert.ThrowsException<SieveIncompatibleMethodException>(() => _processor.ApplyFiltering(model, _posts));
}
[TestMethod]
public void OrFilteringWorks()
{
var model = new SieveModel()
{
Filters = "(Title|LikeCount)==3",
};
var result = _processor.ApplyFiltering(model, _posts);
Assert.AreEqual(result.First().Id, 3);
Assert.IsTrue(result.Count() == 1);
}
}
}