mirror of
https://github.com/Biarity/Sieve.git
synced 2024-11-22 13:32:33 +01:00
Tests for simple OR logic functionality (#8)
This commit is contained in:
parent
3e671f56ad
commit
c861ada8fa
@ -30,10 +30,10 @@ namespace Sieve.Models
|
|||||||
if (filter.StartsWith("("))
|
if (filter.StartsWith("("))
|
||||||
{
|
{
|
||||||
var filterOpAndVal = filter.Substring(filter.LastIndexOf(")") + 1);
|
var filterOpAndVal = filter.Substring(filter.LastIndexOf(")") + 1);
|
||||||
filter = filter.Replace(subfilterOpAndVal, "").Replace("(", "").Replace(")","");
|
var subfilters = filter.Replace(filterOpAndVal, "").Replace("(", "").Replace(")","");
|
||||||
foreach (var subfilter in filter.Split("|"))
|
foreach (var subfilter in subfilters.Split('|'))
|
||||||
{
|
{
|
||||||
value.Add(new FilterTerm(subfilter + filterOpAndVal))
|
value.Add(new FilterTerm(subfilter + filterOpAndVal));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -41,6 +41,12 @@ namespace SieveUnitTests
|
|||||||
Title = "C",
|
Title = "C",
|
||||||
LikeCount = 0
|
LikeCount = 0
|
||||||
},
|
},
|
||||||
|
new Post() {
|
||||||
|
Id = 3,
|
||||||
|
Title = "3",
|
||||||
|
LikeCount = 3,
|
||||||
|
IsDraft = true
|
||||||
|
},
|
||||||
}.AsQueryable();
|
}.AsQueryable();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,7 +135,7 @@ namespace SieveUnitTests
|
|||||||
var result = _processor.ApplyFiltering(model, _posts);
|
var result = _processor.ApplyFiltering(model, _posts);
|
||||||
|
|
||||||
Assert.IsFalse(result.Any(p => p.Id == 0));
|
Assert.IsFalse(result.Any(p => p.Id == 0));
|
||||||
Assert.IsTrue(result.Count() == 2);
|
Assert.IsTrue(result.Count() == 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
@ -153,6 +159,20 @@ namespace SieveUnitTests
|
|||||||
|
|
||||||
Assert.ThrowsException<SieveIncompatibleMethodException>(() => _processor.ApplyFiltering(model, _posts));
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user