public void SaveAssembly_Saves_Assembly()
        {
            var    module   = new Module(GetType().Assembly.Location);
            string fileName = Path.GetFileName(module.AssemblyLocation);

            using (var testDirectory = new TestDirectory())
            {
                testDirectory.SaveAssembly(module);
                Assert.IsTrue(File.Exists(Path.Combine(testDirectory.FullName, fileName)));
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// A helper method that copies the test folder, and saves the mutated
        /// assembly under test into it before returning an instance of
        /// <see cref="MutantMetaData" />.
        /// </summary>
        /// <param name="method">
        /// A <see cref="MethodDefinition" /> for the method on which mutation
        /// testing is to be carried out.
        /// </param>
        /// <param name="module">
        /// A <see cref="Module" /> representing the main module of the
        /// containing assembly.
        /// </param>
        /// <param name="description">
        /// A description of the mutation that has been applied.
        /// </param>
        /// <param name="index">
        /// The index of the (first) IL instruction at which the mutation was
        /// applied.
        /// </param>
        /// <returns></returns>
        protected MutantMetaData DoYield(MethodDefinition method, Module module, string description, int index)
        {
            var toCopy = new List <string>()
            {
                method.DeclaringType.Module.ToString()
            };
            var testDirectory = new TestDirectory(Path.GetDirectoryName(module.AssemblyLocation), toCopy);

            testDirectory.SaveAssembly(module);
            return(new MutantMetaData(
                       module,
                       description,
                       method,
                       index,
                       testDirectory
                       ));
        }
        public void SaveAssembly_Logs_Save()
        {
            var    module   = new Module(GetType().Assembly.Location);
            string fileName = Path.GetFileName(module.AssemblyLocation);

            string path;

            using (var testDirectory = new TestDirectory())
            {
                testDirectory.SaveAssembly(module);
                path = testDirectory.FullName;
            }

            string expectedMessage = string.Format("DEBUG|Writing assembly \"{0}\" to \"{1}\".|", fileName, path);

            AssertLogContains(expectedMessage);
        }
        public void SaveAssembly_Logs_Save()
        {
            var module = new Module(GetType().Assembly.Location);
            string fileName = Path.GetFileName(module.AssemblyLocation);

            string path;
            using (var testDirectory = new TestDirectory())
            {
                testDirectory.SaveAssembly(module);
                path = testDirectory.FullName;
            }

            string expectedMessage = string.Format("DEBUG|Writing assembly \"{0}\" to \"{1}\".|", fileName, path);
            AssertLogContains(expectedMessage);
        }
Exemplo n.º 5
0
        public void SaveAssembly_Saves_Assembly()
		{
		    var module = new Module(GetType().Assembly.Location);
			string fileName = Path.GetFileName(module.AssemblyLocation);
			
			using (var testDirectory = new TestDirectory())
			{
				testDirectory.SaveAssembly(module);
				Assert.IsTrue(File.Exists(Path.Combine(testDirectory.FullName, fileName)));
			}
		}
Exemplo n.º 6
0
        /// <summary>
        /// Runs the tests specified from the test assembly, found within the
        /// test directory identified in the provided
        /// <see cref="MutantMetaData" /> instance.
        /// <remarks>
        /// This method won't be called
        /// from a user's testing code, it is called internally by
        /// NinjaTurtles, and is only exposed publicly to allow for a new
        /// implementation to be provided as an extension to NinjaTurtles.
        /// </remarks>
        /// </summary>
        /// <param name="testDirectory">
        /// The <see cref="TestDirectory" /> containing the test image.
        /// </param>
        /// <param name="testAssemblyLocation">
        ///   The file name (with or without path) of the unit test assembly.
        /// </param>
        /// <param name="testsToRun">
        ///   A list of qualified unit test names.
        /// </param>
        /// <returns>
        /// A <see cref="Process" /> instance to run the unit test runner.
        /// </returns>
        public override Process GetRunnerProcess(TestDirectory testDirectory, string testAssemblyLocation, IEnumerable<string> testsToRun)
        {
            string originalTestAssemblyLocation = testAssemblyLocation;
            testAssemblyLocation = Path.Combine(testDirectory.FullName, Path.GetFileName(testAssemblyLocation));

            // HACKTAG: In the absence of a simple way to limit the tests
            // xUnit runs, we inject TraitAttributes to specify this.
            var testModule = new Module(testAssemblyLocation);
            var xUnitModule =
                AssemblyDefinition.ReadAssembly(Path.Combine(Path.GetDirectoryName(testAssemblyLocation), "xunit.dll"));
            var traitConstructor =
                testModule.Definition.Import(
                    xUnitModule.MainModule
                        .Types.Single(t => t.Name == "TraitAttribute")
                        .Methods.Single(m => m.Name == Methods.CONSTRUCTOR));
            var customAttribute = new CustomAttribute(traitConstructor);
            customAttribute.ConstructorArguments.Add(
                new CustomAttributeArgument(
                    testModule.Definition.TypeSystem.String, "NinjaTurtles"));
            customAttribute.ConstructorArguments.Add(
                new CustomAttributeArgument(
                    testModule.Definition.TypeSystem.String, "run"));

            foreach (var module in testModule.Definition.Types)
            {
                foreach (var method in module.Methods)
                {
                    string qualifiedMethodName = module.FullName + "." + method.Name;
                    if (testsToRun.Contains(qualifiedMethodName))
                    {
                        method.CustomAttributes.Add(customAttribute);
                    }
                }
            }
            testDirectory.SaveAssembly(testModule);

            string arguments = string.Format("\"{0}\" {{0}}noshadow {{0}}trait \"NinjaTurtles=run\"",
                     testAssemblyLocation);

            var searchPath = new List<string>();

            AddSearchPathTermsForxUnitVersion(testAssemblyLocation, originalTestAssemblyLocation, searchPath);

            return ConsoleProcessFactory.CreateProcess("xunit.console.clr4.exe", arguments, searchPath);
        }
Exemplo n.º 7
0
 /// <summary>
 /// A helper method that copies the test folder, and saves the mutated
 /// assembly under test into it before returning an instance of
 /// <see cref="MutantMetaData" />.
 /// </summary>
 /// <param name="method">
 /// A <see cref="MethodDefinition" /> for the method on which mutation
 /// testing is to be carried out.
 /// </param>
 /// <param name="module">
 /// A <see cref="Module" /> representing the main module of the
 /// containing assembly.
 /// </param>
 /// <param name="description">
 /// A description of the mutation that has been applied.
 /// </param>
 /// <param name="index">
 /// The index of the (first) IL instruction at which the mutation was
 /// applied.
 /// </param>
 /// <returns></returns>
 protected MutantMetaData DoYield(MethodDefinition method, Module module, string description, int index)
 {
     var testDirectory = new TestDirectory(Path.GetDirectoryName(module.AssemblyLocation));
     testDirectory.SaveAssembly(module);
     return new MutantMetaData(
         module,
         description,
         method,
         index,
         testDirectory
     );
 }