Esempio n. 1
0
            public void InvokeNullCandidate_NoException()
            {
                var specification = MockSpecification <FakeType> .True();

                var sut = new CastSpecification <object, FakeType>(specification);

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

                Assert.Null(exception);
            }
            public void CastCorrectSpecification_ReturnExpressionWithParameterFromSelector()
            {
                var specification = MockSpecification <object> .True();

                var sut = new CastSpecification <FakeType, object>(specification);

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

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

                var sut = new CastSpecification <FakeType, object>(specification);

                var expected   = sut.GetExpression();
                var expression = (Expression <Func <FakeType, bool> >)sut;

                Assert.Equal(expected, expression);
            }
Esempio n. 4
0
            public void InvokeCastToInterfaceType_ReturnTrue()
            {
                var candidate     = new FakeType();
                var specification = MockSpecification <IEnumerable <char> > .True();

                var sut = new CastSpecification <FakeType, IEnumerable <char> >(specification);

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

                Assert.True(result);
            }
Esempio n. 5
0
            public void InvokeCastToBaseType_ReturnTrue()
            {
                var candidate     = new ChildFakeType();
                var specification = MockSpecification <FakeType> .True();

                var sut = new CastSpecification <ChildFakeType, FakeType>(specification);

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

                Assert.True(result);
            }
Esempio n. 6
0
            public void InvokeCastFromObject_ReturnTrue()
            {
                var candidate     = 0;
                var specification = MockSpecification <object> .True();

                var sut = new CastSpecification <int, object>(specification);

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

                Assert.True(result);
            }
Esempio n. 7
0
            public void CorrectSpecification_ReturnExpressionWithParameterFromSelector()
            {
                var specification = MockSpecification <object> .True();

                var sut = new CastSpecification <FakeType, object>(specification);

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

                Assert.Matches(@"candidate => .*\.IsSatisfiedBy\(Convert\(candidate.*\)\)", result);
            }
Esempio n. 8
0
            public void InvokeInvalidTypeCandidate_CastException()
            {
                var specification = MockSpecification <List <int> > .True();

                var sut = new CastSpecification <IEnumerable <int>, List <int> >(specification);

                var exception = Record.Exception(() => sut.GetExpression().Compile().Invoke(new int[0]));

                Assert.NotNull(exception);
                Assert.IsType <InvalidCastException>(exception);
            }
Esempio n. 9
0
            public void CorrectSpecification_ReturnExpressionAsAbstractExpression()
            {
                var specification = MockSpecification <object> .True();

                var sut = new CastSpecification <FakeType, object>(specification);

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

                Assert.Equal(expected, result);
            }
Esempio n. 10
0
            public void InvokeCastNumeric_ReturnTrue()
            {
                var candidate     = 0.0;
                var specification = MockSpecification <int> .True();

                var sut = new CastSpecification <double, int>(specification);

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

                Assert.True(result);
            }