public void DoMutate_Returns_Correct_Sequences()
        {
            var module = new Module(Assembly.GetExecutingAssembly().Location);
            module.LoadDebugInformation();
            var method = module.Definition
                .Types.Single(t => t.Name == "VariableReadClassUnderTest")
                .Methods.Single(t => t.Name == "AddAndDouble");

            var mutatedInstruction = method.Body.Instructions.First(i => i.OpCode == OpCodes.Ldarg_1);
            string hexPrefix = string.Format("{0:x4}: ", mutatedInstruction.Offset);

            var mutator = new VariableReadTurtle();
            IList<MutantMetaData> mutations = mutator
                .Mutate(method, module, method.Body.Instructions.Select(i => i.Offset).ToArray()).ToList();

            // V2 is only read for the return statement; this case is excluded in the code.
            Assert.AreEqual(9, mutations.Count);
            StringAssert.EndsWith(hexPrefix + "read substitution Int32.a => Int32.b", mutations[0].Description);
            StringAssert.EndsWith("read substitution Int32.a => Int32.total", mutations[1].Description);
            StringAssert.EndsWith("read substitution Int32.a => Int32.CS$1$0000", mutations[2].Description);
            StringAssert.EndsWith("read substitution Int32.b => Int32.a", mutations[3].Description);
            StringAssert.EndsWith("read substitution Int32.b => Int32.total", mutations[4].Description);
            StringAssert.EndsWith("read substitution Int32.b => Int32.CS$1$0000", mutations[5].Description);
            StringAssert.EndsWith("read substitution Int32.total => Int32.a", mutations[6].Description);
            StringAssert.EndsWith("read substitution Int32.total => Int32.b", mutations[7].Description);
            StringAssert.EndsWith("read substitution Int32.total => Int32.CS$1$0000", mutations[8].Description);
        }
        public void CreateMutant_Returns_Correct_Sequences()
        {
            var module = new Module(Assembly.GetExecutingAssembly().Location);
            module.LoadDebugInformation();
            var method = module.Definition
                .Types.Single(t => t.Name == "SequencePointDeletionClassUnderTest")
                .Methods.Single(t => t.Name == "SimpleMethod");

            var mutator = new SequencePointDeletionTurtle();
            IList<MutantMetaData> mutations = mutator
                .Mutate(method, module, method.Body.Instructions.Select(i => i.Offset).ToArray()).ToList();

            Assert.AreEqual(3, mutations.Count);
            StringAssert.EndsWith("deleting Ldarg, Stloc", mutations[0].Description);
            StringAssert.EndsWith("deleting Ldloc, Ldarg, Ldarg, Mul, Add, Stloc", mutations[1].Description);
            StringAssert.EndsWith("deleting Ldloc, Ldarg, Ldarg, Mul, Ldarg, Mul, Add, Stloc", mutations[2].Description);
        }
        public void DoMutate_Returns_Correct_Sequences_With_Fields()
        {
            var module = new Module(Assembly.GetExecutingAssembly().Location);
            module.LoadDebugInformation();
            var method = module.Definition
                .Types.Single(t => t.Name == "VariableWriteClassUnderTest")
                .Methods.Single(t => t.Name == "AddWithPointlessNonsenseViaFields");

            var mutator = new VariableWriteTurtle();
            IList<MutantMetaData> mutations = mutator
                .Mutate(method, module, method.Body.Instructions.Select(i => i.Offset).ToArray()).ToList();

            Assert.AreEqual(2, mutations.Count);
            StringAssert.EndsWith("write substitution Int32._pointlessA => Int32.CS$1$0000", mutations[0].Description);
            StringAssert.EndsWith("write substitution Int32._pointlessB => Int32.CS$1$0000", mutations[1].Description);
        }
        public void DoMutate_Returns_No_Results_As_Appropriate()
        {
            var module = new Module(Assembly.GetExecutingAssembly().Location);
            module.LoadDebugInformation();
            var method = module.Definition
                .Types.Single(t => t.Name == "VariableWriteClassUnderTest")
                .Methods.Single(t => t.Name == "AddWithoutPointlessNonsense");

            var mutator = new VariableWriteTurtle();
            IList<MutantMetaData> mutations = mutator
                .Mutate(method, module, method.Body.Instructions.Select(i => i.Offset).ToArray()).ToList();

            Assert.AreEqual(0, mutations.Count);
        }
        public void DoMutate_Skips_Writes_In_Dispose()
        {
            var assembly = CreateTestAssembly();

            string tempAssemblyFileName = GetTempAssemblyFileName();
            assembly.Write(tempAssemblyFileName);
            var module = new Module(tempAssemblyFileName);
            module.LoadDebugInformation();

            var method = module.Definition
                .Types.Single(t => t.Name == "TestClass")
                .Methods.Single(t => t.Name == "TestMethod");

            var mutator = new VariableWriteTurtle();
            IList<MutantMetaData> mutations = mutator
                .Mutate(method, module, method.Body.Instructions.Select(i => i.Offset).ToArray()).ToList();

            Assert.AreEqual(1, mutations.Count);
            string expectedMessage = string.Format(
                "{0:x4}: write substitution Int32. => Int32.",
                _mutatedInstruction.Offset);
            StringAssert.EndsWith(expectedMessage, mutations[0].Description);
        }