public void InvokeTrueSpecification_ReturnTrue <T>(FakeType candidate,
                                                               Expression <Func <FakeType, T> > selector)
            {
                var specification = MockSpecification <T> .True();

                var sut = new PropertySpecification <FakeType, T>(selector, specification);

                var result = sut.GetExpression().Compile().Invoke(candidate);

                Assert.True(result);
            }
            public void InvokeNullSubPropertyValue_RaiseException()
            {
                Expression <Func <FakeType, bool> > selector = ft => ft.Inter.Third;
                var specification = MockSpecification <bool> .True();

                var sut = new PropertySpecification <FakeType, bool>(selector, specification);

                var exception = Record.Exception(() => sut.GetExpression().Compile().Invoke(new FakeType()));

                Assert.NotNull(exception);
                Assert.IsType <NullReferenceException>(exception);
            }
            public void InvokeNullCandidate_RaiseException()
            {
                Expression <Func <FakeType, string> > selector = ft => ft.Second;
                var specification = MockSpecification <string> .True();

                var sut = new PropertySpecification <FakeType, string>(selector, specification);

                var exception = Record.Exception(() => sut.GetExpression().Compile().Invoke(null));

                Assert.NotNull(exception);
                Assert.IsType <NullReferenceException>(exception);
            }
            public void CorrectSpecification_ReturnExpressionWithParameterFromSelector()
            {
                Expression <Func <FakeType, string> > selector = ft => ft.Second;
                var specification = MockSpecification <string> .True();

                var sut = new PropertySpecification <FakeType, string>(selector, specification);

                var sutExpression = sut.GetExpression();
                var result        = sutExpression.ToString();

                Assert.Matches(@"ft => .*\.IsSatisfiedBy\(ft.Second\)", result);
            }
            public void CorrectSpecification_ReturnExpressionAsAbstractExpression()
            {
                Expression <Func <FakeType, string> > selector = ft => ft.Second;
                var specification = MockSpecification <string> .True();

                var sut = new PropertySpecification <FakeType, string>(selector, specification);

                var expected = sut.GetExpression();
                var result   = ((ILinqSpecification)sut).GetExpression();

                Assert.Equal(expected, result);
            }
            public void InvokeFalseSpecification_ReturnFalse <T>(FakeType candidate,
                                                                 Expression <Func <FakeType, T> > selector)
            {
                candidate = candidate.Second != "null" ? candidate : null;
                var specification = MockSpecification <T> .False();

                var sut = new PropertySpecification <FakeType, T>(selector, specification);

                var result = sut.GetExpression().Compile().Invoke(candidate);

                Assert.False(result);
            }
            public void CastCorrectSpecification_ReturnExpressionWithParameterFromSelector()
            {
                Expression <Func <FakeType, string> > selector = ft => ft.Second;
                var specification = MockSpecification <string> .True();

                var sut = new PropertySpecification <FakeType, string>(selector, specification);

                var expected = sut.GetExpression();
                var result   = (Expression)sut;

                Assert.Equal(expected, result);
            }
            public void RelatedTypes_NoException()
            {
                var specification = MockSpecification <IEnumerable <char> > .True();

                var exception = Record.Exception(() =>
                {
                    var sut = new PropertySpecification <FakeType, string>(
                        ft => ft.Second, specification);
                    sut.GetExpression().Compile().Invoke(new FakeType());
                });

                Assert.Null(exception);
            }