public void simple_adhoc_equals_itself() { var specification = LinqSpec.For <string>(n => n.StartsWith("J")); Assert.True(specification.Equals(specification)); Assert.Equal(specification.GetHashCode(), specification.Expression.GetHashCode()); }
public void should_notequals_othertype() { var startWithJ = LinqSpec.For <string>(n => n.StartsWith("J")); var spec = !startWithJ; Assert.False(spec.Equals(startWithJ)); }
public void should_not_equal_null() { var startWithJ = LinqSpec.For <string>(n => n.StartsWith("J")); var endsWithE = LinqSpec.For <string>(n => n.EndsWith("e")); var spec = startWithJ || endsWithE; Assert.False(spec.Equals(null)); }
public void should_equals_itself() { var startWithJ = LinqSpec.For <string>(n => n.StartsWith("J")); var spec = !startWithJ; Assert.True(spec.Equals(spec)); Assert.Equal(spec.GetHashCode(), spec.GetHashCode()); }
public void should_not_equals_othertype() { var startWithJ = LinqSpec.For <string>(n => n.StartsWith("J")); var endsWithE = LinqSpec.For <string>(n => n.EndsWith("e")); var spec = startWithJ & endsWithE; Assert.False(spec.Equals(startWithJ | endsWithE)); }
public void equals_return_true_when_the_negated_spec_are_equals() { var startWithJ = LinqSpec.For <string>(n => n.StartsWith("J")); var spec = !startWithJ; spec.Should().Be.EqualTo(!startWithJ); }
public void should_equal_self() { var startWithJ = LinqSpec.For <string>(n => n.StartsWith("J")); var endsWithE = LinqSpec.For <string>(n => n.EndsWith("e")); var spec = startWithJ || endsWithE; Assert.True(spec.Equals(spec)); Assert.Equal(spec.GetHashCode(), spec.GetHashCode()); }
public static LinqSpec <CardTransaction> ForToday(Guid cardId, TimeZoneInfo timeZone) { var now = DateTime.UtcNow; var localTime = TimeZoneInfo.ConvertTimeFromUtc(now, timeZone); var startOfDay = localTime.Date; var endOfDay = localTime.Date.AddDays(1); return(LinqSpec.For <CardTransaction>(x => x.Card.Id == cardId && x.CreatedDateUtc >= startOfDay && x.CreatedDateUtc < endOfDay)); }
public void equals_return_false_when_both_sides_are_not_equals() { var startWithJ = LinqSpec.For <string>(n => n.StartsWith("J")); var endsWithE = LinqSpec.For <string>(n => n.EndsWith("e")); var endsWithF = LinqSpec.For <string>(n => n.EndsWith("f")); var spec = startWithJ & endsWithE; spec.Should().Not.Be.EqualTo(startWithJ & endsWithF); }
public void equals_return_false_when_the_negated_spec_are_not_equals() { var startWithJ = LinqSpec.For <string>(n => n.StartsWith("J")); var anotherAdHocSpec = LinqSpec.For <string>(n => n.StartsWith("dasdas")); var spec = !startWithJ; spec.Should().Not.Be.EqualTo(!anotherAdHocSpec); }
public LinqSpec <HistoricalTransaction> OriginalKey(params object[] keys) { Argument.NotNull(keys, "keys"); Argument.Satisfies(keys, x => x.Length == 1, "keys"); Argument.Satisfies(keys[0], x => x is Guid); var key = (Guid)keys[0]; return(LinqSpec.For <HistoricalTransaction>(x => x.Id == key)); }
public static DbQuery <UserBriefModel> ToDbQuery(this UsersQuery query) { var spec = LinqSpec.For <UserBriefModel>(x => true); if (query.Roles != null && query.Roles.Length > 0) { spec = spec && Specs.HasAtLeastOneRoleFrom(query.Roles); } return(DbQuery.PagedFor <UserBriefModel>().FromClientQuery(query).AndFilterBy(spec)); }
public void negate_operator_should_work() { var startWithJ = LinqSpec.For <string>(n => n.StartsWith("J")); var result = new SampleRepository() .Retrieve(!startWithJ); result.Satisfy(r => !r.Contains("Jose") && !r.Contains("Julian") && r.Contains("Manuel")); }
public void simple_adhoc_should_work() { var specification = LinqSpec.For <string>(n => n.StartsWith("J")); var result = new SampleRepository() .Retrieve(specification); result.Satisfy(r => r.Contains("Jose") && r.Contains("Julian") && !r.Contains("Manuel")); }
public void equals_return_true_when_both_sides_are_equals() { var startWithJ = LinqSpec.For <string>(n => n.StartsWith("J")); var endsWithE = LinqSpec.For <string>(n => n.EndsWith("e")); var spec = startWithJ & endsWithE; spec.Should().Be.EqualTo(startWithJ & endsWithE); spec.Should("andalso is not conmutable") .Not.Be.EqualTo(endsWithE & startWithJ); }
public void or_should_work() { var startWithJ = LinqSpec.For <string>(n => n.StartsWith("J")); var endsWithN = LinqSpec.For <string>(n => n.EndsWith("n")); var result = new SampleRepository() .Retrieve(startWithJ | endsWithN); result.Satisfy(r => Enumerable.Contains(r, "Jose") && Enumerable.Contains(r, "Julian") && !Enumerable.Contains(r, "Manuel")); }
public void CombineIntSpec() { var intGreaterThan4Spec = LinqSpec.For <int>(i => i > 4); var stringLongerThan4CharsSpec = LinqSpec.OnProperty <string, int>(s => s.Length, intGreaterThan4Spec); var result = new SampleRepository() .Retrieve(stringLongerThan4CharsSpec); result.Satisfy(r => !r.Contains("Jose") && r.Contains("Julian") && r.Contains("Manuel")); }
public void and_should_work() { var startWithJ = LinqSpec.For <string>(n => n.StartsWith("J")); var endsWithE = LinqSpec.For <string>(n => n.EndsWith("e")); var specfication = startWithJ && endsWithE; IEnumerable <string> result = new SampleRepository() .Retrieve(specfication); result.Satisfy(r => r.Contains("Jose") && !r.Contains("Julian") && !r.Contains("Manuel")); }
public void query_sample() { var startWithM = new StartsWithQuery("M"); var endsWithN = LinqSpec.For <string>(n => n.EndsWith("n")); IEnumerable <string> result = new SampleRepository() .Retrieve(startWithM | !endsWithN); result.Satisfy(r => Enumerable.Contains(r, "Jose") && !Enumerable.Contains(r, "Julian") && Enumerable.Contains(r, "Manuel")); }
public void and_operator_should_work() { var startWithJ = LinqSpec.For <string>(n => n.StartsWith("J")); var endsWithE = LinqSpec.For <string>(n => n.EndsWith("e")); // & or && both operators behave as &&. IEnumerable <string> result = new SampleRepository() .Retrieve(startWithJ & endsWithE); result.Satisfy(r => r.Contains("Jose") && !r.Contains("Julian") && !r.Contains("Manuel")); }
public static LinqSpec <UserBriefModel> HasAtLeastOneRoleFrom(IEnumerable <string> roleNames) { return(LinqSpec.For <UserBriefModel>(x => x.Claims.Any(y => y.Type == ClaimTypes.Role && roleNames.Contains(y.Value)))); }
public static LinqSpec <UserCard> ByCardNumberAndExpiration(string cardNumber, DateTime expirationDateUtc) { return(Active && LinqSpec.For <UserCard>(x => x.CardNo == cardNumber && x.ExpirationDateUtc.Month == expirationDateUtc.Month && x.ExpirationDateUtc.Year == expirationDateUtc.Year)); }
public static LinqSpec <UserBriefModel> InRole(string roleName) { return(LinqSpec.For <UserBriefModel>(x => x.Claims.Any(y => y.Type == ClaimTypes.Role && y.Value == roleName))); }
public void should_not_equals_null() { var specification = LinqSpec.For <string>(n => n.StartsWith("J")); Assert.False(specification.Equals(null)); }
public void should_not_equals_othertype() { var specification = LinqSpec.For <string>(n => n.StartsWith("J")); Assert.False(specification.Equals(specification | LinqSpec.For <string>(n => true))); }