Example #1
0
        static ITestResultMethod runMethodTest(
            ITestResultFactory resultFactory,
            IDrawingBackend drawingBackend,
            TestMethod testMethod,
            Action<IDrawingTarget> action)
        {
            var attribute = testMethod.Attribute;

            var width = attribute.Width;
            var height = attribute.Height;

            using (var target = drawingBackend.CreateBitmapDrawingSurface(width, height))
            {
                ITestResultReport testReport;
                using (var drawingTarget = target.BeginDraw())
                {
                    action(drawingTarget);
                    testReport = resultFactory.Report(drawingTarget.Reports);
                }

                var bitmap = resultFactory.Bitmap(width, height, target.ExtractRawBitmap());

                return resultFactory.Method(testMethod.Info.Name, bitmap, testReport);
            }
        }
Example #2
0
 static ITestResultMethod runGeometryTargetTest(
     ITestResultFactory resultFactory,
     IDrawingBackend drawingBackend,
     object instance,
     TestMethod testMethod)
 {
     using (var geometry = drawingBackend.Geometry(target => testMethod.invoke(instance, target, drawingBackend)))
     {
         return runMethodTest(resultFactory, drawingBackend, testMethod, dt =>
             {
                 dt.Fill(color: new Color(0.7, 0.7, 1.0));
                 dt.Geometry(geometry);
             });
     }
 }
Example #3
0
        static ITestResultMethod runMethodTest(
            ITestResultFactory resultFactory,
            IDrawingBackend drawingBackend,
            object instance,
            TestMethod testMethod)
        {
            var firstParameterType = testMethod.FirstParamterType;
            if (firstParameterType.IsAssignableFrom(typeof(IDrawingTarget)))
            {
                return runDrawingTargetTest(resultFactory, drawingBackend, instance, testMethod);
            }

            if (firstParameterType.IsAssignableFrom(typeof(IGeometryTarget)))
            {
                return runGeometryTargetTest(resultFactory, drawingBackend, instance, testMethod);
            }

            throw new Exception("Unable to decide what test to run based on first parameter type {0}\nShould be either IDrawingTarget or IGeometryTarget".format(firstParameterType));
        }
Example #4
0
 static ITestResultMethod runDrawingTargetTest(
     ITestResultFactory resultFactory,
     IDrawingBackend drawingBackend,
     object instance,
     TestMethod testMethod)
 {
     return runMethodTest(resultFactory, drawingBackend, testMethod, drawingTarget => testMethod.invoke(instance, drawingTarget, drawingBackend));
 }