示例#1
0
        public void Test1()
        {
            var assemblyFile = new TestAssemblyFile();
            var assembly     = AssemblyDefinition.ReadAssembly(assemblyFile.FilePath);

            var dinnersController = assembly.MainModule.Types.Single(t => t.Name == "DinnersController");

            var createMethod = dinnersController.Methods.Single(m => m.Name == "Create" && m.Parameters.Count == 1);


            var instr = createMethod.Body.Instructions.Single(i =>
            {
                if (i.OpCode == OpCodes.Call)
                {
                    var method = ((MethodReference)i.Operand);
                    if (method.DeclaringType.FullName == "System.Web.Mvc.Controller" &&
                        method.Name == "View")
                    //  && method.Parameters.Count == 0)
                    {
                        return(true);
                    }
                }
                return(false);
            });
            var mutator = new ReplaceViewWithRedirectToAction();
            var mutationSessionChoices = new MutationSessionChoices
            {
                SelectedOperators = new[] { mutator },
                Assemblies        = new[] { assembly },
                SelectedTypes     = assembly.MainModule.Types
            };
            MutantsContainer mutantsContainer = new MutantsContainer();
            var executedOperator = mutantsContainer.GenerateMutantsForOperators(mutationSessionChoices).Single();

            executedOperator.Mutants.Single(mut =>
            {
                var assembly2 = mut.MutationResult.MutatedAssemblies.Single();

                var dinnersController2 = assembly2.MainModule.Types.Single(t => t.Name == "DinnersController");

                var createMethod2 = dinnersController2.Methods.Single(m => m.Name == "Create" && m.Parameters.Count == 1);

                var instr3 = createMethod2.Body.Instructions.Where(i =>
                {
                    if (i.OpCode == OpCodes.Call)
                    {
                        var method = ((MethodReference)i.Operand);
                        if (method.DeclaringType.FullName == "System.Web.Mvc.Controller" &&
                            method.Name == "RedirectToAction")
                        //  && method.Parameters.Count == 0)
                        {
                            return(true);
                        }
                    }
                    return(false);
                });

                return(instr3.Count() == (2));
            });
        }
示例#2
0
        public void Test1()
        {
            var assemblyFile = new TestAssemblyFile();
            var assembly     = AssemblyDefinition.ReadAssembly(assemblyFile.FilePath);

            var mutator = new SwapActionNames();

            //   mutator.Mutate(assembly.MainModule, assembly.MainModule.Types);

            assembly.Write(assemblyFile.FilePath);

            var assembly2 = AssemblyDefinition.ReadAssembly(assemblyFile.FilePath);
        }
        public void Test1()
        {

            var assemblyFile = new TestAssemblyFile();
            var assembly = AssemblyDefinition.ReadAssembly(assemblyFile.FilePath);

     
            var mutator = new ChangeRoute();

          //  mutator.Mutate(assembly.MainModule, assembly.MainModule.Types);

            assembly.Write(assemblyFile.FilePath);

            var assembly2 = AssemblyDefinition.ReadAssembly(assemblyFile.FilePath);


                

        }
        public void Test1()
        {
            var assemblyFile = new TestAssemblyFile();
            var assembly = AssemblyDefinition.ReadAssembly(assemblyFile.FilePath);

            var dinnersController = assembly.MainModule.Types.Single(t => t.Name == "DinnersController");

            var createMethod = dinnersController.Methods.Single(m => m.Name == "Create" && m.Parameters.Count == 1);


            var instr = createMethod.Body.Instructions.Single(i =>
            {
                if (i.OpCode == OpCodes.Call)
                {
                    var method = ((MethodReference)i.Operand);
                    if (method.DeclaringType.FullName == "System.Web.Mvc.Controller"
                        && method.Name == "View")
                    //  && method.Parameters.Count == 0)
                    {
                        return true;
                    }
                }
                return false;
            });
            var mutator = new ReplaceViewWithRedirectToAction();
            var mutationSessionChoices = new MutationSessionChoices
            {
                SelectedOperators = new[] { mutator },
                Assemblies = new[] { assembly },
                SelectedTypes = assembly.MainModule.Types 
            };
            MutantsContainer mutantsContainer = new MutantsContainer();
            var executedOperator = mutantsContainer.GenerateMutantsForOperators(mutationSessionChoices).Single();

            executedOperator.Mutants.Single(mut =>
            {
                var assembly2 = mut.MutationResult.MutatedAssemblies.Single();

                var dinnersController2 = assembly2.MainModule.Types.Single(t => t.Name == "DinnersController");

                var createMethod2 = dinnersController2.Methods.Single(m => m.Name == "Create" && m.Parameters.Count == 1);

                var instr3 = createMethod2.Body.Instructions.Where(i =>
                {
                    if (i.OpCode == OpCodes.Call)
                    {
                        var method = ((MethodReference)i.Operand);
                        if (method.DeclaringType.FullName == "System.Web.Mvc.Controller"
                            && method.Name == "RedirectToAction")
                        //  && method.Parameters.Count == 0)
                        {
                            return true;
                        }
                    }
                    return false;
                });

                return instr3.Count()==(2);
            });

     



                

            
           
        }