示例#1
0
        private void DoRegularTest(TestAgent test, TestUnit testUnit, Object container, Object testedObject, Int32 iterationIndex)
        {
            var timeMonitor = new Stopwatch();
            var memoryMonitor = new MemoryMonitor();

            Object[] invokeParameters = null;
            if (test.TestedType != null)
            {
                invokeParameters = new Object[1] { testedObject };
            }

            memoryMonitor.Prepare();
            memoryMonitor.Start();
            timeMonitor.Start();
            var result = testUnit.TestMethod.Invoke(container, invokeParameters);
            timeMonitor.Stop();
            memoryMonitor.Stop();

            //skip results of first call storing
            if (iterationIndex != -1)
            {
                bool isValid = true;
                if (testUnit.ValidatorMethod != null)
                {
                    invokeParameters = new Object[1] { result };
                    isValid = (bool)testUnit.ValidatorMethod.Invoke(container, invokeParameters);
                }

                var runResult = new PassResult(timeMonitor.Elapsed, memoryMonitor.Usage, test.Metrics, isValid);
                _resultHandler.AddResult(runResult, testUnit.Id, iterationIndex);

                _progressHandler.PortionDone();
            }
        }
示例#2
0
        public void CompleteFilling()
        {
            if (_testMethods == null)
            {
                _warningHandler.NoTestMethodsWereFoundWarning(ContainerType, Id);
                return;
            }

            TestUnits = new List<TestUnit>();

            bool isNamelessValidatorApplied = false;
            foreach (var testMethodAttribute in _testMethods)
            {
                var testMethod = testMethodAttribute.Item1;
                var testAttribute = testMethodAttribute.Item2;
                MethodInfo validator = null;
                if (_validatorMethods != null)
                {
                    validator = _validatorMethods[testMethod.Name];
                    if (validator != null)
                    {
                        _validatorMethods.Remove(testMethod.Name);
                    }
                    else
                    {
                        validator = _validatorMethods[String.Empty];
                        isNamelessValidatorApplied = validator != null;
                    }
                }

                //check matching of test return and validator parameter types
                if (validator != null)
                {
                    var validatorParameterType = validator.GetParameters().First().ParameterType;
                    var testReturnType = testMethod.ReturnType;
                    if (!validatorParameterType.IsAssignableFrom(testReturnType))
                    {
                        _warningHandler.ValidatorParameterTypeMismatchWarning(testMethod, validator);
                        validator = null;
                    }
                }

                if (testAttribute.Validate && validator == null)
                {
                    _warningHandler.NoValidatorWasFoundWarning(testMethodAttribute);
                }
                else if (!testAttribute.Validate && validator != null)
                {
                    _warningHandler.ExcessValidatorWasFoundWarning(testMethodAttribute, validator);

                }

                var testUnit = new TestUnit(testMethod, testAttribute, validator);
                TestUnits.Add(testUnit);
            }

            if (_validatorMethods != null)
            {
                if (isNamelessValidatorApplied && _validatorMethods.Count > 1)
                {
                    _validatorMethods.Remove(String.Empty);
                }
                foreach (var excessValidator in _validatorMethods.Values)
                {
                    _warningHandler.ExcessValidatorWasFoundWarning(null, excessValidator);
                }
            }

            IsValid = true;
        }
示例#3
0
文件: Program.cs 项目: Coderik/NGauge
        private static PassResult DoJITTest(TestAgent agent, TestUnit testUnit, Object container, Object testedObject, Int32 iterationIndex)
        {
            var timeMonitor = new Stopwatch();
            var memoryMonitor = new MemoryMonitor();

            Object[] invokeParameters = null;
            if (agent.TestedType != null)
            {
                invokeParameters = new Object[1] { testedObject };
            }

            //todo: Create delegates to call instead of Invoking
            //Test test = (Test)Delegate.CreateDelegate(typeof(Test), container, testUnit.TestMethod);
            Object result = null;

            Assembly.Load("System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");

            memoryMonitor.Prepare();
            memoryMonitor.Start();
            timeMonitor.Start();
            result = testUnit.TestMethod.Invoke(container, invokeParameters);
            //test();
            timeMonitor.Stop();
            memoryMonitor.Stop();

            bool isValid = true;
            if (testUnit.ValidatorMethod != null)
            {
                invokeParameters = new Object[1] { result };
                isValid = (bool)testUnit.ValidatorMethod.Invoke(container, invokeParameters);
            }

            var runResult = new PassResult(timeMonitor.Elapsed, memoryMonitor.Usage, agent.Metrics, isValid);
            return runResult;
        }