Ejemplo n.º 1
0
 public When_custom_theory_attribute_skips()
 {
     method = testClass.AddMethod("TestMethod1", _ => { }, new[] { Parameter.Create <int>("value") },
                                  new SkippingTheoryAttribute(),
                                  new InlineDataAttribute(12), new InlineDataAttribute(33));
     theoryTask = method.TheoryTasks[0];
 }
 public When_custom_theory_attribute_skips()
 {
     method = testClass.AddMethod("TestMethod1", _ => { }, new[] {Parameter.Create<int>("value")},
         new SkippingTheoryAttribute(),
         new InlineDataAttribute(12), new InlineDataAttribute(33));
     theoryTask = method.TheoryTasks[0];
 }
        public override IList <UnitTestTask> GetTaskSequence(ICollection <IUnitTestElement> explicitElements, IUnitTestLaunch launch)
        {
            var sequence   = ((XunitBaseElement)Parent).GetTaskSequence(explicitElements, launch);
            var theoryTask = new XunitTestTheoryTask(MethodElement.AssemblyLocation, MethodElement.TypeName.FullName, MethodElement.MethodName, ShortName);

            sequence.Add(new UnitTestTask(this, theoryTask));
            return(sequence);
        }
Ejemplo n.º 4
0
        public override IList <UnitTestTask> GetTaskSequence(ICollection <IUnitTestElement> explicitElements, IUnitTestRun run)
        {
            var sequence   = Parent.GetTaskSequence(explicitElements, run);
            var methodTask = sequence[sequence.Count - 1].RemoteTask as XunitTestMethodTask;
            var theoryTask = new XunitTestTheoryTask(methodTask, ShortName);

            sequence.Add(new UnitTestTask(this, theoryTask));
            return(sequence);
        }
        public void Should_rename_second_usage_of_repeated_theory_name()
        {
            var method = GetMethodWithTheoryAndParamterWithRepeatedToString();

            Run();

            var methodTask = method.Task;
            var theoryTasks = method.TheoryTasks;
            var secondTheoryTask = new XunitTestTheoryTask(methodTask, theoryTasks[1].TheoryName + " [2]");

            Messages.OfEquivalentTask(theoryTasks[0]).AssertTaskStarting();
            Messages.OfEquivalentTask(secondTheoryTask).AssertTaskStarting();
        }
        public void Should_rename_second_usage_of_repeated_theory_name()
        {
            var method = GetMethodWithTheoryAndParamterWithRepeatedToString();

            Run();

            var methodTask       = method.Task;
            var theoryTasks      = method.TheoryTasks;
            var secondTheoryTask = new XunitTestTheoryTask(methodTask, theoryTasks[1].TheoryName + " [2]");

            Messages.OfEquivalentTask(theoryTasks[0]).AssertTaskStarting();
            Messages.OfEquivalentTask(secondTheoryTask).AssertTaskStarting();
        }
Ejemplo n.º 7
0
        public void Add(XunitTestTheoryTask theoryTask)
        {
            // TheoryName is the display name with any type prefix stripped off
            // TODO: Why strip off the type prefix? It's not used anywhere
            var fullyQualifiedMethodName = string.Format("{0}.{1}", theoryTask.TypeName, theoryTask.MethodName);
            var key = string.Format("{0}-{1}", fullyQualifiedMethodName, theoryTask.TheoryName);

            lock (lockObject)
            {
                // TODO: Does this handle repeated tasks?
                if (!tasksByTheoryId.ContainsKey(key))
                    AddTheoryTask(key, fullyQualifiedMethodName, new RemoteTaskWrapper(theoryTask, server));
            }
        }
        public void Should_rename_subequent_usages_of_repeated_theory_name()
        {
            var method = GetMethodWithTheoryAndParamterWithRepeatedToString(4);

            Run();

            var methodTask       = method.Task;
            var theoryTasks      = method.TheoryTasks;
            var secondTheoryTask = new XunitTestTheoryTask(methodTask, theoryTasks[1].TheoryName + " [2]");
            var thirdTheoryTask  = new XunitTestTheoryTask(methodTask, theoryTasks[2].TheoryName + " [3]");
            var fourthTheoryTask = new XunitTestTheoryTask(methodTask, theoryTasks[3].TheoryName + " [4]");

            Messages.AssertEqualTask(theoryTasks[0]).TaskStarting();
            Messages.AssertEqualTask(secondTheoryTask).TaskStarting();
            Messages.AssertEqualTask(thirdTheoryTask).TaskStarting();
            Messages.AssertEqualTask(fourthTheoryTask).TaskStarting();
        }
        public void Should_rename_subsequent_usages_of_theories_with_the_same_parameter_value()
        {
            var method = GetMethodWithTheoryAndRepeatedValues(4);

            Run();

            var methodTask       = method.Task;
            var theoryTasks      = method.TheoryTasks;
            var secondTheoryTask = new XunitTestTheoryTask(methodTask, theoryTasks[1].TheoryName + " [2]");
            var thirdTheoryTask  = new XunitTestTheoryTask(methodTask, theoryTasks[2].TheoryName + " [3]");
            var fourthTheoryTask = new XunitTestTheoryTask(methodTask, theoryTasks[3].TheoryName + " [4]");

            Messages.OfEquivalentTask(theoryTasks[0]).AssertTaskStarting();
            Messages.OfEquivalentTask(secondTheoryTask).AssertTaskStarting();
            Messages.OfEquivalentTask(thirdTheoryTask).AssertTaskStarting();
            Messages.OfEquivalentTask(fourthTheoryTask).AssertTaskStarting();
        }
Ejemplo n.º 10
0
 private static bool IsParentMethodTask(XunitTestMethodTask methodTask, XunitTestTheoryTask theoryTask)
 {
     return(methodTask.AssemblyLocation == theoryTask.AssemblyLocation &&
            methodTask.TypeName == theoryTask.TypeName &&
            methodTask.MethodName == theoryTask.MethodName);
 }
Ejemplo n.º 11
0
        private IUnitTestElement GetDynamicTheoryElement(Dictionary <RemoteTask, IUnitTestElement> tasks, XunitTestTheoryTask theoryTask)
        {
            var methodElement = (from kvp in tasks
                                 where kvp.Key is XunitTestMethodTask &&
                                 IsParentMethodTask((XunitTestMethodTask)kvp.Key, theoryTask)
                                 select kvp.Value).FirstOrDefault() as XunitTestMethodElement;

            if (methodElement == null)
            {
                return(null);
            }

            using (ReadLockCookie.Create())
            {
                var project = methodElement.GetProject();
                if (project == null)
                {
                    return(null);
                }

                var element = UnitTestElementFactory.GetTestTheory(project, methodElement, theoryTask.TheoryName);

                // Make sure we return an element, even if the system already knows about it. If it's
                // part of the test run, it will already have been added in GetTaskSequence, and this
                // method (GetDynamicElement) doesn't get called. But if you try and run just a single
                // theory, xunit will run ALL theories for that method, and will need the elements
                // for those theories not included in the task sequence. This is necessary because if
                // one of those theories throws an exception, UnitTestLaunch.TaskException doesn't
                // have an element to report against, and displays a message box
                if (element != null)
                {
                    // If the element is invalid, it's been removed from its parent, so add it back,
                    // and reset the state
                    if (element.State == UnitTestElementState.Invalid)
                    {
                        element.State  = UnitTestElementState.Dynamic;
                        element.Parent = methodElement;
                    }
                    return(element);
                }

                return(UnitTestElementFactory.CreateTestTheory(this, project, methodElement, theoryTask.TheoryName));
            }
        }
Ejemplo n.º 12
0
        public RemoteTask GetTheoryTask(string name, string type, string method)
        {
            if (!IsTheory(name, type, method))
                return null;

            var methodTask = (XunitTestMethodTask)GetMethodTask(name, type, method);
            if (!theoryTasks.ContainsKey(methodTask))
                theoryTasks.Add(methodTask, new List<XunitTestTheoryTask>());

            var shortName = GetTheoryShortName(name, type);
            var theoryTask = theoryTasks[methodTask].FirstOrDefault(t => t.TheoryName == shortName);
            if (theoryTask == null)
            {
                theoryTask = new XunitTestTheoryTask(methodTask.AssemblyLocation, methodTask.TypeName, methodTask.MethodName, shortName);
                theoryTasks[methodTask].Add(theoryTask);
                server.CreateDynamicElement(theoryTask);
            }
            return theoryTask;
        }
 private static bool IsParentMethodTask(XunitTestMethodTask methodTask, XunitTestTheoryTask theoryTask)
 {
     return methodTask.AssemblyLocation == theoryTask.AssemblyLocation
         && methodTask.TypeName == theoryTask.TypeName
         && methodTask.MethodName == theoryTask.MethodName;
 }
Ejemplo n.º 14
0
        private IUnitTestElement GetDynamicTheoryElement(Dictionary<string, IUnitTestElement> tasks, XunitTestTheoryTask theoryTask)
        {
            IUnitTestElement parentElement;
            if (!tasks.TryGetValue(theoryTask.UncollapsedParentTaskId, out parentElement))
                return null;

            var methodElement = parentElement as XunitTestMethodElement;
            if (methodElement == null)
                return null;

            using (ReadLockCookie.Create())
            {
                var project = methodElement.Id.GetProject();
                if (project == null)
                    return null;

                // Make sure we return an element, even if the system already knows about it. If it's
                // part of the test run, it will already have been added in GetTaskSequence, and this
                // method (GetDynamicElement) doesn't get called. But if you try and run just a single
                // theory, xunit will run ALL theories for that method, and will need the elements
                // for those theories not included in the task sequence. This is necessary because if
                // one of those theories throws an exception, UnitTestLaunch.TaskException doesn't
                // have an element to report against, and displays a message box

                var services = project.GetSolution().GetComponent<XunitServiceProvider>();
                var unitTestElementFactory = new UnitTestElementFactory(services, null, false);
                var element = unitTestElementFactory.GetOrCreateTestTheory(methodElement.Id.Project, methodElement, theoryTask.TheoryName);

                element.State = UnitTestElementState.Dynamic;

                return element;
            }
        }
        private IUnitTestElement GetDynamicTheoryElement(Dictionary<RemoteTask, IUnitTestElement> tasks, XunitTestTheoryTask theoryTask)
        {
            var methodElement = (from kvp in tasks
                                 where kvp.Key is XunitTestMethodTask &&
                                       IsParentMethodTask((XunitTestMethodTask) kvp.Key, theoryTask)
                                 select kvp.Value).FirstOrDefault() as XunitTestMethodElement;
            if (methodElement == null)
                return null;

            using (ReadLockCookie.Create())
            {
                var project = methodElement.GetProject();
                if (project == null)
                    return null;

                var element = UnitTestElementFactory.GetTestTheory(project, methodElement, theoryTask.TheoryName);

                // Make sure we return an element, even if the system already knows about it. If it's
                // part of the test run, it will already have been added in GetTaskSequence, and this
                // method (GetDynamicElement) doesn't get called. But if you try and run just a single
                // theory, xunit will run ALL theories for that method, and will need the elements
                // for those theories not included in the task sequence. This is necessary because if
                // one of those theories throws an exception, UnitTestLaunch.TaskException doesn't
                // have an element to report against, and displays a message box
                if (element != null)
                {
                    // If the element is invalid, it's been removed from its parent, so add it back,
                    // and reset the state
                    if (element.State == UnitTestElementState.Invalid)
                    {
                        element.State = UnitTestElementState.Dynamic;
                        element.Parent = methodElement;
                    }

                    element.SetCategories(methodElement.Categories);
                    return element;
                }

                return UnitTestElementFactory.CreateTestTheory(this, project, methodElement, theoryTask.TheoryName);
            }
        }
        public void Should_rename_subsequent_usages_of_theories_with_the_same_parameter_value()
        {
            var method = GetMethodWithTheoryAndRepeatedValues(4);

            Run();

            var methodTask = method.Task;
            var theoryTasks = method.TheoryTasks;
            var secondTheoryTask = new XunitTestTheoryTask(methodTask, theoryTasks[1].TheoryName + " [2]");
            var thirdTheoryTask = new XunitTestTheoryTask(methodTask, theoryTasks[2].TheoryName + " [3]");
            var fourthTheoryTask = new XunitTestTheoryTask(methodTask, theoryTasks[3].TheoryName + " [4]");

            Messages.OfEquivalentTask(theoryTasks[0]).AssertTaskStarting();
            Messages.OfEquivalentTask(secondTheoryTask).AssertTaskStarting();
            Messages.OfEquivalentTask(thirdTheoryTask).AssertTaskStarting();
            Messages.OfEquivalentTask(fourthTheoryTask).AssertTaskStarting();
        }
Ejemplo n.º 17
0
 private RemoteTaskWrapper CreateDynamicTheoryTask(ITestMethod testMethod, string theoryName)
 {
     var methodTask = GetMethodTask(testMethod, testMethod.Method.Name);
     var theoryTask = new XunitTestTheoryTask((XunitTestMethodTask) methodTask.RemoteTask,
         DisplayNameUtil.Escape(theoryName));
     var task = new RemoteTaskWrapper(theoryTask, server);
     server.CreateDynamicElement(theoryTask);
     return task;
 }
Ejemplo n.º 18
0
 private void AddTheory(XunitTestMethodTask methodTask, XunitTestTheoryTask theoryTask)
 {
     if (!theoryTasks.ContainsKey(methodTask))
         theoryTasks.Add(methodTask, new List<XunitTestTheoryTask>());
     theoryTasks[methodTask].Add(theoryTask);
 }
Ejemplo n.º 19
0
        private IUnitTestElement GetDynamicTheoryElement(Dictionary <string, IUnitTestElement> tasks, XunitTestTheoryTask theoryTask)
        {
            IUnitTestElement parentElement;

            if (!tasks.TryGetValue(theoryTask.UncollapsedParentTaskId, out parentElement))
            {
                return(null);
            }

            var methodElement = parentElement as XunitTestMethodElement;

            if (methodElement == null)
            {
                return(null);
            }

            using (ReadLockCookie.Create())
            {
                var project = methodElement.Id.GetProject();
                if (project == null)
                {
                    return(null);
                }

                // Make sure we return an element, even if the system already knows about it. If it's
                // part of the test run, it will already have been added in GetTaskSequence, and this
                // method (GetDynamicElement) doesn't get called. But if you try and run just a single
                // theory, xunit will run ALL theories for that method, and will need the elements
                // for those theories not included in the task sequence. This is necessary because if
                // one of those theories throws an exception, UnitTestLaunch.TaskException doesn't
                // have an element to report against, and displays a message box

                var services = project.GetSolution().GetComponent <XunitServiceProvider>();
                var unitTestElementFactory = new UnitTestElementFactory(services, null, false);
                var element = unitTestElementFactory.GetOrCreateTestTheory(methodElement.Id.Project, methodElement, theoryTask.TheoryName);

                element.State = UnitTestElementState.Dynamic;

                return(element);
            }
        }