public void ShouldMutateBlockStatements()
        {
            var options = new StrykerOptions
            {
                MutationLevel    = MutationLevel.Complete,
                OptimizationMode = OptimizationModes.CoverageBasedTest,
            };

            _target = new CsharpMutantOrchestrator(options: options);

            string source   = @"private void Move()
			{
				;
			}"            ;
            string expected = @"private void Move()
    {if(StrykerNamespace.MutantControl.IsActive(0)){}else		    {
                    ;
                }}"    ;

            ShouldMutateSourceInClassToExpected(source, expected);

            source   = @"private int Move()
			{
				;
			}"            ;
            expected = @"private int Move()
    {if(StrykerNamespace.MutantControl.IsActive(1)){}else		    {
                    ;
                } return default(int);}"    ;

            ShouldMutateSourceInClassToExpected(source, expected);
        }
        public void ShouldRollBackFailedConstructor()
        {
            var source = @"class Test {
static TestClass()=> Value-='a';}";

            var orchestrator = new CsharpMutantOrchestrator(options: new StrykerOptions
            {
                OptimizationMode = OptimizationModes.CoverageBasedTest,
                MutationLevel    = MutationLevel.Complete
            });
            var actualNode = orchestrator.Mutate(CSharpSyntaxTree.ParseText(source).GetRoot());

            var node = actualNode.DescendantNodes().First(t => t is BlockSyntax);

            // Remove marker
            var restored = MutantPlacer.RemoveMutant(node);

            actualNode = actualNode.ReplaceNode(node, restored);

            // remove mutation
            node       = actualNode.DescendantNodes().First(t => t.IsKind(SyntaxKind.IfStatement));
            restored   = MutantPlacer.RemoveMutant(node);
            actualNode = actualNode.ReplaceNode(node, restored);

            // remove expression to body conversion
            node       = actualNode.DescendantNodes().First(t => t is ConstructorDeclarationSyntax);
            restored   = MutantPlacer.RemoveMutant(node);
            actualNode = actualNode.ReplaceNode(node, restored);

            var expectedNode = CSharpSyntaxTree.ParseText(source.Replace("StrykerNamespace", CodeInjection.HelperNamespace)).GetRoot();

            expectedNode.ShouldNotContainErrors();
            actualNode.ShouldBeSemantically(expectedNode);
            actualNode.ShouldNotContainErrors();
        }
Пример #3
0
        public MutantOrchestratorTestsBase()
        {
            var options = new StrykerOptions
            {
                MutationLevel    = MutationLevel.Complete,
                OptimizationMode = OptimizationModes.CoverageBasedTest,
            };

            _target = new CsharpMutantOrchestrator(options: options);
        }
 public MemberDeclarationOrchestrator(CsharpMutantOrchestrator mutantOrchestrator) : base(mutantOrchestrator)
 {
 }
 public StatementSpecificOrchestrator(CsharpMutantOrchestrator mutantOrchestrator) : base(mutantOrchestrator)
 {
 }
 public AccessorSyntaxOrchestrator(CsharpMutantOrchestrator mutantOrchestrator) : base(mutantOrchestrator)
 {
 }
 public ExpressionSpecificOrchestrator(CsharpMutantOrchestrator mutantOrchestrator) : base(mutantOrchestrator)
 {
 }
 public MutantOrchestratorTests()
 {
     _target = new CsharpMutantOrchestrator(options: new StrykerOptions(mutationLevel: MutationLevel.Complete.ToString()));
 }
Пример #9
0
 public SyntaxNodeOrchestrator(CsharpMutantOrchestrator mutantOrchestrator) : base(mutantOrchestrator)
 {
 }
Пример #10
0
 public StaticFieldDeclarationOrchestrator(CsharpMutantOrchestrator mutantOrchestrator) : base(mutantOrchestrator)
 {
 }
Пример #11
0
 public BlockOrchestrator(CsharpMutantOrchestrator mutantOrchestrator) : base(mutantOrchestrator)
 {
 }
Пример #12
0
 public ConstLocalDeclarationOrchestrator(CsharpMutantOrchestrator mutantOrchestrator) : base(mutantOrchestrator)
 {
 }
 public PropertyDeclarationOrchestrator(CsharpMutantOrchestrator mutantOrchestrator) : base(mutantOrchestrator)
 {
 }
Пример #14
0
 public StaticConstructorOrchestrator(CsharpMutantOrchestrator mutantOrchestrator) : base(mutantOrchestrator)
 {
 }
Пример #15
0
 public AssignmentStatementOrchestrator(CsharpMutantOrchestrator mutantOrchestrator) : base(mutantOrchestrator)
 {
 }
Пример #16
0
 public PostfixUnaryExpressionOrchestrator(CsharpMutantOrchestrator mutantOrchestrator) : base(mutantOrchestrator)
 {
 }
Пример #17
0
 public ForStatementOrchestrator(CsharpMutantOrchestrator mutantOrchestrator) : base(mutantOrchestrator)
 {
 }
Пример #18
0
 protected BlockScopeOrchestrator(CsharpMutantOrchestrator mutantOrchestrator) : base(mutantOrchestrator)
 {
 }
 public ArrayInitializerOrchestrator(CsharpMutantOrchestrator mutantOrchestrator) : base(mutantOrchestrator)
 {
 }
Пример #20
0
 protected NodeSpecificOrchestrator(CsharpMutantOrchestrator mutantOrchestrator)
 {
     MutantOrchestrator = mutantOrchestrator;
 }
 public BaseMethodDeclarationOrchestrator(CsharpMutantOrchestrator mutantOrchestrator) : base(mutantOrchestrator)
 {
 }
Пример #22
0
        public void ShouldRollbackIssueInExpression()
        {
            var syntaxTree = CSharpSyntaxTree.ParseText(@"
    using System;
    using System.Collections.Generic;
    using System.Linq;

    namespace ExampleProject
    {
       public class Test
       {
           public void SomeLinq()
           {
               var list = new List<List<double>>();
               int[] listProjected = list.Select(l => l.Count()).ToArray();
           }
       }
    }");
            var mutator    = new CsharpMutantOrchestrator(options: new StrykerOptions(mutationLevel: MutationLevel.Complete.ToString(), devMode: true));
            var helpers    = new List <SyntaxTree>();

            foreach (var(name, code) in CodeInjection.MutantHelpers)
            {
                helpers.Add(CSharpSyntaxTree.ParseText(code, path: name, encoding: Encoding.UTF32));
            }

            var mutant = mutator.Mutate(syntaxTree.GetRoot());

            helpers.Add(mutant.SyntaxTree);
            var references = new List <PortableExecutableReference>()
            {
                MetadataReference.CreateFromFile(typeof(object).Assembly.Location),
                MetadataReference.CreateFromFile(typeof(List <string>).Assembly.Location),
                MetadataReference.CreateFromFile(typeof(Enumerable).Assembly.Location),
                MetadataReference.CreateFromFile(typeof(PipeStream).Assembly.Location),
            };

            Assembly.GetEntryAssembly().GetReferencedAssemblies().ToList().ForEach(a => references.Add(MetadataReference.CreateFromFile(Assembly.Load(a).Location)));

            var input = new MutationTestInput()
            {
                ProjectInfo = new ProjectInfo()
                {
                    ProjectUnderTestAnalyzerResult = TestHelper.SetupProjectAnalyzerResult(properties: new Dictionary <string, string>()
                    {
                        { "TargetDir", "" },
                        { "AssemblyName", "AssemblyName" },
                        { "TargetFileName", "TargetFileName.dll" },
                        { "SignAssembly", "true" },
                        { "AssemblyOriginatorKeyFile", Path.GetFullPath(Path.Combine("TestResources", "StrongNameKeyFile.snk")) }
                    },
                                                                                           projectFilePath: "TestResources").Object,
                    TestProjectAnalyzerResults = new List <IAnalyzerResult> {
                        TestHelper.SetupProjectAnalyzerResult(properties: new Dictionary <string, string>()
                        {
                            { "AssemblyName", "AssemblyName" },
                        }).Object
                    }
                },
                AssemblyReferences = references
            };

            var rollbackProcess = new RollbackProcess();

            var target = new CompilingProcess(input, rollbackProcess);

            using (var ms = new MemoryStream())
            {
                var result = target.Compile(helpers, ms, null, true);
                result.RollbackResult.RollbackedIds.Count().ShouldBe(1);
            }
        }