Exemplo n.º 1
0
        public void TestStepRunShouldBeNormalized()
        {
            TestStepRun testStepRun = Runner.GetPrimaryTestStepRun(CodeReference.CreateFromMember(typeof(ModelNormalizationSample).GetMethod("Test")));

            Assert.AreEqual("Test *?* Name", testStepRun.Step.Name, "Name should be normalized.");
            Assert.AreEqual("Value *?*", testStepRun.Step.Metadata.GetValue("Key *?*"), "Metadata should be normalized.");
            AssertLogContains(testStepRun, "Section *?*");
            AssertLogContains(testStepRun, "Text *?* Content");
        }
Exemplo n.º 2
0
 void ITextEditorHelper.FollowReference(CodeReference codeRef, bool newTab)
 {
     Debug.Assert(FileTab != null);
     if (FileTab == null)
     {
         return;
     }
     FileTab.FollowReference(codeRef, newTab);
 }
Exemplo n.º 3
0
        public void WhenNoFailure_FixturePasses()
        {
            var fixtureRun = Runner.GetPrimaryTestStepRun(CodeReference.CreateFromType(typeof(Fixture)));

            Assert.Multiple(() =>
            {
                Assert.AreEqual(TestOutcome.Passed, fixtureRun.Result.Outcome);
                Assert.IsFalse(fixtureRun.Step.IsTestCase);
            });
        }
Exemplo n.º 4
0
        public void WhenTestFails_FixtureFails()
        {
            var fixtureRun = Runner.GetPrimaryTestStepRun(CodeReference.CreateFromType(typeof(FixtureWithFailingTest)));

            Assert.Multiple(() =>
            {
                Assert.AreEqual(TestOutcome.Failed, fixtureRun.Result.Outcome);
                Assert.IsFalse(fixtureRun.Step.IsTestCase);
            });
        }
Exemplo n.º 5
0
        public void FailTestFailed()
        {
            TestStepRun run = Runner.GetPrimaryTestStepRun(CodeReference.CreateFromMember(typeof(SimpleTest).GetMethod("Fail")));

            Assert.AreEqual("Fail", run.Step.Name);
            Assert.IsTrue(run.Step.IsPrimary);
            Assert.IsFalse(run.Step.IsDynamic);
            Assert.AreEqual(TestStatus.Failed, run.Result.Outcome.Status);
            Assert.Contains(run.TestLog.GetStream(MarkupStreamNames.Failures).ToString(), "Boom");
        }
        public void Test()
        {
            var run       = Runner.GetPrimaryTestStepRun(CodeReference.CreateFromMember(typeof(ImpersonateAttributeSample).GetMethod("Test")));
            var userNames = GetLogs(run.Children)
                            .Select(x => Regex.Match(x, @"User = \w+\\(?<UserName>\w+)"))
                            .Where(m => m.Success)
                            .Select(m => m.Groups["UserName"].Value);

            Assert.AreElementsEqualIgnoringOrder(new[] { "TestUser", "AnotherTestUser" }, userNames);
        }
Exemplo n.º 7
0
        public void WhenFixtureInitializerFails_FixtureFailsAndBecomesATestCase()
        {
            var fixtureRun = Runner.GetPrimaryTestStepRun(CodeReference.CreateFromType(typeof(FixtureWithFailingFixtureInitializer)));

            Assert.Multiple(() =>
            {
                Assert.AreEqual(TestOutcome.Failed, fixtureRun.Result.Outcome);
                Assert.IsTrue(fixtureRun.Step.IsTestCase);
                AssertLogContains(fixtureRun, "[Constructor] Outcome: passed\n[FixtureInitializer] Outcome: passed\n[Dispose] Outcome: failed");
            });
        }
Exemplo n.º 8
0
        public void WhenNoFailure_FixturePasses()
        {
            var fixtureRun = Runner.GetPrimaryTestStepRun(CodeReference.CreateFromType(typeof(Fixture)));

            Assert.Multiple(() =>
            {
                Assert.AreEqual(TestOutcome.Passed, fixtureRun.Result.Outcome);
                Assert.IsFalse(fixtureRun.Step.IsTestCase);
                AssertLogContains(fixtureRun, "[Constructor] Outcome: passed\n[FixtureInitializer] Outcome: passed\n[Dispose] Outcome: passed");
            });
        }
        public void parse_namespace_name_nominal()
        {
            var cr = CodeReference.Parse("N:System.Json");

            Assert.True(cr.IsValid);
            Assert.Equal(SymbolType.Namespace, cr.MetadataName.SymbolType);

            var name = (NamespaceName)cr.MetadataName;

            Assert.Equal("System.Json", name.FullName);
        }
        public void WhenTestFails_FixtureFails()
        {
            var fixtureRun = Runner.GetPrimaryTestStepRun(CodeReference.CreateFromType(typeof(FixtureWithFailingTest)));

            Assert.Multiple(() =>
            {
                Assert.AreEqual(TestOutcome.Failed, fixtureRun.Result.Outcome);
                Assert.IsFalse(fixtureRun.Step.IsTestCase);
                AssertLogContains(fixtureRun, "[FixtureSetUp] Outcome: passed\n[FixtureTearDown] Outcome: failed");
            });
        }
Exemplo n.º 11
0
        public void CreateByNameAndResolve()
        {
            var r = new CodeReference(assembly.FullName, type.Namespace, type.FullName, member.Name, parameter.Name);
            Assert.AreEqual(assembly.FullName, r.AssemblyName);
            Assert.AreEqual(type.Namespace, r.NamespaceName);
            Assert.AreEqual(type.FullName, r.TypeName);
            Assert.AreEqual(member.Name, r.MemberName);
            Assert.AreEqual(parameter.Name, r.ParameterName);

            Assert.AreEqual(CodeReferenceKind.Parameter, r.Kind);
        }
Exemplo n.º 12
0
        public void DependentTestsRunInOrderByDependency()
        {
            TestStepRun test1Run = Runner.GetPrimaryTestStepRun(CodeReference.CreateFromMember(typeof(DependsOnSample).GetMethod("Test1_DependsOnTest2_Fail")));
            TestStepRun test2Run = Runner.GetPrimaryTestStepRun(CodeReference.CreateFromMember(typeof(DependsOnSample).GetMethod("Test2_Pass")));
            TestStepRun test3Run = Runner.GetPrimaryTestStepRun(CodeReference.CreateFromMember(typeof(DependsOnSample).GetMethod("Test3_DependsOnTest1_Fail")));
            TestStepRun test4Run = Runner.GetPrimaryTestStepRun(CodeReference.CreateFromMember(typeof(DependsOnSample).GetMethod("Test4_DependsOnTest2_Pass")));

            Assert.LessThanOrEqualTo(test2Run.StartTime, test1Run.StartTime);
            Assert.LessThanOrEqualTo(test1Run.StartTime, test3Run.StartTime);
            Assert.LessThanOrEqualTo(test2Run.StartTime, test4Run.StartTime);
        }
Exemplo n.º 13
0
        private void PopulateTestName()
        {
            CodeReference codeReference = CodeElement.CodeReference;

            testName = String.Empty;
            if (String.IsNullOrEmpty(codeReference.NamespaceName))
            {
                testName += codeReference.NamespaceName + ".";
            }
            testName += codeReference.TypeName + "." + codeReference.MemberName;
        }
Exemplo n.º 14
0
        public void DependentTestsRunIfTheirDependenciesPasses()
        {
            TestStepRun test1Run = Runner.GetPrimaryTestStepRun(CodeReference.CreateFromMember(typeof(DependsOnSample).GetMethod("Test1_DependsOnTest2_Fail")));
            TestStepRun test4Run = Runner.GetPrimaryTestStepRun(CodeReference.CreateFromMember(typeof(DependsOnSample).GetMethod("Test4_DependsOnTest2_Pass")));

            Assert.Contains(test1Run.TestLog.ToString(), "Run");
            Assert.AreEqual(TestOutcome.Failed, test1Run.Result.Outcome);

            Assert.Contains(test4Run.TestLog.ToString(), "Run");
            Assert.AreEqual(TestOutcome.Passed, test4Run.Result.Outcome);
        }
Exemplo n.º 15
0
        public void Metadata()
        {
            TestStepRun run = Runner.GetPrimaryTestStepRun(CodeReference.CreateFromMember(typeof(CsvDataSample).GetMethod("FileWithHeader")));

            Assert.AreEqual(@"..\Framework\CsvDataTest.csv(2)", run.Children[0].Step.Metadata.GetValue(MetadataKeys.DataLocation));
            Assert.AreEqual(@"Worm", run.Children[0].Step.Metadata.GetValue("ConsumedBy"));
            Assert.AreEqual(@"..\Framework\CsvDataTest.csv(3)", run.Children[1].Step.Metadata.GetValue(MetadataKeys.DataLocation));
            Assert.AreEqual(@"Monkey", run.Children[1].Step.Metadata.GetValue("ConsumedBy"));
            Assert.AreEqual(@"..\Framework\CsvDataTest.csv(4)", run.Children[2].Step.Metadata.GetValue(MetadataKeys.DataLocation));
            Assert.AreEqual(@"Cookie Monster", run.Children[2].Step.Metadata.GetValue("ConsumedBy"));
        }
Exemplo n.º 16
0
        public void CreateFromParameter()
        {
            var r = CodeReference.CreateFromParameter(parameter);

            Assert.AreEqual(assembly.FullName, r.AssemblyName);
            Assert.AreEqual(@namespace, r.NamespaceName);
            Assert.AreEqual(type.FullName, r.TypeName);
            Assert.AreEqual(member.Name, r.MemberName);
            Assert.AreEqual(parameter.Name, r.ParameterName);

            Assert.AreEqual(CodeReferenceKind.Parameter, r.Kind);
        }
Exemplo n.º 17
0
        public void CreateByNameAndResolve()
        {
            var r = new CodeReference(assembly.FullName, type.Namespace, type.FullName, member.Name, parameter.Name);

            Assert.AreEqual(assembly.FullName, r.AssemblyName);
            Assert.AreEqual(type.Namespace, r.NamespaceName);
            Assert.AreEqual(type.FullName, r.TypeName);
            Assert.AreEqual(member.Name, r.MemberName);
            Assert.AreEqual(parameter.Name, r.ParameterName);

            Assert.AreEqual(CodeReferenceKind.Parameter, r.Kind);
        }
Exemplo n.º 18
0
        public void CreateFromNamespace()
        {
            CodeReference r = CodeReference.CreateFromNamespace(@namespace);

            Assert.IsNull(r.AssemblyName);
            Assert.AreEqual(@namespace, r.NamespaceName);
            Assert.IsNull(r.TypeName);
            Assert.IsNull(r.MemberName);
            Assert.IsNull(r.ParameterName);

            Assert.AreEqual(CodeReferenceKind.Namespace, r.Kind);
        }
Exemplo n.º 19
0
        public void VerifyThatSetUpFixtureRan()
        {
            TestStepRun methodRun = Runner.GetPrimaryTestStepRun(CodeReference.CreateFromMember(typeof(FixtureDependentUponSetUpFixture).GetMethod("VerifyThatSetUpFixtureRan")));

            Assert.IsNotNull(methodRun);
            Assert.AreEqual(TestStatus.Passed, methodRun.Result.Outcome.Status);

            TestStepRun namespaceRun = Runner.GetPrimaryTestStepRun(x => x.Step.Name == "SetUpFixtureSample");

            AssertLogContains(namespaceRun, "[SetUpFixture] SetUp", MarkupStreamNames.ConsoleOutput);
            AssertLogContains(namespaceRun, "[SetUpFixture] TearDown", MarkupStreamNames.ConsoleOutput);
        }
Exemplo n.º 20
0
        /// <summary>
        /// Gets the primary test step run of a test with the given code reference.
        /// </summary>
        /// <remarks>
        /// <para>
        /// If there are multiple primary steps, returns the first one found.
        /// </para>
        /// <para>
        /// Can only be called after the tests have run.
        /// </para>
        /// </remarks>
        /// <param name="codeReference">The code reference of the test.</param>
        /// <returns>The first test step run, or null if not found.</returns>
        public TestStepRun GetPrimaryTestStepRun(CodeReference codeReference)
        {
            foreach (TestStepRun run in GetTestStepRuns(codeReference))
            {
                if (run.Step.IsPrimary)
                {
                    return(run);
                }
            }

            return(null);
        }
Exemplo n.º 21
0
        public void VerifyTestOnTestData1File()
        {
            TestStepRun run = Runner.GetPrimaryTestStepRun(
                CodeReference.CreateFromMember(typeof(XmlDataObjectWithTestData1File).GetMethod("Test")));

            Assert.AreElementsEqual(new[] {
                "ID = 'Admin', UserName = '******', Password = '******'",
                "ID = 'User', UserName = '******', Password = '******'"
            },
                                    run.Children.Select(x => x.TestLog.GetStream(MarkupStreamNames.Default).ToString()),
                                    (x, y) => y.Contains(x));
        }
Exemplo n.º 22
0
        public void PopulateTestTree_CapturesTestStructureAndBasicMetadata()
        {
            TestModel testModel = PopulateTestTree();

            Test rootTest = testModel.RootTest;

            Assert.IsNull(rootTest.Parent);
            Assert.AreEqual(TestKinds.Root, rootTest.Kind);
            Assert.IsNull(rootTest.CodeElement);
            Assert.IsFalse(rootTest.IsTestCase);
            Assert.Count(1, rootTest.Children);

            Test assemblyTest = rootTest.Children[0];

            Assert.AreSame(rootTest, assemblyTest.Parent);
            Assert.AreEqual(AssemblyKind, assemblyTest.Kind);
            Assert.AreEqual(SimpleFixtureAssembly.Location, assemblyTest.Metadata.GetValue(MetadataKeys.File), StringComparison.OrdinalIgnoreCase);
            Assert.AreEqual(CodeReference.CreateFromAssembly(SimpleFixtureAssembly), assemblyTest.CodeElement.CodeReference);
            Assert.AreEqual(SimpleFixtureAssembly.GetName().Name, assemblyTest.Name);
            Assert.IsFalse(assemblyTest.IsTestCase);
            Assert.GreaterThanOrEqualTo(assemblyTest.Children.Count, 1);

            Test fixtureTest = GetDescendantByName(assemblyTest, "SimpleTest");

            Assert.AreEqual(TestKinds.Fixture, fixtureTest.Kind);
            Assert.AreEqual(new CodeReference(SimpleFixtureAssembly.FullName, SimpleFixtureNamespace, SimpleFixtureNamespace + ".SimpleTest", null, null),
                            fixtureTest.CodeElement.CodeReference);
            Assert.AreEqual("SimpleTest", fixtureTest.Name);
            Assert.IsFalse(fixtureTest.IsTestCase);
            Assert.Count(2, fixtureTest.Children);

            Test passTest = GetDescendantByName(fixtureTest, PassTestName);
            Test failTest = GetDescendantByName(fixtureTest, FailTestName);

            Assert.IsNotNull(passTest, "Cannot find test case '{0}'", PassTestName);
            Assert.IsNotNull(failTest, "Cannot find test case '{0}'", FailTestName);

            Assert.AreSame(fixtureTest, passTest.Parent);
            Assert.AreEqual(TestKinds.Test, passTest.Kind);
            Assert.AreEqual(new CodeReference(SimpleFixtureAssembly.FullName, SimpleFixtureNamespace, SimpleFixtureNamespace + ".SimpleTest", "Pass", null),
                            passTest.CodeElement.CodeReference);
            Assert.AreEqual(PassTestName, passTest.Name);
            Assert.IsTrue(passTest.IsTestCase);
            Assert.Count(0, passTest.Children);

            Assert.AreSame(fixtureTest, failTest.Parent);
            Assert.AreEqual(TestKinds.Test, failTest.Kind);
            Assert.AreEqual(new CodeReference(SimpleFixtureAssembly.FullName, SimpleFixtureNamespace, SimpleFixtureNamespace + ".SimpleTest", "Fail", null),
                            failTest.CodeElement.CodeReference);
            Assert.AreEqual(FailTestName, failTest.Name);
            Assert.IsTrue(failTest.IsTestCase);
            Assert.Count(0, failTest.Children);
        }
Exemplo n.º 23
0
        public void WhenNoFailure_TestPasses()
        {
            var fixtureRun = Runner.GetPrimaryTestStepRun(CodeReference.CreateFromType(typeof(Fixture)));
            var testRun    = fixtureRun.Children[0];

            Assert.Multiple(() =>
            {
                Assert.AreEqual(TestOutcome.Passed, testRun.Result.Outcome);
                Assert.IsTrue(testRun.Step.IsTestCase);
                AssertLogContains(testRun, "[SetUp] Outcome: passed\n[Test] Outcome: passed\n[TearDown] Outcome: passed");
            });
        }
Exemplo n.º 24
0
        public void parse_property_nominal()
        {
            var cr = CodeReference.Parse("P:System.Json.JsonValueChangeEventArgs.Key");

            Assert.True(cr.IsValid);
            Assert.Equal(SymbolType.Property, cr.MetadataName.SymbolType);

            var name = (PropertyName)cr.MetadataName;

            Assert.Equal("System.Json.JsonValueChangeEventArgs", name.DeclaringType.FullName);
            Assert.Equal("Key", name.Name);
        }
Exemplo n.º 25
0
        public void Equality()
        {
            Assert.IsFalse(CodeReference.Unknown.Equals(null));

            Assert.IsFalse(CodeReference.Unknown.Equals(CodeReference.CreateFromParameter(parameter)));
            Assert.IsFalse(CodeReference.Unknown == CodeReference.CreateFromParameter(parameter));
            Assert.IsTrue(CodeReference.Unknown != CodeReference.CreateFromParameter(parameter));

            Assert.IsTrue(CodeReference.CreateFromParameter(parameter).Equals(CodeReference.CreateFromParameter(parameter)));
            Assert.IsTrue(CodeReference.CreateFromParameter(parameter) == CodeReference.CreateFromParameter(parameter));
            Assert.IsFalse(CodeReference.CreateFromParameter(parameter) != CodeReference.CreateFromParameter(parameter));
        }
Exemplo n.º 26
0
        public void WhenSetUpFails_TestFailsAndTestMethodDoesNotRun()
        {
            var fixtureRun = Runner.GetPrimaryTestStepRun(CodeReference.CreateFromType(typeof(FixtureWithFailingSetUp)));
            var testRun    = fixtureRun.Children[0];

            Assert.Multiple(() =>
            {
                Assert.AreEqual(TestOutcome.Failed, testRun.Result.Outcome);
                Assert.IsTrue(testRun.Step.IsTestCase);
                AssertLogContains(testRun, "[SetUp] Outcome: passed\n[TearDown] Outcome: failed");
            });
        }
Exemplo n.º 27
0
        public void VerifySampleOutput(string sampleName, string[] output)
        {
            TestStepRun run = Runner.GetPrimaryTestStepRun(CodeReference.CreateFromMember(typeof(CsvDataSample).GetMethod(sampleName)));

            Assert.AreEqual(output.Length, run.Children.Count, "Different number of runs than expected.");

            for (int i = 0; i < output.Length; i++)
            {
                AssertLogContains(run.Children[i], output[i]);
                Assert.IsNotNull(run.Children[i].Step.Metadata.GetValue(MetadataKeys.DataLocation));
            }
        }
Exemplo n.º 28
0
        public void CreateFromAssembly()
        {
            var r = CodeReference.CreateFromAssembly(assembly);

            Assert.AreEqual(assembly.FullName, r.AssemblyName);
            Assert.IsNull(r.NamespaceName);
            Assert.IsNull(r.TypeName);
            Assert.IsNull(r.MemberName);
            Assert.IsNull(r.ParameterName);

            Assert.AreEqual(CodeReferenceKind.Assembly, r.Kind);
        }
Exemplo n.º 29
0
        public void parse_event_nominal()
        {
            var cr = CodeReference.Parse("E:System.Json.JsonValue.Changed");

            Assert.Equal(SymbolType.Event, cr.MetadataName.SymbolType);
            EventName name = (EventName)cr.MetadataName;

            Assert.Equal("System.Json.JsonValue", name.DeclaringType.FullName);
            Assert.Equal("Changed", name.Name);

            Assert.Equal("E:System.Json.JsonValue.Changed", cr.ToString());
        }
Exemplo n.º 30
0
 public void UseInstanceParameters()
 {
     TestStepRun[] runs = Runner.GetTestStepRuns(CodeReference.CreateFromMember(typeof(SharedParamFixtureTest).GetMethod("UseInstanceParameters"))).ToArray();
     Assert.Count(2, runs);
     Assert.ForAll(runs, run => run.Result.Outcome == TestOutcome.Passed);
     AssertLogLike(runs[0], "Parameter is 123|456", MarkupStreamNames.Default);
     AssertLogContains(runs[0], "Service is ConcreteService");
     AssertLogContains(runs[0], "Service is ConcreteService1");
     AssertLogLike(runs[1], "Parameter is 123|456", MarkupStreamNames.Default);
     AssertLogContains(runs[1], "Service is ConcreteService");
     AssertLogContains(runs[1], "Service is ConcreteService1");
 }
Exemplo n.º 31
0
        public void VerifySampleOutput(Type fixtureType, string sampleName, string[] output)
        {
            IList <TestStepRun> runs = Runner.GetTestCaseRunsWithin(
                CodeReference.CreateFromMember(fixtureType.GetMethod(sampleName)));

            Assert.AreEqual(output.Length, runs.Count, "Different number of runs than expected.");

            for (int i = 0; i < output.Length; i++)
            {
                AssertLogContains(runs[i], output[i]);
            }
        }
        public void Namespace_spec_should_match_on_partial_namespace()
        {
            var specification = new NamespaceSpecification("test");
            var codeReference = new CodeReference("", "some.test.namespace", "", "", "");
            var testData = new TestData("id", "name", "fullName")
            {
                CodeReference = codeReference
            };

            var matches = specification.Matches(new TestDataNode(testData));

            Assert.IsTrue(matches);
        }
        public void Namespace_spec_should_not_match_if_namespace_is_different()
        {
            var specification = new NamespaceSpecification("wahwahwah");
            var codeReference = new CodeReference("", "some.test.namespace", "", "", "");
            var testData = new TestData("id", "name", "fullName")
            {
                CodeReference = codeReference
            };

            var matches = specification.Matches(new TestDataNode(testData));

            Assert.IsFalse(matches);
        }
Exemplo n.º 34
0
        public override void Apply(XmlDocument document, string key) {
            XPathNodeIterator nodesIterator = document.CreateNavigator().Select(selector);
            XPathNavigator[] nodes = ConvertIteratorToArray(nodesIterator);

            foreach (XPathNavigator node in nodes) {
                CodeReference cref = new CodeReference(node.Value);

                SampleInfo si = null;
                if (sampleInfoTable != null && cref.ExampleName != null)
                    sampleInfoTable.TryGetValue(cref.ExampleName, out si);

                WriteMessage(MessageLevel.Info, string.Format("*** codeReference={0}; approved={1}; type={2}",
                    node.Value, (si == null) ? false : si.IsApproved("CS"), cref.Type));


                switch (cref.Type) {
                    case CodeReferenceType.Msdn:
                        // TODO: remove "msdn:" from code reference and let ExampleComponent handle the snippet.
                        // We'll either pass this through to the regular ExampleComponent or delete the node.
                        WriteMessage(MessageLevel.Warn, "MSDN-only links not implemented yet.");
                        break;

                    case CodeReferenceType.Run:
                    case CodeReferenceType.View:
                        if (si != null || !omitBadExamples) {
                            WriteMessage(MessageLevel.Info, string.Format("+ LiveCode: Kind={0}, SampleName={1}", cref.Type.ToString(), cref.ExamplePath));
                            XmlWriter writer = node.InsertAfter();
                            writer.WriteStartElement(wdxPrefix, "LiveCode", wdxNamespace);
                            writer.WriteAttributeString("Kind", cref.Type.ToString());
                            writer.WriteAttributeString("SampleName", cref.ExamplePath);
                            writer.WriteAttributeString("runat", "server");
                            writer.WriteEndElement();
                            writer.Close();
                            node.DeleteSelf();
                        }
                        break;

                    case CodeReferenceType.Snippet:
                        // Ignore; let ExampleComponent handle the snippet.
                        break;

                    default:
                        WriteMessage(MessageLevel.Warn, string.Format("Invalid code example reference ignored: '{0}'", node.Value));
                        break;
                }
            }
        }
Exemplo n.º 35
0
        /// <summary>
        /// Copies the contents of a test component.
        /// </summary>
        /// <param name="source">The source object.</param>
        public TestComponentData(TestComponent source)
        {
            if (source == null)
                throw new ArgumentNullException(@"source");

            id = source.Id;
            name = source.Name;
            codeElement = source.CodeElement;

            if (codeElement != null)
            {
                codeReference = codeElement.CodeReference;
                codeLocation = codeElement.GetCodeLocation();
            }

            metadata = source.Metadata.Copy();
        }
Exemplo n.º 36
0
        /// <summary>
        /// Resolves the specified <see cref="CodeReference" />. 
        /// </summary>
        /// <param name="reference">The code reference.</param>
        /// <param name="throwOnError">If true, throws an exception on error.</param>
        /// <returns>The associated code element, or null if the code reference
        /// is of kind <see cref="CodeReferenceKind.Unknown" /></returns>
        /// <exception cref="InvalidOperationException">Thrown if <paramref name="throwOnError"/>
        /// is true and <paramref name="reference"/> cannot be resolved.</exception>
        public static ICodeElementInfo Resolve(CodeReference reference, bool throwOnError)
        {
            try
            {
                CodeReferenceKind kind = reference.Kind;

                if (kind == CodeReferenceKind.Unknown)
                    return null;

                if (kind == CodeReferenceKind.Namespace)
                    return WrapNamespace(reference.NamespaceName);

                Assembly assembly = Assembly.Load(reference.AssemblyName);
                if (kind == CodeReferenceKind.Assembly)
                    return Wrap(assembly);

                Type type = assembly.GetType(reference.TypeName, true);
                if (kind == CodeReferenceKind.Type)
                    return Wrap(type);

                // TODO: Handle overloading by signature.
                MemberInfo[] members = type.GetMember(reference.MemberName,
                    BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);

                if (members.Length != 1)
                    throw new AmbiguousMatchException("There was not exactly one matching member.");

                MemberInfo member = members[0];

                if (kind == CodeReferenceKind.Member)
                    return Wrap(member);

                MethodBase method = member as MethodBase;
                if (method == null)
                    throw new AmbiguousMatchException("The member that was found was not a constructor or method as expected.");

                ParameterInfo parameter = Array.Find(method.GetParameters(), delegate(ParameterInfo candidate)
                {
                    return candidate.Name == reference.ParameterName;
                });

                if (parameter == null)
                    throw new AmbiguousMatchException("The named parameter was not found.");

                return Wrap(parameter);
            }
            catch (Exception ex)
            {
                if (throwOnError)
                    throw new InvalidOperationException(
                        String.Format("Could not resolve '{0}'.", reference), ex);
                return null;
            }
        }
Exemplo n.º 37
0
        /// <summary>
        /// Gets all test step runs that represent test cases within a test with
        /// the specified code reference.
        /// </summary>
        /// <remarks>
        /// <para>
        /// Can only be called after the tests have run.
        /// </para>
        /// </remarks>
        /// <param name="codeReference">The code reference of the test.</param>
        /// <returns>The first test step run, or null if not found.</returns>
        public IList<TestStepRun> GetTestCaseRunsWithin(CodeReference codeReference)
        {
            List<TestStepRun> runs = new List<TestStepRun>();
            foreach (TestStepRun containerRun in Report.TestPackageRun.AllTestStepRuns)
            {
                if (containerRun.Step.IsPrimary && containerRun.Step.CodeReference == codeReference)
                {
                    foreach (TestStepRun run in containerRun.AllTestStepRuns)
                    {
                        if (run.Step.IsTestCase)
                            runs.Add(run);
                    }
                }
            }

            return runs;
        }
        public void Establish_context()
        {
            mocks = new MockRepository();
            namespaceTreeBuilder = new NamespaceTreeBuilder();

            testModelData = new TestModelData();
            var assembly = new TestData("assembly", "assembly", "assembly");
            testModelData.RootTest.Children.Add(assembly);

            var nsRootCodeElement = mocks.StrictMock<ICodeElementInfo>();
            var nsRootCodeReference = new CodeReference("assembly", null, null, null, null);
            var nsRoot = new Test("nsRoot", nsRootCodeElement);

            using (mocks.Record())
            {
                Expect.Call(nsRootCodeElement.CodeReference).Return(nsRootCodeReference);
                Expect.Call(nsRootCodeElement.GetCodeLocation()).Return(new CodeLocation("about:blank", 1, 1));
            }
            nsRoot.Kind = Gallio.Model.TestKinds.Namespace;
            nsRoot.IsTestCase = false;

            var nsRootTest = new TestData(nsRoot, true);
            assembly.Children.Add(nsRootTest);

            var nsLevel1CodeElement = mocks.StrictMock<ICodeElementInfo>();
            var nsLevel1CodeReference = new CodeReference("assembly", null, null, null, null);
            var nsLevel1 = new Test("nsLevel1", nsLevel1CodeElement);

            using (mocks.Record())
            {
                Expect.Call(nsLevel1CodeElement.CodeReference).Return(nsLevel1CodeReference);
                Expect.Call(nsLevel1CodeElement.GetCodeLocation()).Return(new CodeLocation("about:blank", 1, 1));
            }
            nsLevel1.Kind = Gallio.Model.TestKinds.Namespace;
            nsLevel1.IsTestCase = false;

            var nsLevel1Test = new TestData(nsLevel1, true);
            nsRootTest.Children.Add(nsLevel1Test);

            var nsLevel2CodeElement = mocks.StrictMock<ICodeElementInfo>();
            var nsLevel2CodeReference = new CodeReference("assembly", null, null, null, null);
            var nsLevel2 = new Test("nsLevel2", nsLevel2CodeElement);

            using (mocks.Record())
            {
                Expect.Call(nsLevel2CodeElement.CodeReference).Return(nsLevel2CodeReference);
                Expect.Call(nsLevel2CodeElement.GetCodeLocation()).Return(new CodeLocation("about:blank", 1, 1));
            }
            nsLevel2.Kind = Gallio.Model.TestKinds.Namespace;
            nsLevel2.IsTestCase = false;

            var nsLevel2Test = new TestData(nsLevel2, true);
            nsLevel1Test.Children.Add(nsLevel2Test);

            var nsLevel2aCodeElement = mocks.StrictMock<ICodeElementInfo>();
            var nsLevel2aCodeReference = new CodeReference("assembly", null, null, null, null);
            var nsLevel2a = new Test("nsLevel2a", nsLevel2aCodeElement);

            using (mocks.Record())
            {
                Expect.Call(nsLevel2aCodeElement.CodeReference).Return(nsLevel2aCodeReference);
                Expect.Call(nsLevel2aCodeElement.GetCodeLocation()).Return(new CodeLocation("about:blank", 1, 1));
            }
            nsLevel2a.Kind = Gallio.Model.TestKinds.Namespace;
            nsLevel2a.IsTestCase = false;

            var nsLevel2aTest = new TestData(nsLevel2a, true);
            nsLevel1Test.Children.Add(nsLevel2aTest);

            var fixture1CodeElement = mocks.StrictMock<ICodeElementInfo>();
            var fixture1CodeReference = new CodeReference("assembly", "nsRoot.nsLevel1.nsLevel2", "fixture1", null, null);
            var fixture1 = new Test("fixture1", fixture1CodeElement);

            using (mocks.Record())
            {
                Expect.Call(fixture1CodeElement.CodeReference).Return(fixture1CodeReference);
                Expect.Call(fixture1CodeElement.GetCodeLocation()).Return(new CodeLocation("about:blank", 1, 1));
            }
            fixture1.Kind = Gallio.Model.TestKinds.Fixture;
            fixture1.IsTestCase = false;

            var fixture1Test = new TestData(fixture1, true);
            nsLevel2Test.Children.Add(fixture1Test);

            var fixture2CodeElement = mocks.StrictMock<ICodeElementInfo>();
            var fixture2CodeReference = new CodeReference("assembly", "nsRoot.nsLevel1.nsLevel2a", "fixture2", null, null);
            var fixture2 = new Test("fixture2", fixture2CodeElement);

            using (mocks.Record())
            {
                Expect.Call(fixture2CodeElement.CodeReference).Return(fixture2CodeReference);
                Expect.Call(fixture2CodeElement.GetCodeLocation()).Return(new CodeLocation("about:blank", 1, 1));
            }
            fixture2.Kind = Gallio.Model.TestKinds.Fixture;
            fixture2.IsTestCase = false;

            var fixture2Test = new TestData(fixture2, true);
            nsLevel2aTest.Children.Add(fixture2Test);
        }
Exemplo n.º 39
0
 /// <summary>
 /// Gets information about the test with the given code reference.
 /// </summary>
 /// <remarks>
 /// <para>
 /// Can only be called after the tests have run.
 /// </para>
 /// </remarks>
 /// <param name="codeReference">The code reference of the test.</param>
 /// <returns>The test data, or null if not found.</returns>
 public TestData GetTestData(CodeReference codeReference)
 {
     return GetTestData(test => test.CodeReference == codeReference);
 }
Exemplo n.º 40
0
 /// <summary>
 /// Gets all test step runs with the given code reference.
 /// </summary>
 /// <remarks>
 /// <para>
 /// Can only be called after the tests have run.
 /// </para>
 /// </remarks>
 /// <param name="codeReference">The code reference of the test.</param>
 /// <returns>The enumeration of test step runs, or null if not found.</returns>
 public IEnumerable<TestStepRun> GetTestStepRuns(CodeReference codeReference)
 {
     return GetTestStepRuns(run => run.Step.CodeReference == codeReference);
 }
Exemplo n.º 41
0
        /// <summary>
        /// Gets the primary test step run of a test with the given code reference.
        /// </summary>
        /// <remarks>
        /// <para>
        /// If there are multiple primary steps, returns the first one found.
        /// </para>
        /// <para>
        /// Can only be called after the tests have run.
        /// </para>
        /// </remarks>
        /// <param name="codeReference">The code reference of the test.</param>
        /// <returns>The first test step run, or null if not found.</returns>
        public TestStepRun GetPrimaryTestStepRun(CodeReference codeReference)
        {
            foreach (TestStepRun run in GetTestStepRuns(codeReference))
                if (run.Step.IsPrimary)
                    return run;

            return null;
        }