public void Invoke_member_with_incompatible_argument_should_throw_exception()
        {
            var mockScope = ArrangeMockScope();
            var invoker   = new FixtureMemberInvoker <bool>(null, mockScope, "Add");

            Assert.Throws <PatternUsageErrorException>(() => invoker.Invoke(1, new object(), 3));
        }
        public void Invoke_member_with_invalid_number_of_arguments_should_throw_exception()
        {
            var mockScope = ArrangeMockScope();
            var invoker   = new FixtureMemberInvoker <bool>(null, mockScope, "Add");

            Assert.Throws <PatternUsageErrorException>(() => invoker.Invoke(1, 2));
        }
        public void Invoke_member_not_found_should_throw_exception()
        {
            var mockScope = ArrangeMockScope();
            var invoker   = new FixtureMemberInvoker <bool>(null, mockScope, "DoesNotExist");

            Assert.Throws <PatternUsageErrorException>(() => invoker.Invoke());
        }
Beispiel #4
0
        /// <inheritdoc />
        protected override void PopulateDataSource(IPatternScope scope, DataSource dataSource, ICodeElementInfo codeElement)
        {
            var invoker = new FixtureMemberInvoker <IEnumerable>(type, scope, memberName);
            var dataSet = new FactoryDataSet(() => invoker.Invoke(), kind, columnCount);

            dataSource.AddDataSet(dataSet);
        }
        public void Invoke_member_with_argument(int input, bool expectedResult)
        {
            var  mockScope    = ArrangeMockScope();
            var  invoker      = new FixtureMemberInvoker <bool>(null, mockScope, "IsOdd");
            bool actualResult = invoker.Invoke(input);

            Assert.AreEqual(expectedResult, actualResult);
        }
        public void Invoke_argument_less_member <T>(string memberName, Type source, T expectedValue)
        {
            var mockScope   = ArrangeMockScope();
            var invoker     = new FixtureMemberInvoker <T>(source, mockScope, memberName);
            T   actualValue = invoker.Invoke();

            Assert.AreEqual <T>(expectedValue, actualValue);
        }
 /// <inheritdoc />
 protected override void PopulateDataSource(IPatternScope scope, DataSource dataSource, ICodeElementInfo codeElement)
 {
     var invoker = new FixtureMemberInvoker<IEnumerable>(factoryType, scope, factoryMethodName);
     XDocument xdocument = OpenXDocument(codeElement);
     var parameters = new object[] { GetElementList(xdocument, xPath) };
     var dataSet = new FactoryDataSet(() => invoker.Invoke(parameters), kind, columnCount);
     dataSource.AddDataSet(dataSet);
 }
        /// <inheritdoc />
        protected override void PopulateDataSource(IPatternScope scope, DataSource dataSource, ICodeElementInfo codeElement)
        {
            var       invoker    = new FixtureMemberInvoker <IEnumerable>(factoryType, scope, factoryMethodName);
            XDocument xdocument  = OpenXDocument(codeElement);
            var       parameters = new object[] { GetElementList(xdocument, xPath) };
            var       dataSet    = new FactoryDataSet(() => invoker.Invoke(parameters), kind, columnCount);

            dataSource.AddDataSet(dataSet);
        }
        /// <summary>
        /// Generates static or dynamic tests from the contract.
        /// </summary>
        /// <param name="fieldScope">The field scope.</param>
        /// <param name="field">The field.</param>
        /// <param name="containingScope">The containing scope.</param>
        protected virtual void GenerateTestsFromContract(IPatternScope fieldScope, IFieldInfo field, IPatternScope containingScope)
        {
            if (field.IsStatic)
            {
                FieldInfo resolvedField = field.Resolve(false);
                if (resolvedField == null)
                {
                    fieldScope.TestModelBuilder.AddAnnotation(new Annotation(AnnotationType.Info, field,
                                                                             "This test runner does not fully support static contract verifier methods "
                                                                             + "because the code that defines the contract cannot be executed "
                                                                             + "at test exploration time.  Consider making the contract field non-static instead."));
                    return;
                }

                var contract = resolvedField.GetValue(null) as IContract;
                if (contract == null)
                {
                    fieldScope.TestModelBuilder.AddAnnotation(new Annotation(AnnotationType.Error, field,
                                                                             "Expected the contract field to contain a value that is assignable "
                                                                             + "to type IContract."));
                    return;
                }

                IEnumerable <Test> contractTests = GetContractVerificationTests(contract, field);
                Test.BuildStaticTests(contractTests, fieldScope, field);
            }
            else
            {
                fieldScope.TestBuilder.TestInstanceActions.ExecuteTestInstanceChain.After(state =>
                {
                    var invoker = new FixtureMemberInvoker <IContract>(null, containingScope, field.Name);
                    IContract contract;

                    try
                    {
                        contract = invoker.Invoke(FixtureMemberInvokerTargets.Field);
                    }
                    catch (PatternUsageErrorException exception)
                    {
                        throw new TestFailedException(
                            String.Format(
                                "The field '{0}' must contain an instance of type IContract that describes a contract to be verified.",
                                field.Name), exception);
                    }

                    IEnumerable <Test> contractTests = GetContractVerificationTests(contract, field);

                    TestOutcome outcome = Test.RunDynamicTests(contractTests, field, null, null);
                    if (outcome != TestOutcome.Passed)
                    {
                        throw new SilentTestException(outcome);
                    }
                });
            }
        }
        private Predicate <decimal> MakeFilterInvoker(IPatternScope scope)
        {
            if (Filter == null)
            {
                return(null);
            }

            var invoker = new FixtureMemberInvoker <bool>(null, scope, Filter);

            return(d => invoker.Invoke(d));
        }
        /// <inheritdoc />
        protected override void PopulateDataSource(IPatternScope scope, DataSource dataSource, ICodeElementInfo codeElement)
        {
            var invoker = new FixtureMemberInvoker <IEnumerable>(factoryType, scope, factoryMethodName);
            // Get List-of-Lists of Eleemnts
            var listOfListsOfElements = BuildListOfNodeLists(codeElement);

            // Use Gallio's invoker object to execute factory method
            var parameters = new object[] { listOfListsOfElements };
            var dataSet    = new FactoryDataSet(() => invoker.Invoke(parameters), kind, columnCount);

            dataSource.AddDataSet(dataSet);
        }
        /// <inheritdoc />
        protected override void PopulateDataSource(IPatternScope scope, DataSource dataSource, ICodeElementInfo codeElement)
        {
            // Create the invoker object which Gallio will call by reflection
            var invoker = new FixtureMemberInvoker<IEnumerable>(factoryType, scope, factoryMethodName);

            // Get an ADO DataTable from the implementation.
            DataTable dataTable = BuildDataTable();
            
            // Create the array of arguments which will be passed to the method called by the invoker
            var parameters = new object[] {dataTable, 
                this.RowIndexIncludeFilterArray, this.RowIndexExcludeFilterArray,
                this.CellValueIncludeFilterArray, this.CellValueExcludeFilterArray};

            // Create a FactoryDataSet with an invoker of our factory methods in the delegate 
            var dataSet = new FactoryDataSet(() => invoker.Invoke(parameters), FactoryKind.Auto, 0);
            dataSource.AddDataSet(dataSet);
        }
Beispiel #13
0
        /// <inheritdoc />
        protected override void PopulateDataSource(IPatternScope scope, DataSource dataSource, ICodeElementInfo codeElement)
        {
            // Create the invoker object which Gallio will call by reflection
            var invoker = new FixtureMemberInvoker <IEnumerable>(factoryType, scope, factoryMethodName);

            // Get an ADO DataTable from the implementation.
            DataTable dataTable = BuildDataTable();

            // Create the array of arguments which will be passed to the method called by the invoker
            var parameters = new object[] { dataTable,
                                            this.RowIndexIncludeFilterArray, this.RowIndexExcludeFilterArray,
                                            this.CellValueIncludeFilterArray, this.CellValueExcludeFilterArray };

            // Create a FactoryDataSet with an invoker of our factory methods in the delegate
            var dataSet = new FactoryDataSet(() => invoker.Invoke(parameters), FactoryKind.Auto, 0);

            dataSource.AddDataSet(dataSet);
        }
        /// <inheritdoc />
        protected override void PopulateDataSource(IPatternScope scope, DataSource dataSource, ICodeElementInfo codeElement)
        {
            var invoker = new FixtureMemberInvoker<IEnumerable>(factoryType, scope, factoryMethodName);
            // Get List-of-Lists of Eleemnts
            var listOfListsOfElements = BuildListOfNodeLists(codeElement);

            // Use Gallio's invoker object to execute factory method
            var parameters = new object[] { listOfListsOfElements };
            var dataSet = new FactoryDataSet(() => invoker.Invoke(parameters), kind, columnCount);
            dataSource.AddDataSet(dataSet);
        }
        /// <summary>
        /// Generates static or dynamic tests from the contract.
        /// </summary>
        /// <param name="fieldScope">The field scope.</param>
        /// <param name="field">The field.</param>
        /// <param name="containingScope">The containing scope.</param>
        protected virtual void GenerateTestsFromContract(IPatternScope fieldScope, IFieldInfo field, IPatternScope containingScope)
        {
            if (field.IsStatic)
            {
                FieldInfo resolvedField = field.Resolve(false);
                if (resolvedField == null)
                {
                    fieldScope.TestModelBuilder.AddAnnotation(new Annotation(AnnotationType.Info, field,
                        "This test runner does not fully support static contract verifier methods "
                        + "because the code that defines the contract cannot be executed "
                        + "at test exploration time.  Consider making the contract field non-static instead."));
                    return;
                }

                var contract = resolvedField.GetValue(null) as IContract;
                if (contract == null)
                {
                    fieldScope.TestModelBuilder.AddAnnotation(new Annotation(AnnotationType.Error, field,
                        "Expected the contract field to contain a value that is assignable "
                        + "to type IContract."));
                    return;
                }

                IEnumerable<Test> contractTests = GetContractVerificationTests(contract, field);
                Test.BuildStaticTests(contractTests, fieldScope, field);
            }
            else
            {
                fieldScope.TestBuilder.TestInstanceActions.ExecuteTestInstanceChain.After(state =>
                {
                    var invoker = new FixtureMemberInvoker<IContract>(null, containingScope, field.Name);
                    IContract contract;

                    try
                    {
                        contract = invoker.Invoke(FixtureMemberInvokerTargets.Field);
                    }
                    catch (PatternUsageErrorException exception)
                    {
                        throw new TestFailedException(
                            String.Format(
                                "The field '{0}' must contain an instance of type IContract that describes a contract to be verified.",
                                field.Name), exception);
                    }

                    IEnumerable<Test> contractTests = GetContractVerificationTests(contract, field);

                    TestOutcome outcome = Test.RunDynamicTests(contractTests, field, null, null);
                    if (outcome != TestOutcome.Passed)
                        throw new SilentTestException(outcome);
                });
            }
        }
        private Predicate<decimal> MakeFilterInvoker(IPatternScope scope)
        {
            if (Filter == null)
                return null;

            var invoker = new FixtureMemberInvoker<bool>(null, scope, Filter);
            return d => invoker.Invoke(d);
        }
 /// <inheritdoc />
 protected override void PopulateDataSource(IPatternScope scope, DataSource dataSource, ICodeElementInfo codeElement)
 {
     var invoker = new FixtureMemberInvoker<IEnumerable>(type, scope, memberName);
     var dataSet = new FactoryDataSet(() => invoker.Invoke(), kind, columnCount);
     dataSource.AddDataSet(dataSet);
 }