Esempio n. 1
0
        public void GetVersionLabel_WhenAssemblyIsProvided_ReturnsFormattedLabel()
        {
            var assembly = typeof(VersionPolicy).Assembly;
            var version  = VersionPolicy.GetVersionNumber(assembly);

            string label = VersionPolicy.GetVersionLabel(version);

            Assert.AreEqual(string.Format("{0}.{1} build {2}", version.Major, version.Minor, version.Build), label);
        }
        public void PopulateTestTree_WhenAssemblyReferencesMbUnit_ContainsSimpleTest()
        {
            TestModel testModel = PopulateTestTree();

            Version expectedVersion = VersionPolicy.GetVersionNumber(typeof(Assert).Assembly);

            Test rootTest = testModel.RootTest;

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

            Test assemblyTest = rootTest.Children[0];

            Assert.AreSame(rootTest, assemblyTest.Parent);
            Assert.AreEqual(MbUnitTestFramework.AssemblyKind, assemblyTest.Kind);
            Assert.AreEqual(MbUnitTestFramework.VersionLabel, assemblyTest.Metadata.GetValue(MetadataKeys.Framework));
            Assert.AreEqual(CodeReference.CreateFromAssembly(SimpleFixtureAssembly), assemblyTest.CodeElement.CodeReference);
            Assert.AreEqual(SimpleFixtureAssembly, ((IAssemblyInfo)assemblyTest.CodeElement).Resolve(true));
            Assert.GreaterThanOrEqualTo(assemblyTest.Children.Count, 1);

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

            Assert.IsNotNull(typeTest, "Could not find the SimpleTest fixture.");
            Assert.AreSame(assemblyTest, typeTest.Parent);
            Assert.AreEqual(TestKinds.Fixture, typeTest.Kind);
            Assert.AreEqual(CodeReference.CreateFromType(typeof(SimpleTest)), typeTest.CodeElement.CodeReference);
            Assert.AreEqual(typeof(SimpleTest), ((ITypeInfo)typeTest.CodeElement).Resolve(true));
            Assert.AreEqual("SimpleTest", typeTest.Name);
            Assert.Count(2, typeTest.Children);

            Test passTest = GetDescendantByName(typeTest, "Pass");

            Assert.IsNotNull(passTest, "Could not find the Pass test.");
            Assert.AreSame(typeTest, passTest.Parent);
            Assert.AreEqual(TestKinds.Test, passTest.Kind);
            Assert.AreEqual(CodeReference.CreateFromMember(typeof(SimpleTest).GetMethod("Pass")), passTest.CodeElement.CodeReference);
            Assert.AreEqual(typeof(SimpleTest).GetMethod("Pass"), ((IMethodInfo)passTest.CodeElement).Resolve(true));
            Assert.AreEqual("Pass", passTest.Name);

            Test failTest = GetDescendantByName(typeTest, "Fail");

            Assert.IsNotNull(failTest, "Could not find the Fail test.");
            Assert.AreSame(typeTest, failTest.Parent);
            Assert.AreEqual(TestKinds.Test, failTest.Kind);
            Assert.AreEqual(CodeReference.CreateFromMember(typeof(SimpleTest).GetMethod("Fail")), failTest.CodeElement.CodeReference);
            Assert.AreEqual(typeof(SimpleTest).GetMethod("Fail"), ((IMethodInfo)failTest.CodeElement).Resolve(true));
            Assert.AreEqual("Fail", failTest.Name);
        }
Esempio n. 3
0
        public void GetVersionNumber_WhenAssemblyIsProvided_ReturnsFileVersionWhenAvailableOrAssemblyVersionOtherwise()
        {
            var assembly = typeof(VersionPolicy).Assembly;

            var version = VersionPolicy.GetVersionNumber(typeof(VersionPolicy).Assembly);

            var attribs = (AssemblyFileVersionAttribute[])assembly.GetCustomAttributes(typeof(AssemblyFileVersionAttribute), false);

            if (attribs.Length != 0)
            {
                Assert.AreEqual(version.ToString(), attribs[0].Version);
            }
            else
            {
                Assert.AreEqual(version, assembly.GetName().Version);
            }
        }
Esempio n. 4
0
 public void GetVersionNumber_WhenAssemblyIsNull_Throws()
 {
     Assert.Throws <ArgumentNullException>(() => VersionPolicy.GetVersionNumber(null));
 }