示例#1
0
        internal TestInstance CreateInstance(TestContext ctx, TestPath path, TestInstance parent)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }

            var instance = CreateInstance(path, parent);

            instance.Initialize(ctx);
            return(instance);
        }
示例#2
0
        internal TestInstance CreateInstance(TestContext ctx, TestNode node, TestInstance parent)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            var instance = CreateInstance(node, parent);

            instance.Initialize(ctx);
            return(instance);
        }
        bool MoveNext(TestContext ctx, TestInstance instance)
        {
            ctx.LogDebug(10, "MoveNext({0}): {1} {2}", ctx.Name, TestLogger.Print(Host), TestLogger.Print(instance));

            try {
                return(((ParameterizedTestInstance)instance).MoveNext(ctx));
            } catch (OperationCanceledException) {
                ctx.OnTestCanceled();
                return(false);
            } catch (Exception ex) {
                ctx.OnError(ex);
                return(false);
            }
        }
示例#4
0
        bool SetUp(TestContext ctx, TestInstance instance)
        {
            ctx.LogDebug(10, "SetUp({0}): {1} {2}", ctx.FriendlyName, TestLogger.Print(Builder), TestLogger.Print(instance));

            try {
                ResolveChildren(ctx);
                return(true);
            } catch (OperationCanceledException) {
                ctx.OnTestCanceled();
                return(false);
            } catch (Exception ex) {
                ctx.OnError(ex);
                return(false);
            }
        }
示例#5
0
        protected TestInstance(TestHost host, TestPath path, TestInstance parent)
        {
            if (host == null)
            {
                throw new ArgumentNullException("host");
            }
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }

            Host   = host;
            Parent = parent;
            Path   = path;
        }
        public override async Task <bool> Invoke(
            TestContext ctx, TestInstance instance, CancellationToken cancellationToken)
        {
            var parameterizedInstance = SetUp(ctx, instance);

            if (parameterizedInstance == null)
            {
                return(false);
            }

            bool found   = false;
            bool success = true;

            while (success && parameterizedInstance.HasNext())
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    break;
                }

                success = MoveNext(ctx, parameterizedInstance);
                if (!success)
                {
                    break;
                }

                var path = parameterizedInstance.GetCurrentPath();

                found = true;

                var innerCtx = ctx.CreateChild(path, ctx.Result);

                ctx.LogDebug(10, "InnerInvoke({0}): {1} {2} {3}", path.FullName,
                             TestLogger.Print(Host), TestLogger.Print(parameterizedInstance), Inner);

                success = await InvokeInner(innerCtx, parameterizedInstance, Inner, cancellationToken);

                ctx.LogDebug(10, "InnerInvoke({0}) done: {1} {2} {3}", path.FullName,
                             TestLogger.Print(Host), TestLogger.Print(parameterizedInstance), success);
            }

            if (success && !found)
            {
                ctx.OnTestIgnored();
            }

            return(success);
        }
        ParameterizedTestInstance SetUp(TestContext ctx, TestInstance instance)
        {
            ctx.LogDebug(10, "SetUp({0}): {1} {2}", ctx.Name, TestLogger.Print(Host), TestLogger.Print(instance));

            try {
                var parameterizedInstance = CreateInstance(instance);
                parameterizedInstance.Initialize(ctx);
                return(parameterizedInstance);
            } catch (OperationCanceledException) {
                ctx.OnTestCanceled();
                return(null);
            } catch (Exception ex) {
                ctx.OnError(ex);
                return(null);
            }
        }
        public override async Task <bool> Invoke(
            TestContext ctx, TestInstance instance, CancellationToken cancellationToken)
        {
            if (!await PreRun(ctx, instance, cancellationToken))
            {
                return(false);
            }

            var success = await InvokeInner(ctx, instance, Inner, cancellationToken);

            if (!await PostRun(ctx, instance, cancellationToken))
            {
                success = false;
            }

            return(success);
        }
示例#9
0
        protected FixtureTestInstance GetFixtureInstance()
        {
            TestInstance instance = this;

            while (instance != null)
            {
                var fixtureInstance = instance as FixtureTestInstance;
                if (fixtureInstance != null)
                {
                    return(fixtureInstance);
                }

                instance = instance.Parent;
            }

            throw new InternalErrorException();
        }
示例#10
0
        public sealed override async Task <bool> Invoke(
            TestContext ctx, TestInstance instance, CancellationToken cancellationToken)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                return(false);
            }

            if (!SetUp(ctx, instance))
            {
                return(false);
            }

            ctx.LogDebug(10, "Invoke({0}): {1} {2} {3}", ctx.FriendlyName,
                         Flags, TestLogger.Print(instance), children.Count);

            bool success = true;

            foreach (var child in children)
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    break;
                }

                ctx.LogDebug(10, "InnerInvoke({0}): {1} {2}", ctx.FriendlyName,
                             TestLogger.Print(instance), child);

                var invoker = child.Item2;

                success = await InvokeInner(ctx, instance, invoker, cancellationToken);

                ctx.LogDebug(10, "InnerInvoke({0}) done: {1} {2}", ctx.FriendlyName,
                             TestLogger.Print(instance), success);

                if (!success)
                {
                    break;
                }
            }

            ctx.LogDebug(10, "Invoke({0}) done: {1} {2} - {3}", ctx.FriendlyName,
                         Flags, TestLogger.Print(instance), success);

            return(success);
        }
示例#11
0
        protected TestInstance(TestHost host, TestNode node, TestInstance parent)
        {
            if (host == null)
            {
                throw new ArgumentNullException("host");
            }
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            Host   = host;
            Node   = node;
            Parent = parent;

            ParentPath = Parent?.GetCurrentPath();
            Path       = new TestPath(ParentPath, Node);
        }
示例#12
0
        protected async Task <bool> InvokeInner(
            TestContext ctx, TestInstance instance, TestInvoker invoker,
            CancellationToken cancellationToken)
        {
            ctx.LogDebug(10, "Running({0}): {1}", ctx.Name, invoker);

            try {
                cancellationToken.ThrowIfCancellationRequested();
                var success = await invoker.Invoke(ctx, instance, cancellationToken);

                return(success || ContinueOnError);
            } catch (OperationCanceledException) {
                ctx.OnTestFinished(TestStatus.Canceled);
                return(false);
            } catch (Exception ex) {
                ctx.OnError(ex);
                return(false);
            }
        }
示例#13
0
        async Task <HeavyTestInstance> SetUp(
            TestContext ctx, TestInstance instance, CancellationToken cancellationToken)
        {
            ctx.LogDebug(10, "SetUp({0}): {1} {2}", ctx.FriendlyName, TestLogger.Print(Host), TestLogger.Print(instance));

            try {
                cancellationToken.ThrowIfCancellationRequested();
                var childInstance = (HeavyTestInstance)Host.CreateInstance(ctx, Node, instance);
                await childInstance.Initialize(ctx, cancellationToken);

                return(childInstance);
            } catch (OperationCanceledException) {
                ctx.OnTestCanceled();
                return(null);
            } catch (Exception ex) {
                ctx.OnError(ex);
                return(null);
            }
        }
示例#14
0
        TestBuilderInstance SetUp(TestContext ctx, TestInstance instance)
        {
            ctx.LogDebug(10, "SetUp({0}): {1} {2}", ctx.FriendlyName, TestLogger.Print(Host), TestLogger.Print(instance));

            try {
                if (!Filter(ctx))
                {
                    ctx.OnTestIgnored();
                    return(null);
                }
                return((TestBuilderInstance)Host.CreateInstance(ctx, Node, instance));
            } catch (OperationCanceledException) {
                ctx.OnTestCanceled();
                return(null);
            } catch (Exception ex) {
                ctx.OnError(ex);
                return(null);
            }
        }
示例#15
0
        public override async Task <bool> Invoke(
            TestContext ctx, TestInstance instance, CancellationToken cancellationToken)
        {
            var innerInstance = SetUp(ctx, instance);

            if (innerInstance == null)
            {
                return(false);
            }

            var innerCtx = ctx.CreateChild(TestInstance.GetTestName(innerInstance), innerInstance);

            var success = await InvokeInner(innerCtx, innerInstance, Inner, cancellationToken);

            if (!TearDown(ctx, innerInstance))
            {
                success = false;
            }

            return(success);
        }
示例#16
0
        async Task <bool> PostRun(
            TestContext ctx, TestInstance instance, CancellationToken cancellationToken)
        {
            ctx.LogDebug(10, "PostRun({0}): {1}", ctx.Name, TestLogger.Print(instance));

            try {
                for (var current = instance; current != null; current = current.Parent)
                {
                    var heavy = current as HeavyTestInstance;
                    if (heavy != null)
                    {
                        await heavy.PostRun(ctx, cancellationToken);
                    }
                }
                return(true);
            } catch (OperationCanceledException) {
                ctx.OnTestCanceled();
                return(false);
            } catch (Exception ex) {
                ctx.OnError(ex);
                return(false);
            }
        }
 public ParameterizedTestInstance(ParameterizedTestHost host, TestPath path, TestInstance parent)
     : base(host, path, parent)
 {
 }
 public ParameterizedTestInstance(ParameterizedTestHost host, TestNode node, TestInstance parent)
     : base(host, node, parent)
 {
 }
示例#19
0
 public HeavyTestInstance(HeavyTestHost host, TestPath path, TestInstance parent)
     : base(host, path, parent)
 {
 }
示例#20
0
 internal sealed override TestInstance CreateInstance(TestInstance parent)
 {
     return(new InvokableTestInstance(this, parent));
 }
示例#21
0
 internal abstract ITestParameter GetParameter(TestInstance instance);
示例#22
0
        internal override ITestParameter GetParameter(TestInstance instance)
        {
            var parameterizedInstance = (ParameterizedTestInstance)instance;

            return(parameterizedInstance.Current.Parameter);
        }
示例#23
0
 internal override TestInstance CreateInstance(TestPath path, TestInstance parent)
 {
     return(new FixedParameterInstance <T> (this, path, parent));
 }
示例#24
0
 internal override TestInstance CreateInstance(TestPath path, TestInstance parent)
 {
     return(new CustomTestInstance(this, path, parent, HostType, UseFixtureInstance));
 }
示例#25
0
 public CustomTestInstance(CustomTestHost host, TestNode node, TestInstance parent)
     : base(host, node, parent)
 {
 }
示例#26
0
 internal override TestInstance CreateInstance(TestPath path, TestInstance parent)
 {
     throw new NotImplementedException();
 }
示例#27
0
 public abstract Task <bool> Invoke(TestContext ctx, TestInstance instance, CancellationToken cancellationToken);
示例#28
0
 internal override ITestParameter GetParameter(TestInstance instance)
 {
     return(null);
 }
示例#29
0
 public FixedParameterInstance(FixedParameterHost <T> host, TestPath path, TestInstance parent)
     : base(host, path, parent)
 {
 }
示例#30
0
 internal abstract TestInstance CreateInstance(TestNode node, TestInstance parent);