protected override async Task <(IQueryable <TEntity> DataQueryable, long Total)> DoPageFindAsync(int pageIndex, int pageSize, ISpecification <TEntity> specification, params OrderExpression[] orderExpressions) { if (pageIndex < 0) { throw new ArgumentException("InvalidPageIndex"); } if (pageSize <= 0) { throw new ArgumentException("InvalidPageCount"); } if (orderExpressions == null || orderExpressions.Length == 0) { throw new ArgumentNullException($"OrderByExpressionCannotBeNull"); } if (specification == null) { specification = new AllSpecification <TEntity>(); } var query = DoFindAll(specification, orderExpressions); return(query.GetPageElements(pageIndex, pageSize), await query.CountAsync()); }
public void Test_All_Normal() { AllSpecification s = new AllSpecification(new PredicateSpecification <int>(delegate(int i) { return(i > 0); })); Assert.IsFalse(s.Test(new int[] { 0, 1, 2 }).Success); Assert.IsTrue(s.Test(new int[] { 1, 2, 3 }).Success); }
public void Test_All_InvalidType() { // cannot test a non-enumerable object AllSpecification s = new AllSpecification(AlwaysTrue); s.Test(new object()); }
protected override IQueryable <TEntity> DoPageFind(int pageIndex, int pageSize, ISpecification <TEntity> specification, params OrderExpression[] orderExpressions) { //checking arguments for this query if (pageIndex < 0) { throw new ArgumentException("InvalidPageIndex"); } if (pageSize <= 0) { throw new ArgumentException("InvalidPageCount"); } if (orderExpressions == null || orderExpressions.Length == 0) { throw new ArgumentNullException("OrderByExpressionCannotBeNull"); } if (specification == null) { specification = new AllSpecification <TEntity>(); } var query = DoFindAll(specification, orderExpressions); return(query.GetPageElements(pageIndex, pageSize)); }
public void Test_All_Empty() { AllSpecification s1 = new AllSpecification(AlwaysFalse); Assert.IsTrue(s1.Test(new object[0]).Success); AllSpecification s2 = new AllSpecification(AlwaysTrue); Assert.IsTrue(s2.Test(new object[0]).Success); }
public void NullCollectionLinqToEntities_NoException() { var specification = MockComplexSpecification <int> .True(); var sut = new AllSpecification <int[], int>(specification, true); var exception = Record.Exception(() => sut.IsSatisfiedBy(null)); Assert.Null(exception); }
public void AllElementsValid_ReturnTrue <T, TType>(T candidate, Expression <Func <TType, bool> > expression) where T : IEnumerable <TType> { var specification = new MockComplexSpecification <TType>(expression); var sut = new AllSpecification <T, TType>(specification); var result = sut.IsSatisfiedBy(candidate); Assert.True(result); }
public void InvokeNullCollectionLinqToEntities_Exception() { var specification = MockComplexSpecification <int> .True(); var sut = new AllSpecification <int[], int>(specification, true); var exception = Record.Exception(() => sut.GetExpression().Compile().Invoke(null)); Assert.NotNull(exception); Assert.IsType <ArgumentNullException>(exception); }
public void InvokeCompositeAll_ReturnAllSpecification() { var specification = MockComplexSpecification <int> .True(); var expected = new AllSpecification <FakeType, int>(specification, true); var sut = new MockCompositeSpecification <FakeType>().All(specification); Assert.Equal(expected, sut, new SpecificationComparer()); }
public void NotAllElementsValid_ReturnFalse <T, TType>(T candidate, Expression <Func <TType, bool> > expression) where T : IEnumerable <TType> { candidate = candidate?.ToString() != "null" ? candidate : default; var specification = new MockComplexSpecification <TType>(expression); var sut = new AllSpecification <T, TType>(specification); var result = sut.IsSatisfiedBy(candidate); Assert.False(result); }
public void CorrectComplexSpecification_ReturnExpressionForAll() { ISpecification <string> specification = MockComplexSpecification <string> .True(); var sut = new AllSpecification <string[], string>(specification); var sutExpression = sut.GetExpression(); var result = sutExpression.ToString(); Assert.Equal(@"candidate => ((candidate != null) AndAlso candidate.All(candidate => True))", result); }
public void RelatedTypes_NoException() { var specification = MockComplexSpecification <IEnumerable <int> > .True(); var exception = Record.Exception(() => { var sut = new AllSpecification <IEnumerable <EquatableFakeType>, EquatableFakeType>(specification); sut.IsSatisfiedBy(new EquatableFakeType[0]); }); Assert.Null(exception); }
public void CastCorrectSpecification_ReturnExpressionWithParameterFromSelector() { ISpecification <string> specification = MockComplexSpecification <string> .True(); var sut = new AllSpecification <string[], string>(specification); var expected = sut.GetExpression().ToString(); var sutExpression = (Expression)sut; var result = sutExpression.ToString(); Assert.Equal(expected, result); }
public void CastCorrectSpecification_ReturnIsSatisfiedByFunction() { ISpecification <string> specification = MockComplexSpecification <string> .True(); var sut = new AllSpecification <string[], string>(specification); Func <string[], bool> expected = sut.IsSatisfiedBy; var result = (Func <string[], bool>)sut; Assert.NotNull(result); Assert.Equal(expected, result); }
public void AllElementsValid_ReturnExpectedResultObject <T, TType>(T candidate, Expression <Func <TType, bool> > expression, SpecificationResult expected) where T : IEnumerable <TType> { var specification = new MockComplexSpecification <TType>(expression); var sut = new AllSpecification <T, TType>(specification); var overall = sut.IsSatisfiedBy(candidate, out var result); Assert.True(overall); Assert.Equal(expected, result, new SpecificationResultComparer()); }
public void NonGenericILinqSpecification_ReturnBaseExpressionAsAbstractExpression() { ISpecification <string> specification = MockComplexSpecification <string> .True(); var sut = new AllSpecification <string[], string>(specification); var expected = sut.GetExpression().ToString(); var sutExpression = ((ILinqSpecification)sut).GetExpression(); var result = sutExpression.ToString(); Assert.Equal(expected, result); }
public void InvokeRelatedTypes_NoException() { var specification = MockComplexSpecification <IEnumerable <int> > .True(); var exception = Record.Exception(() => { var sut = new AllSpecification <IEnumerable <EquatableFakeType>, EquatableFakeType>(specification); sut.GetExpression().Compile().Invoke(new EquatableFakeType[0]); }); Assert.Null(exception); }
public void NotAllElementsValid_ReturnExpectedResultObject <T, TType>(T candidate, Expression <Func <TType, bool> > expression, SpecificationResult expected) where T : IEnumerable <TType> { candidate = candidate?.ToString() != "null" ? candidate : default; var specification = new MockComplexSpecification <TType>(expression); var sut = new AllSpecification <T, TType>(specification); var overall = sut.IsSatisfiedBy(candidate, out var result); Assert.False(overall); Assert.Equal(expected, result, new SpecificationResultComparer(candidate, new Dictionary <string, object> { { "SpecificationForAll", specification }, { "Expression", expression } })); }
public void IsSatisfiedBy_should_always_return_true() { var spec = new AllSpecification<CIServer>(); spec.IsSatisfiedBy(null).ShouldBeTrue(); }
public void SetUp() { fixture = new Fixture(); specificationUnderTest = new AllSpecification <TestCandidate>(); }
public void Test_All_Normal() { AllSpecification s = new AllSpecification(new PredicateSpecification<int>(delegate(int i) { return i > 0; })); Assert.IsFalse(s.Test(new int[] { 0, 1, 2 }).Success); Assert.IsTrue(s.Test(new int[] { 1, 2, 3 }).Success); }
public Task <IEnumerable <T> > ListAll() { var allSpecification = new AllSpecification <T>(); return(ListBySpecification(allSpecification)); }
public void AllNot() { var sut = new AllSpecification( new[] { true, true, false }.Select( x => new SuppliedSpecification( x ) ).ToArray() ); Assert.False( sut.IsSatisfiedBy( Defaults.Parameter ) ); }